Skip to content

Commit 1472904

Browse files
committed
added tests, reconstruction operators can now also used with lazy_interpolate!
1 parent 3c5022c commit 1472904

3 files changed

Lines changed: 58 additions & 6 deletions

File tree

src/reconstructionhandlers.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ Weighted reconstruction operator: evaluates a reconstructed version of a finite
1919
# Parameters
2020
- `FETypeR`: The reconstruction finite element space type (target space for reconstruction).
2121
- `O`: The standard function operator to be evaluated (e.g., identity, gradient, etc.).
22-
- `F`: The type of the weight function (should be callable, e.g., a function or functor).
22+
- `w`: The type of the weight function (should be callable, e.g., a function or functor of type w(x)).
2323
"""
24-
abstract type WeightedReconstruct{FETypeR, O, F} <: Reconstruct{FETypeR, O} end
24+
abstract type WeightedReconstruct{FETypeR, O, w} <: Reconstruct{FETypeR, O} end
2525

26-
weight_type(::Type{<:WeightedReconstruct{FETypeR, O, F}}) where {FETypeR, O, F} = F
26+
weight_type(::Type{<:WeightedReconstruct{FETypeR, O, w}}) where {FETypeR, O, w} = w
2727

2828

2929
################## SPECIAL INTERPOLATORS ####################
@@ -474,7 +474,7 @@ boundary_coefficients!(coefficients, RH::ReconstructionHandler, cell)
474474
475475
generates the coefficients for the facial dofs of the reconstruction operator on the cell
476476
"""
477-
function boundary_coefficients!(coefficients, RH::ReconstructionHandler{Tv, Ti, <: Reconstruct, <:H1CR{ncomponents}, <:HDIVRT0{ncomponents}, <:ON_CELLS, EG}, cell) where {Tv, Ti, ncomponents, EG}
477+
function boundary_coefficients!(coefficients, RH::ReconstructionHandler{Tv, Ti, <:Reconstruct, <:H1CR{ncomponents}, <:HDIVRT0{ncomponents}, <:ON_CELLS, EG}, cell) where {Tv, Ti, ncomponents, EG}
478478
xFaceVolumes = RH.xFaceVolumes
479479
xFaceNormals = RH.xFaceNormals
480480
xCellFaces = RH.xCellFaces
@@ -709,4 +709,3 @@ function boundary_coefficients!(coefficients, RH::ReconstructionHandler{Tv, Ti,
709709
end
710710
return nothing
711711
end
712-

src/reconstructionoperators.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ReconstructionSpace(::Type{<:ReconstructionOperator{FETypeR, O}}) where {FETypeR
44
NeededDerivative4Operator(::Type{<:ReconstructionOperator{FETypeR, O}}) where {FETypeR, O} = NeededDerivative4Operator(O)
55
Length4Operator(::Type{<:ReconstructionOperator{FETypeR, O}}, xdim, nc) where {FETypeR, O} = Length4Operator(O, xdim, nc)
66
DefaultName4Operator(::Type{Reconstruct{FETypeR, O}}) where {FETypeR, O} = "R(" * DefaultName4Operator(O) * ")"
7-
DefaultName4Operator(::Type{WeightedReconstruct{FETypeR, O}}) where {FETypeR, O} = "R(r" * DefaultName4Operator(O) * ")"
7+
DefaultName4Operator(::Type{WeightedReconstruct{FETypeR, O, w}}) where {FETypeR, O, w} = "wR(r" * DefaultName4Operator(O) * ")"
88

99
struct FEReconstEvaluator{T, TvG, TiG, FEType, FEType2, stdop, RH} <: FEEvaluator{T, TvG, TiG}
1010
citem::Base.RefValue{Int} # current item
@@ -66,6 +66,10 @@ function FEEvaluator(
6666
return FEReconstEvaluator{T, TvG, TiG, FEType, FETypeReconst, stdop, typeof(reconst_handler)}(FEB.citem, FE, FEB, cvals, coefficients2, reconst_handler)
6767
end
6868

69+
function relocate_xref!(FEB::FEReconstEvaluator, new_xref)
70+
return relocate_xref!(FEB.FEB, new_xref)
71+
end
72+
6973
function update_basis!(FEBE::FEReconstEvaluator)
7074
## evaluate standard operator in reconstruction basis (->cvals_reconst)
7175
update_basis!(FEBE.FEB)

test/test_operators.jl

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
1213
end
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+
1463
function test_derivatives2D()
1564
## define test function and expected operator evals
1665
function testf(result, qpinfo)

0 commit comments

Comments
 (0)