comparison src/Grids/manifolds.jl @ 1785:96f8cad255b4 feature/sbp_operators/laplace_curvilinear

Merge feature/grids/manifolds
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 16 Sep 2024 10:33:47 +0200
parents 614f731af685
children 1987347752ef
comparison
equal deleted inserted replaced
1751:f3d7e2d7a43f 1785:96f8cad255b4
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 Base.ndims(::ParameterSpace{D}) where D = D
22 # TBD: Should implement domain_dim? 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
23 37
24 struct HyperBox{T,D} <: ParameterSpace{D} 38 struct HyperBox{T,D} <: ParameterSpace{D}
25 a::SVector{D,T} 39 a::SVector{D,T}
26 b::SVector{D,T} 40 b::SVector{D,T}
27 end 41 end
28 42
29 function HyperBox(a,b) 43 function HyperBox(a,b)
30 T = SVector{length(a)} 44 ET = promote_type(eltype(a),eltype(b))
45 T = SVector{length(a),ET}
31 HyperBox(convert(T,a), convert(T,b)) 46 HyperBox(convert(T,a), convert(T,b))
32 end 47 end
33 48
34 Interval{T} = HyperBox{T,1}
35 Rectangle{T} = HyperBox{T,2} 49 Rectangle{T} = HyperBox{T,2}
36 Box{T} = HyperBox{T,3} 50 Box{T} = HyperBox{T,3}
37 51
38 limits(box::HyperBox, d) = (box.a[d], box.b[d]) 52 limits(box::HyperBox, d) = (box.a[d], box.b[d])
39 limits(box::HyperBox) = (box.a, box.b) 53 limits(box::HyperBox) = (box.a, box.b)
40 54
41 unitinterval(T=Float64) = unithyperbox(T,1)
42 unitsquare(T=Float64) = unithyperbox(T,2) 55 unitsquare(T=Float64) = unithyperbox(T,2)
43 unitcube(T=Float64) = unithyperbox(T,3) 56 unitcube(T=Float64) = unithyperbox(T,3)
44 unithyperbox(T, D) = HyperBox((@SVector zeros(T,D)), (@SVector ones(T,D))) 57 unithyperbox(T, D) = HyperBox((@SVector zeros(T,D)), (@SVector ones(T,D)))
45 unithyperbox(D) = unithyperbox(Float64,D) 58 unithyperbox(D) = unithyperbox(Float64,D)
46 59
47 60
48 struct Simplex{T,D,NV} <: ParameterSpace{D} 61 struct Simplex{T,D,NV} <: ParameterSpace{D}
49 verticies::NTuple{NV,SVector{D,T}} 62 verticies::NTuple{NV,SVector{D,T}}
50 end 63 end
51 64
52 Simplex(verticies::Vararg{AbstractArray}) = Simplex(Tuple(SVector(v...) for v ∈ verticies)) 65 function Simplex(verticies::Vararg{AbstractArray})
66 ET = mapreduce(eltype,promote_type,verticies)
67 T = SVector{length(verticies[1]),ET}
68
69 return Simplex(Tuple(convert(T,v) for v ∈ verticies))
70 end
53 71
54 verticies(s::Simplex) = s.verticies 72 verticies(s::Simplex) = s.verticies
55 73
56 Triangle{T} = Simplex{T,2} 74 Triangle{T} = Simplex{T,2}
57 Tetrahedron{T} = Simplex{T,3} 75 Tetrahedron{T} = Simplex{T,3}
74 struct Chart{D, PST<:ParameterSpace{D}, MT} 92 struct Chart{D, PST<:ParameterSpace{D}, MT}
75 mapping::MT 93 mapping::MT
76 parameterspace::PST 94 parameterspace::PST
77 end 95 end
78 96
79 domain_dim(::Chart{D}) where D = D 97 Base.ndims(::Chart{D}) where D = D
80 (c::Chart)(ξ) = c.mapping(ξ) 98 (c::Chart)(ξ) = c.mapping(ξ)
81 parameterspace(c::Chart) = c.parameterspace 99 parameterspace(c::Chart) = c.parameterspace
82 100
83 """ 101 """
84 jacobian(c::Chart, ξ) 102 jacobian(c::Chart, ξ)
129 struct CartesianAtlas <: Atlas 147 struct CartesianAtlas <: Atlas
130 charts::Matrix{Chart} 148 charts::Matrix{Chart}
131 end 149 end
132 150
133 charts(a::CartesianAtlas) = a.charts 151 charts(a::CartesianAtlas) = a.charts
152 connections(a::CartesianAtlas) = nothing
134 153
135 struct UnstructuredAtlas <: Atlas 154 struct UnstructuredAtlas <: Atlas
136 charts::Vector{Chart} 155 charts::Vector{Chart}
137 connections 156 connections
138 end 157 end
139 158
140 charts(a::UnstructuredAtlas) = a.charts 159 charts(a::UnstructuredAtlas) = a.charts
160 connections(a::UnstructuredAtlas) = nothing
141 161
142 162
143 ### 163 ###
144 # Geometry 164 # Geometry
145 ### 165 ###