Mercurial > repos > public > sbplib_julia
changeset 1282:11b08b242e48 refactor/grids
Make equdistant_grid return an EquidistantGrid for the 1d Case
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 27 Feb 2023 15:39:13 +0100 |
parents | 1cc45207817e |
children | 54c3ed752730 |
files | src/Grids/equidistant_grid.jl test/Grids/equidistant_grid_test.jl test/SbpOperators/boundaryops/boundary_restriction_test.jl |
diffstat | 3 files changed, 21 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Grids/equidistant_grid.jl Mon Feb 27 08:48:38 2023 +0100 +++ b/src/Grids/equidistant_grid.jl Mon Feb 27 15:39:13 2023 +0100 @@ -96,30 +96,24 @@ behaviours. """ function equidistant_grid(size::Dims, limit_lower, limit_upper) - if any(size .<= 0) - throw(DomainError("all components of size must be postive")) - end - - if any(limit_upper.-limit_lower .<= 0) - throw(DomainError("all side lengths must be postive")) - end - - gs = map(size, limit_lower, limit_upper) do s,l,u - EquidistantGrid(range(l, u, length=s)) # TBD: Should it use LinRange instead? - end - + gs = map(equidistant_grid, size, limit_lower, limit_upper) return TensorGrid(gs...) end - """ equidistant_grid(size::Int, limit_lower::T, limit_upper::T) Constructs a 1D equidistant grid. """ function equidistant_grid(size::Int, limit_lower::T, limit_upper::T) where T - # TBD: Should this really return a TensorGrid? - return equidistant_grid((size,),(limit_lower,),(limit_upper,)) + if any(size .<= 0) + throw(DomainError("size must be postive")) + end + + if any(limit_upper.-limit_lower .<= 0) + throw(DomainError("side length must be postive")) + end + return EquidistantGrid(range(limit_lower, limit_upper, length=size)) # TBD: Should it use LinRange instead? end CartesianBoundary{D,BID} = TensorGridBoundary{D,BID} # TBD: What should we do about the naming of this boundary?
--- a/test/Grids/equidistant_grid_test.jl Mon Feb 27 08:48:38 2023 +0100 +++ b/test/Grids/equidistant_grid_test.jl Mon Feb 27 15:39:13 2023 +0100 @@ -85,13 +85,17 @@ @testset "equidistant_grid" begin - @test equidistant_grid(4,0.0,1.0) isa TensorGrid - @test equidistant_grid(4,0.0,8.0) isa TensorGrid + @test equidistant_grid(4,0.0,1.0) isa EquidistantGrid + @test equidistant_grid((4,3),(0.0,0.0),(8.0,5.0)) isa TensorGrid + # constuctor @test_throws DomainError equidistant_grid(0,0.0,1.0) @test_throws DomainError equidistant_grid(1,1.0,1.0) @test_throws DomainError equidistant_grid(1,1.0,-1.0) - @test equidistant_grid(4,0.0,1.0) == equidistant_grid((4,),(0.0,),(1.0,)) + + @test_throws DomainError equidistant_grid((0,0),(0.0,0.0),(1.0,1.0)) + @test_throws DomainError equidistant_grid((1,1),(1.0,1.0),(1.0,1.0)) + @test_throws DomainError equidistant_grid((1,1),(1.0,1.0),(-1.0,-1.0)) @testset "Base" begin @test eltype(equidistant_grid(4,0.0,1.0)) == Float64
--- a/test/SbpOperators/boundaryops/boundary_restriction_test.jl Mon Feb 27 08:48:38 2023 +0100 +++ b/test/SbpOperators/boundaryops/boundary_restriction_test.jl Mon Feb 27 15:39:13 2023 +0100 @@ -14,13 +14,13 @@ @testset "boundary_restriction" begin @testset "1D" begin - e_l = boundary_restriction(g_1D,stencil_set,CartesianBoundary{1,Lower}()) - @test e_l == BoundaryOperator(g_1D.grids[1],Stencil{Float64}(e_closure),Lower()) + e_l = boundary_restriction(g_1D,stencil_set,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 LazyTensor{T,0,1} where T - e_r = boundary_restriction(g_1D,stencil_set,CartesianBoundary{1,Upper}()) - @test e_r == BoundaryOperator(g_1D.grids[1],Stencil{Float64}(e_closure),Upper()) + e_r = boundary_restriction(g_1D,stencil_set,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 LazyTensor{T,0,1} where T end @@ -35,7 +35,7 @@ @testset "Application" begin @testset "1D" begin 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) + v = eval_on(g_1D,x->1+x^2) u = fill(3.124) @test (e_l*v)[] == v[1]