-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_interpolators.jl
More file actions
158 lines (146 loc) · 5.37 KB
/
test_interpolators.jl
File metadata and controls
158 lines (146 loc) · 5.37 KB
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
function run_interpolator_tests()
# list of FETypes that should be tested
TestCatalog1D = [
L2P0{1} => 0,
H1P1{1} => 1,
H1P2{1, 1} => 2,
H1P3{1, 1} => 3,
H1Pk{1, 1, 3} => 3,
H1Pk{1, 1, 4} => 4,
H1Pk{1, 1, 5} => 5,
]
TestCatalog2D = [
HCURLN0{2} => 0,
HCURLN1{2} => 1,
HDIVRT0{2} => 0,
HDIVRTk{2, 0} => 0,
HDIVBDM1{2} => 1,
HDIVRT1{2} => 1,
HDIVRTk{2, 1} => 1,
HDIVBDM2{2} => 2,
HDIVRTk{2, 2} => 2,
HDIVRTk{2, 3} => 3,
HDIVRTk{2, 4} => 4,
L2P0{2} => 0,
L2P1{2} => 1,
H1P1{2} => 1,
H1Q1{2} => 1,
H1CR{2} => 1,
H1MINI{2, 2} => 1,
H1P1TEB{2} => 1,
H1BR{2} => 1,
H1P2{2, 2} => 2,
H1P2B{2, 2} => 2,
H1Q2{2, 2} => 2,
H1P3{2, 2} => 3,
H1Pk{2, 2, 3} => 3,
H1Pk{2, 2, 4} => 4,
H1Pk{2, 2, 5} => 5,
]
TestCatalog3D = [
HCURLN0{3} => 0,
HDIVRT0{3} => 0,
HDIVBDM1{3} => 1,
HDIVRT1{3} => 1,
L2P0{3} => 0,
H1P1{3} => 1,
H1Q1{3} => 1,
H1CR{3} => 1,
H1MINI{3, 3} => 1,
H1P1TEB{3} => 1,
H1BR{3} => 1,
H1P2{3, 3} => 2,
H1P3{3, 3} => 3,
]
## function that computes errors at enough quadrature points for polynomial of degree order
function compute_error(uh::FEVectorBlock, u::Function, order = get_polynomialorder(get_FEType(uh), uh.FES.xgrid[CellGeometries][1]))
xgrid = uh.FES.xgrid
FES = uh.FES
EGs = xgrid[UniqueCellGeometries]
ncomponents = get_ncomponents(uh)
cells4eg = xgrid[ExtendableGrids.CellAssemblyGroups]
celldofs = FES[CellDofs]
error = zeros(Float64, ncomponents, num_cells(xgrid))
uhval = zeros(Float64, ncomponents)
uval = zeros(Float64, ncomponents)
for (j, EG) in enumerate(EGs)
cells = view(cells4eg, :, j)
L2G = L2GTransformer(EG, xgrid, ON_CELLS)
QP = QPInfos(xgrid)
qf = VertexRule(EG, order)
FEB = FEEvaluator(FES, Identity, qf)
@show FEB
for cell::Int in cells
update_trafo!(L2G, cell)
update_basis!(FEB, cell)
for (qp, weight) in enumerate(qf.w)
## evaluate uh
fill!(uhval, 0)
eval_febe!(uhval, FEB, view(uh.entries, view(celldofs, :, cell)), qp)
## evaluate u
fill!(uval, 0)
eval_trafo!(QP.x, L2G, qf.xref[qp])
u(uval, QP)
## evaluate error
view(error, :, cell) .+= abs.(uval - uhval)
end
end
end
return error
end
function test_interpolation(xgrid, FEType, order, broken::Bool = false)
u, ~ = exact_function(Val(size(xgrid[Coordinates], 1)), order)
# choose FE and generate FESpace
FES = FESpace{FEType}(xgrid; broken = broken)
AT = ON_CELLS
# interpolate
Solution = FEVector(FES)
interpolate!(Solution[1], u; bonus_quadorder = order)
@show Solution
# compute error
error = compute_error(Solution[1], u, order)
println("FEType = $FEType $(broken ? "broken" : "") $AT | ndofs = $(FES.ndofs) | order = $order | error = $(norm(error, Inf))")
return @test norm(error) < tolerance
end
@testset "Interpolations" begin
println("\n")
println("============================")
println("Testing Interpolations in 1D")
println("============================")
xgrid = testgrid(Edge1D)
for n in 1:length(TestCatalog1D)
test_interpolation(xgrid, TestCatalog1D[n].first, TestCatalog1D[n].second)
test_interpolation(xgrid, TestCatalog1D[n].first, TestCatalog1D[n].second, true)
end
println("\n")
println("============================")
println("Testing Interpolations in 2D")
println("============================")
for EG in [Triangle2D, Parallelogram2D]
xgrid = uniform_refine(reference_domain(EG), 1)
println("EG = $EG")
for n in 1:length(TestCatalog2D), broken in (false, true)
if ExtendableFEMBase.isdefined(TestCatalog2D[n].first, EG, broken)
test_interpolation(xgrid, TestCatalog2D[n].first, TestCatalog2D[n].second, broken)
else
@warn "$(TestCatalog2D[n]) (broken = $broken) not defined on $EG (skipping test case)"
end
end
end
println("\n")
println("============================")
println("Testing Interpolations in 3D")
println("============================")
for EG in [Tetrahedron3D, Parallelepiped3D]
xgrid = uniform_refine(reference_domain(EG), 1)
for n in 1:length(TestCatalog3D), broken in (false, true)
if ExtendableFEMBase.isdefined(TestCatalog3D[n].first, EG, broken)
test_interpolation(xgrid, TestCatalog3D[n].first, TestCatalog3D[n].second, broken)
else
@warn "$(TestCatalog3D[n]) (broken = $broken) not defined on $EG (skipping test case)"
end
end
end
end
return println("")
end