diff test/Grids/tensor_grid_test.jl @ 1954:b0915f43b122 feature/sbp_operators/laplace_curvilinear

Merge feature/grids/geometry_functions
author Jonatan Werpers <jonatan@werpers.com>
date Sat, 08 Feb 2025 09:38:58 +0100
parents fa96b57af6a1
children
line wrap: on
line diff
--- a/test/Grids/tensor_grid_test.jl	Sat Feb 08 09:35:13 2025 +0100
+++ b/test/Grids/tensor_grid_test.jl	Sat Feb 08 09:38:58 2025 +0100
@@ -137,6 +137,27 @@
         @test axes(g) == (1:11,1:6)
     end
 
+    @testset "spacing" begin
+        g₁ = EquidistantGrid(range(0,1,length=11))
+        g₂ = EquidistantGrid(range(2,3,length=6))
+        g₃ = ZeroDimGrid(@SVector[1,2])
+
+        @test spacing(TensorGrid(g₁)) == (1/10,)
+        @test spacing(TensorGrid(g₂)) == (1/5,)
+
+        @test spacing(TensorGrid(g₁, g₂)) == (1/10, 1/5)
+
+        @test spacing(TensorGrid(g₁, g₃)) == (1/10,)
+        @test spacing(TensorGrid(g₃, g₂)) == (1/5,)
+
+
+        @test spacing(TensorGrid(g₁, g₂, g₁)) == (1/10, 1/5, 1/10)
+
+        @test spacing(TensorGrid(g₃, g₂, g₁)) == (1/5, 1/10)
+        @test spacing(TensorGrid(g₁, g₃, g₁)) == (1/10, 1/10)
+        @test spacing(TensorGrid(g₁, g₂, g₃)) == (1/10, 1/5)
+    end
+
     @testset "min_spacing" begin
         g₁ = EquidistantGrid(range(0,1,length=11))
         g₂ = EquidistantGrid(range(2,3,length=6))
@@ -183,14 +204,26 @@
         g₂ = EquidistantGrid(range(2,3,length=6))
         g₄ = ZeroDimGrid(@SVector[1,2])
 
-        @test boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, LowerBoundary}()) == (1,:)
-        @test boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, UpperBoundary}()) == (11,:)
-        @test boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, LowerBoundary}()) == (:,1)
-        @test boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, UpperBoundary}()) == (:,6)
-        @test boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, LowerBoundary}()) == (1,)
-        @test boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, UpperBoundary}()) == (11,)
-        @test boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, LowerBoundary}()) == (1,)
-        @test boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, UpperBoundary}()) == (11,)
+        gf = reshape(1:(11*6),11,6)
+        @test gf[boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, LowerBoundary}())] == gf[1,:]
+        @test gf[boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, UpperBoundary}())] == gf[11,:]
+        @test gf[boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, LowerBoundary}())] == gf[:,1]
+        @test gf[boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, UpperBoundary}())] == gf[:,6]
+
+        gf = rand(11)
+        @test gf[boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, LowerBoundary}())] == gf[1]
+        @test gf[boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, UpperBoundary}())] == gf[11]
+        @test gf[boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, LowerBoundary}())] == gf[1]
+        @test gf[boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, UpperBoundary}())] == gf[11]
+
+        @test collect(boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, LowerBoundary}())) == [CartesianIndex(1,i) for i ∈ 1:6]
+        @test collect(boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, UpperBoundary}())) == [CartesianIndex(11,i) for i ∈ 1:6]
+        @test collect(boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, LowerBoundary}())) == [CartesianIndex(i,1) for i ∈ 1:11]
+        @test collect(boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, UpperBoundary}())) == [CartesianIndex(i,6) for i ∈ 1:11]
+        @test collect(boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, LowerBoundary}())) == fill(1)
+        @test collect(boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, UpperBoundary}())) == fill(11)
+        @test collect(boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, LowerBoundary}())) == fill(1)
+        @test collect(boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, UpperBoundary}())) == fill(11)
     end
 end