-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathh1v_p1teb.jl
278 lines (246 loc) · 12.2 KB
/
h1v_p1teb.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
"""
````
abstract type H1P1TEB{edim} <: AbstractH1FiniteElementWithCoefficients where {edim<:Int}
````
vector-valued (ncomponents = edim) element that uses P1 functions + tangential-weighted edge bubbles
as suggested by [Diening, L., Storn, J. & Tscherpel, T., "Fortin operator for the Taylor–Hood element", Num. Math. 150, 671–689 (2022)]
(is inf-sup stable for Stokes if paired with continuous P1 pressure space, less degrees of freedom than MINI)
allowed ElementGeometries:
- Triangle2D
- Tetrahedron3D
"""
abstract type H1P1TEB{edim} <: AbstractH1FiniteElementWithCoefficients where {edim <: Int} end
H1P1TEB(edim::Int) = H1P1TEB{edim}
function Base.show(io::Core.IO, ::Type{<:H1P1TEB{edim}}) where {edim}
return print(io, "H1P1TEB{$edim}")
end
get_ncomponents(FEType::Type{<:H1P1TEB}) = FEType.parameters[1]
get_ndofs(::Union{Type{<:ON_FACES}, Type{<:ON_BFACES}}, FEType::Type{<:H1P1TEB{2}}, EG::Type{<:AbstractElementGeometry}) = 1 + num_nodes(EG) * FEType.parameters[1]
get_ndofs(::Type{ON_CELLS}, FEType::Type{<:H1P1TEB{2}}, EG::Type{<:AbstractElementGeometry}) = num_faces(EG) + num_nodes(EG) * FEType.parameters[1]
get_ndofs(::Union{Type{<:ON_EDGES}, Type{<:ON_BEDGES}}, FEType::Type{<:H1P1TEB{3}}, EG::Type{<:AbstractElementGeometry}) = 1 + num_nodes(EG) * FEType.parameters[1]
get_ndofs(::Union{Type{<:ON_FACES}, Type{<:ON_BFACES}}, FEType::Type{<:H1P1TEB{3}}, EG::Type{<:AbstractElementGeometry}) = num_edges(EG) + num_nodes(EG) * FEType.parameters[1]
get_ndofs(::Type{ON_CELLS}, FEType::Type{<:H1P1TEB{3}}, EG::Type{<:AbstractElementGeometry}) = num_edges(EG) + num_nodes(EG) * FEType.parameters[1]
get_polynomialorder(::Type{<:H1P1TEB{2}}, ::Type{<:Edge1D}) = 2
get_polynomialorder(::Type{<:H1P1TEB{2}}, ::Type{<:Triangle2D}) = 2
get_polynomialorder(::Type{<:H1P1TEB{3}}, ::Type{<:Edge1D}) = 2
get_polynomialorder(::Type{<:H1P1TEB{3}}, ::Type{<:Triangle2D}) = 2
get_polynomialorder(::Type{<:H1P1TEB{3}}, ::Type{<:Tetrahedron3D}) = 2
get_dofmap_pattern(FEType::Type{<:H1P1TEB{2}}, ::Type{CellDofs}, EG::Type{<:Triangle2D}) = "N1f1"
get_dofmap_pattern(FEType::Type{<:H1P1TEB{2}}, ::Union{Type{FaceDofs}, Type{BFaceDofs}}, EG::Type{<:Edge1D}) = "N1i1"
get_dofmap_pattern(FEType::Type{<:H1P1TEB{3}}, ::Type{EdgeDofs}, EG::Type{<:Edge1D}) = "N1i1"
get_dofmap_pattern(FEType::Type{<:H1P1TEB{3}}, ::Type{CellDofs}, EG::Type{<:Tetrahedron3D}) = "N1e1"
get_dofmap_pattern(FEType::Type{<:H1P1TEB{3}}, ::Union{Type{FaceDofs}, Type{BFaceDofs}}, EG::Type{<:Triangle2D}) = "N1e1"
isdefined(FEType::Type{<:H1P1TEB}, ::Type{<:Triangle2D}) = true
isdefined(FEType::Type{<:H1P1TEB}, ::Type{<:Tetrahedron3D}) = true
function ExtendableGrids.interpolate!(Target, FE::FESpace{Tv, Ti, FEType, APT}, ::Type{AT_NODES}, exact_function!; items = [], kwargs...) where {Tv, Ti, FEType <: H1P1TEB, APT}
nnodes = size(FE.dofgrid[Coordinates], 2)
return point_evaluation!(Target, FE, AT_NODES, exact_function!; items = items, component_offset = nnodes, kwargs...)
end
function ExtendableGrids.interpolate!(Target, FE::FESpace{Tv, Ti, FEType, APT}, ::Type{ON_EDGES}, exact_function!; items = [], kwargs...) where {Tv, Ti, FEType <: H1P1TEB{2}, APT}
# delegate edge nodes to node interpolation
subitems = slice(FE.dofgrid[EdgeNodes], items)
return interpolate!(Target, FE, AT_NODES, exact_function!; items = subitems, kwargs...)
end
function ExtendableGrids.interpolate!(Target, FE::FESpace{Tv, Ti, FEType, APT}, ::Type{ON_FACES}, exact_function!; items = [], kwargs...) where {Tv, Ti, FEType <: H1P1TEB{3}, APT}
# delegate edges to edge interpolation
subitems = slice(FE.dofgrid[FaceEdges], items)
return interpolate!(Target, FE, ON_EDGES, exact_function!; items = subitems, kwargs...)
end
function ExtendableGrids.interpolate!(Target::AbstractArray{T, 1}, FE::FESpace{Tv, Ti, FEType, APT}, ::Type{ON_FACES}, exact_function!; items = [], bonus_quadorder = 0, kwargs...) where {T, Tv, Ti, FEType <: H1P1TEB{2}, APT}
# delegate face nodes to node interpolation
subitems = slice(FE.dofgrid[FaceNodes], items)
interpolate!(Target, FE, AT_NODES, exact_function!; items = subitems, kwargs...)
# preserve face means in tangential direction
xItemVolumes = FE.dofgrid[FaceVolumes]
xItemNodes = FE.dofgrid[FaceNodes]
xItemGeometries = FE.dofgrid[FaceGeometries]
xFaceNormals = FE.dofgrid[FaceNormals]
xItemDofs = FE[FaceDofs]
ncomponents = get_ncomponents(FEType)
nnodes = size(FE.dofgrid[Coordinates], 2)
nitems = num_sources(xItemNodes)
offset = ncomponents * nnodes
if items == []
items = 1:nitems
end
# compute exact face means
facemeans = zeros(T, ncomponents, nitems)
integrate!(facemeans, FE.dofgrid, ON_FACES, exact_function!; quadorder = 2 + bonus_quadorder, items = items, kwargs...)
P1flux::T = 0
value::T = 0
itemEG = Edge1D
nitemnodes::Int = 0
for item in items
itemEG = xItemGeometries[item]
nitemnodes = num_nodes(itemEG)
# compute normal flux (minus linear part)
value = 0
for c in 1:ncomponents
P1flux = 0
for dof in 1:nitemnodes
P1flux += Target[xItemDofs[(c - 1) * nitemnodes + dof, item]] * xItemVolumes[item] / nitemnodes
end
if c == 1
value -= (facemeans[c, item] - P1flux) * xFaceNormals[2, item]
else
value += (facemeans[c, item] - P1flux) * xFaceNormals[1, item]
end
end
# set face bubble value
Target[offset + item] = value / xItemVolumes[item]
end
return
end
function ExtendableGrids.interpolate!(Target::AbstractArray{T, 1}, FE::FESpace{Tv, Ti, FEType, APT}, ::Type{ON_EDGES}, exact_function!; items = [], bonus_quadorder = 0, kwargs...) where {T, Tv, Ti, FEType <: H1P1TEB{3}, APT}
# delegate face nodes to node interpolation
subitems = slice(FE.dofgrid[EdgeNodes], items)
interpolate!(Target, FE, AT_NODES, exact_function!; items = subitems, kwargs...)
# preserve edge means in tangential direction
xItemVolumes = FE.dofgrid[EdgeVolumes]
xItemNodes = FE.dofgrid[EdgeNodes]
xItemGeometries = FE.dofgrid[EdgeGeometries]
xEdgeTangents = FE.dofgrid[EdgeTangents]
xItemDofs = FE[EdgeDofs]
nnodes = size(FE.dofgrid[Coordinates], 2)
nitems = num_sources(xItemNodes)
ncomponents = get_ncomponents(FEType)
offset = ncomponents * nnodes
if items == []
items = 1:nitems
end
# compute exact face means
edgemeans = zeros(T, ncomponents, nitems)
integrate!(edgemeans, FE.dofgrid, ON_EDGES, exact_function!; quadorder = 2 + bonus_quadorder, items = items, kwargs...)
P1flux::T = 0
value::T = 0
itemEG = Edge1D
nitemnodes::Int = 0
for item in items
itemEG = xItemGeometries[item]
nitemnodes = num_nodes(itemEG)
# compute normal flux (minus linear part)
value = 0
for c in 1:ncomponents
P1flux = 0
for dof in 1:nitemnodes
P1flux += Target[xItemDofs[(c - 1) * nitemnodes + dof, item]] * xItemVolumes[item] / nitemnodes
end
value += (edgemeans[c, item] - P1flux) * xEdgeTangents[c, item]
end
# set face bubble value
Target[offset + item] = value / xItemVolumes[item]
end
return
end
function ExtendableGrids.interpolate!(Target, FE::FESpace{Tv, Ti, FEType, APT}, ::Type{ON_CELLS}, exact_function!; items = [], kwargs...) where {Tv, Ti, FEType <: H1P1TEB, APT}
# delegate cell faces to face interpolation
subitems = slice(FE.dofgrid[CellFaces], items)
return interpolate!(Target, FE, ON_FACES, exact_function!; items = subitems, kwargs...)
end
############
# 2D basis #
############
function get_basis(AT::Union{Type{<:ON_FACES}, Type{<:ON_BFACES}}, ::Type{H1P1TEB{2}}, EG::Type{<:Edge1D})
refbasis_P1 = get_basis(AT, H1P1{2}, EG)
offset = get_ndofs(AT, H1P1{2}, EG)
return function closure(refbasis, xref)
refbasis_P1(refbasis, xref)
# add face bubble to P1 basis
refbasis[offset + 1, 1] = 6 * xref[1] * refbasis[1, 1]
return refbasis[offset + 1, 2] = refbasis[offset + 1, 1]
end
end
function get_basis(AT::Type{ON_CELLS}, ::Type{H1P1TEB{2}}, EG::Type{<:Triangle2D})
refbasis_P1 = get_basis(AT, H1P1{2}, EG)
offset = get_ndofs(AT, H1P1{2}, EG)
return function closure(refbasis, xref)
refbasis_P1(refbasis, xref)
# add face bubbles to P1 basis
refbasis[offset + 1, 1] = 6 * xref[1] * refbasis[1, 1]
refbasis[offset + 2, 1] = 6 * xref[2] * xref[1]
refbasis[offset + 3, 1] = 6 * refbasis[1, 1] * xref[2]
refbasis[offset + 1, 2] = refbasis[offset + 1, 1]
refbasis[offset + 2, 2] = refbasis[offset + 2, 1]
return refbasis[offset + 3, 2] = refbasis[offset + 3, 1]
end
end
function get_coefficients(::Type{ON_CELLS}, FE::FESpace{Tv, Ti, H1P1TEB{2}, APT}, ::Type{<:Triangle2D}) where {Tv, Ti, APT}
xFaceNormals::Array{Tv, 2} = FE.dofgrid[FaceNormals]
xCellFaces = FE.dofgrid[CellFaces]
return function closure(coefficients::Array{<:Real, 2}, cell)
fill!(coefficients, 1.0)
coefficients[1, 7] = -xFaceNormals[2, xCellFaces[1, cell]]
coefficients[2, 7] = xFaceNormals[1, xCellFaces[1, cell]]
coefficients[1, 8] = -xFaceNormals[2, xCellFaces[2, cell]]
coefficients[2, 8] = xFaceNormals[1, xCellFaces[2, cell]]
coefficients[1, 9] = -xFaceNormals[2, xCellFaces[3, cell]]
return coefficients[2, 9] = xFaceNormals[1, xCellFaces[3, cell]]
end
end
function get_coefficients(::Type{<:ON_FACES}, FE::FESpace{Tv, Ti, H1P1TEB{2}, APT}, ::Type{<:Edge1D}) where {Tv, Ti, APT}
xFaceNormals::Array{Tv, 2} = FE.dofgrid[FaceNormals]
return function closure(coefficients::Array{<:Real, 2}, face)
# multiplication of face bubble with normal vector of face
fill!(coefficients, 1.0)
coefficients[1, 5] = -xFaceNormals[2, face]
return coefficients[2, 5] = xFaceNormals[1, face]
end
end
############
# 3D basis #
############
function get_basis(AT::Union{Type{<:ON_FACES}, Type{<:ON_BFACES}}, ::Type{H1P1TEB{3}}, EG::Type{<:Triangle2D})
refbasis_P1 = get_basis(AT, H1P1{3}, EG)
offset = get_ndofs(AT, H1P1{3}, EG)
return function closure(refbasis, xref)
refbasis_P1(refbasis, xref)
# add edge bubbles to P1 basis
refbasis[offset + 1, 1] = 6 * xref[1] * refbasis[1, 1]
refbasis[offset + 2, 1] = 6 * xref[2] * xref[1]
refbasis[offset + 3, 1] = 6 * refbasis[1, 1] * xref[2]
for j in 1:3, k in 2:3
refbasis[offset + j, k] = refbasis[offset + j, 1]
end
return
end
end
function get_basis(AT::Type{ON_CELLS}, ::Type{H1P1TEB{3}}, EG::Type{<:Tetrahedron3D})
refbasis_P1 = get_basis(AT, H1P1{3}, EG)
offset = get_ndofs(AT, H1P1{3}, EG)
return function closure(refbasis, xref)
refbasis_P1(refbasis, xref)
# add edge bubbles to P1 basis
refbasis[offset + 1, 1] = 6 * xref[1] * refbasis[1, 1]
refbasis[offset + 2, 1] = 6 * xref[2] * refbasis[1, 1]
refbasis[offset + 3, 1] = 6 * xref[3] * refbasis[1, 1]
refbasis[offset + 4, 1] = 6 * xref[1] * xref[2]
refbasis[offset + 5, 1] = 6 * xref[1] * xref[3]
refbasis[offset + 6, 1] = 6 * xref[2] * xref[3]
for j in 1:6, k in 2:3
refbasis[offset + j, k] = refbasis[offset + j, 1]
end
return nothing
end
end
function get_coefficients(::Type{ON_CELLS}, FE::FESpace{Tv, Ti, H1P1TEB{3}, APT}, ::Type{<:Tetrahedron3D}, xgrid) where {Tv, Ti, APT}
xEdgeTangents::Array{Tv, 2} = xgrid[EdgeTangents]
xCellEdges = xgrid[CellEdges]
return function closure(coefficients::Array{<:Real, 2}, cell)
fill!(coefficients, 1.0)
for e in 1:6, k in 1:2
coefficients[k, 8 + e] = xEdgeTangents[k, xCellEdges[e, cell]]
end
return nothing
end
end
function get_coefficients(::Type{<:ON_FACES}, FE::FESpace{Tv, Ti, H1P1TEB{3}, APT}, ::Type{<:Triangle2D}, xgrid) where {Tv, Ti, APT}
xEdgeTangents::Array{Tv, 2} = xgrid[EdgeTangents]
xFaceEdges = xgrid[FaceEdges]
return function closure(coefficients::Array{<:Real, 2}, face)
fill!(coefficients, 1.0)
for e in 1:3, k in 1:2
coefficients[k, 6 + e] = xEdgeTangents[k, xFaceEdges[e, face]]
end
return nothing
end
end