Mercurial > repos > public > sbplib_julia
diff Grids/src/EquidistantGrid.jl @ 291:0f94dc29c4bf
Merge in branch boundary_conditions
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 22 Jun 2020 21:43:05 +0200 |
parents | 12b738f260a0 |
children | 047dee8efaef |
line wrap: on
line diff
--- a/Grids/src/EquidistantGrid.jl Wed Jun 26 15:07:47 2019 +0200 +++ b/Grids/src/EquidistantGrid.jl Mon Jun 22 21:43:05 2020 +0200 @@ -10,13 +10,13 @@ size::NTuple{Dim, Int} # First coordinate direction stored first limit_lower::NTuple{Dim, T} limit_upper::NTuple{Dim, T} - inverse_spacing::NTuple{Dim, T} # The reciprocal of the grid spacing + inverse_spacing::NTuple{Dim, T} # Reciprocal of grid spacing # General constructor function EquidistantGrid(size::NTuple{Dim, Int}, limit_lower::NTuple{Dim, T}, limit_upper::NTuple{Dim, T}) where Dim where T @assert all(size.>0) @assert all(limit_upper.-limit_lower .!= 0) - inverse_spacing = (size.-1)./abs.(limit_upper.-limit_lower) + inverse_spacing = (size.-1)./ abs.(limit_upper.-limit_lower) return new{Dim,T}(size, limit_lower, limit_upper, inverse_spacing) end end @@ -25,6 +25,8 @@ CartesianIndices(grid.size) end +Base.size(g::EquidistantGrid) = g.size + # Returns the number of dimensions of an EquidistantGrid. # # @Input: grid - an EquidistantGrid @@ -33,11 +35,20 @@ return length(grid.size) end -# Returns the spacing of the grid +# Returns the reciprocal of the spacing of the grid # +function inverse_spacing(grid::EquidistantGrid) + return grid.inverse_spacing +end +export inverse_spacing + +# Returns the reciprocal of the spacing of the grid +# +# TODO: Evaluate if divisions affect performance function spacing(grid::EquidistantGrid) return 1.0./grid.inverse_spacing end +export spacing # Computes the points of an EquidistantGrid as an array of tuples with # the same dimension as the grid.