Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

Commit 2c2ec5b

Browse files
ajozefiakChrisRackauckas
authored andcommitted
tests/implementation for same number of bpc, still needs 3rd dimension handling
1 parent 0087375 commit 2c2ec5b

File tree

2 files changed

+128
-40
lines changed

2 files changed

+128
-40
lines changed

src/derivative_operators/derivative_operator_functions.jl

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -413,54 +413,68 @@ function LinearAlgebra.mul!(x_temp::AbstractArray{T,3}, A::AbstractDiffEqComposi
413413

414414
# convolve boundary and interior points near boundary
415415
# partition operator indices along axis of differentiation
416-
if pad[1] > 0 || pad[2] > 0
416+
if pad[1] > 0 || pad[2] > 0 || pad[3] > 0
417417
ops_1 = Int64[]
418418
ops_1_max_bpc_idx = [0]
419419
ops_2 = Int64[]
420420
ops_2_max_bpc_idx = [0]
421+
ops_3 = Int64[]
422+
ops_3_max_bpc_idx = [0]
423+
421424
for i in 1:length(opsA)
422425
L = opsA[i]
423426
if typeof(L).parameters[2] == 1
424427
push!(ops_1,i)
425428
if L.boundary_point_count == pad[1]
426429
ops_1_max_bpc_idx[1] = i
427430
end
428-
else
431+
elseif typeof(L).parameters[2] == 2
429432
push!(ops_2,i)
430433
if L.boundary_point_count == pad[2]
431434
ops_2_max_bpc_idx[1]= i
432435
end
436+
else
437+
push!(ops_3,i)
438+
if L.boundary_point_count == pad[3]
439+
ops_3_max_bpc_idx[1]= i
440+
end
433441
end
434442
end
435443

436444
# need offsets since some axis may have ghost nodes and some may not
437445
offset_x = 0
438446
offset_y = 0
447+
offset_z = 0
439448

440-
if length(ops_2) > 0
449+
if length(ops_1) > 0
441450
offset_x = 1
442451
end
443-
if length(ops_1) > 0
452+
if length(ops_2) > 0
444453
offset_y = 1
445454
end
455+
if length(ops_3) > 0
456+
offset_z = 1
457+
end
446458

447459
# convolve boundaries and unaccounted for interior in axis 1
448460
if length(ops_1) > 0
449461
for i in 1:size(x_temp)[2]
450-
convolve_BC_left!(view(x_temp,:,i), view(M,:,i+offset_x), opsA[ops_1_max_bpc_idx...])
451-
convolve_BC_right!(view(x_temp,:,i), view(M,:,i+offset_x), opsA[ops_1_max_bpc_idx...])
452-
if i <= pad[2] || i > size(x_temp)[2]-pad[2]
453-
convolve_interior!(view(x_temp,:,i), view(M,:,i+offset_x), opsA[ops_1_max_bpc_idx...])
454-
end
462+
for j in 1:size(x_temp)[3]
463+
convolve_BC_left!(view(x_temp,:,i,j), view(M,:,i+offset_y,j+offset_z), opsA[ops_1_max_bpc_idx...])
464+
convolve_BC_right!(view(x_temp,:,i,j), view(M,:,i+offset_y,j+offset_z), opsA[ops_1_max_bpc_idx...])
465+
if i <= pad[2] || i > size(x_temp)[2]-pad[2] || j <= pad[3] || j > size(x_temp)[3]-pad[3]
466+
convolve_interior!(view(x_temp,:,i,j), view(M,:,i+offset_y,j+offset_z), opsA[ops_1_max_bpc_idx...])
467+
end
455468

456-
for Lidx in ops_1
457-
if Lidx != ops_1_max_bpc_idx[1]
458-
convolve_BC_left!(view(x_temp,:,i), view(M,:,i+offset_x), opsA[Lidx], overwrite = false)
459-
convolve_BC_right!(view(x_temp,:,i), view(M,:,i+offset_x), opsA[Lidx], overwrite = false)
460-
if i <= pad[2] || i > size(x_temp)[2]-pad[2]
461-
convolve_interior!(view(x_temp,:,i), view(M,:,i+offset_x), opsA[Lidx], overwrite = false)
462-
elseif pad[1] - opsA[Lidx].boundary_point_count > 0
463-
convolve_interior_add_range!(view(x_temp,:,i), view(M,:,i+offset_x), opsA[Lidx], pad[1] - opsA[Lidx].boundary_point_count)
469+
for Lidx in ops_1
470+
if Lidx != ops_1_max_bpc_idx[1]
471+
convolve_BC_left!(view(x_temp,:,i,j), view(M,:,i+offset_y,j+offset_z), opsA[Lidx], overwrite = false)
472+
convolve_BC_right!(view(x_temp,:,i,j), view(M,:,i+offset_y,j+offset_z), opsA[Lidx], overwrite = false)
473+
if i <= pad[2] || i > size(x_temp)[2]-pad[2] || j <= pad[3] || j > size(x_temp)[3]-pad[3]
474+
convolve_interior!(view(x_temp,:,i,j), view(M,:,i+offset_y,j+offset_z), opsA[Lidx], overwrite = false)
475+
elseif pad[1] - opsA[Lidx].boundary_point_count > 0 # TODO 475-477
476+
convolve_interior_add_range!(view(x_temp,:,i), view(M,:,i+offset_x), opsA[Lidx], pad[1] - opsA[Lidx].boundary_point_count)
477+
end
464478
end
465479
end
466480
end
@@ -469,30 +483,32 @@ function LinearAlgebra.mul!(x_temp::AbstractArray{T,3}, A::AbstractDiffEqComposi
469483
# convolve boundaries and unaccounted for interior in axis 2
470484
if length(ops_2) > 0
471485
for i in 1:size(x_temp)[1]
472-
# in the case of no axis 1 operators, we need to overwrite x_temp
473-
if length(ops_1) == 0
474-
convolve_BC_left!(view(x_temp,i,:), view(M,i+offset_y,:), opsA[ops_2_max_bpc_idx...])
475-
convolve_BC_right!(view(x_temp,i,:), view(M,i+offset_y,:), opsA[ops_2_max_bpc_idx...])
476-
if i <= pad[1] || i > size(x_temp)[1]-pad[1]
477-
convolve_interior!(view(x_temp,i,:), view(M,i+offset_y,:), opsA[ops_2_max_bpc_idx...])
478-
end
486+
for j in 1:size(x_temp)[3]
487+
# in the case of no axis 1 operators, we need to overwrite x_temp
488+
if length(ops_1) == 0
489+
convolve_BC_left!(view(x_temp,i,:,j), view(M,i+offset_x,:,j+offset_z), opsA[ops_2_max_bpc_idx...])
490+
convolve_BC_right!(view(x_temp,i,:,j), view(M,i+offset_x,:,j+offset_z), opsA[ops_2_max_bpc_idx...])
491+
if i <= pad[1] || i > size(x_temp)[1]-pad[1] #TODO 491-493
492+
convolve_interior!(view(x_temp,i,:), view(M,i+offset_y,:), opsA[ops_2_max_bpc_idx...])
493+
end
479494

480-
else
481-
convolve_BC_left!(view(x_temp,i,:), view(M,i+offset_y,:), opsA[ops_2_max_bpc_idx...], overwrite = false)
482-
convolve_BC_right!(view(x_temp,i,:), view(M,i+offset_y,:), opsA[ops_2_max_bpc_idx...], overwrite = false)
483-
if i <= pad[1] || i > size(x_temp)[1]-pad[1]
484-
convolve_interior!(view(x_temp,i,:), view(M,i+offset_y,:), opsA[ops_2_max_bpc_idx...], overwrite = false)
485-
end
495+
else
496+
convolve_BC_left!(view(x_temp,i,:,j), view(M,i+offset_x,:,j+offset_z), opsA[ops_2_max_bpc_idx...], overwrite = false)
497+
convolve_BC_right!(view(x_temp,i,:,j), view(M,i+offset_x,:,j+offset_z), opsA[ops_2_max_bpc_idx...], overwrite = false)
498+
if i <= pad[1] || i > size(x_temp)[1]-pad[1] || j <= pad[3] || j > size(x_temp)[3]-pad[3]
499+
convolve_interior!(view(x_temp,i,:,j), view(M,i+offset_y,:,j+offset_z), opsA[ops_2_max_bpc_idx...], overwrite = false)
500+
end
486501

487-
end
488-
for Lidx in ops_2
489-
if Lidx != ops_2_max_bpc_idx[1]
490-
convolve_BC_left!(view(x_temp,i,:), view(M,i+offset_y,:), opsA[Lidx], overwrite = false)
491-
convolve_BC_right!(view(x_temp,i,:), view(M,i+offset_y,:), opsA[Lidx], overwrite = false)
492-
if i <= pad[1] || i > size(x_temp)[1]-pad[1]
493-
convolve_interior!(view(x_temp,i,:), view(M,i+offset_y,:), opsA[Lidx], overwrite = false)
494-
elseif pad[2] - opsA[Lidx].boundary_point_count > 0
495-
convolve_interior_add_range!(view(x_temp,i,:), view(M,i+offset_y,:), opsA[Lidx], pad[2] - opsA[Lidx].boundary_point_count)
502+
end
503+
for Lidx in ops_2
504+
if Lidx != ops_2_max_bpc_idx[1]
505+
convolve_BC_left!(view(x_temp,i,:,j), view(M,i+offset_x,:,j+offset_z), opsA[Lidx], overwrite = false)
506+
convolve_BC_right!(view(x_temp,i,:,j), view(M,i+offset_x,:,j+offset_z), opsA[Lidx], overwrite = false)
507+
if i <= pad[1] || i > size(x_temp)[1]-pad[1] || j <= pad[3] || j > size(x_temp)[3]-pad[3]
508+
convolve_interior!(view(x_temp,i,:,j), view(M,i+offset_x,:,j+offset_z), opsA[Lidx], overwrite = false)
509+
elseif pad[2] - opsA[Lidx].boundary_point_count > 0 #TODO 509-511
510+
convolve_interior_add_range!(view(x_temp,i,:), view(M,i+offset_y,:), opsA[Lidx], pad[2] - opsA[Lidx].boundary_point_count)
511+
end
496512
end
497513
end
498514
end
@@ -502,7 +518,7 @@ function LinearAlgebra.mul!(x_temp::AbstractArray{T,3}, A::AbstractDiffEqComposi
502518

503519
# Here we compute mul! (additively) for every operator in opsB
504520

505-
operating_dims = zeros(Int64,2)
521+
operating_dims = zeros(Int64,3)
506522
# need to consider all dimensions and operators to determine the truncation
507523
# of M to x_temp
508524
for L in A.ops

test/2D_3D_fast_multiplication.jl

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,3 +712,75 @@ end
712712
@test M_temp ((Lx*M)[1:N,2:N+1,2:N+1] +(Ly*M)[2:N+1,1:N,2:N+1] + (Lxx*M)[1:N,2:N+1,2:N+1] +(Lyy*M)[2:N+1,1:N,2:N+1] + (Lz*M)[2:N+1,2:N+1,1:N] +(Lzz*M)[2:N+1,2:N+1,1:N])
713713

714714
end
715+
716+
@testset "3D Multiplication with identical bpc and dx = dy = dz = 1.0" begin
717+
718+
N = 100
719+
M = zeros(N+2,N+2,N+2)
720+
for i in 1:N+2
721+
for j in 1:N+2
722+
for k in 1:N+2
723+
M[i,j,k] = cos(0.1i)+sin(0.1j) + exp(0.01k)
724+
end
725+
end
726+
end
727+
728+
# Test a single axis, multiple operators: (Lxxx + Lxxxx)*M, dx = dy = dz = 1.0
729+
# Lx3 and Lx4 have the same number of boundary points
730+
Lx3 = CenteredDifference{1}(3,4,1.0,N)
731+
Lx4 = CenteredDifference{1}(4,4,1.0,N)
732+
A = Lx3 + Lx4
733+
734+
M_temp = zeros(N,N+2,N+2)
735+
mul!(M_temp, A, M)
736+
737+
@test M_temp ((Lx3*M)+(Lx4*M))
738+
739+
# Test a single axis, multiple operators: (Lyyy + Lyyyy)*M, dx = dy = dz = 1.0, no coefficient
740+
# Ly3 and Ly4 have the same number of boundary points
741+
Ly3 = CenteredDifference{2}(3,4,1.0,N)
742+
Ly4 = CenteredDifference{2}(4,4,1.0,N)
743+
A = Ly3 + Ly4
744+
745+
M_temp = zeros(N+2,N,N+2)
746+
mul!(M_temp, A, M)
747+
748+
@test M_temp ((Ly3*M)+(Ly4*M))
749+
750+
# Test a single axis, multiple operators: (Lzzz + Lzzzz)*M, dx = dy = dz = 1.0, no coefficient
751+
# Lz3 and Lz4 have the same number of boundary points
752+
Lz3 = CenteredDifference{3}(3,4,1.0,N)
753+
Lz4 = CenteredDifference{3}(4,4,1.0,N)
754+
A = Lz3 + Lz4
755+
756+
M_temp = zeros(N+2,N+2,N)
757+
@test_broken mul!(M_temp, A, M)
758+
759+
@test_broken M_temp ((Lz3*M)+(Lz4*M))
760+
761+
# Test (Lxxxx + Lyyyy)*M, dx = 1.0, no coefficient, two boundary points on each axis
762+
763+
M_temp = zeros(N,N,N+2)
764+
A = Lx4 + Ly4
765+
mul!(M_temp, A, M)
766+
767+
@test M_temp ((Lx4*M)[1:N,2:N+1,:] +(Ly4*M)[2:N+1,1:N,:])
768+
769+
# Test (Lxxx + Lyyy)*M, no coefficient. These operators have non-symmetric interior stencils
770+
A = Lx3 + Ly3
771+
M_temp = zeros(N,N,N+2)
772+
mul!(M_temp, A, M)
773+
774+
@test M_temp ((Lx3*M)[1:N,2:N+1,:] +(Ly3*M)[2:N+1,1:N,:])
775+
776+
# Test multiple operators on both axis: (Lxxx + Lyyy + Lxxxx + Lyyyy)*M, no coefficient
777+
A = Lx3 + Ly3 + Lx4 + Ly4
778+
M_temp = zeros(N,N,N+2)
779+
mul!(M_temp, A, M)
780+
781+
@test M_temp ((Lx3*M)[1:N,2:N+1,:] +(Ly3*M)[2:N+1,1:N,:] + (Lx4*M)[1:N,2:N+1,:] +(Ly4*M)[2:N+1,1:N,:])
782+
783+
# TODO implement/test all combinations of x-z and y-z compositions.
784+
# TODO implement/test combinations of x-y-z compositions
785+
786+
end

0 commit comments

Comments
 (0)