comparison src/Grids/EquidistantGrid.jl @ 909:b900fea1c057 feature/equidistant_grid/refine

Clean up the docs a bit
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 15 Feb 2022 12:57:41 +0100
parents bc71dd5b8311
children 9b40aeac4269 5b3d4a8ec3ab
comparison
equal deleted inserted replaced
908:bc71dd5b8311 909:b900fea1c057
6 export boundary_grid 6 export boundary_grid
7 export refine 7 export refine
8 export coarsen 8 export coarsen
9 9
10 """ 10 """
11 EquidistantGrid(size::NTuple{Dim, Int}, limit_lower::NTuple{Dim, T}, limit_upper::NTuple{Dim, T}) 11 EquidistantGrid{Dim,T<:Real} <: AbstractGrid
12 EquidistantGrid{T}()
13 12
14 `EquidistantGrid` is a grid with equidistant grid spacing per coordinat direction. 13 `Dim`-dimensional equidistant grid with coordinates of type `T`.
15
16 `EquidistantGrid(size, limit_lower, limit_upper)` construct the grid with the
17 domain defined by the two points P1, and P2 given by `limit_lower` and
18 `limit_upper`. The length of the domain sides are given by the components of
19 (P2-P1). E.g for a 2D grid with P1=(-1,0) and P2=(1,2) the domain is defined
20 as (-1,1)x(0,2). The side lengths of the grid are not allowed to be negative.
21 The number of equidistantly spaced points in each coordinate direction are given
22 by `size`.
23
24 `EquidistantGrid{T}()` constructs a 0-dimensional grid.
25
26 """ 14 """
27 struct EquidistantGrid{Dim,T<:Real} <: AbstractGrid 15 struct EquidistantGrid{Dim,T<:Real} <: AbstractGrid
28 size::NTuple{Dim, Int} 16 size::NTuple{Dim, Int}
29 limit_lower::NTuple{Dim, T} 17 limit_lower::NTuple{Dim, T}
30 limit_upper::NTuple{Dim, T} 18 limit_upper::NTuple{Dim, T}
31 19
32 # General constructor
33 function EquidistantGrid{Dim,T}(size::NTuple{Dim, Int}, limit_lower::NTuple{Dim, T}, limit_upper::NTuple{Dim, T}) where {Dim,T} 20 function EquidistantGrid{Dim,T}(size::NTuple{Dim, Int}, limit_lower::NTuple{Dim, T}, limit_upper::NTuple{Dim, T}) where {Dim,T}
34 if any(size .<= 0) 21 if any(size .<= 0)
35 throw(DomainError("all components of size must be postive")) 22 throw(DomainError("all components of size must be postive"))
36 end 23 end
37 if any(limit_upper.-limit_lower .<= 0) 24 if any(limit_upper.-limit_lower .<= 0)
39 end 26 end
40 return new{Dim,T}(size, limit_lower, limit_upper) 27 return new{Dim,T}(size, limit_lower, limit_upper)
41 end 28 end
42 end 29 end
43 30
31 """
32 EquidistantGrid(size, limit_lower, limit_upper)
33
34 Construct an equidistant grid with corners at the coordinates `limit_lower` and
35 `limit_upper`.
36
37 The length of the domain sides are given by the components of
38 `limit_upper-limit_lower`. E.g for a 2D grid with `limit_lower=(-1,0)` and `limit_upper=(1,2)` the domain is defined
39 as `(-1,1)x(0,2)`. The side lengths of the grid are not allowed to be negative.
40
41 The number of equidistantly spaced points in each coordinate direction are given
42 by the tuple `size`.
43 """
44 function EquidistantGrid(size, limit_lower, limit_upper) 44 function EquidistantGrid(size, limit_lower, limit_upper)
45 return EquidistantGrid{length(size), eltype(limit_lower)}(size, limit_lower, limit_upper) 45 return EquidistantGrid{length(size), eltype(limit_lower)}(size, limit_lower, limit_upper)
46 end 46 end
47
48 """
49 EquidistantGrid{T}()
50
51 Constructs a 0-dimensional grid.
52 """
47 EquidistantGrid{T}() where T = EquidistantGrid{0,T}((),(),()) # Convenience constructor for 0-dim grid 53 EquidistantGrid{T}() where T = EquidistantGrid{0,T}((),(),()) # Convenience constructor for 0-dim grid
48 54
49 """ 55 """
50 EquidistantGrid(size::Int, limit_lower::T, limit_upper::T) 56 EquidistantGrid(size::Int, limit_lower::T, limit_upper::T)
51 57
69 dimension(grid::EquidistantGrid{Dim}) where Dim = Dim 75 dimension(grid::EquidistantGrid{Dim}) where Dim = Dim
70 76
71 """ 77 """
72 spacing(grid::EquidistantGrid) 78 spacing(grid::EquidistantGrid)
73 79
74 The spacing between the grid points of the grid. 80 The spacing between grid points.
75 """ 81 """
76 spacing(grid::EquidistantGrid) = (grid.limit_upper.-grid.limit_lower)./(grid.size.-1) 82 spacing(grid::EquidistantGrid) = (grid.limit_upper.-grid.limit_lower)./(grid.size.-1)
77 83
78 """ 84 """
79 inverse_spacing(grid::EquidistantGrid) 85 inverse_spacing(grid::EquidistantGrid)
80 86
81 The reciprocal of the spacing between the grid points of the grid. 87 The reciprocal of the spacing between grid points.
82 """ 88 """
83 inverse_spacing(grid::EquidistantGrid) = 1 ./ spacing(grid) 89 inverse_spacing(grid::EquidistantGrid) = 1 ./ spacing(grid)
84 90
85 """ 91 """
86 points(grid::EquidistantGrid) 92 points(grid::EquidistantGrid)
98 end 104 end
99 105
100 """ 106 """
101 restrict(::EquidistantGrid, dim) 107 restrict(::EquidistantGrid, dim)
102 108
103 Pick out given dimensions from the grid and return a grid for them 109 Pick out given dimensions from the grid and return a grid for them.
104 """ 110 """
105 function restrict(grid::EquidistantGrid, dim) 111 function restrict(grid::EquidistantGrid, dim)
106 size = grid.size[dim] 112 size = grid.size[dim]
107 limit_lower = grid.limit_lower[dim] 113 limit_lower = grid.limit_lower[dim]
108 limit_upper = grid.limit_upper[dim] 114 limit_upper = grid.limit_upper[dim]