changeset 1934:1b012e2d5db1 feature/grids/manifolds

Add function for getting boundaries from CartesianAtlas
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 07 Feb 2025 11:11:54 +0100
parents 2801507dbee1
children 378d38bab1df
files src/Grids/Grids.jl src/Grids/manifolds.jl test/Grids/manifolds_test.jl
diffstat 3 files changed, 92 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/Grids/Grids.jl	Fri Feb 07 09:22:50 2025 +0100
+++ b/src/Grids/Grids.jl	Fri Feb 07 11:11:54 2025 +0100
@@ -29,6 +29,7 @@
 export Atlas
 export charts
 export connections
+export boundaries
 export CartesianAtlas
 
 export parameterspace
--- a/src/Grids/manifolds.jl	Fri Feb 07 09:22:50 2025 +0100
+++ b/src/Grids/manifolds.jl	Fri Feb 07 11:11:54 2025 +0100
@@ -86,6 +86,26 @@
     return c
 end
 
+function boundaries(a::CartesianAtlas)
+    c = MultiBlockBoundary[]
+
+    for d ∈ 1:ndims(charts(a))
+        Is = eachslice(CartesianIndices(charts(a)); dims=d)
+
+        for (i,b) ∈ ((1,LowerBoundary),(length(Is),UpperBoundary)) # For first and last slice
+            for jk ∈ eachindex(Is[i]) # For each block in slice
+                Iᵢⱼₖ = Tuple(Is[i][jk])
+                push!(c,
+                    MultiBlockBoundary{Iᵢⱼₖ,   CartesianBoundary{d,b}}(),
+                )
+            end
+        end
+    end
+
+    return c
+end
+
+
 struct UnstructuredAtlas <: Atlas
     charts::Vector{Chart}
     connections::Vector{Tuple{MultiBlockBoundary, MultiBlockBoundary}}
--- a/test/Grids/manifolds_test.jl	Fri Feb 07 09:22:50 2025 +0100
+++ b/test/Grids/manifolds_test.jl	Fri Feb 07 11:11:54 2025 +0100
@@ -36,12 +36,15 @@
     end
 
     @testset "connections" begin
-        # 2D
-        a = CartesianAtlas(fill(Chart(identity, unitsquare()), 2,3))
         west = CartesianBoundary{1,LowerBoundary}
         east = CartesianBoundary{1,UpperBoundary}
         south = CartesianBoundary{2,LowerBoundary}
         north = CartesianBoundary{2,UpperBoundary}
+        bottom = CartesianBoundary{3, LowerBoundary}
+        top = CartesianBoundary{3, UpperBoundary}
+
+        # 2D
+        a = CartesianAtlas(fill(Chart(identity, unitsquare()), 2,3))
 
         @test Set(connections(a)) == Set([
             (MultiBlockBoundary{(1,1), east}(), MultiBlockBoundary{(2,1), west}()),
@@ -55,8 +58,6 @@
 
         # 3D
         a = CartesianAtlas(fill(Chart(identity, unitsquare()), 2,2,3))
-        bottom = CartesianBoundary{3, LowerBoundary}
-        top = CartesianBoundary{3, UpperBoundary}
         @test Set(connections(a)) == Set([
             (MultiBlockBoundary{(1,1,1), east}(),  MultiBlockBoundary{(2,1,1), west}()),
             (MultiBlockBoundary{(1,1,1), north}(), MultiBlockBoundary{(1,2,1), south}()),
@@ -84,6 +85,72 @@
             (MultiBlockBoundary{(2,2,2), top}(), MultiBlockBoundary{(2,2,3), bottom}()),
         ])
     end
+
+    @testset "boundaries" begin
+        west = CartesianBoundary{1,LowerBoundary}
+        east = CartesianBoundary{1,UpperBoundary}
+        south = CartesianBoundary{2,LowerBoundary}
+        north = CartesianBoundary{2,UpperBoundary}
+        bottom = CartesianBoundary{3, LowerBoundary}
+        top = CartesianBoundary{3, UpperBoundary}
+
+        # 2D
+        a = CartesianAtlas(fill(Chart(identity, unitsquare()), 2,3))
+        @test Set(boundaries(a)) == Set([
+            MultiBlockBoundary{(1,1), south}(),
+            MultiBlockBoundary{(2,1), south}(),
+            MultiBlockBoundary{(2,1), east}(),
+            MultiBlockBoundary{(2,2), east}(),
+            MultiBlockBoundary{(2,3), east}(),
+            MultiBlockBoundary{(1,3), north}(),
+            MultiBlockBoundary{(2,3), north}(),
+            MultiBlockBoundary{(1,1), west}(),
+            MultiBlockBoundary{(1,2), west}(),
+            MultiBlockBoundary{(1,3), west}(),
+        ])
+
+        # 3D
+        a = CartesianAtlas(fill(Chart(identity, unitsquare()), 2,2,3))
+        @test Set(boundaries(a)) == Set([
+            MultiBlockBoundary{(1,1,1), bottom}(),
+            MultiBlockBoundary{(2,1,1), bottom}(),
+            MultiBlockBoundary{(1,2,1), bottom}(),
+            MultiBlockBoundary{(2,2,1), bottom}(),
+
+            MultiBlockBoundary{(1,1,3), top}(),
+            MultiBlockBoundary{(2,1,3), top}(),
+            MultiBlockBoundary{(1,2,3), top}(),
+            MultiBlockBoundary{(2,2,3), top}(),
+
+            MultiBlockBoundary{(1,1,1), west}(),
+            MultiBlockBoundary{(1,2,1), west}(),
+            MultiBlockBoundary{(1,1,2), west}(),
+            MultiBlockBoundary{(1,2,2), west}(),
+            MultiBlockBoundary{(1,1,3), west}(),
+            MultiBlockBoundary{(1,2,3), west}(),
+
+            MultiBlockBoundary{(2,1,1), east}(),
+            MultiBlockBoundary{(2,2,1), east}(),
+            MultiBlockBoundary{(2,1,2), east}(),
+            MultiBlockBoundary{(2,2,2), east}(),
+            MultiBlockBoundary{(2,1,3), east}(),
+            MultiBlockBoundary{(2,2,3), east}(),
+
+            MultiBlockBoundary{(1,1,1), south}(),
+            MultiBlockBoundary{(2,1,1), south}(),
+            MultiBlockBoundary{(1,1,2), south}(),
+            MultiBlockBoundary{(2,1,2), south}(),
+            MultiBlockBoundary{(1,1,3), south}(),
+            MultiBlockBoundary{(2,1,3), south}(),
+
+            MultiBlockBoundary{(1,2,1), north}(),
+            MultiBlockBoundary{(2,2,1), north}(),
+            MultiBlockBoundary{(1,2,2), north}(),
+            MultiBlockBoundary{(2,2,2), north}(),
+            MultiBlockBoundary{(1,2,3), north}(),
+            MultiBlockBoundary{(2,2,3), north}(),
+        ])
+    end
 end
 
 @testset "UnstructuredAtlas" begin