changeset 1113:4e4c5011140d feature/grids

Add functions orthogonal_dims and boundary_size
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 14 Jul 2022 18:33:36 +0200
parents 5b3d4a8ec3ab
children fc57804c9bf4
files src/Grids/EquidistantGrid.jl
diffstat 1 files changed, 29 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/Grids/EquidistantGrid.jl	Mon Jul 04 22:55:32 2022 +0200
+++ b/src/Grids/EquidistantGrid.jl	Thu Jul 14 18:33:36 2022 +0200
@@ -2,8 +2,10 @@
 export spacing
 export inverse_spacing
 export restrict
+export orthogonal_dims
 export boundary_identifiers
 export boundary_grid
+export boundary_size
 export refine
 export coarsen
 
@@ -116,6 +118,20 @@
     return EquidistantGrid(size, limit_lower, limit_upper)
 end
 
+"""
+    orthogonal_dims(grid::EquidistantGrid,dim)
+
+Returns the dimensions of grid orthogonal to that of dim.
+"""
+function orthogonal_dims(grid::EquidistantGrid, dim)
+    dims = 1:dimension(grid)
+    orth_dims = filter(i -> i != dim, dims)
+	if orth_dims == dims
+		throw(DomainError(string("dimension ",string(dim)," not matching grid")))
+	end
+    return orth_dims
+end
+
 
 """
     boundary_identifiers(::EquidistantGrid)
@@ -137,16 +153,22 @@
 grid is a zero-dimensional grid.
 """
 function boundary_grid(grid::EquidistantGrid, id::CartesianBoundary)
-	dims = 1:dimension(grid)
-    # Extract dimensions orthogonal to dim(id)
-    orth_dims = filter(i -> i != dim(id), dims)
-	if orth_dims == dims
-		throw(DomainError("boundary identifier not matching grid"))
-	end
-    return restrict(grid,orth_dims)
+    orth_dims = orthogonal_dims(grid, dim(id))
+    return restrict(grid, orth_dims)
 end
 boundary_grid(::EquidistantGrid{1,T},::CartesianBoundary{1}) where T = EquidistantGrid{T}()
 
+"""
+    boundary_size(grid::EquidistantGrid, id::CartesianBoundary)
+
+Returns the size of the boundary of `grid` specified by `id`.
+"""
+function boundary_size(grid::EquidistantGrid, id::CartesianBoundary)
+	orth_dims = orthogonal_dims(grid, dim(id))
+    return  grid.size[orth_dims]
+end
+boundary_size(::EquidistantGrid{1,T},::CartesianBoundary{1}) where T = ()
+
 
 """
     refine(grid::EquidistantGrid, r::Int)