Mercurial > repos > public > sbplib_julia
changeset 1684:22a9992471be feature/grids/curvilinear
Add min_spacing for mapped 1d grid
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 21 Aug 2024 19:03:01 +0200 |
parents | 88021d580320 |
children | 3ac94e8f28b3 |
files | src/Grids/mapped_grid.jl test/Grids/mapped_grid_test.jl |
diffstat | 2 files changed, 27 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Grids/mapped_grid.jl Thu Jul 11 11:50:10 2024 +0200 +++ b/src/Grids/mapped_grid.jl Wed Aug 21 19:03:01 2024 +0200 @@ -81,6 +81,18 @@ end end +function min_spacing(g::MappedGrid{T,1} where T) + n, = size(g) + + ms = Inf + for i ∈ 1:n-1 + ms = min(ms, norm(g[i+1]-g[i])) + end + + return ms +end + + """ normal(g::MappedGrid, boundary)
--- a/test/Grids/mapped_grid_test.jl Thu Jul 11 11:50:10 2024 +0200 +++ b/test/Grids/mapped_grid_test.jl Wed Aug 21 19:03:01 2024 +0200 @@ -169,6 +169,21 @@ @test_broken false end + + @testset "min_spacing" begin + let g = mapped_grid(identity, x->@SMatrix[1], 11) + @test min_spacing(g) ≈ 0.1 + end + + let g = mapped_grid(x->x+x.^2/2, x->@SMatrix[1 .+ x], 11) + @test min_spacing(g) ≈ 0.105 + end + + let g = mapped_grid(x->x + x.*(1 .- x)/2, x->@SMatrix[1.5 .- x], 11) + @test min_spacing(g) ≈ 0.055 + end + end + end @testset "mapped_grid" begin