Mercurial > repos > public > sbplib_julia
changeset 1281:1cc45207817e refactor/grids
Fix tests for boundary operator and boundary restriction
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 27 Feb 2023 08:48:38 +0100 |
parents | 17d435c08773 |
children | 11b08b242e48 |
files | src/SbpOperators/boundaryops/boundary_operator.jl src/SbpOperators/boundaryops/boundary_restriction.jl test/SbpOperators/boundaryops/boundary_operator_test.jl test/SbpOperators/boundaryops/boundary_restriction_test.jl |
diffstat | 4 files changed, 27 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/src/SbpOperators/boundaryops/boundary_operator.jl Mon Feb 27 08:48:08 2023 +0100 +++ b/src/SbpOperators/boundaryops/boundary_operator.jl Mon Feb 27 08:48:38 2023 +0100 @@ -13,12 +13,12 @@ end """ - BoundaryOperator(grid::EquidistantGrid{1}, closure_stencil, region) + BoundaryOperator(grid::EquidistantGrid, closure_stencil, region) -Constructs the BoundaryOperator with stencil `closure_stencil` for a one-dimensional `grid`, restricting to +Constructs the BoundaryOperator with stencil `closure_stencil` for a `EquidistantGrid` `grid`, restricting to to the boundary specified by `region`. """ -function BoundaryOperator(grid::EquidistantGrid{1}, closure_stencil::Stencil{T,N}, region::Region) where {T,N} +function BoundaryOperator(grid::EquidistantGrid, closure_stencil::Stencil{T,N}, region::Region) where {T,N} return BoundaryOperator{T,typeof(region),N}(closure_stencil,size(grid)[1]) end
--- a/src/SbpOperators/boundaryops/boundary_restriction.jl Mon Feb 27 08:48:08 2023 +0100 +++ b/src/SbpOperators/boundaryops/boundary_restriction.jl Mon Feb 27 08:48:38 2023 +0100 @@ -1,25 +1,23 @@ """ - boundary_restriction(grid, closure_stencil::Stencil, boundary) + boundary_restriction(g, closure_stencil::Stencil, boundary) Creates boundary restriction operators `e` as `LazyTensor`s on `boundary` `e` is the restriction of a grid function to `boundary` using a `Stencil` `closure_stencil`. `e'` is the prolongation of a grid function on `boundary` to the whole grid using the same `closure_stencil`. -On a one-dimensional `grid`, `e` is a `BoundaryOperator`. On a multi-dimensional `grid`, `e` is the inflation of +On a one-dimensional grid, `e` is a `BoundaryOperator`. On a multi-dimensional grid, `e` is the inflation of a `BoundaryOperator`. See also: [`BoundaryOperator`](@ref), [`LazyTensors.inflate`](@ref). """ -function boundary_restriction(grid, closure_stencil, boundary) - converted_stencil = convert(Stencil{eltype(grid)}, closure_stencil) - - op = BoundaryOperator(restrict(grid, dim(boundary)), converted_stencil, region(boundary)) - return LazyTensors.inflate(op, size(grid), dim(boundary)) +#TODO: Check docstring +function boundary_restriction(g::TensorGrid, stencil_set::StencilSet, boundary::TensorGridBoundary) + op = boundary_restriction(g.grids[grid_id(boundary)], stencil_set, boundary_id(boundary)) + return LazyTensors.inflate(op, size(g), grid_id(boundary)) end -""" - boundary_restriction(grid, stencil_set, boundary) - -Creates a `boundary_restriction` operator on `grid` given a `stencil_set`. -""" -boundary_restriction(grid, stencil_set::StencilSet, boundary) = boundary_restriction(grid, parse_stencil(stencil_set["e"]["closure"]), boundary) +function boundary_restriction(g::EquidistantGrid, stencil_set::StencilSet, boundary) + closure_stencil = parse_stencil(stencil_set["e"]["closure"]) + converted_stencil = convert(Stencil{eltype(g)}, closure_stencil) + return BoundaryOperator(g, converted_stencil, boundary) +end
--- a/test/SbpOperators/boundaryops/boundary_operator_test.jl Mon Feb 27 08:48:08 2023 +0100 +++ b/test/SbpOperators/boundaryops/boundary_operator_test.jl Mon Feb 27 08:48:38 2023 +0100 @@ -10,8 +10,7 @@ @testset "BoundaryOperator" begin closure_stencil = Stencil(2.,1.,3.; center = 1) - g_1D = EquidistantGrid(11, 0.0, 1.0) - g_2D = EquidistantGrid((11,15), (0.0, 0.0), (1.0,1.0)) + g_1D = EquidistantGrid(range(0,1,length=11)) @testset "Constructors" begin @test BoundaryOperator(g_1D, closure_stencil, Lower()) isa LazyTensor{T,0,1} where T @@ -30,7 +29,7 @@ end @testset "Application" begin - v = evalOn(g_1D,x->1+x^2) + v = eval_on(g_1D,x->1+x^2) u = fill(3.124) @test (op_l*v)[] == 2*v[1] + v[2] + 3*v[3] @test (op_r*v)[] == 2*v[end] + v[end-1] + 3*v[end-2] @@ -38,7 +37,7 @@ @test op_l'*u == [2*u[]; u[]; 3*u[]; zeros(8)] @test op_r'*u == [zeros(8); 3*u[]; u[]; 2*u[]] - v = evalOn(g_1D, x->1. +x*im) + v = eval_on(g_1D, x->1. +x*im) @test (op_l*v)[] isa ComplexF64 u = fill(1. +im)
--- a/test/SbpOperators/boundaryops/boundary_restriction_test.jl Mon Feb 27 08:48:08 2023 +0100 +++ b/test/SbpOperators/boundaryops/boundary_restriction_test.jl Mon Feb 27 08:48:38 2023 +0100 @@ -9,27 +9,24 @@ @testset "boundary_restriction" begin stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order = 4) e_closure = parse_stencil(stencil_set["e"]["closure"]) - g_1D = EquidistantGrid(11, 0.0, 1.0) - g_2D = EquidistantGrid((11,15), (0.0, 0.0), (1.0,1.0)) + g_1D = equidistant_grid(11, 0.0, 1.0) + g_2D = equidistant_grid((11,15), (0.0, 0.0), (1.0,1.0)) @testset "boundary_restriction" begin @testset "1D" begin - e_l = boundary_restriction(g_1D,e_closure,CartesianBoundary{1,Lower}()) - @test e_l == boundary_restriction(g_1D,stencil_set,CartesianBoundary{1,Lower}()) - @test e_l == BoundaryOperator(g_1D,Stencil{Float64}(e_closure),Lower()) + e_l = boundary_restriction(g_1D,stencil_set,CartesianBoundary{1,Lower}()) + @test e_l == BoundaryOperator(g_1D.grids[1],Stencil{Float64}(e_closure),Lower()) @test e_l isa BoundaryOperator{T,Lower} where T @test e_l isa LazyTensor{T,0,1} where T - e_r = boundary_restriction(g_1D,e_closure,CartesianBoundary{1,Upper}()) - @test e_r == boundary_restriction(g_1D,stencil_set,CartesianBoundary{1,Upper}()) - @test e_r == BoundaryOperator(g_1D,Stencil{Float64}(e_closure),Upper()) + e_r = boundary_restriction(g_1D,stencil_set,CartesianBoundary{1,Upper}()) + @test e_r == BoundaryOperator(g_1D.grids[1],Stencil{Float64}(e_closure),Upper()) @test e_r isa BoundaryOperator{T,Upper} where T @test e_r isa LazyTensor{T,0,1} where T end @testset "2D" begin - e_w = boundary_restriction(g_2D,e_closure,CartesianBoundary{1,Upper}()) - @test e_w == boundary_restriction(g_2D,stencil_set,CartesianBoundary{1,Upper}()) + e_w = boundary_restriction(g_2D,stencil_set,CartesianBoundary{1,Upper}()) @test e_w isa InflatedTensor @test e_w isa LazyTensor{T,1,2} where T end @@ -37,8 +34,8 @@ @testset "Application" begin @testset "1D" begin - e_l, e_r = boundary_restriction.(Ref(g_1D), Ref(e_closure), boundary_identifiers(g_1D)) - v = evalOn(g_1D,x->1+x^2) + e_l, e_r = boundary_restriction.(Ref(g_1D), Ref(stencil_set), boundary_identifiers(g_1D)) + v = eval_on(g_1D,x->1+x[1]^2) # TBD: We don't want an SVector here right? (For 1D) u = fill(3.124) @test (e_l*v)[] == v[1] @@ -47,7 +44,7 @@ end @testset "2D" begin - e_w, e_e, e_s, e_n = boundary_restriction.(Ref(g_2D), Ref(e_closure), boundary_identifiers(g_2D)) + e_w, e_e, e_s, e_n = boundary_restriction.(Ref(g_2D), Ref(stencil_set), boundary_identifiers(g_2D)) v = rand(11, 15) u = fill(3.124)