Mercurial > repos > public > sbplib_julia
annotate src/Grids/manifolds.jl @ 1644:e213bd857f3f feature/grids/manifolds
Add some todos and tbds
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Wed, 26 Jun 2024 11:06:32 +0200 |
| parents | 84c3b9d71218 |
| children | 2a8a2b52a112 |
| 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 |
|
1644
e213bd857f3f
Add some todos and tbds
Jonatan Werpers <jonatan@werpers.com>
parents:
1625
diff
changeset
|
22 # TBD: Should implement domain_dim? |
| 1558 | 23 |
| 24 struct HyperBox{T,D} <: ParameterSpace{D} | |
| 25 a::SVector{D,T} | |
| 26 b::SVector{D,T} | |
| 27 end | |
| 28 | |
| 29 function HyperBox(a,b) | |
| 30 T = SVector{length(a)} | |
| 31 HyperBox(convert(T,a), convert(T,b)) | |
| 32 end | |
| 33 | |
| 34 Interval{T} = HyperBox{T,1} | |
| 35 Rectangle{T} = HyperBox{T,2} | |
| 36 Box{T} = HyperBox{T,3} | |
| 37 | |
| 38 limits(box::HyperBox, d) = (box.a[d], box.b[d]) | |
| 39 limits(box::HyperBox) = (box.a, box.b) | |
| 40 | |
| 41 unitinterval(T=Float64) = unithyperbox(T,1) | |
| 42 unitsquare(T=Float64) = unithyperbox(T,2) | |
| 43 unitcube(T=Float64) = unithyperbox(T,3) | |
| 44 unithyperbox(T, D) = HyperBox((@SVector zeros(T,D)), (@SVector ones(T,D))) | |
| 45 unithyperbox(D) = unithyperbox(Float64,D) | |
| 46 | |
| 47 | |
|
1579
14d79b13b54f
Add tests, fix bugs, add exports, for Simplex and friends
Jonatan Werpers <jonatan@werpers.com>
parents:
1578
diff
changeset
|
48 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
|
49 verticies::NTuple{NV,SVector{D,T}} |
| 1558 | 50 end |
| 51 | |
|
1564
35fe4375b35f
Export things and fix ConcreteChart and Simplex
Jonatan Werpers <jonatan@werpers.com>
parents:
1558
diff
changeset
|
52 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
|
53 |
|
1579
14d79b13b54f
Add tests, fix bugs, add exports, for Simplex and friends
Jonatan Werpers <jonatan@werpers.com>
parents:
1578
diff
changeset
|
54 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
|
55 |
| 1558 | 56 Triangle{T} = Simplex{T,2} |
| 57 Tetrahedron{T} = Simplex{T,3} | |
| 58 | |
|
1579
14d79b13b54f
Add tests, fix bugs, add exports, for Simplex and friends
Jonatan Werpers <jonatan@werpers.com>
parents:
1578
diff
changeset
|
59 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
|
60 unittetrahedron(T=Float64) = unitsimplex(T,3) |
| 1558 | 61 function unitsimplex(T,D) |
| 62 z = @SVector zeros(T,D) | |
| 63 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
|
64 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
|
65 return Simplex((z,verticies...)) |
| 1558 | 66 end |
|
1579
14d79b13b54f
Add tests, fix bugs, add exports, for Simplex and friends
Jonatan Werpers <jonatan@werpers.com>
parents:
1578
diff
changeset
|
67 unitsimplex(D) = unitsimplex(Float64, D) |
| 1558 | 68 |
| 69 """ | |
|
1581
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
70 Chart{D} |
| 1558 | 71 |
| 72 A parametrized description of a manifold or part of a manifold. | |
| 73 """ | |
|
1581
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
74 struct Chart{D, PST<:ParameterSpace{D}, MT} |
|
1564
35fe4375b35f
Export things and fix ConcreteChart and Simplex
Jonatan Werpers <jonatan@werpers.com>
parents:
1558
diff
changeset
|
75 mapping::MT |
| 1558 | 76 parameterspace::PST |
| 77 end | |
| 78 | |
|
1581
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
79 domain_dim(::Chart{D}) where D = D |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
80 (c::Chart)(ξ) = c.mapping(ξ) |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
81 parameterspace(c::Chart) = c.parameterspace |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
82 |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
83 """ |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
84 jacobian(c::Chart, ξ) |
| 1558 | 85 |
|
1581
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
86 The jacobian of the mapping evaluated at `ξ`. This defers to the |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
87 implementation of `jacobian` for the mapping itself. If no implementation is |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
88 available one can easily be specified for either the mapping function or the |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
89 chart itself. |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
90 ```julia |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
91 c = Chart(f, ps) |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
92 jacobian(f::typeof(f), ξ) = f′(ξ) |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
93 ``` |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
94 or |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
95 ```julia |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
96 c = Chart(f, ps) |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
97 jacobian(c::typeof(c),ξ) = f′(ξ) |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
98 ``` |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
99 which will both allow calling `jacobian(c,ξ)`. |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
100 """ |
|
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
101 jacobian(c::Chart, ξ) = jacobian(c.mapping, ξ) |
|
1644
e213bd857f3f
Add some todos and tbds
Jonatan Werpers <jonatan@werpers.com>
parents:
1625
diff
changeset
|
102 # TBD: Can we register a error hint for when jacobian is called with a function that doesn't have a registered jacobian? |
|
1581
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
103 |
| 1558 | 104 |
|
1644
e213bd857f3f
Add some todos and tbds
Jonatan Werpers <jonatan@werpers.com>
parents:
1625
diff
changeset
|
105 # TBD: Should Charts, parameterspaces have boundary names? |
|
e213bd857f3f
Add some todos and tbds
Jonatan Werpers <jonatan@werpers.com>
parents:
1625
diff
changeset
|
106 |
| 1558 | 107 """ |
| 108 Atlas | |
| 109 | |
| 110 A collection of charts and their connections. | |
| 111 Should implement methods for `charts` and | |
| 112 """ | |
| 113 abstract type Atlas end | |
| 114 | |
| 115 """ | |
| 116 charts(::Atlas) | |
| 117 | |
| 118 The colloction of charts in the atlas. | |
| 119 """ | |
| 120 function charts end | |
| 121 | |
| 122 """ | |
| 123 connections | |
| 124 | |
| 125 TBD: What exactly should this return? | |
| 126 | |
| 127 """ | |
| 128 | |
| 129 struct CartesianAtlas <: Atlas | |
| 130 charts::Matrix{Chart} | |
| 131 end | |
| 132 | |
| 133 charts(a::CartesianAtlas) = a.charts | |
| 134 | |
| 135 struct UnstructuredAtlas <: Atlas | |
| 136 charts::Vector{Chart} | |
| 137 connections | |
| 138 end | |
| 139 | |
| 140 charts(a::UnstructuredAtlas) = a.charts | |
| 141 | |
| 142 | |
| 143 ### | |
| 144 # Geometry | |
| 145 ### | |
| 146 | |
| 147 abstract type Curve end | |
| 148 abstract type Surface end | |
| 149 | |
| 150 | |
| 151 struct Line{PT} <: Curve | |
| 152 p::PT | |
| 153 tangent::PT | |
| 154 end | |
| 155 | |
| 156 (c::Line)(s) = c.p + s*c.tangent | |
| 157 | |
| 158 | |
| 159 struct LineSegment{PT} <: Curve | |
| 160 a::PT | |
| 161 b::PT | |
| 162 end | |
| 163 | |
| 164 (c::LineSegment)(s) = (1-s)*c.a + s*c.b | |
| 165 | |
| 166 | |
|
1625
84c3b9d71218
Add linesegments function
Jonatan Werpers <jonatan@werpers.com>
parents:
1581
diff
changeset
|
167 function linesegments(ps...) |
|
84c3b9d71218
Add linesegments function
Jonatan Werpers <jonatan@werpers.com>
parents:
1581
diff
changeset
|
168 return [LineSegment(ps[i], ps[i+1]) for i ∈ 1:length(ps)-1] |
|
84c3b9d71218
Add linesegments function
Jonatan Werpers <jonatan@werpers.com>
parents:
1581
diff
changeset
|
169 end |
|
84c3b9d71218
Add linesegments function
Jonatan Werpers <jonatan@werpers.com>
parents:
1581
diff
changeset
|
170 |
|
84c3b9d71218
Add linesegments function
Jonatan Werpers <jonatan@werpers.com>
parents:
1581
diff
changeset
|
171 |
|
84c3b9d71218
Add linesegments function
Jonatan Werpers <jonatan@werpers.com>
parents:
1581
diff
changeset
|
172 function polygon_edges(ps...) |
|
84c3b9d71218
Add linesegments function
Jonatan Werpers <jonatan@werpers.com>
parents:
1581
diff
changeset
|
173 n = length(ps) |
|
84c3b9d71218
Add linesegments function
Jonatan Werpers <jonatan@werpers.com>
parents:
1581
diff
changeset
|
174 return [LineSegment(ps[i], ps[mod1(i+1,n)]) for i ∈ eachindex(Ps)] |
|
84c3b9d71218
Add linesegments function
Jonatan Werpers <jonatan@werpers.com>
parents:
1581
diff
changeset
|
175 end |
|
84c3b9d71218
Add linesegments function
Jonatan Werpers <jonatan@werpers.com>
parents:
1581
diff
changeset
|
176 |
| 1558 | 177 struct Circle{T,PT} <: Curve |
| 178 c::PT | |
| 179 r::T | |
| 180 end | |
| 181 | |
| 182 (c::Circle)(θ) = c.c + r*@SVector[cos(Θ), sin(Θ)] | |
| 183 | |
| 184 struct TransfiniteInterpolationSurface{T1,T2,T3,T4} <: Surface | |
| 185 c₁::T1 | |
| 186 c₂::T2 | |
| 187 c₃::T3 | |
| 188 c₄::T4 | |
| 189 end | |
| 190 | |
| 191 function (s::TransfiniteInterpolationSurface)(u,v) | |
| 192 c₁, c₂, c₃, c₄ = s.c₁, s.c₂, s.c₃, s.c₄ | |
| 193 P₀₀ = c₁(0) | |
| 194 P₁₀ = c₂(0) | |
| 195 P₁₁ = c₃(0) | |
| 196 P₀₁ = c₄(0) | |
| 197 return (1-v)*c₁(u) + u*c₂(v) + v*c₃(1-u) + (1-u)*c₄(1-v) - ( | |
| 198 (1-u)*(1-v)*P₀₀ + u*(1-v)*P₁₀ + u*v*P₁₁ + (1-u)*v*P₀₁ | |
| 199 ) | |
| 200 end | |
| 201 | |
| 202 function (s::TransfiniteInterpolationSurface)(ξ̄::AbstractArray) | |
| 203 s(ξ̄...) | |
| 204 end | |
| 205 | |
|
1644
e213bd857f3f
Add some todos and tbds
Jonatan Werpers <jonatan@werpers.com>
parents:
1625
diff
changeset
|
206 # TODO: Implement jacobian() for the different mapping helpers |
| 1558 | 207 |
