Mercurial > repos > public > sbplib_julia
annotate src/Grids/manifolds.jl @ 1625:84c3b9d71218 feature/grids/manifolds
Add linesegments function
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 14 Jun 2024 13:09:00 +0200 |
parents | f77c5309dd2b |
children | e213bd857f3f |
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 """ | |
1581
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
69 Chart{D} |
1558 | 70 |
71 A parametrized description of a manifold or part of a manifold. | |
72 """ | |
1581
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
73 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
|
74 mapping::MT |
1558 | 75 parameterspace::PST |
76 end | |
77 | |
1581
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
78 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
|
79 (c::Chart)(ξ) = c.mapping(ξ) |
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
80 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
|
81 |
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 jacobian(c::Chart, ξ) |
1558 | 84 |
1581
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
85 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
|
86 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
|
87 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
|
88 chart itself. |
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
89 ```julia |
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
90 c = Chart(f, ps) |
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
91 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
|
92 ``` |
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
93 or |
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
94 ```julia |
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
95 c = Chart(f, ps) |
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
96 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
|
97 ``` |
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
98 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
|
99 """ |
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
100 jacobian(c::Chart, ξ) = jacobian(c.mapping, ξ) |
f77c5309dd2b
Rename ConcreteChart to Chart and remove the abstarct chart type
Jonatan Werpers <jonatan@werpers.com>
parents:
1580
diff
changeset
|
101 |
1558 | 102 |
103 """ | |
104 Atlas | |
105 | |
106 A collection of charts and their connections. | |
107 Should implement methods for `charts` and | |
108 """ | |
109 abstract type Atlas end | |
110 | |
111 """ | |
112 charts(::Atlas) | |
113 | |
114 The colloction of charts in the atlas. | |
115 """ | |
116 function charts end | |
117 | |
118 """ | |
119 connections | |
120 | |
121 TBD: What exactly should this return? | |
122 | |
123 """ | |
124 | |
125 struct CartesianAtlas <: Atlas | |
126 charts::Matrix{Chart} | |
127 end | |
128 | |
129 charts(a::CartesianAtlas) = a.charts | |
130 | |
131 struct UnstructuredAtlas <: Atlas | |
132 charts::Vector{Chart} | |
133 connections | |
134 end | |
135 | |
136 charts(a::UnstructuredAtlas) = a.charts | |
137 | |
138 | |
139 ### | |
140 # Geometry | |
141 ### | |
142 | |
143 abstract type Curve end | |
144 abstract type Surface end | |
145 | |
146 | |
147 struct Line{PT} <: Curve | |
148 p::PT | |
149 tangent::PT | |
150 end | |
151 | |
152 (c::Line)(s) = c.p + s*c.tangent | |
153 | |
154 | |
155 struct LineSegment{PT} <: Curve | |
156 a::PT | |
157 b::PT | |
158 end | |
159 | |
160 (c::LineSegment)(s) = (1-s)*c.a + s*c.b | |
161 | |
162 | |
1625
84c3b9d71218
Add linesegments function
Jonatan Werpers <jonatan@werpers.com>
parents:
1581
diff
changeset
|
163 function linesegments(ps...) |
84c3b9d71218
Add linesegments function
Jonatan Werpers <jonatan@werpers.com>
parents:
1581
diff
changeset
|
164 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
|
165 end |
84c3b9d71218
Add linesegments function
Jonatan Werpers <jonatan@werpers.com>
parents:
1581
diff
changeset
|
166 |
84c3b9d71218
Add linesegments function
Jonatan Werpers <jonatan@werpers.com>
parents:
1581
diff
changeset
|
167 |
84c3b9d71218
Add linesegments function
Jonatan Werpers <jonatan@werpers.com>
parents:
1581
diff
changeset
|
168 function polygon_edges(ps...) |
84c3b9d71218
Add linesegments function
Jonatan Werpers <jonatan@werpers.com>
parents:
1581
diff
changeset
|
169 n = length(ps) |
84c3b9d71218
Add linesegments function
Jonatan Werpers <jonatan@werpers.com>
parents:
1581
diff
changeset
|
170 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
|
171 end |
84c3b9d71218
Add linesegments function
Jonatan Werpers <jonatan@werpers.com>
parents:
1581
diff
changeset
|
172 |
1558 | 173 struct Circle{T,PT} <: Curve |
174 c::PT | |
175 r::T | |
176 end | |
177 | |
178 (c::Circle)(θ) = c.c + r*@SVector[cos(Θ), sin(Θ)] | |
179 | |
180 struct TransfiniteInterpolationSurface{T1,T2,T3,T4} <: Surface | |
181 c₁::T1 | |
182 c₂::T2 | |
183 c₃::T3 | |
184 c₄::T4 | |
185 end | |
186 | |
187 function (s::TransfiniteInterpolationSurface)(u,v) | |
188 c₁, c₂, c₃, c₄ = s.c₁, s.c₂, s.c₃, s.c₄ | |
189 P₀₀ = c₁(0) | |
190 P₁₀ = c₂(0) | |
191 P₁₁ = c₃(0) | |
192 P₀₁ = c₄(0) | |
193 return (1-v)*c₁(u) + u*c₂(v) + v*c₃(1-u) + (1-u)*c₄(1-v) - ( | |
194 (1-u)*(1-v)*P₀₀ + u*(1-v)*P₁₀ + u*v*P₁₁ + (1-u)*v*P₀₁ | |
195 ) | |
196 end | |
197 | |
198 function (s::TransfiniteInterpolationSurface)(ξ̄::AbstractArray) | |
199 s(ξ̄...) | |
200 end | |
201 | |
202 |