Mercurial > repos > public > sbplib_julia
comparison src/Grids/manifolds.jl @ 1903:04c251bccbd4 feature/grids/manifolds
Merge feature/grids/parameter_spaces
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Sat, 01 Feb 2025 22:17:39 +0100 |
| parents | 20bd8887db0d |
| children | e7f8d11c4670 |
comparison
equal
deleted
inserted
replaced
| 1901:edee7d677efb | 1903:04c251bccbd4 |
|---|---|
| 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 Base.ndims(::ParameterSpace{D}) where D = D | |
| 22 | |
| 23 struct Interval{T} <: ParameterSpace{1} | |
| 24 a::T | |
| 25 b::T | |
| 26 | |
| 27 function Interval(a,b) | |
| 28 a, b = promote(a, b) | |
| 29 new{typeof(a)}(a,b) | |
| 30 end | |
| 31 end | |
| 32 | |
| 33 limits(i::Interval) = (i.a, i.b) | |
| 34 | |
| 35 unitinterval(T=Float64) = Interval(zero(T), one(T)) | |
| 36 | |
| 37 | |
| 38 struct HyperBox{T,D} <: ParameterSpace{D} | |
| 39 a::SVector{D,T} | |
| 40 b::SVector{D,T} | |
| 41 end | |
| 42 | |
| 43 function HyperBox(a,b) | |
| 44 ET = promote_type(eltype(a),eltype(b)) | |
| 45 T = SVector{length(a),ET} | |
| 46 HyperBox(convert(T,a), convert(T,b)) | |
| 47 end | |
| 48 | |
| 49 Rectangle{T} = HyperBox{T,2} | |
| 50 Box{T} = HyperBox{T,3} | |
| 51 | |
| 52 limits(box::HyperBox, d) = (box.a[d], box.b[d]) | |
| 53 limits(box::HyperBox) = (box.a, box.b) | |
| 54 | |
| 55 unitsquare(T=Float64) = unithyperbox(T,2) | |
| 56 unitcube(T=Float64) = unithyperbox(T,3) | |
| 57 unithyperbox(T, D) = HyperBox((@SVector zeros(T,D)), (@SVector ones(T,D))) | |
| 58 unithyperbox(D) = unithyperbox(Float64,D) | |
| 59 | |
| 60 | |
| 61 struct Simplex{T,D,NV} <: ParameterSpace{D} | |
| 62 verticies::NTuple{NV,SVector{D,T}} | |
| 63 | |
| 64 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.")) | |
| 66 end | |
| 67 | |
| 68 function Simplex(verticies::Vararg{AbstractArray}) | |
| 69 ET = mapreduce(eltype,promote_type,verticies) | |
| 70 T = SVector{length(verticies[1]),ET} | |
| 71 | |
| 72 return Simplex(Tuple(convert(T,v) for v ∈ verticies)) | |
| 73 end | |
| 74 | |
| 75 verticies(s::Simplex) = s.verticies | |
| 76 | |
| 77 Triangle{T} = Simplex{T,2} | |
| 78 Tetrahedron{T} = Simplex{T,3} | |
| 79 | |
| 80 unittriangle(T=Float64) = unitsimplex(T,2) | |
| 81 unittetrahedron(T=Float64) = unitsimplex(T,3) | |
| 82 function unitsimplex(T,D) | |
| 83 z = @SVector zeros(T,D) | |
| 84 unitelement = one(eltype(z)) | |
| 85 verticies = ntuple(i->setindex(z, unitelement, i), D) | |
| 86 return Simplex((z,verticies...)) | |
| 87 end | |
| 88 unitsimplex(D) = unitsimplex(Float64, D) | |
| 89 | |
| 90 """ | 1 """ |
| 91 Chart{D} | 2 Chart{D} |
| 92 | 3 |
| 93 A parametrized description of a manifold or part of a manifold. | 4 A parametrized description of a manifold or part of a manifold. |
| 94 """ | 5 """ |
