comparison src/Grids/EquidistantGrid.jl @ 769:0158c3fd521c operator_storage_array_of_table

Merge in default
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 15 Jul 2021 00:06:16 +0200
parents e9e46a587370
children dd2ab001a7b6
comparison
equal deleted inserted replaced
768:7c87a33963c5 769:0158c3fd521c
1 """ 1 """
2 EquidistantGrid(size::NTuple{Dim, Int}, limit_lower::NTuple{Dim, T}, limit_upper::NTuple{Dim, T} 2 EquidistantGrid(size::NTuple{Dim, Int}, limit_lower::NTuple{Dim, T}, limit_upper::NTuple{Dim, T})
3 EquidistantGrid{T}()
3 4
4 EquidistantGrid is a grid with equidistant grid spacing per coordinat direction. 5 `EquidistantGrid` is a grid with equidistant grid spacing per coordinat direction.
5 The domain is defined through the two points P1 = x̄₁, P2 = x̄₂ by the exterior 6
6 product of the vectors obtained by projecting (x̄₂-x̄₁) onto the coordinate 7 `EquidistantGrid(size, limit_lower, limit_upper)` construct the grid with the
7 directions. E.g for a 2D grid with x̄₁=(-1,0) and x̄₂=(1,2) the domain is defined 8 domain defined by the two points P1, and P2 given by `limit_lower` and
8 as (-1,1)x(0,2). The side lengths of the grid are not allowed to be negative 9 `limit_upper`. The length of the domain sides are given by the components of
10 (P2-P1). E.g for a 2D grid with P1=(-1,0) and P2=(1,2) the domain is defined
11 as (-1,1)x(0,2). The side lengths of the grid are not allowed to be negative.
12 The number of equidistantly spaced points in each coordinate direction are given
13 by `size`.
14
15 `EquidistantGrid{T}()` constructs a 0-dimensional grid.
16
9 """ 17 """
10 struct EquidistantGrid{Dim,T<:Real} <: AbstractGrid 18 struct EquidistantGrid{Dim,T<:Real} <: AbstractGrid
11 size::NTuple{Dim, Int} 19 size::NTuple{Dim, Int}
12 limit_lower::NTuple{Dim, T} 20 limit_lower::NTuple{Dim, T}
13 limit_upper::NTuple{Dim, T} 21 limit_upper::NTuple{Dim, T}
20 if any(limit_upper.-limit_lower .<= 0) 28 if any(limit_upper.-limit_lower .<= 0)
21 throw(DomainError("all side lengths must be postive")) 29 throw(DomainError("all side lengths must be postive"))
22 end 30 end
23 return new{Dim,T}(size, limit_lower, limit_upper) 31 return new{Dim,T}(size, limit_lower, limit_upper)
24 end 32 end
33
34 # Specialized constructor for 0-dimensional grid
35 EquidistantGrid{T}() where T = new{0,T}((),(),())
25 end 36 end
26 export EquidistantGrid 37 export EquidistantGrid
27 38
28 39
29 """ 40 """
33 """ 44 """
34 function EquidistantGrid(size::Int, limit_lower::T, limit_upper::T) where T 45 function EquidistantGrid(size::Int, limit_lower::T, limit_upper::T) where T
35 return EquidistantGrid((size,),(limit_lower,),(limit_upper,)) 46 return EquidistantGrid((size,),(limit_lower,),(limit_upper,))
36 end 47 end
37 48
38 function Base.eachindex(grid::EquidistantGrid) 49 Base.eltype(grid::EquidistantGrid{Dim,T}) where {Dim,T} = T
39 CartesianIndices(grid.size) 50
40 end 51 Base.eachindex(grid::EquidistantGrid) = CartesianIndices(grid.size)
41 52
42 Base.size(g::EquidistantGrid) = g.size 53 Base.size(g::EquidistantGrid) = g.size
43 54
44 """ 55 """
45 dimension(grid::EquidistantGrid) 56 dimension(grid::EquidistantGrid)
102 CartesianBoundary(2,Lower), 113 CartesianBoundary(2,Lower),
103 ...) 114 ...)
104 """ 115 """
105 boundary_identifiers(g::EquidistantGrid) = (((ntuple(i->(CartesianBoundary{i,Lower}(),CartesianBoundary{i,Upper}()),dimension(g)))...)...,) 116 boundary_identifiers(g::EquidistantGrid) = (((ntuple(i->(CartesianBoundary{i,Lower}(),CartesianBoundary{i,Upper}()),dimension(g)))...)...,)
106 export boundary_identifiers 117 export boundary_identifiers
118
119
120 """
121 boundary_grid(grid::EquidistantGrid,id::CartesianBoundary)
122 boundary_grid(::EquidistantGrid{1},::CartesianBoundary{1})
123
124 Creates the lower-dimensional restriciton of `grid` spanned by the dimensions
125 orthogonal to the boundary specified by `id`. The boundary grid of a 1-dimensional
126 grid is a zero-dimensional grid.
127 """
128 function boundary_grid(grid::EquidistantGrid,id::CartesianBoundary)
129 dims = collect(1:dimension(grid))
130 orth_dims = dims[dims .!= dim(id)]
131 if orth_dims == dims
132 throw(DomainError("boundary identifier not matching grid"))
133 end
134 return restrict(grid,orth_dims)
135 end
136 export boundary_grid
137 boundary_grid(::EquidistantGrid{1,T},::CartesianBoundary{1}) where T = EquidistantGrid{T}()