Mercurial > repos > public > sbplib_julia
diff src/Grids/EquidistantGrid.jl @ 680:1d3e29ffc6c6 feature/boundary_quads
Add support for 0-dimensional grid, and add method boundary_grid
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Mon, 08 Feb 2021 18:43:38 +0100 |
parents | f0ceddeae993 |
children | 3ed922e95a35 |
line wrap: on
line diff
--- a/src/Grids/EquidistantGrid.jl Sun Feb 07 21:28:53 2021 +0100 +++ b/src/Grids/EquidistantGrid.jl Mon Feb 08 18:43:38 2021 +0100 @@ -22,6 +22,13 @@ end return new{Dim,T}(size, limit_lower, limit_upper) end + + # Special constructor for 0-dimensional grids. + function EquidistantGrid(size::Tuple{}, limit_lower::Tuple{}, limit_upper::Tuple{}) + #TODO: Need to specialize T. + # Is Float64 a good choice here? How to propage from arguments? + return new{0,Float64}(size, limit_lower, limit_upper) + end end export EquidistantGrid @@ -104,3 +111,21 @@ """ boundary_identifiers(g::EquidistantGrid) = (((ntuple(i->(CartesianBoundary{i,Lower}(),CartesianBoundary{i,Upper}()),dimension(g)))...)...,) export boundary_identifiers + + +""" + boundary_grid(grid::EquidistantGrid,id::CartesianBoundary) + boundary_grid(::EquidistantGrid{1},::CartesianBoundary{1}) + +Creates the lower-dimensional restriciton of `grid` spanned by the dimensions +orthogonal to the boundary specified by `id`. The boundary grid of a 1-dimensional +grid is a zero-dimensional grid. +""" +function boundary_grid(grid::EquidistantGrid,id::CartesianBoundary) + dims = collect(1:dimension(grid)) + orth_dims = dims[dims .!= dim(id)] + return restrict(grid,orth_dims) +end +export boundary_grid +boundary_grid(::EquidistantGrid{1},::CartesianBoundary{1}) = EquidistantGrid((),(),()) +boundary_grid(::EquidistantGrid{1},::CartesianBoundary) = throw(DimensionMismatch("dimension of Grid and BoundaryIdentifier not matching"))