Mercurial > repos > public > sbplib_julia
comparison Grids/src/EquidistantGrid.jl @ 261:01017d2b46b0 boundary_conditions
Store grid spacing as property in EquidistantGrid
| author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
|---|---|
| date | Tue, 26 Nov 2019 08:19:22 -0800 |
| parents | d8f42733f392 |
| children | f67ce2eb6019 |
comparison
equal
deleted
inserted
replaced
| 260:f89718833620 | 261:01017d2b46b0 |
|---|---|
| 8 | 8 |
| 9 struct EquidistantGrid{Dim,T<:Real} <: AbstractGrid | 9 struct EquidistantGrid{Dim,T<:Real} <: AbstractGrid |
| 10 size::NTuple{Dim, Int} # First coordinate direction stored first | 10 size::NTuple{Dim, Int} # First coordinate direction stored first |
| 11 limit_lower::NTuple{Dim, T} | 11 limit_lower::NTuple{Dim, T} |
| 12 limit_upper::NTuple{Dim, T} | 12 limit_upper::NTuple{Dim, T} |
| 13 inverse_spacing::NTuple{Dim, T} # The reciprocal of the grid spacing | 13 spacing::NTuple{Dim, T} # Grid spacing |
| 14 inverse_spacing::NTuple{Dim, T} # Reciprocal of grid spacing | |
| 14 | 15 |
| 15 # General constructor | 16 # General constructor |
| 16 function EquidistantGrid(size::NTuple{Dim, Int}, limit_lower::NTuple{Dim, T}, limit_upper::NTuple{Dim, T}) where Dim where T | 17 function EquidistantGrid(size::NTuple{Dim, Int}, limit_lower::NTuple{Dim, T}, limit_upper::NTuple{Dim, T}) where Dim where T |
| 17 @assert all(size.>0) | 18 @assert all(size.>0) |
| 18 @assert all(limit_upper.-limit_lower .!= 0) | 19 @assert all(limit_upper.-limit_lower .!= 0) |
| 19 inverse_spacing = (size.-1)./abs.(limit_upper.-limit_lower) | 20 spacing = abs.(limit_upper.-limit_lower)./(size.-1) |
| 20 return new{Dim,T}(size, limit_lower, limit_upper, inverse_spacing) | 21 inverse_spacing = 1.0./spacing |
| 22 return new{Dim,T}(size, limit_lower, limit_upper, spacing, inverse_spacing) | |
| 21 end | 23 end |
| 22 end | 24 end |
| 23 | 25 |
| 24 function Base.eachindex(grid::EquidistantGrid) | 26 function Base.eachindex(grid::EquidistantGrid) |
| 25 CartesianIndices(grid.size) | 27 CartesianIndices(grid.size) |
| 33 # @Return: dimension - The dimension of the grid | 35 # @Return: dimension - The dimension of the grid |
| 34 function dimension(grid::EquidistantGrid) | 36 function dimension(grid::EquidistantGrid) |
| 35 return length(grid.size) | 37 return length(grid.size) |
| 36 end | 38 end |
| 37 | 39 |
| 38 # Returns the spacing of the grid | 40 # TODO: Keep the below functions or just use properties? |
| 41 # Returns the reciprocal of the spacing of the grid | |
| 42 # | |
| 43 function inverse_spacing(grid::EquidistantGrid) | |
| 44 return grid.inverse_spacing | |
| 45 end | |
| 46 export inverse_spacing | |
| 47 | |
| 48 # Returns the reciprocal of the spacing of the grid | |
| 39 # | 49 # |
| 40 function spacing(grid::EquidistantGrid) | 50 function spacing(grid::EquidistantGrid) |
| 41 return 1.0./grid.inverse_spacing | 51 return grid.spacing |
| 42 end | 52 end |
| 43 export spacing | 53 export spacing |
| 44 | 54 |
| 45 # Computes the points of an EquidistantGrid as an array of tuples with | 55 # Computes the points of an EquidistantGrid as an array of tuples with |
| 46 # the same dimension as the grid. | 56 # the same dimension as the grid. |
