Mercurial > repos > public > sbplib_julia
comparison test/SbpOperators/boundaryops/boundary_operator_test.jl @ 2057:8a2a0d678d6f feature/lazy_tensors/pretty_printing
Merge default
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Tue, 10 Feb 2026 22:41:19 +0100 |
| parents | 471a948cd2b2 |
| children |
comparison
equal
deleted
inserted
replaced
| 1110:c0bff9f6e0fb | 2057:8a2a0d678d6f |
|---|---|
| 1 using Test | 1 using Test |
| 2 | 2 |
| 3 using Sbplib.LazyTensors | 3 using Diffinitive.LazyTensors |
| 4 using Sbplib.SbpOperators | 4 using Diffinitive.SbpOperators |
| 5 using Sbplib.Grids | 5 using Diffinitive.Grids |
| 6 using Sbplib.RegionIndices | 6 using Diffinitive.RegionIndices |
| 7 import Sbplib.SbpOperators.Stencil | 7 import Diffinitive.SbpOperators.Stencil |
| 8 import Sbplib.SbpOperators.BoundaryOperator | 8 import Diffinitive.SbpOperators.BoundaryOperator |
| 9 import Sbplib.SbpOperators.boundary_operator | 9 |
| 10 | 10 |
| 11 @testset "BoundaryOperator" begin | 11 @testset "BoundaryOperator" begin |
| 12 closure_stencil = Stencil(2.,1.,3.; center = 1) | 12 closure_stencil = Stencil(2.,1.,3.; center = 1) |
| 13 g_1D = EquidistantGrid(11, 0.0, 1.0) | 13 g_1D = EquidistantGrid(range(0,1,length=11)) |
| 14 g_2D = EquidistantGrid((11,15), (0.0, 0.0), (1.0,1.0)) | |
| 15 | 14 |
| 16 @testset "Constructors" begin | 15 @testset "Constructors" begin |
| 17 @testset "1D" begin | 16 @test BoundaryOperator(g_1D, closure_stencil, LowerBoundary()) isa LazyTensor{T,0,1} where T |
| 18 op_l = BoundaryOperator{Lower}(closure_stencil,size(g_1D)[1]) | 17 @test BoundaryOperator(g_1D, closure_stencil, UpperBoundary()) isa LazyTensor{T,0,1} where T |
| 19 @test op_l == BoundaryOperator(g_1D,closure_stencil,Lower()) | 18 end |
| 20 @test op_l == boundary_operator(g_1D,closure_stencil,CartesianBoundary{1,Lower}()) | |
| 21 @test op_l isa LazyTensor{T,0,1} where T | |
| 22 | 19 |
| 23 op_r = BoundaryOperator{Upper}(closure_stencil,size(g_1D)[1]) | 20 op_l = BoundaryOperator(g_1D, closure_stencil, LowerBoundary()) |
| 24 @test op_r == BoundaryOperator(g_1D,closure_stencil,Upper()) | 21 op_r = BoundaryOperator(g_1D, closure_stencil, UpperBoundary()) |
| 25 @test op_r == boundary_operator(g_1D,closure_stencil,CartesianBoundary{1,Upper}()) | |
| 26 @test op_r isa LazyTensor{T,0,1} where T | |
| 27 end | |
| 28 | |
| 29 @testset "2D" begin | |
| 30 e_w = boundary_operator(g_2D,closure_stencil,CartesianBoundary{1,Upper}()) | |
| 31 @test e_w isa InflatedTensor | |
| 32 @test e_w isa LazyTensor{T,1,2} where T | |
| 33 end | |
| 34 end | |
| 35 op_l, op_r = boundary_operator.(Ref(g_1D), Ref(closure_stencil), boundary_identifiers(g_1D)) | |
| 36 op_w, op_e, op_s, op_n = boundary_operator.(Ref(g_2D), Ref(closure_stencil), boundary_identifiers(g_2D)) | |
| 37 | 22 |
| 38 @testset "Sizes" begin | 23 @testset "Sizes" begin |
| 39 @testset "1D" begin | 24 @test domain_size(op_l) == (11,) |
| 40 @test domain_size(op_l) == (11,) | 25 @test domain_size(op_r) == (11,) |
| 41 @test domain_size(op_r) == (11,) | |
| 42 | 26 |
| 43 @test range_size(op_l) == () | 27 @test range_size(op_l) == () |
| 44 @test range_size(op_r) == () | 28 @test range_size(op_r) == () |
| 45 end | |
| 46 | |
| 47 @testset "2D" begin | |
| 48 @test domain_size(op_w) == (11,15) | |
| 49 @test domain_size(op_e) == (11,15) | |
| 50 @test domain_size(op_s) == (11,15) | |
| 51 @test domain_size(op_n) == (11,15) | |
| 52 | |
| 53 @test range_size(op_w) == (15,) | |
| 54 @test range_size(op_e) == (15,) | |
| 55 @test range_size(op_s) == (11,) | |
| 56 @test range_size(op_n) == (11,) | |
| 57 end | |
| 58 end | 29 end |
| 59 | 30 |
| 60 @testset "Application" begin | 31 @testset "Application" begin |
| 61 @testset "1D" begin | 32 v = eval_on(g_1D,x->1+x^2) |
| 62 v = evalOn(g_1D,x->1+x^2) | 33 u = fill(3.124) |
| 63 u = fill(3.124) | 34 @test (op_l*v)[] == 2*v[1] + v[2] + 3*v[3] |
| 64 @test (op_l*v)[] == 2*v[1] + v[2] + 3*v[3] | 35 @test (op_r*v)[] == 2*v[end] + v[end-1] + 3*v[end-2] |
| 65 @test (op_r*v)[] == 2*v[end] + v[end-1] + 3*v[end-2] | 36 @test (op_r*v)[1] == 2*v[end] + v[end-1] + 3*v[end-2] |
| 66 @test (op_r*v)[1] == 2*v[end] + v[end-1] + 3*v[end-2] | 37 @test op_l'*u == [2*u[]; u[]; 3*u[]; zeros(8)] |
| 67 @test op_l'*u == [2*u[]; u[]; 3*u[]; zeros(8)] | 38 @test op_r'*u == [zeros(8); 3*u[]; u[]; 2*u[]] |
| 68 @test op_r'*u == [zeros(8); 3*u[]; u[]; 2*u[]] | |
| 69 | 39 |
| 70 v = evalOn(g_1D, x->1. +x*im) | 40 v = eval_on(g_1D, x->1. +x*im) |
| 71 @test (op_l*v)[] isa ComplexF64 | 41 @test (op_l*v)[] isa ComplexF64 |
| 72 | 42 |
| 73 u = fill(1. +im) | 43 u = fill(1. +im) |
| 74 @test (op_l'*u)[1] isa ComplexF64 | 44 @test (op_l'*u)[1] isa ComplexF64 |
| 75 @test (op_l'*u)[5] isa ComplexF64 | 45 @test (op_l'*u)[5] isa ComplexF64 |
| 76 @test (op_l'*u)[11] isa ComplexF64 | 46 @test (op_l'*u)[11] isa ComplexF64 |
| 77 end | |
| 78 | 47 |
| 79 @testset "2D" begin | 48 u = fill(3.124) |
| 80 v = rand(size(g_2D)...) | 49 @test (op_l'*u)[Index(1,Lower)] == 2*u[] |
| 81 u = fill(3.124) | 50 @test (op_l'*u)[Index(2,Lower)] == u[] |
| 82 @test op_w*v ≈ 2*v[1,:] + v[2,:] + 3*v[3,:] rtol = 1e-14 | 51 @test (op_l'*u)[Index(6,Interior)] == 0 |
| 83 @test op_e*v ≈ 2*v[end,:] + v[end-1,:] + 3*v[end-2,:] rtol = 1e-14 | 52 @test (op_l'*u)[Index(10,Upper)] == 0 |
| 84 @test op_s*v ≈ 2*v[:,1] + v[:,2] + 3*v[:,3] rtol = 1e-14 | 53 @test (op_l'*u)[Index(11,Upper)] == 0 |
| 85 @test op_n*v ≈ 2*v[:,end] + v[:,end-1] + 3*v[:,end-2] rtol = 1e-14 | |
| 86 | 54 |
| 87 | 55 @test (op_r'*u)[Index(1,Lower)] == 0 |
| 88 g_x = rand(size(g_2D)[1]) | 56 @test (op_r'*u)[Index(2,Lower)] == 0 |
| 89 g_y = rand(size(g_2D)[2]) | 57 @test (op_r'*u)[Index(6,Interior)] == 0 |
| 90 | 58 @test (op_r'*u)[Index(10,Upper)] == u[] |
| 91 G_w = zeros(Float64, size(g_2D)...) | 59 @test (op_r'*u)[Index(11,Upper)] == 2*u[] |
| 92 G_w[1,:] = 2*g_y | |
| 93 G_w[2,:] = g_y | |
| 94 G_w[3,:] = 3*g_y | |
| 95 | |
| 96 G_e = zeros(Float64, size(g_2D)...) | |
| 97 G_e[end,:] = 2*g_y | |
| 98 G_e[end-1,:] = g_y | |
| 99 G_e[end-2,:] = 3*g_y | |
| 100 | |
| 101 G_s = zeros(Float64, size(g_2D)...) | |
| 102 G_s[:,1] = 2*g_x | |
| 103 G_s[:,2] = g_x | |
| 104 G_s[:,3] = 3*g_x | |
| 105 | |
| 106 G_n = zeros(Float64, size(g_2D)...) | |
| 107 G_n[:,end] = 2*g_x | |
| 108 G_n[:,end-1] = g_x | |
| 109 G_n[:,end-2] = 3*g_x | |
| 110 | |
| 111 @test op_w'*g_y == G_w | |
| 112 @test op_e'*g_y == G_e | |
| 113 @test op_s'*g_x == G_s | |
| 114 @test op_n'*g_x == G_n | |
| 115 end | |
| 116 | |
| 117 @testset "Regions" begin | |
| 118 u = fill(3.124) | |
| 119 @test (op_l'*u)[Index(1,Lower)] == 2*u[] | |
| 120 @test (op_l'*u)[Index(2,Lower)] == u[] | |
| 121 @test (op_l'*u)[Index(6,Interior)] == 0 | |
| 122 @test (op_l'*u)[Index(10,Upper)] == 0 | |
| 123 @test (op_l'*u)[Index(11,Upper)] == 0 | |
| 124 | |
| 125 @test (op_r'*u)[Index(1,Lower)] == 0 | |
| 126 @test (op_r'*u)[Index(2,Lower)] == 0 | |
| 127 @test (op_r'*u)[Index(6,Interior)] == 0 | |
| 128 @test (op_r'*u)[Index(10,Upper)] == u[] | |
| 129 @test (op_r'*u)[Index(11,Upper)] == 2*u[] | |
| 130 end | |
| 131 end | 60 end |
| 132 | 61 |
| 133 @testset "Inferred" begin | 62 @testset "Inferred" begin |
| 134 v = ones(Float64, 11) | 63 v = ones(Float64, 11) |
| 135 u = fill(1.) | 64 u = fill(1.) |
