Mercurial > repos > public > sbplib_julia
comparison Grids/src/EquidistantGrid.jl @ 268:f67ce2eb6019 boundary_conditions
Remove property spacing in EquidistantGrid, due to redundancy.
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Thu, 05 Dec 2019 09:44:34 +0100 |
parents | 01017d2b46b0 |
children | 12b738f260a0 |
comparison
equal
deleted
inserted
replaced
267:634453a4e1d8 | 268:f67ce2eb6019 |
---|---|
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 spacing::NTuple{Dim, T} # Grid spacing | |
14 inverse_spacing::NTuple{Dim, T} # Reciprocal of grid spacing | 13 inverse_spacing::NTuple{Dim, T} # Reciprocal of grid spacing |
15 | 14 |
16 # General constructor | 15 # General constructor |
17 function EquidistantGrid(size::NTuple{Dim, Int}, limit_lower::NTuple{Dim, T}, limit_upper::NTuple{Dim, T}) where Dim where T | 16 function EquidistantGrid(size::NTuple{Dim, Int}, limit_lower::NTuple{Dim, T}, limit_upper::NTuple{Dim, T}) where Dim where T |
18 @assert all(size.>0) | 17 @assert all(size.>0) |
19 @assert all(limit_upper.-limit_lower .!= 0) | 18 @assert all(limit_upper.-limit_lower .!= 0) |
20 spacing = abs.(limit_upper.-limit_lower)./(size.-1) | 19 inverse_spacing = (size.-1)./ abs.(limit_upper.-limit_lower) |
21 inverse_spacing = 1.0./spacing | 20 return new{Dim,T}(size, limit_lower, limit_upper, inverse_spacing) |
22 return new{Dim,T}(size, limit_lower, limit_upper, spacing, inverse_spacing) | |
23 end | 21 end |
24 end | 22 end |
25 | 23 |
26 function Base.eachindex(grid::EquidistantGrid) | 24 function Base.eachindex(grid::EquidistantGrid) |
27 CartesianIndices(grid.size) | 25 CartesianIndices(grid.size) |
35 # @Return: dimension - The dimension of the grid | 33 # @Return: dimension - The dimension of the grid |
36 function dimension(grid::EquidistantGrid) | 34 function dimension(grid::EquidistantGrid) |
37 return length(grid.size) | 35 return length(grid.size) |
38 end | 36 end |
39 | 37 |
40 # TODO: Keep the below functions or just use properties? | |
41 # Returns the reciprocal of the spacing of the grid | 38 # Returns the reciprocal of the spacing of the grid |
42 # | 39 # |
43 function inverse_spacing(grid::EquidistantGrid) | 40 function inverse_spacing(grid::EquidistantGrid) |
44 return grid.inverse_spacing | 41 return grid.inverse_spacing |
45 end | 42 end |
46 export inverse_spacing | 43 export inverse_spacing |
47 | 44 |
48 # Returns the reciprocal of the spacing of the grid | 45 # Returns the reciprocal of the spacing of the grid |
49 # | 46 # |
50 function spacing(grid::EquidistantGrid) | 47 function spacing(grid::EquidistantGrid) |
51 return grid.spacing | 48 return 1.0./grid.inverse_spacing |
52 end | 49 end |
53 export spacing | 50 export spacing |
54 | 51 |
55 # Computes the points of an EquidistantGrid as an array of tuples with | 52 # Computes the points of an EquidistantGrid as an array of tuples with |
56 # the same dimension as the grid. | 53 # the same dimension as the grid. |