Skip to content

Commit

Permalink
Fix tolerances for high N tet elements (#173)
Browse files Browse the repository at this point in the history
* reduce tolerances for high N

* add test
  • Loading branch information
jlchan authored Jun 28, 2024
1 parent 5f0ff52 commit 81924a2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/MeshData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,9 @@ function MeshData(VX, VY, VZ, EToV, rd::RefElemData{3}; is_periodic=(false, fals
periodicity)

if any(is_periodic)
md = make_periodic(md, is_periodic)
# loosen the tolerance if N >> 1
tol = length(rd.r) * 100 * eps()
md = make_periodic(md, is_periodic; tol)
end

return md
Expand Down
3 changes: 2 additions & 1 deletion src/RefElemData_polynomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ function RefElemData(elem::Union{Tet, Hex},

# Construct matrices on reference elements
r, s, t = nodes(elem, N)
Fmask = hcat(find_face_nodes(elem, r, s, t)...)
tol = 1e2 * eps() * length(r) # loosen the tolerance if N >> 1
Fmask = hcat(find_face_nodes(elem, r, s, t, tol)...)
VDM, Vr, Vs, Vt = basis(elem, N, r, s, t)
Dr, Ds, Dt = (A -> A / VDM).((Vr, Vs, Vt))

Expand Down
23 changes: 23 additions & 0 deletions test/MeshData_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,26 @@ approx_elem_types_to_test = [(Polynomial(), Hex()),

end
end

@testset "Very high orders" begin
@testset "Tet" begin
N = 12
rd = RefElemData(Tet(), N)
md = MeshData(uniform_mesh(Tet(), 2), rd; is_periodic=true)

(; x, y, z) = md
u = @. sin(pi * x) * sin(pi * y) * sin(pi * z)
dudx_exact = @. pi * cos(pi * x) * sin(pi * y) * sin(pi * z)
dudy_exact = @. pi * sin(pi * x) * cos(pi * y) * sin(pi * z)
dudz_exact = @. pi * sin(pi * x) * sin(pi * y) * cos(pi * z)

dudr, duds, dudt = (D -> D * u).(rd.Drst)
dudx = @. (md.rxJ * dudr + md.sxJ * duds + md.txJ * dudt) / md.J
dudy = @. (md.ryJ * dudr + md.syJ * duds + md.tyJ * dudt) / md.J
dudz = @. (md.rzJ * dudr + md.szJ * duds + md.tzJ * dudt) / md.J

@test norm(dudx - dudx_exact, Inf) < 1e-3
@test norm(dudy - dudy_exact, Inf) < 1e-3
@test norm(dudz - dudz_exact, Inf) < 1e-3
end
end

0 comments on commit 81924a2

Please sign in to comment.