@@ -8,9 +8,58 @@ function run_operator_tests()
88 @test error < 1.0e-14
99 error = test_derivatives3D ()
1010 @test error < 1.0e-14
11+ test_reconstructions ()
1112 end
1213end
1314
15+ function test_reconstructions ()
16+ # # divergence-free axisymmetric velocity field u(r,z) = (r,-2z) in cylindrical coordinates
17+ function u! (result, qpinfo)
18+ x = qpinfo. x
19+ result[1 ] = x[1 ]
20+ return result[2 ] = - 2 * x[2 ]
21+ end
22+
23+ # # vector field times r, should have zero divergence div(ru) = (d/dr, d/dz) \cdot (ru) = 0
24+ function ru! (result, qpinfo)
25+ x = qpinfo. x
26+ result[1 ] = x[1 ]^ 2
27+ return result[2 ] = - 2 * x[1 ] * x[2 ]
28+ end
29+
30+ xgrid = testgrid (Triangle2D)
31+
32+ # # interpolate u into H1BR{2} (inf-sup stable Stokes element)
33+ FES = FESpace {H1BR{2}} (xgrid)
34+ uh = FEVector (FES)
35+ interpolate! (uh[1 ], u!; bonus_quadorder = 2 )
36+
37+ for FETypeR in [HDIVRT0{2 }, HDIVBDM1{2 }]
38+ # # interpolate ru into HDIVRTO{2} or HDIVBDM1{2}
39+ FES2 = FESpace {FETypeR} (xgrid)
40+ Πur = FEVector (FES2)
41+ interpolate! (Πur[1 ], ru!; bonus_quadorder = 2 )
42+
43+ # # test if interpolate of ru is divergence-free by interpolating into P0 function and checking its coefficients
44+ FES3 = FESpace {L2P0{1}} (xgrid)
45+ divΠur = FEVector (FES3)
46+ lazy_interpolate! (divΠur[1 ], Πur, [(1 , Divergence)])
47+ @test sqrt (sum ((divΠur. entries .^ 2 ))) < 1.0e-14
48+
49+ # # test if r-weighted reconstruction of uh is divergence-free by interpolating into P0 function and checking its coefficients
50+ weight = (x) -> (x[1 ])
51+ lazy_interpolate! (divΠur[1 ], uh, [(1 , WeightedReconstruct{FETypeR, Divergence, typeof (weight)})])
52+ @test sqrt (sum ((divΠur. entries .^ 2 ))) < 1.0e-14
53+
54+ # # test if weighted reconstruction of uh and interpolation of ru are identical
55+ FES4 = FESpace {L2P1{1}} (xgrid)
56+ diff = FEVector (FES4)
57+ lazy_interpolate! (diff[1 ], [uh[1 ], Πur[1 ]], [(1 , WeightedReconstruct{FETypeR, Identity, typeof (weight)}), (2 , Identity)]; postprocess = (result, args, qpinfo) -> (result[1 ] = (args[1 ] - args[3 ])^ 2 + (args[2 ] - args[4 ])^ 2 ))
58+ @test sqrt (sum ((diff. entries))) < 1.0e-14
59+ end
60+ return
61+ end
62+
1463function test_derivatives2D ()
1564 # # define test function and expected operator evals
1665 function testf (result, qpinfo)
0 commit comments