changeset 1091:e3b41d48b5aa feature/variable_derivatives

Merge refactor/grids
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 26 Apr 2022 14:29:08 +0200
parents de972d825289 (current diff) 9b40aeac4269 (diff)
children 703eaa3e50c4
files
diffstat 2 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/Grids/EquidistantGrid.jl	Tue Apr 12 22:17:41 2022 +0200
+++ b/src/Grids/EquidistantGrid.jl	Tue Apr 26 14:29:08 2022 +0200
@@ -67,6 +67,11 @@
 
 Base.size(g::EquidistantGrid) = g.size
 
+function Base.getindex(g::EquidistantGrid, I...)
+    h = spacing(g)
+    return g.limit_lower .+ (I.-1).*h
+end
+
 """
     dimension(grid::EquidistantGrid)
 
--- a/test/Grids/EquidistantGrid_test.jl	Tue Apr 12 22:17:41 2022 +0200
+++ b/test/Grids/EquidistantGrid_test.jl	Tue Apr 26 14:29:08 2022 +0200
@@ -43,6 +43,17 @@
         @test [gp[i]...] ≈ [p[i]...] atol=5e-13
     end
 
+
+    @testset "getindex" begin
+        g = EquidistantGrid((5,3), (-1.0,0.0), (0.0,7.11))
+        @test g[1,1] == (-1.0,0.0)
+        @test g[1,3] == (-1.0,7.11)
+        @test g[5,1] == (0.0,0.0)
+        @test g[5,3] == (0.0,7.11)
+
+        @test g[4,2] == (-0.25,7.11/2)
+    end
+
     # restrict
     g = EquidistantGrid((5,3), (0.0,0.0), (2.0,1.0))
     @test restrict(g, 1) == EquidistantGrid(5,0.0,2.0)