comparison src/Grids/equidistant_grid.jl @ 1133:a8c8517a310f feature/boundary_conditions

Merge with default
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Wed, 05 Oct 2022 22:05:23 +0200
parents dfbd62c7eb09
children 9275d95e2d90 102ebdaf7c11
comparison
equal deleted inserted replaced
1132:302d36b5ba8e 1133:a8c8517a310f
60 60
61 Base.eachindex(grid::EquidistantGrid) = CartesianIndices(grid.size) 61 Base.eachindex(grid::EquidistantGrid) = CartesianIndices(grid.size)
62 62
63 Base.size(g::EquidistantGrid) = g.size 63 Base.size(g::EquidistantGrid) = g.size
64 64
65 Base.ndims(::EquidistantGrid{Dim}) where Dim = Dim
65 66
66 """
67 dim(grid::EquidistantGrid)
68 67
69 The dimension of the grid. 68
70 """
71 dim(::EquidistantGrid{Dim}) where Dim = Dim
72 69
73 70
74 """ 71 """
75 spacing(grid::EquidistantGrid) 72 spacing(grid::EquidistantGrid)
76 73
138 (CartesianBoundary(1,Lower), 135 (CartesianBoundary(1,Lower),
139 CartesianBoundary(1,Upper), 136 CartesianBoundary(1,Upper),
140 CartesianBoundary(2,Lower), 137 CartesianBoundary(2,Lower),
141 ...) 138 ...)
142 """ 139 """
143 boundary_identifiers(g::EquidistantGrid) = (((ntuple(i->(CartesianBoundary{i,Lower}(),CartesianBoundary{i,Upper}()),dim(g)))...)...,) 140 boundary_identifiers(g::EquidistantGrid) = (((ntuple(i->(CartesianBoundary{i,Lower}(),CartesianBoundary{i,Upper}()),ndims(g)))...)...,)
144 141
145 142
146 """ 143 """
147 boundary_grid(grid::EquidistantGrid, id::CartesianBoundary) 144 boundary_grid(grid::EquidistantGrid, id::CartesianBoundary)
148 145
156 end 153 end
157 boundary_grid(::EquidistantGrid{1,T},::CartesianBoundary{1}) where T = EquidistantGrid{T}() 154 boundary_grid(::EquidistantGrid{1,T},::CartesianBoundary{1}) where T = EquidistantGrid{T}()
158 155
159 156
160 """ 157 """
161 boundary_size(grid::EquidistantGrid, id::CartesianBoundary)
162
163 Returns the size of the boundary of `grid` specified by `id`.
164 """
165 function boundary_size(grid::EquidistantGrid, id::CartesianBoundary)
166 orth_dims = orthogonal_dims(grid, dim(id))
167 return grid.size[orth_dims]
168 end
169 boundary_size(::EquidistantGrid{1,T},::CartesianBoundary{1}) where T = ()
170
171
172 """
173 refine(grid::EquidistantGrid, r::Int) 158 refine(grid::EquidistantGrid, r::Int)
174 159
175 Refines `grid` by a factor `r`. The factor is applied to the number of 160 Refines `grid` by a factor `r`. The factor is applied to the number of
176 intervals which is 1 less than the size of the grid. 161 intervals which is 1 less than the size of the grid.
177 162
178 See also: [`coarsen`](@ref) 163 See also: [`coarsen`](@ref)
179 """ 164 """
180 function refine(grid::EquidistantGrid, r::Int) 165 function refine(grid::EquidistantGrid, r::Int)
181 sz = size(grid) 166 sz = size(grid)
182 new_sz = (sz .- 1).*r .+ 1 167 new_sz = (sz .- 1).*r .+ 1
183 return EquidistantGrid{dim(grid), eltype(grid)}(new_sz, grid.limit_lower, grid.limit_upper) 168 return EquidistantGrid{ndims(grid), eltype(grid)}(new_sz, grid.limit_lower, grid.limit_upper)
184 end 169 end
185 170
186 171
187 """ 172 """
188 coarsen(grid::EquidistantGrid, r::Int) 173 coarsen(grid::EquidistantGrid, r::Int)
200 throw(DomainError(r, "Size minus 1 must be divisible by the ratio.")) 185 throw(DomainError(r, "Size minus 1 must be divisible by the ratio."))
201 end 186 end
202 187
203 new_sz = (sz .- 1).÷r .+ 1 188 new_sz = (sz .- 1).÷r .+ 1
204 189
205 return EquidistantGrid{dim(grid), eltype(grid)}(new_sz, grid.limit_lower, grid.limit_upper) 190 return EquidistantGrid{ndims(grid), eltype(grid)}(new_sz, grid.limit_lower, grid.limit_upper)
206 end 191 end