Mercurial > repos > public > sbplib_julia
changeset 926:47425442bbc5 feature/laplace_opset
Fix tests after refactoring
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Mon, 21 Feb 2022 23:33:29 +0100 |
parents | 6b47a9ee1632 |
children | d360fc2d9620 |
files | src/SbpOperators/volumeops/laplace/laplace.jl test/SbpOperators/boundaryops/boundary_operator_test.jl test/SbpOperators/boundaryops/boundary_restriction_test.jl test/SbpOperators/boundaryops/normal_derivative_test.jl test/SbpOperators/volumeops/laplace/laplace_test.jl |
diffstat | 5 files changed, 23 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/src/SbpOperators/volumeops/laplace/laplace.jl Mon Feb 21 13:13:37 2022 +0100 +++ b/src/SbpOperators/volumeops/laplace/laplace.jl Mon Feb 21 23:33:29 2022 +0100 @@ -1,12 +1,11 @@ """ - Laplace{T, DiffOp} <: TensorMapping{T,Dim,Dim} - Laplace(grid::Equidistant, stencil_set) + Laplace{T, Dim, DiffOp} <: TensorMapping{T, Dim, Dim} Implements the Laplace operator, approximating ∑d²/xᵢ² , i = 1,...,`Dim` as a `TensorMapping`. Additionally `Laplace` stores the stencil set (parsed from TOML) used to construct the `TensorMapping`. """ -struct Laplace{T, DiffOp<:TensorMapping{T,Dim,Dim}} <: TensorMapping{T,Dim,Dim} +struct Laplace{T, Dim, DiffOp<:TensorMapping{T, Dim, Dim}} <: TensorMapping{T, Dim, Dim} D::DiffOp# Differential operator stencil_set # Stencil set of the operator end @@ -17,7 +16,7 @@ Creates the `Laplace`` operator `Δ` on `grid` given a parsed TOML `stencil_set`. See also [`laplace`](@ref). """ -function Laplace(grid::Equidistant, stencil_set) +function Laplace(grid::EquidistantGrid, stencil_set) inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) Δ = laplace(grid, inner_stencil,closure_stencils) @@ -44,8 +43,8 @@ multi-dimensional `grid`, `Δ` is the sum of multi-dimensional `second_derivative`s where the sum is carried out lazily. See also [`second_derivative`](@ref). """ -function laplace(grid::Equidistant, inner_stencil, closure_stencils) - second_derivative(grid, inner_stencil, closure_stencils, 1) +function laplace(grid::EquidistantGrid, inner_stencil, closure_stencils) + Δ = second_derivative(grid, inner_stencil, closure_stencils, 1) for d = 2:dimension(grid) Δ += second_derivative(grid, inner_stencil, closure_stencils, d) end
--- a/test/SbpOperators/boundaryops/boundary_operator_test.jl Mon Feb 21 13:13:37 2022 +0100 +++ b/test/SbpOperators/boundaryops/boundary_operator_test.jl Mon Feb 21 23:33:29 2022 +0100 @@ -32,14 +32,8 @@ @test e_w isa TensorMapping{T,1,2} where T end end - - op_l = boundary_operator(g_1D, closure_stencil, CartesianBoundary{1,Lower}()) - op_r = boundary_operator(g_1D, closure_stencil, CartesianBoundary{1,Upper}()) - - op_w = boundary_operator(g_2D, closure_stencil, CartesianBoundary{1,Lower}()) - op_e = boundary_operator(g_2D, closure_stencil, CartesianBoundary{1,Upper}()) - op_s = boundary_operator(g_2D, closure_stencil, CartesianBoundary{2,Lower}()) - op_n = boundary_operator(g_2D, closure_stencil, CartesianBoundary{2,Upper}()) + (op_l, op_r) = map(id -> boundary_operator(g_1D, closure_stencil, id), boundary_identifiers(g_1D)) + (op_w, op_e, op_s, op_n) = map(id -> boundary_operator(g_2D, closure_stencil, id), boundary_identifiers(g_2D)) @testset "Sizes" begin @testset "1D" begin
--- a/test/SbpOperators/boundaryops/boundary_restriction_test.jl Mon Feb 21 13:13:37 2022 +0100 +++ b/test/SbpOperators/boundaryops/boundary_restriction_test.jl Mon Feb 21 23:33:29 2022 +0100 @@ -2,7 +2,6 @@ using Sbplib.SbpOperators using Sbplib.Grids -using Sbplib.RegionIndices using Sbplib.LazyTensors import Sbplib.SbpOperators.BoundaryOperator @@ -15,14 +14,12 @@ @testset "boundary_restriction" begin @testset "1D" begin - e_l = boundary_restriction(g_1D,e_closure,Lower()) - @test e_l == boundary_restriction(g_1D,e_closure,CartesianBoundary{1,Lower}()) + e_l = boundary_restriction(g_1D,e_closure,CartesianBoundary{1,Lower}()) @test e_l == BoundaryOperator(g_1D,Stencil{Float64}(e_closure),Lower()) @test e_l isa BoundaryOperator{T,Lower} where T @test e_l isa TensorMapping{T,0,1} where T - e_r = boundary_restriction(g_1D,e_closure,Upper()) - @test e_r == boundary_restriction(g_1D,e_closure,CartesianBoundary{1,Upper}()) + e_r = boundary_restriction(g_1D,e_closure,CartesianBoundary{1,Upper}()) @test e_r == BoundaryOperator(g_1D,Stencil{Float64}(e_closure),Upper()) @test e_r isa BoundaryOperator{T,Upper} where T @test e_r isa TensorMapping{T,0,1} where T @@ -37,8 +34,8 @@ @testset "Application" begin @testset "1D" begin - e_l = boundary_restriction(g_1D, e_closure, CartesianBoundary{1,Lower}()) - e_r = boundary_restriction(g_1D, e_closure, CartesianBoundary{1,Upper}()) + (e_l, e_r) = + map(id -> boundary_restriction(g_1D, e_closure, id), boundary_identifiers(g_1D)) v = evalOn(g_1D,x->1+x^2) u = fill(3.124) @@ -49,10 +46,8 @@ end @testset "2D" begin - e_w = boundary_restriction(g_2D, e_closure, CartesianBoundary{1,Lower}()) - e_e = boundary_restriction(g_2D, e_closure, CartesianBoundary{1,Upper}()) - e_s = boundary_restriction(g_2D, e_closure, CartesianBoundary{2,Lower}()) - e_n = boundary_restriction(g_2D, e_closure, CartesianBoundary{2,Upper}()) + (e_w, e_e, e_s, e_n) = + map(id -> boundary_restriction(g_2D, e_closure, id), boundary_identifiers(g_2D)) v = rand(11, 15) u = fill(3.124)
--- a/test/SbpOperators/boundaryops/normal_derivative_test.jl Mon Feb 21 13:13:37 2022 +0100 +++ b/test/SbpOperators/boundaryops/normal_derivative_test.jl Mon Feb 21 23:33:29 2022 +0100 @@ -2,7 +2,6 @@ using Sbplib.SbpOperators using Sbplib.Grids -using Sbplib.RegionIndices using Sbplib.LazyTensors import Sbplib.SbpOperators.BoundaryOperator @@ -14,8 +13,7 @@ stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) d_closure = parse_stencil(stencil_set["d1"]["closure"]) @testset "1D" begin - d_l = normal_derivative(g_1D, d_closure, Lower()) - @test d_l == normal_derivative(g_1D, d_closure, CartesianBoundary{1,Lower}()) + d_l = normal_derivative(g_1D, d_closure, CartesianBoundary{1,Lower}()) @test d_l isa BoundaryOperator{T,Lower} where T @test d_l isa TensorMapping{T,0,1} where T end @@ -24,8 +22,8 @@ d_n = normal_derivative(g_2D, d_closure, CartesianBoundary{2,Upper}()) Ix = IdentityMapping{Float64}((size(g_2D)[1],)) Iy = IdentityMapping{Float64}((size(g_2D)[2],)) - d_l = normal_derivative(restrict(g_2D,1),d_closure,Lower()) - d_r = normal_derivative(restrict(g_2D,2),d_closure,Upper()) + d_l = normal_derivative(restrict(g_2D,1),d_closure,CartesianBoundary{1,Lower}()) + d_r = normal_derivative(restrict(g_2D,2),d_closure,CartesianBoundary{1,Upper}()) @test d_w == d_l⊗Iy @test d_n == Ix⊗d_r @test d_w isa TensorMapping{T,1,2} where T @@ -40,10 +38,8 @@ @testset "2nd order" begin stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) d_closure = parse_stencil(stencil_set["d1"]["closure"]) - d_w = normal_derivative(g_2D, d_closure, CartesianBoundary{1,Lower}()) - d_e = normal_derivative(g_2D, d_closure, CartesianBoundary{1,Upper}()) - d_s = normal_derivative(g_2D, d_closure, CartesianBoundary{2,Lower}()) - d_n = normal_derivative(g_2D, d_closure, CartesianBoundary{2,Upper}()) + (d_w, d_e, d_s, d_n) = + map(id -> normal_derivative(g_2D, d_closure, id), boundary_identifiers(g_2D)) @test d_w*v ≈ v∂x[1,:] atol = 1e-13 @test d_e*v ≈ -v∂x[end,:] atol = 1e-13 @@ -52,12 +48,10 @@ end @testset "4th order" begin - stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) + stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) d_closure = parse_stencil(stencil_set["d1"]["closure"]) - d_w = normal_derivative(g_2D, d_closure, CartesianBoundary{1,Lower}()) - d_e = normal_derivative(g_2D, d_closure, CartesianBoundary{1,Upper}()) - d_s = normal_derivative(g_2D, d_closure, CartesianBoundary{2,Lower}()) - d_n = normal_derivative(g_2D, d_closure, CartesianBoundary{2,Upper}()) + (d_w, d_e, d_s, d_n) = + map(id -> normal_derivative(g_2D, d_closure, id), boundary_identifiers(g_2D)) @test d_w*v ≈ v∂x[1,:] atol = 1e-13 @test d_e*v ≈ -v∂x[end,:] atol = 1e-13
--- a/test/SbpOperators/volumeops/laplace/laplace_test.jl Mon Feb 21 13:13:37 2022 +0100 +++ b/test/SbpOperators/volumeops/laplace/laplace_test.jl Mon Feb 21 23:33:29 2022 +0100 @@ -3,19 +3,17 @@ using Sbplib.SbpOperators using Sbplib.Grids using Sbplib.LazyTensors -using Sbplib.RegionIndices # Default stencils (4th order) operator_path = sbp_operators_path()*"standard_diagonal.toml" stencil_set = read_stencil_set(operator_path; order=4) inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) +g_1D = EquidistantGrid(101, 0.0, 1.) +g_3D = EquidistantGrid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.)) @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.)) @testset "Constructors" begin - @testset "1D" begin Δ = laplace(g_1D, inner_stencil, closure_stencils) @test Laplace(g_1D, stencil_set) == Laplace(Δ, stencil_set)