Mercurial > repos > public > sbplib_julia
comparison src/Grids/parameter_space.jl @ 1913:e97f4352b8d0 feature/grids/manifolds
Merge feature/grids/parameter_spaces
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sat, 01 Feb 2025 23:20:31 +0100 |
parents | 09c4fda8779d |
children | 15be190a40cd |
comparison
equal
deleted
inserted
replaced
1903:04c251bccbd4 | 1913:e97f4352b8d0 |
---|---|
1 """ | 1 """ |
2 ParameterSpace{D} | 2 ParameterSpace{D} |
3 | 3 |
4 A space of parameters of dimension `D`. Used with `Chart` to indicate which | 4 A space of parameters of dimension `D`. |
5 parameters are valid for that chart. | |
6 | 5 |
7 Common parameter spaces are created using the functions unit sized spaces | 6 Common parameter spaces are created using functions for unit sized spaces |
8 * `unitinterval` | 7 * [`unitinterval`](@ref) |
9 * `unitrectangle` | 8 * [`unitsquare`](@ref) |
10 * `unitbox` | 9 * [`unitcube`](@ref) |
11 * `unittriangle` | 10 * [`unithyperbox`](@ref) |
12 * `unittetrahedron` | 11 * [`unittriangle`](@ref) |
13 * `unithyperbox` | 12 * [`unittetrahedron`](@ref) |
14 * `unitsimplex` | 13 * [`unitsimplex`](@ref) |
15 | 14 |
16 See also: [`Interval`](@ref), [`Rectangle`](@ref), [`Box`](@ref), | 15 See also: [`Interval`](@ref), [`HyperBox`](@ref), |
17 [`Triangle`](@ref), [`Tetrahedron`](@ref), [`HyperBox`](@ref), | 16 [`Simplex`](@ref). |
18 [`Simplex`](@ref), | |
19 """ | 17 """ |
20 abstract type ParameterSpace{D} end | 18 abstract type ParameterSpace{D} end |
21 Base.ndims(::ParameterSpace{D}) where D = D | 19 Base.ndims(::ParameterSpace{D}) where D = D |
22 | 20 |
21 """ | |
22 Interval{T} <: ParameterSpace{1} | |
23 | |
24 A `ParameterSpace` representing an interval. | |
25 """ | |
23 struct Interval{T} <: ParameterSpace{1} | 26 struct Interval{T} <: ParameterSpace{1} |
24 a::T | 27 a::T |
25 b::T | 28 b::T |
26 | |
27 function Interval(a,b) | |
28 a, b = promote(a, b) | |
29 new{typeof(a)}(a,b) | |
30 end | |
31 end | 29 end |
32 | 30 |
31 """ | |
32 Interval(a,b) | |
33 | |
34 An interval with limits `a` and `b`. | |
35 """ | |
36 function Interval(a,b) | |
37 a, b = promote(a, b) | |
38 Interval{typeof(a)}(a,b) | |
39 end | |
40 | |
41 """ | |
42 limits(i::Interval) | |
43 | |
44 The limits of the interval. | |
45 """ | |
33 limits(i::Interval) = (i.a, i.b) | 46 limits(i::Interval) = (i.a, i.b) |
34 | 47 |
48 """ | |
49 unitinterval(T=Float64) | |
50 | |
51 The interval ``(0,1)``. | |
52 """ | |
35 unitinterval(T=Float64) = Interval(zero(T), one(T)) | 53 unitinterval(T=Float64) = Interval(zero(T), one(T)) |
36 | 54 |
37 | 55 |
56 """ | |
57 HyperBox{T,D} <: ParameterSpace{D} | |
58 | |
59 A `ParameterSpace` representing a hyper box. | |
60 """ | |
38 struct HyperBox{T,D} <: ParameterSpace{D} | 61 struct HyperBox{T,D} <: ParameterSpace{D} |
39 a::SVector{D,T} | 62 a::SVector{D,T} |
40 b::SVector{D,T} | 63 b::SVector{D,T} |
41 end | 64 end |
42 | 65 |
66 """ | |
67 HyperBox(a,b) | |
68 | |
69 A `HyperBox` with lower limits `a` and upper limits `b` for each dimension. | |
70 """ | |
43 function HyperBox(a,b) | 71 function HyperBox(a,b) |
44 ET = promote_type(eltype(a),eltype(b)) | 72 ET = promote_type(eltype(a),eltype(b)) |
45 T = SVector{length(a),ET} | 73 T = SVector{length(a),ET} |
46 HyperBox(convert(T,a), convert(T,b)) | 74 HyperBox(convert(T,a), convert(T,b)) |
47 end | 75 end |
48 | 76 |
49 Rectangle{T} = HyperBox{T,2} | 77 Rectangle{T} = HyperBox{T,2} |
50 Box{T} = HyperBox{T,3} | 78 Box{T} = HyperBox{T,3} |
51 | 79 |
80 """ | |
81 limits(box::HyperBox, d) | |
82 | |
83 Limits of `box` along dimension `d`. | |
84 """ | |
52 limits(box::HyperBox, d) = (box.a[d], box.b[d]) | 85 limits(box::HyperBox, d) = (box.a[d], box.b[d]) |
86 | |
87 """ | |
88 limits(box::HyperBox) | |
89 | |
90 The lower and upper limits of `box` as tuples. | |
91 """ | |
53 limits(box::HyperBox) = (box.a, box.b) | 92 limits(box::HyperBox) = (box.a, box.b) |
54 | 93 |
94 """ | |
95 unitsquare(T=Float64) | |
96 | |
97 The square starting at ``(0,0)`` with side length 1. | |
98 """ | |
55 unitsquare(T=Float64) = unithyperbox(T,2) | 99 unitsquare(T=Float64) = unithyperbox(T,2) |
100 | |
101 """ | |
102 unitcube(T=Float64) | |
103 | |
104 The cube starting at ``(0,0,0)`` with side length 1. | |
105 """ | |
56 unitcube(T=Float64) = unithyperbox(T,3) | 106 unitcube(T=Float64) = unithyperbox(T,3) |
107 | |
108 """ | |
109 unithyperbox(T=Float64, D) | |
110 | |
111 The hypercube in dimension `D` starting at ``(0,0,0,...)`` with side length 1. | |
112 """ | |
57 unithyperbox(T, D) = HyperBox((@SVector zeros(T,D)), (@SVector ones(T,D))) | 113 unithyperbox(T, D) = HyperBox((@SVector zeros(T,D)), (@SVector ones(T,D))) |
58 unithyperbox(D) = unithyperbox(Float64,D) | 114 unithyperbox(D) = unithyperbox(Float64,D) |
59 | 115 |
60 | 116 |
117 """ | |
118 Simplex{T,D,NV} <: ParameterSpace{D} | |
119 | |
120 A `ParameterSpace` representing a simplex. | |
121 """ | |
61 struct Simplex{T,D,NV} <: ParameterSpace{D} | 122 struct Simplex{T,D,NV} <: ParameterSpace{D} |
62 verticies::NTuple{NV,SVector{D,T}} | 123 verticies::NTuple{NV,SVector{D,T}} |
63 | 124 |
64 Simplex(verticies::Tuple{SVector{D,T}, Vararg{SVector{D,T},N}}) where {T,D,N} = new{T,D,N+1}(verticies) | 125 Simplex(verticies::Tuple{SVector{D,T}, Vararg{SVector{D,T},N}}) where {T,D,N} = new{T,D,N+1}(verticies) |
65 Simplex(::Tuple{}) = throw(ArgumentError("Must provide at least one vertex.")) | 126 Simplex(::Tuple{}) = throw(ArgumentError("Must provide at least one vertex.")) |
66 end | 127 end |
67 | 128 |
129 """ | |
130 Simplex(verticies...) | |
131 | |
132 A simplex with the given vierticies. | |
133 """ | |
68 function Simplex(verticies::Vararg{AbstractArray}) | 134 function Simplex(verticies::Vararg{AbstractArray}) |
69 ET = mapreduce(eltype,promote_type,verticies) | 135 ET = mapreduce(eltype,promote_type,verticies) |
70 T = SVector{length(verticies[1]),ET} | 136 T = SVector{length(verticies[1]),ET} |
71 | 137 |
72 return Simplex(Tuple(convert(T,v) for v ∈ verticies)) | 138 return Simplex(Tuple(convert(T,v) for v ∈ verticies)) |
73 end | 139 end |
74 | 140 |
141 """ | |
142 verticies(s::Simplex) | |
143 | |
144 Verticies of `s`. | |
145 """ | |
75 verticies(s::Simplex) = s.verticies | 146 verticies(s::Simplex) = s.verticies |
76 | 147 |
77 Triangle{T} = Simplex{T,2} | 148 Triangle{T} = Simplex{T,2} |
78 Tetrahedron{T} = Simplex{T,3} | 149 Tetrahedron{T} = Simplex{T,3} |
79 | 150 |
151 """ | |
152 unittriangle(T=Float64) | |
153 | |
154 The simplex with verticies ``(0,0)``, ``(1,0)``, and ``(0,1)``. | |
155 """ | |
80 unittriangle(T=Float64) = unitsimplex(T,2) | 156 unittriangle(T=Float64) = unitsimplex(T,2) |
157 | |
158 """ | |
159 unittetrahedron(T=Float64) | |
160 | |
161 The simplex with verticies ``(0,0,0)``, ``(1,0,0)``, ``(0,1,0)``, and ``(0,0,1)``. | |
162 """ | |
81 unittetrahedron(T=Float64) = unitsimplex(T,3) | 163 unittetrahedron(T=Float64) = unitsimplex(T,3) |
164 | |
165 """ | |
166 unitsimplex(T=Float64,D) | |
167 | |
168 The unit simplex in dimension `D` with verticies ``(0,0,0,...)``, ``(1,0,0,...)``, ``(0,1,0,...)``, ``(0,0,1,...)``... | |
169 """ | |
82 function unitsimplex(T,D) | 170 function unitsimplex(T,D) |
83 z = @SVector zeros(T,D) | 171 z = @SVector zeros(T,D) |
84 unitelement = one(eltype(z)) | 172 unitelement = one(eltype(z)) |
85 verticies = ntuple(i->setindex(z, unitelement, i), D) | 173 verticies = ntuple(i->setindex(z, unitelement, i), D) |
86 return Simplex((z,verticies...)) | 174 return Simplex((z,verticies...)) |