Mercurial > repos > public > sbplib_julia
annotate src/Grids/manifolds.jl @ 1564:35fe4375b35f feature/grids/manifolds
Export things and fix ConcreteChart and Simplex
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Thu, 25 Apr 2024 13:17:48 +0200 |
| parents | 81e97d3bec8c |
| children | 90af15f38c62 |
| 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 | |
| 21 | |
| 22 struct HyperBox{T,D} <: ParameterSpace{D} | |
| 23 a::SVector{D,T} | |
| 24 b::SVector{D,T} | |
| 25 end | |
| 26 | |
| 27 function HyperBox(a,b) | |
| 28 T = SVector{length(a)} | |
| 29 HyperBox(convert(T,a), convert(T,b)) | |
| 30 end | |
| 31 | |
| 32 Interval{T} = HyperBox{T,1} | |
| 33 Rectangle{T} = HyperBox{T,2} | |
| 34 Box{T} = HyperBox{T,3} | |
| 35 | |
| 36 limits(box::HyperBox, d) = (box.a[d], box.b[d]) | |
| 37 limits(box::HyperBox) = (box.a, box.b) | |
| 38 | |
| 39 unitinterval(T=Float64) = unithyperbox(T,1) | |
| 40 unitsquare(T=Float64) = unithyperbox(T,2) | |
| 41 unitcube(T=Float64) = unithyperbox(T,3) | |
| 42 unithyperbox(T, D) = HyperBox((@SVector zeros(T,D)), (@SVector ones(T,D))) | |
| 43 unithyperbox(D) = unithyperbox(Float64,D) | |
| 44 | |
| 45 | |
| 46 struct Simplex{T,D} <: ParameterSpace{D} | |
| 47 verticies::NTuple{D,SVector{D,T}} | |
| 48 end | |
| 49 | |
|
1564
35fe4375b35f
Export things and fix ConcreteChart and Simplex
Jonatan Werpers <jonatan@werpers.com>
parents:
1558
diff
changeset
|
50 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
|
51 |
| 1558 | 52 Triangle{T} = Simplex{T,2} |
| 53 Tetrahedron{T} = Simplex{T,3} | |
| 54 | |
| 55 unittriangle(T) = unitsimplex(T,2) | |
| 56 unittetrahedron(T) = unitsimplex(T,3) | |
| 57 function unitsimplex(T,D) | |
| 58 z = @SVector zeros(T,D) | |
| 59 unitelement = one(eltype(z)) | |
| 60 verticies = ntuple(i->setindex(z, unitelement, i), 4) | |
| 61 return Simplex(verticies) | |
| 62 end | |
| 63 | |
| 64 | |
| 65 """ | |
| 66 | |
| 67 A parametrized description of a manifold or part of a manifold. | |
| 68 | |
| 69 Should implement a methods for | |
| 70 * `parameterspace` | |
| 71 * `(::Chart)(ξs...)` | |
| 72 | |
| 73 There is a default implementation for `(::Chart{D})(::SVector{D})` | |
| 74 """ | |
| 75 abstract type Chart{D} end | |
| 76 # abstract type Chart{D,R} end | |
| 77 | |
| 78 domain_dim(::Chart{D}) where D = D | |
| 79 # range_dim(::Chart{D,R}) where {D,R} = R | |
| 80 | |
| 81 """ | |
| 82 The parameterspace of a chart | |
| 83 """ | |
| 84 function parameterspace end | |
| 85 | |
| 86 (c::Chart{D})(x̄::SVector{D}) where D = c(x̄...) | |
| 87 | |
| 88 | |
|
1564
35fe4375b35f
Export things and fix ConcreteChart and Simplex
Jonatan Werpers <jonatan@werpers.com>
parents:
1558
diff
changeset
|
89 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
|
90 mapping::MT |
| 1558 | 91 parameterspace::PST |
| 92 end | |
| 93 | |
| 94 (c::Chart)(x̄) = c.mapping(x̄) | |
| 95 | |
| 96 | |
| 97 """ | |
| 98 Atlas | |
| 99 | |
| 100 A collection of charts and their connections. | |
| 101 Should implement methods for `charts` and | |
| 102 """ | |
| 103 abstract type Atlas end | |
| 104 | |
| 105 """ | |
| 106 charts(::Atlas) | |
| 107 | |
| 108 The colloction of charts in the atlas. | |
| 109 """ | |
| 110 function charts end | |
| 111 | |
| 112 """ | |
| 113 connections | |
| 114 | |
| 115 TBD: What exactly should this return? | |
| 116 | |
| 117 """ | |
| 118 | |
| 119 struct CartesianAtlas <: Atlas | |
| 120 charts::Matrix{Chart} | |
| 121 end | |
| 122 | |
| 123 charts(a::CartesianAtlas) = a.charts | |
| 124 | |
| 125 struct UnstructuredAtlas <: Atlas | |
| 126 charts::Vector{Chart} | |
| 127 connections | |
| 128 end | |
| 129 | |
| 130 charts(a::UnstructuredAtlas) = a.charts | |
| 131 | |
| 132 | |
| 133 ### | |
| 134 # Geometry | |
| 135 ### | |
| 136 | |
| 137 abstract type Curve end | |
| 138 abstract type Surface end | |
| 139 | |
| 140 | |
| 141 struct Line{PT} <: Curve | |
| 142 p::PT | |
| 143 tangent::PT | |
| 144 end | |
| 145 | |
| 146 (c::Line)(s) = c.p + s*c.tangent | |
| 147 | |
| 148 | |
| 149 struct LineSegment{PT} <: Curve | |
| 150 a::PT | |
| 151 b::PT | |
| 152 end | |
| 153 | |
| 154 (c::LineSegment)(s) = (1-s)*c.a + s*c.b | |
| 155 | |
| 156 | |
| 157 struct Circle{T,PT} <: Curve | |
| 158 c::PT | |
| 159 r::T | |
| 160 end | |
| 161 | |
| 162 (c::Circle)(θ) = c.c + r*@SVector[cos(Θ), sin(Θ)] | |
| 163 | |
| 164 struct TransfiniteInterpolationSurface{T1,T2,T3,T4} <: Surface | |
| 165 c₁::T1 | |
| 166 c₂::T2 | |
| 167 c₃::T3 | |
| 168 c₄::T4 | |
| 169 end | |
| 170 | |
| 171 function (s::TransfiniteInterpolationSurface)(u,v) | |
| 172 c₁, c₂, c₃, c₄ = s.c₁, s.c₂, s.c₃, s.c₄ | |
| 173 P₀₀ = c₁(0) | |
| 174 P₁₀ = c₂(0) | |
| 175 P₁₁ = c₃(0) | |
| 176 P₀₁ = c₄(0) | |
| 177 return (1-v)*c₁(u) + u*c₂(v) + v*c₃(1-u) + (1-u)*c₄(1-v) - ( | |
| 178 (1-u)*(1-v)*P₀₀ + u*(1-v)*P₁₀ + u*v*P₁₁ + (1-u)*v*P₀₁ | |
| 179 ) | |
| 180 end | |
| 181 | |
| 182 function (s::TransfiniteInterpolationSurface)(ξ̄::AbstractArray) | |
| 183 s(ξ̄...) | |
| 184 end | |
| 185 | |
| 186 | |
| 187 function polygon_sides(Ps...) | |
| 188 n = length(Ps) | |
| 189 return [t->line(t,Ps[i],Ps[mod1(i+1,n)]) for i ∈ eachindex(Ps)] | |
| 190 end |
