changeset 1448:0322c181a1cd feature/grids/curvilinear

Merge default
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 22 Nov 2023 17:53:31 +0100
parents 433245fd33c0 (current diff) f217c6167952 (diff)
children a0b1449dba4e
files src/Grids/tensor_grid.jl test/Grids/tensor_grid_test.jl
diffstat 4 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/Grids/equidistant_grid.jl	Thu Sep 07 16:51:46 2023 +0200
+++ b/src/Grids/equidistant_grid.jl	Wed Nov 22 17:53:31 2023 +0100
@@ -29,6 +29,7 @@
 Base.IteratorSize(::Type{<:EquidistantGrid}) = Base.HasShape{1}()
 Base.length(g::EquidistantGrid) = length(g.points)
 Base.size(g::EquidistantGrid) = size(g.points)
+Base.size(g::EquidistantGrid, d) = size(g.points)[d]
 
 
 """
--- a/src/Grids/tensor_grid.jl	Thu Sep 07 16:51:46 2023 +0200
+++ b/src/Grids/tensor_grid.jl	Wed Nov 22 17:53:31 2023 +0100
@@ -47,6 +47,7 @@
 Base.IteratorSize(::Type{<:TensorGrid{<:Any, D}}) where D = Base.HasShape{D}()
 Base.length(g::TensorGrid) = prod(length, g.grids)
 Base.size(g::TensorGrid) = LazyTensors.concatenate_tuples(size.(g.grids)...)
+Base.size(g::TensorGrid, d) = size(g)[d]
 
 
 refine(g::TensorGrid, r::Int) = mapreduce(g->refine(g,r), TensorGrid, g.grids)
--- a/test/Grids/equidistant_grid_test.jl	Thu Sep 07 16:51:46 2023 +0200
+++ b/test/Grids/equidistant_grid_test.jl	Wed Nov 22 17:53:31 2023 +0100
@@ -31,6 +31,8 @@
         @test size(EquidistantGrid(0:10)) == (11,)
         @test size(EquidistantGrid(0:0.1:10)) == (101,)
 
+        @test size(EquidistantGrid(0:0.1:10),1) == 101
+
         @test collect(EquidistantGrid(0:0.1:0.5)) == [0.0, 0.1, 0.2, 0.3, 0.4, 0.5]
 
         @test Base.IteratorSize(EquidistantGrid{Float64, StepRange{Float64}}) == Base.HasShape{1}()
@@ -107,8 +109,13 @@
     @testset "Base" begin
         @test eltype(equidistant_grid(4,0.0,1.0)) == Float64
         @test eltype(equidistant_grid((4,3),(0,0),(1,3))) <: AbstractVector{Float64}
+
         @test size(equidistant_grid(4,0.0,1.0)) == (4,)
         @test size(equidistant_grid((5,3), (0.0,0.0), (2.0,1.0))) == (5,3)
+
+        @test size(equidistant_grid((5,3), (0.0,0.0), (2.0,1.0)),1) == 5
+        @test size(equidistant_grid((5,3), (0.0,0.0), (2.0,1.0)),2) == 3
+
         @test ndims(equidistant_grid(4,0.0,1.0)) == 1
         @test ndims(equidistant_grid((5,3), (0.0,0.0), (2.0,1.0))) == 2
     end
--- a/test/Grids/tensor_grid_test.jl	Thu Sep 07 16:51:46 2023 +0200
+++ b/test/Grids/tensor_grid_test.jl	Wed Nov 22 17:53:31 2023 +0100
@@ -97,6 +97,12 @@
         @test size(TensorGrid(g₁, g₄)) == (11,)
         @test size(TensorGrid(g₁, g₄, g₂)) == (11,6)
 
+        @test size(TensorGrid(g₁, g₂, g₃),1) == 11
+        @test size(TensorGrid(g₁, g₂, g₃),2) == 6
+        @test size(TensorGrid(g₁, g₂, g₃),3) == 10
+        @test size(TensorGrid(g₁, g₄, g₂),1) == 11
+        @test size(TensorGrid(g₁, g₄, g₂),2) == 6
+
         @test length(TensorGrid(g₁, g₂)) == 66
         @test length(TensorGrid(g₁, g₃)) == 110
         @test length(TensorGrid(g₁, g₂, g₃)) == 660