Mercurial > repos > public > sbplib_julia
comparison 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 |
comparison
equal
deleted
inserted
replaced
231:fbabfd4e8f20 | 291:0f94dc29c4bf |
---|---|
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 inverse_spacing::NTuple{Dim, T} # Reciprocal of grid spacing |
14 | 14 |
15 # General constructor | 15 # General constructor |
16 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 |
17 @assert all(size.>0) | 17 @assert all(size.>0) |
18 @assert all(limit_upper.-limit_lower .!= 0) | 18 @assert all(limit_upper.-limit_lower .!= 0) |
19 inverse_spacing = (size.-1)./abs.(limit_upper.-limit_lower) | 19 inverse_spacing = (size.-1)./ abs.(limit_upper.-limit_lower) |
20 return new{Dim,T}(size, limit_lower, limit_upper, inverse_spacing) | 20 return new{Dim,T}(size, limit_lower, limit_upper, inverse_spacing) |
21 end | 21 end |
22 end | 22 end |
23 | 23 |
24 function Base.eachindex(grid::EquidistantGrid) | 24 function Base.eachindex(grid::EquidistantGrid) |
25 CartesianIndices(grid.size) | 25 CartesianIndices(grid.size) |
26 end | 26 end |
27 | |
28 Base.size(g::EquidistantGrid) = g.size | |
27 | 29 |
28 # Returns the number of dimensions of an EquidistantGrid. | 30 # Returns the number of dimensions of an EquidistantGrid. |
29 # | 31 # |
30 # @Input: grid - an EquidistantGrid | 32 # @Input: grid - an EquidistantGrid |
31 # @Return: dimension - The dimension of the grid | 33 # @Return: dimension - The dimension of the grid |
32 function dimension(grid::EquidistantGrid) | 34 function dimension(grid::EquidistantGrid) |
33 return length(grid.size) | 35 return length(grid.size) |
34 end | 36 end |
35 | 37 |
36 # Returns the spacing of the grid | 38 # Returns the reciprocal of the spacing of the grid |
37 # | 39 # |
40 function inverse_spacing(grid::EquidistantGrid) | |
41 return grid.inverse_spacing | |
42 end | |
43 export inverse_spacing | |
44 | |
45 # Returns the reciprocal of the spacing of the grid | |
46 # | |
47 # TODO: Evaluate if divisions affect performance | |
38 function spacing(grid::EquidistantGrid) | 48 function spacing(grid::EquidistantGrid) |
39 return 1.0./grid.inverse_spacing | 49 return 1.0./grid.inverse_spacing |
40 end | 50 end |
51 export spacing | |
41 | 52 |
42 # Computes the points of an EquidistantGrid as an array of tuples with | 53 # Computes the points of an EquidistantGrid as an array of tuples with |
43 # the same dimension as the grid. | 54 # the same dimension as the grid. |
44 # | 55 # |
45 # @Input: grid - an EquidistantGrid | 56 # @Input: grid - an EquidistantGrid |