Mercurial > repos > public > sbplib_julia
comparison src/Grids/EquidistantGrid.jl @ 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 |
comparison
equal
deleted
inserted
replaced
1111:5b3d4a8ec3ab | 1113:4e4c5011140d |
---|---|
1 export EquidistantGrid | 1 export EquidistantGrid |
2 export spacing | 2 export spacing |
3 export inverse_spacing | 3 export inverse_spacing |
4 export restrict | 4 export restrict |
5 export orthogonal_dims | |
5 export boundary_identifiers | 6 export boundary_identifiers |
6 export boundary_grid | 7 export boundary_grid |
8 export boundary_size | |
7 export refine | 9 export refine |
8 export coarsen | 10 export coarsen |
9 | 11 |
10 """ | 12 """ |
11 EquidistantGrid{Dim,T<:Real} <: AbstractGrid | 13 EquidistantGrid{Dim,T<:Real} <: AbstractGrid |
114 limit_upper = grid.limit_upper[dim] | 116 limit_upper = grid.limit_upper[dim] |
115 | 117 |
116 return EquidistantGrid(size, limit_lower, limit_upper) | 118 return EquidistantGrid(size, limit_lower, limit_upper) |
117 end | 119 end |
118 | 120 |
121 """ | |
122 orthogonal_dims(grid::EquidistantGrid,dim) | |
123 | |
124 Returns the dimensions of grid orthogonal to that of dim. | |
125 """ | |
126 function orthogonal_dims(grid::EquidistantGrid, dim) | |
127 dims = 1:dimension(grid) | |
128 orth_dims = filter(i -> i != dim, dims) | |
129 if orth_dims == dims | |
130 throw(DomainError(string("dimension ",string(dim)," not matching grid"))) | |
131 end | |
132 return orth_dims | |
133 end | |
134 | |
119 | 135 |
120 """ | 136 """ |
121 boundary_identifiers(::EquidistantGrid) | 137 boundary_identifiers(::EquidistantGrid) |
122 | 138 |
123 Returns a tuple containing the boundary identifiers for the grid, stored as | 139 Returns a tuple containing the boundary identifiers for the grid, stored as |
135 Creates the lower-dimensional restriciton of `grid` spanned by the dimensions | 151 Creates the lower-dimensional restriciton of `grid` spanned by the dimensions |
136 orthogonal to the boundary specified by `id`. The boundary grid of a 1-dimensional | 152 orthogonal to the boundary specified by `id`. The boundary grid of a 1-dimensional |
137 grid is a zero-dimensional grid. | 153 grid is a zero-dimensional grid. |
138 """ | 154 """ |
139 function boundary_grid(grid::EquidistantGrid, id::CartesianBoundary) | 155 function boundary_grid(grid::EquidistantGrid, id::CartesianBoundary) |
140 dims = 1:dimension(grid) | 156 orth_dims = orthogonal_dims(grid, dim(id)) |
141 # Extract dimensions orthogonal to dim(id) | 157 return restrict(grid, orth_dims) |
142 orth_dims = filter(i -> i != dim(id), dims) | |
143 if orth_dims == dims | |
144 throw(DomainError("boundary identifier not matching grid")) | |
145 end | |
146 return restrict(grid,orth_dims) | |
147 end | 158 end |
148 boundary_grid(::EquidistantGrid{1,T},::CartesianBoundary{1}) where T = EquidistantGrid{T}() | 159 boundary_grid(::EquidistantGrid{1,T},::CartesianBoundary{1}) where T = EquidistantGrid{T}() |
160 | |
161 """ | |
162 boundary_size(grid::EquidistantGrid, id::CartesianBoundary) | |
163 | |
164 Returns the size of the boundary of `grid` specified by `id`. | |
165 """ | |
166 function boundary_size(grid::EquidistantGrid, id::CartesianBoundary) | |
167 orth_dims = orthogonal_dims(grid, dim(id)) | |
168 return grid.size[orth_dims] | |
169 end | |
170 boundary_size(::EquidistantGrid{1,T},::CartesianBoundary{1}) where T = () | |
149 | 171 |
150 | 172 |
151 """ | 173 """ |
152 refine(grid::EquidistantGrid, r::Int) | 174 refine(grid::EquidistantGrid, r::Int) |
153 | 175 |