changeset 1268:dbddd0f61bde refactor/grids

Add refine, coarsen, boundary_identifiers, and boundary_grid methods to ZeroDimGrid
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 24 Feb 2023 21:54:39 +0100
parents 30729cba1095
children 20f42cf0800c
files src/Grids/zero_dim_grid.jl test/Grids/tensor_grid_test.jl test/Grids/zero_dim_grid_test.jl
diffstat 3 files changed, 18 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/Grids/zero_dim_grid.jl	Fri Feb 24 21:48:01 2023 +0100
+++ b/src/Grids/zero_dim_grid.jl	Fri Feb 24 21:54:39 2023 +0100
@@ -17,3 +17,10 @@
 Base.IteratorSize(::Type{<:ZeroDimGrid}) = Base.HasShape{0}()
 Base.length(g::ZeroDimGrid) = 1
 Base.size(g::ZeroDimGrid) = ()
+
+
+refine(g::ZeroDimGrid, ::Int) = g
+coarsen(g::ZeroDimGrid, ::Int) = g
+
+boundary_identifiers(g::ZeroDimGrid) = ()
+boundary_grid(g::ZeroDimGrid, ::Any) = throw(ArgumentError("ZeroDimGrid has no boundaries"))
--- a/test/Grids/tensor_grid_test.jl	Fri Feb 24 21:48:01 2023 +0100
+++ b/test/Grids/tensor_grid_test.jl	Fri Feb 24 21:54:39 2023 +0100
@@ -80,8 +80,8 @@
         @test refine(TensorGrid(g1(11), g2(6)),1) == TensorGrid(g1(11), g2(6))
         @test refine(TensorGrid(g1(11), g2(6)),2) == TensorGrid(g1(21), g2(11))
         @test refine(TensorGrid(g1(11), g2(6)),3) == TensorGrid(g1(31), g2(16))
-        @test_broken refine(TensorGrid(g1(11), g₄), 1) == TensorGrid(g1(11), g₄)
-        @test_broken refine(TensorGrid(g1(11), g₄), 2) == TensorGrid(g1(21), g₄)
+        @test refine(TensorGrid(g1(11), g₄), 1) == TensorGrid(g1(11), g₄)
+        @test refine(TensorGrid(g1(11), g₄), 2) == TensorGrid(g1(21), g₄)
     end
 
     @testset "coarsen" begin
@@ -91,13 +91,13 @@
         @test coarsen(TensorGrid(g1(11), g2(6)),1) == TensorGrid(g1(11), g2(6))
         @test coarsen(TensorGrid(g1(21), g2(11)),2) == TensorGrid(g1(11), g2(6))
         @test coarsen(TensorGrid(g1(31), g2(16)),3) == TensorGrid(g1(11), g2(6))
-        @test_broken coarsen(TensorGrid(g1(11), g₄), 1) == TensorGrid(g1(11), g₄)
-        @test_broken coarsen(TensorGrid(g1(21), g₄), 2) == TensorGrid(g1(11), g₄)
+        @test coarsen(TensorGrid(g1(11), g₄), 1) == TensorGrid(g1(11), g₄)
+        @test coarsen(TensorGrid(g1(21), g₄), 2) == TensorGrid(g1(11), g₄)
     end
 
     @testset "boundary_identifiers" begin
         @test boundary_identifiers(TensorGrid(g₁, g₂)) == map((n,id)->TensorGridBoundary{n,id}(), (1,1,2,2), (Lower,Upper,Lower,Upper))
-        @test_broken boundary_identifiers(TensorGrid(g₁, g₄)) == (TensorGridBoundary{1,Lower}(),TensorGridBoundary{1,Upper}())
+        @test boundary_identifiers(TensorGrid(g₁, g₄)) == (TensorGridBoundary{1,Lower}(),TensorGridBoundary{1,Upper}())
     end
 
     @testset "boundary_grid" begin
--- a/test/Grids/zero_dim_grid_test.jl	Fri Feb 24 21:48:01 2023 +0100
+++ b/test/Grids/zero_dim_grid_test.jl	Fri Feb 24 21:54:39 2023 +0100
@@ -25,19 +25,20 @@
     end
 
     @testset "refine" begin
-        @test_broken false
+        @test refine(ZeroDimGrid(@SVector[1.0,2.0]),1) == ZeroDimGrid(@SVector[1.0,2.0])
+        @test refine(ZeroDimGrid(@SVector[1.0,2.0]),2) == ZeroDimGrid(@SVector[1.0,2.0])
     end
 
     @testset "coarsen" begin
-        @test_broken false
+        @test coarsen(ZeroDimGrid(@SVector[1.0,2.0]),1) == ZeroDimGrid(@SVector[1.0,2.0])
+        @test coarsen(ZeroDimGrid(@SVector[1.0,2.0]),2) == ZeroDimGrid(@SVector[1.0,2.0])
     end
 
     @testset "boundary_identifiers" begin
-        @test_broken false
+        @test boundary_identifiers(ZeroDimGrid(@SVector[1.0,2.0])) == ()
     end
 
     @testset "boundary_grid" begin
-        @test_broken false
-        # Test that it throws an error
+        @test_throws ArgumentError("ZeroDimGrid has no boundaries") boundary_grid(ZeroDimGrid(@SVector[1.0,2.0]), :bid)
     end
 end