Mercurial > repos > public > sbplib_julia
changeset 2026:1b6f150d95c5 feature/grids/multiblock_grids
Implement min_spacing, coarsen, refine
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Thu, 10 Apr 2025 16:20:22 +0200 |
| parents | d35a4cb170ff |
| children | 0f27ddff6f92 |
| files | src/Grids/multiblockgrids.jl test/Grids/multiblockgrids_test.jl |
| diffstat | 2 files changed, 46 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Grids/multiblockgrids.jl Thu Apr 10 08:45:08 2025 +0200 +++ b/src/Grids/multiblockgrids.jl Thu Apr 10 16:20:22 2025 +0200 @@ -18,9 +18,25 @@ # function boundary_identifiers end # Requires function from manifolds? # function boundary_grid end # Should return a MultiBlockGrid with the right connections? -# function min_spacing end -# function refine end -# function coarsen end + +min_spacing(g::MultiBlockGrid) = minimum(min_spacing, grids(g)) + +function refine(g::MultiBlockGrid, n) + gs = map(grids(g)) do gᵢ + refine(gᵢ,n) + end + + return MultiBlockGrid(gs, connections(g)) +end + +function coarsen(g::MultiBlockGrid, n) + gs = map(grids(g)) do gᵢ + coarsen(gᵢ,n) + end + + return MultiBlockGrid(gs, connections(g)) +end + # function boundary_indices end # Need to figure out the grid functions first? # function eval_on end # Need to figure out the grid functions first?
--- a/test/Grids/multiblockgrids_test.jl Thu Apr 10 08:45:08 2025 +0200 +++ b/test/Grids/multiblockgrids_test.jl Thu Apr 10 16:20:22 2025 +0200 @@ -18,7 +18,7 @@ function multiblockgrid2d() g₁₁ = equidistant_grid((0,0),(1,1),5,5) g₁₂ = equidistant_grid((0,0),(1,1),5,5) - g₂₁ = equidistant_grid((0,0),(1,1),5,5) + g₂₁ = equidistant_grid((0,0),(1,1),11,11) g₂₂ = equidistant_grid((0,0),(1,1),5,5) C = map(((i1,d1,b1,i2,d2,b2),)->connection(i1,CartesianBoundary{d1,b1}(), i2, CartesianBoundary{d2,b2}()),[ @@ -34,7 +34,7 @@ function multiblockgrid_matrix() g₁₁ = equidistant_grid((0,0),(1,1),5,5) g₁₂ = equidistant_grid((0,0),(1,1),5,5) - g₂₁ = equidistant_grid((0,0),(1,1),5,5) + g₂₁ = equidistant_grid((0,0),(1,1),11,11) g₂₂ = equidistant_grid((0,0),(1,1),5,5) C = map(((i1,d1,b1,i2,d2,b2),)->connection(CartesianIndex(i1),CartesianBoundary{d1,b1}(), CartesianIndex(i2), CartesianBoundary{d2,b2}()),[ @@ -124,15 +124,37 @@ end @testset "min_spacing" begin - @test_broken false + gs, cs = multiblockgrid2d() + @test min_spacing(MultiBlockGrid(gs,cs)) isa Float64 + @test min_spacing(MultiBlockGrid(gs,cs)) == 0.1 end @testset "refine" begin - @test_broken false + gs, cs = multiblockgrid2d() + @test refine(MultiBlockGrid(gs,cs),2) isa MultiBlockGrid + + rg = refine(MultiBlockGrid(gs,cs),2) + @test connections(rg) == cs + @test grids(rg) == [ + equidistant_grid((0,0),(1,1),9,9), + equidistant_grid((0,0),(1,1),9,9), + equidistant_grid((0,0),(1,1),21,21), + equidistant_grid((0,0),(1,1),9,9), + ] end @testset "coarsen" begin - @test_broken false + gs, cs = multiblockgrid2d() + @test coarsen(MultiBlockGrid(gs,cs),2) isa MultiBlockGrid + + cg = coarsen(MultiBlockGrid(gs,cs),2) + @test connections(cg) == cs + @test grids(cg) == [ + equidistant_grid((0,0),(1,1),3,3), + equidistant_grid((0,0),(1,1),3,3), + equidistant_grid((0,0),(1,1),6,6), + equidistant_grid((0,0),(1,1),3,3), + ] end @testset "boundary_indices" begin
