Mercurial > repos > public > sbplib_julia
changeset 1595:611ae2308aa1 feature/boundary_conditions
Add orthogonal_grid
author | Vidar Stiernström <vidar.stiernstrom@gmail.com> |
---|---|
date | Sun, 26 May 2024 17:35:52 -0700 |
parents | d68d02dd882f |
children | 84dc3b9b449b |
files | src/Grids/Grids.jl src/Grids/equidistant_grid.jl src/Grids/grid.jl src/Grids/tensor_grid.jl test/Grids/equidistant_grid_test.jl test/Grids/tensor_grid_test.jl |
diffstat | 6 files changed, 33 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Grids/Grids.jl Sat May 25 16:07:10 2024 -0700 +++ b/src/Grids/Grids.jl Sun May 26 17:35:52 2024 -0700 @@ -18,6 +18,7 @@ export eval_on export componentview export ArrayComponentView +export orthogonal_grid export BoundaryIdentifier export TensorGridBoundary
--- a/src/Grids/equidistant_grid.jl Sat May 25 16:07:10 2024 -0700 +++ b/src/Grids/equidistant_grid.jl Sun May 26 17:35:52 2024 -0700 @@ -47,12 +47,12 @@ """ inverse_spacing(g::EquidistantGrid) = 1/step(g.points) - boundary_identifiers(::EquidistantGrid) = (Lower(), Upper()) boundary_grid(g::EquidistantGrid, id::Lower) = ZeroDimGrid(g[begin]) boundary_grid(g::EquidistantGrid, id::Upper) = ZeroDimGrid(g[end]) boundary_indices(g::EquidistantGrid, id::Lower) = (1,) boundary_indices(g::EquidistantGrid, id::Upper) = (length(g),) +orthogonal_grid(g::EquidistantGrid, id::Union{Lower,Upper}) = g """ refine(g::EquidistantGrid, r::Int)
--- a/src/Grids/grid.jl Sat May 25 16:07:10 2024 -0700 +++ b/src/Grids/grid.jl Sun May 26 17:35:52 2024 -0700 @@ -128,6 +128,16 @@ function boundary_indices end """ + orthogonal_grid(g::Grid, id::BoundaryIdentifier) + +The grid for the coordinate direction orthogonal to that of the boundary +with given id +""" +function orthogonal_grid end + +function boundary_indices end + +""" eval_on(g::Grid, f) Lazy evaluation of `f` on the grid. `f` can either be on the form `f(x,y,...)`
--- a/src/Grids/tensor_grid.jl Sat May 25 16:07:10 2024 -0700 +++ b/src/Grids/tensor_grid.jl Sun May 26 17:35:52 2024 -0700 @@ -95,6 +95,9 @@ return LazyTensors.concatenate_tuples(b_ind...) end +orthogonal_grid(g::TensorGrid, id::BoundaryIdentifier) = g.grids[grid_id(id)] + + function combined_coordinate_vector_type(coordinate_types...) combined_coord_length = mapreduce(_ncomponents, +, coordinate_types) combined_coord_type = mapreduce(eltype, promote_type, coordinate_types) @@ -133,3 +136,4 @@ return (I, d-cumsum(nds)[I-1]) end end +
--- a/test/Grids/equidistant_grid_test.jl Sat May 25 16:07:10 2024 -0700 +++ b/test/Grids/equidistant_grid_test.jl Sun May 26 17:35:52 2024 -0700 @@ -79,6 +79,12 @@ end + @testset "orthogonal_grid" begin + g = EquidistantGrid(0:0.1:1) + @test orthogonal_grid(g, Lower()) == g + @test orthogonal_grid(g, Upper()) == g + end + @testset "refine" begin g = EquidistantGrid(0:0.1:1) @test refine(g, 1) == g
--- a/test/Grids/tensor_grid_test.jl Sat May 25 16:07:10 2024 -0700 +++ b/test/Grids/tensor_grid_test.jl Sun May 26 17:35:52 2024 -0700 @@ -184,6 +184,17 @@ @test boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, Lower}()) == (1,) @test boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, Upper}()) == (11,) end + + @testset "orthogonal_grid" begin + g₁ = EquidistantGrid(range(0,1,length=11)) + g₂ = EquidistantGrid(range(2,3,length=6)) + g₃ = EquidistantGrid(range(4,5,length=7)) + + @test orthogonal_grid(TensorGrid(g₁, g₂, g₃), TensorGridBoundary{1, Lower}()) == g₁ + @test orthogonal_grid(TensorGrid(g₁, g₂, g₃), TensorGridBoundary{2, Lower}()) == g₂ + @test orthogonal_grid(TensorGrid(g₁, g₂, g₃), TensorGridBoundary{3, Upper}()) == g₃ + end + end @testset "combined_coordinate_vector_type" begin