Mercurial > repos > public > sbplib_julia
annotate src/Grids/manifolds.jl @ 1580:fdee60ab8c4e feature/grids/manifolds
Add ndims method for ParameterSpace
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 25 Apr 2024 22:15:12 +0200 |
parents | 14d79b13b54f |
children | f77c5309dd2b |
rev | line source |
---|---|
1558 | 1 """ |
2 ParameterSpace{D} | |
3 | |
4 A space of parameters of dimension `D`. Used with `Chart` to indicate which | |
5 parameters are valid for that chart. | |
6 | |
7 Common parameter spaces are created using the functions unit sized spaces | |
8 * `unitinterval` | |
9 * `unitrectangle` | |
10 * `unitbox` | |
11 * `unittriangle` | |
12 * `unittetrahedron` | |
13 * `unithyperbox` | |
14 * `unitsimplex` | |
15 | |
16 See also: [`Interval`](@ref), [`Rectangle`](@ref), [`Box`](@ref), | |
17 [`Triangle`](@ref), [`Tetrahedron`](@ref), [`HyperBox`](@ref), | |
18 [`Simplex`](@ref), | |
19 """ | |
20 abstract type ParameterSpace{D} end | |
1580
fdee60ab8c4e
Add ndims method for ParameterSpace
Jonatan Werpers <jonatan@werpers.com>
parents:
1579
diff
changeset
|
21 Base.ndims(::ParameterSpace{D}) where D = D |
1558 | 22 |
23 struct HyperBox{T,D} <: ParameterSpace{D} | |
24 a::SVector{D,T} | |
25 b::SVector{D,T} | |
26 end | |
27 | |
28 function HyperBox(a,b) | |
29 T = SVector{length(a)} | |
30 HyperBox(convert(T,a), convert(T,b)) | |
31 end | |
32 | |
33 Interval{T} = HyperBox{T,1} | |
34 Rectangle{T} = HyperBox{T,2} | |
35 Box{T} = HyperBox{T,3} | |
36 | |
37 limits(box::HyperBox, d) = (box.a[d], box.b[d]) | |
38 limits(box::HyperBox) = (box.a, box.b) | |
39 | |
40 unitinterval(T=Float64) = unithyperbox(T,1) | |
41 unitsquare(T=Float64) = unithyperbox(T,2) | |
42 unitcube(T=Float64) = unithyperbox(T,3) | |
43 unithyperbox(T, D) = HyperBox((@SVector zeros(T,D)), (@SVector ones(T,D))) | |
44 unithyperbox(D) = unithyperbox(Float64,D) | |
45 | |
46 | |
1579
14d79b13b54f
Add tests, fix bugs, add exports, for Simplex and friends
Jonatan Werpers <jonatan@werpers.com>
parents:
1578
diff
changeset
|
47 struct Simplex{T,D,NV} <: ParameterSpace{D} |
14d79b13b54f
Add tests, fix bugs, add exports, for Simplex and friends
Jonatan Werpers <jonatan@werpers.com>
parents:
1578
diff
changeset
|
48 verticies::NTuple{NV,SVector{D,T}} |
1558 | 49 end |
50 | |
1564
35fe4375b35f
Export things and fix ConcreteChart and Simplex
Jonatan Werpers <jonatan@werpers.com>
parents:
1558
diff
changeset
|
51 Simplex(verticies::Vararg{AbstractArray}) = Simplex(Tuple(SVector(v...) for v ∈ verticies)) |
35fe4375b35f
Export things and fix ConcreteChart and Simplex
Jonatan Werpers <jonatan@werpers.com>
parents:
1558
diff
changeset
|
52 |
1579
14d79b13b54f
Add tests, fix bugs, add exports, for Simplex and friends
Jonatan Werpers <jonatan@werpers.com>
parents:
1578
diff
changeset
|
53 verticies(s::Simplex) = s.verticies |
14d79b13b54f
Add tests, fix bugs, add exports, for Simplex and friends
Jonatan Werpers <jonatan@werpers.com>
parents:
1578
diff
changeset
|
54 |
1558 | 55 Triangle{T} = Simplex{T,2} |
56 Tetrahedron{T} = Simplex{T,3} | |
57 | |
1579
14d79b13b54f
Add tests, fix bugs, add exports, for Simplex and friends
Jonatan Werpers <jonatan@werpers.com>
parents:
1578
diff
changeset
|
58 unittriangle(T=Float64) = unitsimplex(T,2) |
14d79b13b54f
Add tests, fix bugs, add exports, for Simplex and friends
Jonatan Werpers <jonatan@werpers.com>
parents:
1578
diff
changeset
|
59 unittetrahedron(T=Float64) = unitsimplex(T,3) |
1558 | 60 function unitsimplex(T,D) |
61 z = @SVector zeros(T,D) | |
62 unitelement = one(eltype(z)) | |
1579
14d79b13b54f
Add tests, fix bugs, add exports, for Simplex and friends
Jonatan Werpers <jonatan@werpers.com>
parents:
1578
diff
changeset
|
63 verticies = ntuple(i->setindex(z, unitelement, i), D) |
14d79b13b54f
Add tests, fix bugs, add exports, for Simplex and friends
Jonatan Werpers <jonatan@werpers.com>
parents:
1578
diff
changeset
|
64 return Simplex((z,verticies...)) |
1558 | 65 end |
1579
14d79b13b54f
Add tests, fix bugs, add exports, for Simplex and friends
Jonatan Werpers <jonatan@werpers.com>
parents:
1578
diff
changeset
|
66 unitsimplex(D) = unitsimplex(Float64, D) |
1558 | 67 |
68 """ | |
69 | |
70 A parametrized description of a manifold or part of a manifold. | |
71 | |
72 Should implement a methods for | |
73 * `parameterspace` | |
74 * `(::Chart)(ξs...)` | |
75 """ | |
76 abstract type Chart{D} end | |
77 # abstract type Chart{D,R} end | |
78 | |
79 domain_dim(::Chart{D}) where D = D | |
80 # range_dim(::Chart{D,R}) where {D,R} = R | |
81 | |
82 """ | |
83 The parameterspace of a chart | |
84 """ | |
85 function parameterspace end | |
86 | |
87 | |
1568 | 88 # TODO: Add trait for if there is a jacobian available? |
89 # Add package extension to allow calling the getter function anyway if it's not available | |
90 # And can we add an informative error that ForwardDiff could be loaded to make it work? | |
91 # Or can we handle this be custom implementations? For sometypes in the library it can be implemented explicitly. | |
92 # And as an example for ConcreteChart it can be implemented by the user like | |
93 # c = ConcreteChart(...) | |
94 # jacobian(c::typeof(c)) = ... | |
95 | |
1564
35fe4375b35f
Export things and fix ConcreteChart and Simplex
Jonatan Werpers <jonatan@werpers.com>
parents:
1558
diff
changeset
|
96 struct ConcreteChart{D, PST<:ParameterSpace{D}, MT} <: Chart{D} |
35fe4375b35f
Export things and fix ConcreteChart and Simplex
Jonatan Werpers <jonatan@werpers.com>
parents:
1558
diff
changeset
|
97 mapping::MT |
1558 | 98 parameterspace::PST |
99 end | |
100 | |
1578
56da785ab576
Change to using xi for ConcreteChart
Jonatan Werpers <jonatan@werpers.com>
parents:
1577
diff
changeset
|
101 (c::ConcreteChart)(ξ) = c.mapping(ξ) |
1572
157c43966b06
Add some tests and implement parameterspace for ConcreteChart
Jonatan Werpers <jonatan@werpers.com>
parents:
1568
diff
changeset
|
102 parameterspace(c::ConcreteChart) = c.parameterspace |
1558 | 103 |
1578
56da785ab576
Change to using xi for ConcreteChart
Jonatan Werpers <jonatan@werpers.com>
parents:
1577
diff
changeset
|
104 jacobian(c::ConcreteChart, ξ) = jacobian(c.mapping, ξ) |
1558 | 105 |
106 """ | |
107 Atlas | |
108 | |
109 A collection of charts and their connections. | |
110 Should implement methods for `charts` and | |
111 """ | |
112 abstract type Atlas end | |
113 | |
114 """ | |
115 charts(::Atlas) | |
116 | |
117 The colloction of charts in the atlas. | |
118 """ | |
119 function charts end | |
120 | |
121 """ | |
122 connections | |
123 | |
124 TBD: What exactly should this return? | |
125 | |
126 """ | |
127 | |
128 struct CartesianAtlas <: Atlas | |
129 charts::Matrix{Chart} | |
130 end | |
131 | |
132 charts(a::CartesianAtlas) = a.charts | |
133 | |
134 struct UnstructuredAtlas <: Atlas | |
135 charts::Vector{Chart} | |
136 connections | |
137 end | |
138 | |
139 charts(a::UnstructuredAtlas) = a.charts | |
140 | |
141 | |
142 ### | |
143 # Geometry | |
144 ### | |
145 | |
146 abstract type Curve end | |
147 abstract type Surface end | |
148 | |
149 | |
150 struct Line{PT} <: Curve | |
151 p::PT | |
152 tangent::PT | |
153 end | |
154 | |
155 (c::Line)(s) = c.p + s*c.tangent | |
156 | |
157 | |
158 struct LineSegment{PT} <: Curve | |
159 a::PT | |
160 b::PT | |
161 end | |
162 | |
163 (c::LineSegment)(s) = (1-s)*c.a + s*c.b | |
164 | |
165 | |
166 struct Circle{T,PT} <: Curve | |
167 c::PT | |
168 r::T | |
169 end | |
170 | |
171 (c::Circle)(θ) = c.c + r*@SVector[cos(Θ), sin(Θ)] | |
172 | |
173 struct TransfiniteInterpolationSurface{T1,T2,T3,T4} <: Surface | |
174 c₁::T1 | |
175 c₂::T2 | |
176 c₃::T3 | |
177 c₄::T4 | |
178 end | |
179 | |
180 function (s::TransfiniteInterpolationSurface)(u,v) | |
181 c₁, c₂, c₃, c₄ = s.c₁, s.c₂, s.c₃, s.c₄ | |
182 P₀₀ = c₁(0) | |
183 P₁₀ = c₂(0) | |
184 P₁₁ = c₃(0) | |
185 P₀₁ = c₄(0) | |
186 return (1-v)*c₁(u) + u*c₂(v) + v*c₃(1-u) + (1-u)*c₄(1-v) - ( | |
187 (1-u)*(1-v)*P₀₀ + u*(1-v)*P₁₀ + u*v*P₁₁ + (1-u)*v*P₀₁ | |
188 ) | |
189 end | |
190 | |
191 function (s::TransfiniteInterpolationSurface)(ξ̄::AbstractArray) | |
192 s(ξ̄...) | |
193 end | |
194 | |
195 | |
196 function polygon_sides(Ps...) | |
197 n = length(Ps) | |
198 return [t->line(t,Ps[i],Ps[mod1(i+1,n)]) for i ∈ eachindex(Ps)] | |
199 end |