Mercurial > repos > public > sbplib_julia
comparison src/Grids/equidistant_grid.jl @ 1128:dfbd62c7eb09 feature/grids
Rename dim to ndims in Grids.jl
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Wed, 05 Oct 2022 22:00:30 +0200 |
parents | 832ac87a54a3 |
children | 9275d95e2d90 102ebdaf7c11 |
comparison
equal
deleted
inserted
replaced
1127:5490d0a38007 | 1128:dfbd62c7eb09 |
---|---|
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 |
166 See also: [`coarsen`](@ref) | 163 See also: [`coarsen`](@ref) |
167 """ | 164 """ |
168 function refine(grid::EquidistantGrid, r::Int) | 165 function refine(grid::EquidistantGrid, r::Int) |
169 sz = size(grid) | 166 sz = size(grid) |
170 new_sz = (sz .- 1).*r .+ 1 | 167 new_sz = (sz .- 1).*r .+ 1 |
171 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) |
172 end | 169 end |
173 | 170 |
174 | 171 |
175 """ | 172 """ |
176 coarsen(grid::EquidistantGrid, r::Int) | 173 coarsen(grid::EquidistantGrid, r::Int) |
188 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.")) |
189 end | 186 end |
190 | 187 |
191 new_sz = (sz .- 1).÷r .+ 1 | 188 new_sz = (sz .- 1).÷r .+ 1 |
192 | 189 |
193 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) |
194 end | 191 end |