changeset 352:a18bd337a280 feature/equidistant_grid/subgrid

Add function for getting a one dimensional grid for a given dimension from a equidistant grid
author Jonatan Werpers <jonatan@werpers.com>
date Sun, 27 Sep 2020 14:38:05 +0200
parents 28e71a861531
children 8257cc75ea6b
files src/Grids/EquidistantGrid.jl test/testGrids.jl
diffstat 2 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/Grids/EquidistantGrid.jl	Sun Sep 27 13:47:40 2020 +0200
+++ b/src/Grids/EquidistantGrid.jl	Sun Sep 27 14:38:05 2020 +0200
@@ -66,6 +66,15 @@
     return broadcast(I -> grid.limit_lower .+ (I.-1).*h, indices)
 end
 
+function subgrid(grid::EquidistantGrid, dim::Integer)
+    size = grid.size[dim]
+    limit_lower = grid.limit_lower[dim]
+    limit_upper = grid.limit_upper[dim]
+
+    return EquidistantGrid(size, limit_lower, limit_upper)
+end
+export subgrid
+
 function pointsalongdim(grid::EquidistantGrid, dim::Integer)
     @assert dim<=dimension(grid)
     @assert dim>0
--- a/test/testGrids.jl	Sun Sep 27 13:47:40 2020 +0200
+++ b/test/testGrids.jl	Sun Sep 27 14:38:05 2020 +0200
@@ -7,6 +7,10 @@
     @test EquidistantGrid(4,0,1) isa EquidistantGrid
     @test dimension(EquidistantGrid(4,0,1)) == 1
     @test EquidistantGrid(4,0,1) == EquidistantGrid((4,),(0,),(1,))
+
+    g = EquidistantGrid((5,3), (0,0), (2,1))
+    @test subgrid(g, 1) == EquidistantGrid(5,0,2)
+    @test subgrid(g, 2) == EquidistantGrid(3,0,1)
 end
 
 end