Mercurial > repos > public > sbplib_julia
changeset 705:bf1387f867b8 feature/laplace_opset
Add tests for Laplace field getter functions
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Mon, 15 Feb 2021 17:53:13 +0100 |
parents | a7efedbdede9 |
children | 19301615b340 |
files | test/testSbpOperators.jl |
diffstat | 1 files changed, 87 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/test/testSbpOperators.jl Mon Feb 15 17:31:32 2021 +0100 +++ b/test/testSbpOperators.jl Mon Feb 15 17:53:13 2021 +0100 @@ -336,26 +336,28 @@ @testset "Laplace" begin g_1D = EquidistantGrid(101, 0.0, 1.) g_3D = EquidistantGrid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.)) + op2 = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) + op4 = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) @testset "Constructors" begin - op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) + @testset "1D" begin # Create all tensor mappings included in Laplace - Δ = laplace(g_1D, op.innerStencil, op.closureStencils) - H = inner_product(g_1D, op.quadratureClosure) - Hi = inverse_inner_product(g_1D, op.quadratureClosure) + Δ = laplace(g_1D, op4.innerStencil, op4.closureStencils) + H = inner_product(g_1D, op4.quadratureClosure) + Hi = inverse_inner_product(g_1D, op4.quadratureClosure) (id_l, id_r) = boundary_identifiers(g_1D) - e_l = boundary_restriction(g_1D,op.eClosure,id_l) - e_r = boundary_restriction(g_1D,op.eClosure,id_r) + e_l = boundary_restriction(g_1D,op4.eClosure,id_l) + e_r = boundary_restriction(g_1D,op4.eClosure,id_r) e_dict = Dict(Pair(id_l,e_l),Pair(id_r,e_r)) - d_l = normal_derivative(g_1D,op.dClosure,id_l) - d_r = normal_derivative(g_1D,op.dClosure,id_r) + d_l = normal_derivative(g_1D,op4.dClosure,id_l) + d_r = normal_derivative(g_1D,op4.dClosure,id_r) d_dict = Dict(Pair(id_l,d_l),Pair(id_r,d_r)) - H_l = inner_product(boundary_grid(g_1D,id_l),op.quadratureClosure) - H_r = inner_product(boundary_grid(g_1D,id_r),op.quadratureClosure) + H_l = inner_product(boundary_grid(g_1D,id_l),op4.quadratureClosure) + H_r = inner_product(boundary_grid(g_1D,id_r),op4.quadratureClosure) Hb_dict = Dict(Pair(id_l,H_l),Pair(id_r,H_r)) L = Laplace(g_1D, sbp_operators_path()*"standard_diagonal.toml"; order=4) @@ -365,38 +367,38 @@ end @testset "3D" begin # Create all tensor mappings included in Laplace - Δ = laplace(g_3D, op.innerStencil, op.closureStencils) - H = inner_product(g_3D, op.quadratureClosure) - Hi = inverse_inner_product(g_3D, op.quadratureClosure) + Δ = laplace(g_3D, op4.innerStencil, op4.closureStencils) + H = inner_product(g_3D, op4.quadratureClosure) + Hi = inverse_inner_product(g_3D, op4.quadratureClosure) (id_l, id_r, id_s, id_n, id_b, id_t) = boundary_identifiers(g_3D) - e_l = boundary_restriction(g_3D,op.eClosure,id_l) - e_r = boundary_restriction(g_3D,op.eClosure,id_r) - e_s = boundary_restriction(g_3D,op.eClosure,id_s) - e_n = boundary_restriction(g_3D,op.eClosure,id_n) - e_b = boundary_restriction(g_3D,op.eClosure,id_b) - e_t = boundary_restriction(g_3D,op.eClosure,id_t) + e_l = boundary_restriction(g_3D,op4.eClosure,id_l) + e_r = boundary_restriction(g_3D,op4.eClosure,id_r) + e_s = boundary_restriction(g_3D,op4.eClosure,id_s) + e_n = boundary_restriction(g_3D,op4.eClosure,id_n) + e_b = boundary_restriction(g_3D,op4.eClosure,id_b) + e_t = boundary_restriction(g_3D,op4.eClosure,id_t) e_dict = Dict(Pair(id_l,e_l),Pair(id_r,e_r), Pair(id_s,e_s),Pair(id_n,e_n), Pair(id_b,e_b),Pair(id_t,e_t)) - d_l = normal_derivative(g_3D,op.dClosure,id_l) - d_r = normal_derivative(g_3D,op.dClosure,id_r) - d_s = normal_derivative(g_3D,op.dClosure,id_s) - d_n = normal_derivative(g_3D,op.dClosure,id_n) - d_b = normal_derivative(g_3D,op.dClosure,id_b) - d_t = normal_derivative(g_3D,op.dClosure,id_t) + d_l = normal_derivative(g_3D,op4.dClosure,id_l) + d_r = normal_derivative(g_3D,op4.dClosure,id_r) + d_s = normal_derivative(g_3D,op4.dClosure,id_s) + d_n = normal_derivative(g_3D,op4.dClosure,id_n) + d_b = normal_derivative(g_3D,op4.dClosure,id_b) + d_t = normal_derivative(g_3D,op4.dClosure,id_t) d_dict = Dict(Pair(id_l,d_l),Pair(id_r,d_r), Pair(id_s,d_s),Pair(id_n,d_n), Pair(id_b,d_b),Pair(id_t,d_t)) - H_l = inner_product(boundary_grid(g_3D,id_l),op.quadratureClosure) - H_r = inner_product(boundary_grid(g_3D,id_r),op.quadratureClosure) - H_s = inner_product(boundary_grid(g_3D,id_s),op.quadratureClosure) - H_n = inner_product(boundary_grid(g_3D,id_n),op.quadratureClosure) - H_b = inner_product(boundary_grid(g_3D,id_b),op.quadratureClosure) - H_t = inner_product(boundary_grid(g_3D,id_t),op.quadratureClosure) + H_l = inner_product(boundary_grid(g_3D,id_l),op4.quadratureClosure) + H_r = inner_product(boundary_grid(g_3D,id_r),op4.quadratureClosure) + H_s = inner_product(boundary_grid(g_3D,id_s),op4.quadratureClosure) + H_n = inner_product(boundary_grid(g_3D,id_n),op4.quadratureClosure) + H_b = inner_product(boundary_grid(g_3D,id_b),op4.quadratureClosure) + H_t = inner_product(boundary_grid(g_3D,id_t),op4.quadratureClosure) Hb_dict = Dict(Pair(id_l,H_l),Pair(id_r,H_r), Pair(id_s,H_s),Pair(id_n,H_n), Pair(id_b,H_b),Pair(id_t,H_t)) @@ -409,36 +411,78 @@ end @testset "laplace" begin - op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) @testset "1D" begin - L = laplace(g_1D, op.innerStencil, op.closureStencils) - @test L == second_derivative(g_1D, op.innerStencil, op.closureStencils) + L = laplace(g_1D, op4.innerStencil, op4.closureStencils) + @test L == second_derivative(g_1D, op4.innerStencil, op4.closureStencils) @test L isa TensorMapping{T,1,1} where T end @testset "3D" begin - L = laplace(g_3D, op.innerStencil, op.closureStencils) + L = laplace(g_3D, op4.innerStencil, op4.closureStencils) @test L isa TensorMapping{T,3,3} where T - Dxx = second_derivative(g_3D, op.innerStencil, op.closureStencils,1) - Dyy = second_derivative(g_3D, op.innerStencil, op.closureStencils,2) - Dzz = second_derivative(g_3D, op.innerStencil, op.closureStencils,3) + Dxx = second_derivative(g_3D, op4.innerStencil, op4.closureStencils,1) + Dyy = second_derivative(g_3D, op4.innerStencil, op4.closureStencils,2) + Dzz = second_derivative(g_3D, op4.innerStencil, op4.closureStencils,3) @test L == Dxx + Dyy + Dzz @test L isa TensorMapping{T,3,3} where T end end - @testset "quadrature" begin + @testset "inner_product" begin + L = Laplace(g_3D, sbp_operators_path()*"standard_diagonal.toml"; order=4) + @test inner_product(L) == inner_product(g_3D,op4.quadratureClosure) end - @testset "inverse_quadrature" begin + @testset "inverse_inner_product" begin + L = Laplace(g_3D, sbp_operators_path()*"standard_diagonal.toml"; order=4) + @test inverse_inner_product(L) == inverse_inner_product(g_3D,op4.quadratureClosure) end @testset "boundary_restriction" begin + L = Laplace(g_3D, sbp_operators_path()*"standard_diagonal.toml"; order=4) + id_l = CartesianBoundary{1,Lower}() + id_r = CartesianBoundary{1,Upper}() + id_s = CartesianBoundary{2,Lower}() + id_n = CartesianBoundary{2,Upper}() + id_b = CartesianBoundary{3,Lower}() + id_t = CartesianBoundary{3,Upper}() + @test boundary_restriction(L,id_l) == boundary_restriction(g_3D,op4.eClosure,id_l) + @test boundary_restriction(L,id_r) == boundary_restriction(g_3D,op4.eClosure,id_r) + @test boundary_restriction(L,id_s) == boundary_restriction(g_3D,op4.eClosure,id_s) + @test boundary_restriction(L,id_n) == boundary_restriction(g_3D,op4.eClosure,id_n) + @test boundary_restriction(L,id_b) == boundary_restriction(g_3D,op4.eClosure,id_b) + @test boundary_restriction(L,id_t) == boundary_restriction(g_3D,op4.eClosure,id_t) end - @testset "normal_restriction" begin + @testset "normal_derivative" begin + L = Laplace(g_3D, sbp_operators_path()*"standard_diagonal.toml"; order=4) + id_l = CartesianBoundary{1,Lower}() + id_r = CartesianBoundary{1,Upper}() + id_s = CartesianBoundary{2,Lower}() + id_n = CartesianBoundary{2,Upper}() + id_b = CartesianBoundary{3,Lower}() + id_t = CartesianBoundary{3,Upper}() + @test normal_derivative(L,id_l) == normal_derivative(g_3D,op4.dClosure,id_l) + @test normal_derivative(L,id_r) == normal_derivative(g_3D,op4.dClosure,id_r) + @test normal_derivative(L,id_s) == normal_derivative(g_3D,op4.dClosure,id_s) + @test normal_derivative(L,id_n) == normal_derivative(g_3D,op4.dClosure,id_n) + @test normal_derivative(L,id_b) == normal_derivative(g_3D,op4.dClosure,id_b) + @test normal_derivative(L,id_t) == normal_derivative(g_3D,op4.dClosure,id_t) end @testset "boundary_quadrature" begin + L = Laplace(g_3D, sbp_operators_path()*"standard_diagonal.toml"; order=4) + id_l = CartesianBoundary{1,Lower}() + id_r = CartesianBoundary{1,Upper}() + id_s = CartesianBoundary{2,Lower}() + id_n = CartesianBoundary{2,Upper}() + id_b = CartesianBoundary{3,Lower}() + id_t = CartesianBoundary{3,Upper}() + @test boundary_quadrature(L,id_l) == inner_product(boundary_grid(g_3D,id_l),op4.quadratureClosure) + @test boundary_quadrature(L,id_r) == inner_product(boundary_grid(g_3D,id_r),op4.quadratureClosure) + @test boundary_quadrature(L,id_s) == inner_product(boundary_grid(g_3D,id_s),op4.quadratureClosure) + @test boundary_quadrature(L,id_n) == inner_product(boundary_grid(g_3D,id_n),op4.quadratureClosure) + @test boundary_quadrature(L,id_b) == inner_product(boundary_grid(g_3D,id_b),op4.quadratureClosure) + @test boundary_quadrature(L,id_t) == inner_product(boundary_grid(g_3D,id_t),op4.quadratureClosure) end # Exact differentiation is measured point-wise. In other cases @@ -457,8 +501,7 @@ # 2nd order interior stencil, 1st order boundary stencil, # implies that L*v should be exact for binomials up to order 2. @testset "2nd order" begin - op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2) - L = laplace(g_3D,op.innerStencil,op.closureStencils) + L = laplace(g_3D,op2.innerStencil,op2.closureStencils) @test L*polynomials[1] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 @test L*polynomials[2] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 @test L*polynomials[3] ≈ polynomials[1] atol = 5e-9 @@ -469,7 +512,7 @@ # implies that L*v should be exact for binomials up to order 3. @testset "4th order" begin op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) - L = laplace(g_3D,op.innerStencil,op.closureStencils) + L = laplace(g_3D,op4.innerStencil,op4.closureStencils) # NOTE: high tolerances for checking the "exact" differentiation # due to accumulation of round-off errors/cancellation errors? @test L*polynomials[1] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9