comparison src/Grids/manifolds.jl @ 1584:d7483e8af705 feature/sbp_operators/laplace_curvilinear

Merge feature/grids/manifolds
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 26 Apr 2024 08:45:54 +0200
parents f77c5309dd2b
children 84c3b9d71218
comparison
equal deleted inserted replaced
1563:6e910408c51a 1584:d7483e8af705
16 See also: [`Interval`](@ref), [`Rectangle`](@ref), [`Box`](@ref), 16 See also: [`Interval`](@ref), [`Rectangle`](@ref), [`Box`](@ref),
17 [`Triangle`](@ref), [`Tetrahedron`](@ref), [`HyperBox`](@ref), 17 [`Triangle`](@ref), [`Tetrahedron`](@ref), [`HyperBox`](@ref),
18 [`Simplex`](@ref), 18 [`Simplex`](@ref),
19 """ 19 """
20 abstract type ParameterSpace{D} end 20 abstract type ParameterSpace{D} end
21 Base.ndims(::ParameterSpace{D}) where D = D
21 22
22 struct HyperBox{T,D} <: ParameterSpace{D} 23 struct HyperBox{T,D} <: ParameterSpace{D}
23 a::SVector{D,T} 24 a::SVector{D,T}
24 b::SVector{D,T} 25 b::SVector{D,T}
25 end 26 end
41 unitcube(T=Float64) = unithyperbox(T,3) 42 unitcube(T=Float64) = unithyperbox(T,3)
42 unithyperbox(T, D) = HyperBox((@SVector zeros(T,D)), (@SVector ones(T,D))) 43 unithyperbox(T, D) = HyperBox((@SVector zeros(T,D)), (@SVector ones(T,D)))
43 unithyperbox(D) = unithyperbox(Float64,D) 44 unithyperbox(D) = unithyperbox(Float64,D)
44 45
45 46
46 struct Simplex{T,D} <: ParameterSpace{D} 47 struct Simplex{T,D,NV} <: ParameterSpace{D}
47 verticies::NTuple{D,SVector{D,T}} 48 verticies::NTuple{NV,SVector{D,T}}
48 end 49 end
50
51 Simplex(verticies::Vararg{AbstractArray}) = Simplex(Tuple(SVector(v...) for v ∈ verticies))
52
53 verticies(s::Simplex) = s.verticies
49 54
50 Triangle{T} = Simplex{T,2} 55 Triangle{T} = Simplex{T,2}
51 Tetrahedron{T} = Simplex{T,3} 56 Tetrahedron{T} = Simplex{T,3}
52 57
53 unittriangle(T) = unitsimplex(T,2) 58 unittriangle(T=Float64) = unitsimplex(T,2)
54 unittetrahedron(T) = unitsimplex(T,3) 59 unittetrahedron(T=Float64) = unitsimplex(T,3)
55 function unitsimplex(T,D) 60 function unitsimplex(T,D)
56 z = @SVector zeros(T,D) 61 z = @SVector zeros(T,D)
57 unitelement = one(eltype(z)) 62 unitelement = one(eltype(z))
58 verticies = ntuple(i->setindex(z, unitelement, i), 4) 63 verticies = ntuple(i->setindex(z, unitelement, i), D)
59 return Simplex(verticies) 64 return Simplex((z,verticies...))
65 end
66 unitsimplex(D) = unitsimplex(Float64, D)
67
68 """
69 Chart{D}
70
71 A parametrized description of a manifold or part of a manifold.
72 """
73 struct Chart{D, PST<:ParameterSpace{D}, MT}
74 mapping::MT
75 parameterspace::PST
60 end 76 end
61 77
78 domain_dim(::Chart{D}) where D = D
79 (c::Chart)(ξ) = c.mapping(ξ)
80 parameterspace(c::Chart) = c.parameterspace
62 81
63 """ 82 """
83 jacobian(c::Chart, ξ)
64 84
65 A parametrized description of a manifold or part of a manifold. 85 The jacobian of the mapping evaluated at `ξ`. This defers to the
66 86 implementation of `jacobian` for the mapping itself. If no implementation is
67 Should implement a methods for 87 available one can easily be specified for either the mapping function or the
68 * `parameterspace` 88 chart itself.
69 * `(::Chart)(ξs...)` 89 ```julia
70 90 c = Chart(f, ps)
71 There is a default implementation for `(::Chart{D})(::SVector{D})` 91 jacobian(f::typeof(f), ξ) = f′(ξ)
92 ```
93 or
94 ```julia
95 c = Chart(f, ps)
96 jacobian(c::typeof(c),ξ) = f′(ξ)
97 ```
98 which will both allow calling `jacobian(c,ξ)`.
72 """ 99 """
73 abstract type Chart{D} end 100 jacobian(c::Chart, ξ) = jacobian(c.mapping, ξ)
74 # abstract type Chart{D,R} end
75
76 domain_dim(::Chart{D}) where D = D
77 # range_dim(::Chart{D,R}) where {D,R} = R
78
79 """
80 The parameterspace of a chart
81 """
82 function parameterspace end
83
84 (c::Chart{D})(x̄::SVector{D}) where D = c(x̄...)
85
86
87 struct ConcereteChart{PST<:ParameterSpace, MT}
88 parameterspace::PST
89 mapping::MT
90 end
91
92 (c::Chart)(x̄) = c.mapping(x̄)
93 101
94 102
95 """ 103 """
96 Atlas 104 Atlas
97 105