Skip to content

Commit

Permalink
Fix face node ordering for Tetrahedron{3} (#475)
Browse files Browse the repository at this point in the history
This commit fixes the ordering for Ferrite.faces(...) s.t. they are
counter clockwise from the outside. Also adjust the face order for
Lagrange{3,RefCube,2}() to match Lagrange{3,RefCube,1}().
  • Loading branch information
fredrikekre committed Sep 8, 2022
1 parent b9998a0 commit 357e35b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Grid/grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ faces(c::Union{Quadrilateral,QuadraticQuadrilateral}) = ((c.nodes[1],c.nodes[2])
edges(c::Line3D) = ((c.nodes[1],c.nodes[2]),)
vertices(c::Union{Tetrahedron,QuadraticTetrahedron}) = (c.nodes[1], c.nodes[2], c.nodes[3], c.nodes[4])
edges(c::Union{Tetrahedron,QuadraticTetrahedron}) = ((c.nodes[1],c.nodes[2]), (c.nodes[2],c.nodes[3]), (c.nodes[3],c.nodes[1]), (c.nodes[1],c.nodes[4]), (c.nodes[2],c.nodes[4]), (c.nodes[3],c.nodes[4]))
faces(c::Union{Tetrahedron,QuadraticTetrahedron}) = ((c.nodes[1],c.nodes[2],c.nodes[3]), (c.nodes[1],c.nodes[2],c.nodes[4]), (c.nodes[2],c.nodes[3],c.nodes[4]), (c.nodes[1],c.nodes[4],c.nodes[3]))
faces(c::Union{Tetrahedron,QuadraticTetrahedron}) = ((c.nodes[1],c.nodes[3],c.nodes[2]), (c.nodes[1],c.nodes[2],c.nodes[4]), (c.nodes[2],c.nodes[3],c.nodes[4]), (c.nodes[1],c.nodes[4],c.nodes[3]))
vertices(c::Union{Hexahedron,Cell{3,20,6}}) = (c.nodes[1], c.nodes[2], c.nodes[3], c.nodes[4], c.nodes[5], c.nodes[6], c.nodes[7], c.nodes[8])
edges(c::Union{Hexahedron,Cell{3,20,6}}) = ((c.nodes[1],c.nodes[2]), (c.nodes[2],c.nodes[3]), (c.nodes[3],c.nodes[4]), (c.nodes[4],c.nodes[1]), (c.nodes[5],c.nodes[6]), (c.nodes[6],c.nodes[7]), (c.nodes[7],c.nodes[8]), (c.nodes[8],c.nodes[5]), (c.nodes[1],c.nodes[5]), (c.nodes[2],c.nodes[6]), (c.nodes[3],c.nodes[7]), (c.nodes[4],c.nodes[8]))
faces(c::Union{Hexahedron,Cell{3,20,6}}) = ((c.nodes[1],c.nodes[4],c.nodes[3],c.nodes[2]), (c.nodes[1],c.nodes[2],c.nodes[6],c.nodes[5]), (c.nodes[2],c.nodes[3],c.nodes[7],c.nodes[6]), (c.nodes[3],c.nodes[4],c.nodes[8],c.nodes[7]), (c.nodes[1],c.nodes[5],c.nodes[8],c.nodes[4]), (c.nodes[5],c.nodes[6],c.nodes[7],c.nodes[8]))
Expand Down
13 changes: 10 additions & 3 deletions src/interpolations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ end
getnbasefunctions(::Lagrange{3,RefTetrahedron,1}) = 4
nvertexdofs(::Lagrange{3,RefTetrahedron,1}) = 1

faces(::Lagrange{3,RefTetrahedron,1}) = ((1,2,3), (1,2,4), (2,3,4), (1,4,3))
faces(::Lagrange{3,RefTetrahedron,1}) = ((1,3,2), (1,2,4), (2,3,4), (1,4,3))
edges(::Lagrange{3,RefTetrahedron,1}) = ((1,2), (2,3), (3,1), (1,4), (2,4), (3,4))

function reference_coordinates(::Lagrange{3,RefTetrahedron,1})
Expand Down Expand Up @@ -365,7 +365,7 @@ getnbasefunctions(::Lagrange{3,RefTetrahedron,2}) = 10
nvertexdofs(::Lagrange{3,RefTetrahedron,2}) = 1
nedgedofs(::Lagrange{3,RefTetrahedron,2}) = 1

faces(::Lagrange{3,RefTetrahedron,2}) = ((1,2,3,5,6,7), (1,2,4,5,9,8), (2,3,4,6,10,9), (1,4,3,8,10,7))
faces(::Lagrange{3,RefTetrahedron,2}) = ((1,3,2,7,6,5), (1,2,4,5,9,8), (2,3,4,6,10,9), (1,4,3,8,10,7))
edges(::Lagrange{3,RefTetrahedron,2}) = ((1,5,2), (2,6,3), (3,7,1), (1,8,4), (2,9,4), (3,10,4))

function reference_coordinates(::Lagrange{3,RefTetrahedron,2})
Expand Down Expand Up @@ -446,7 +446,14 @@ nedgedofs(::Lagrange{3,RefCube,2}) = 1
nfacedofs(::Lagrange{3,RefCube,2}) = 1
ncelldofs(::Lagrange{3,RefCube,2}) = 1

faces(::Lagrange{3,RefCube,2}) = ((1,2,6,5, 9,18,13,17, 23), (2,3,7,6, 10,19,14,18, 22), (3,4,8,7, 11,20,15,19, 24), (1,5,8,4, 12,17,16,20, 21), (1,4,3,2, 9,10,11,12, 25), (5,6,7,8, 13,14,15,16, 26))
faces(::Lagrange{3,RefCube,2}) = (
(1,4,3,2, 9,10,11,12, 25),
(1,2,6,5, 9,18,13,17, 23),
(2,3,7,6, 10,19,14,18, 22),
(3,4,8,7, 11,20,15,19, 24),
(1,5,8,4, 12,17,16,20, 21),
(5,6,7,8, 13,14,15,16, 26),
)
edges(::Lagrange{3,RefCube,2}) = ((1,2, 9), (2,3, 10), (3,4, 11), (4,1, 12), (1,5, 16), (2,6, 19), (3,7, 18), (4,8, 19), (5,6, 13), (6,7, 14), (7,8, 15), (8,5, 16))

function reference_coordinates(::Lagrange{3,RefCube,2})
Expand Down
24 changes: 24 additions & 0 deletions test/test_interpolations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,30 @@ for interpolation in (Lagrange{1, RefCube, 1}(),
end
end
end

# Test that faces(...) return in counter clockwise order (viewing from the outside)
if interpolation isa Lagrange
function __outward_normal(coords::Vector{<:Vec{1}}, nodes)
n = coords[nodes[1]]
return n / norm(n)
end
function __outward_normal(coords::Vector{<:Vec{2}}, nodes)
p1 = coords[nodes[1]]
p2 = coords[nodes[2]]
n = Vec{2}((p2[2] - p1[2], - p2[1] + p1[1]))
return n / norm(n)
end
function __outward_normal(coords::Vector{<:Vec{3}}, nodes)
p1 = coords[nodes[1]]
p2 = coords[nodes[2]]
p3 = coords[nodes[3]]
n = (p3 - p2) × (p1 - p2)
return n / norm(n)
end
for (facenodes, normal) in zip(Ferrite.faces(interpolation), reference_normals(interpolation))
@test __outward_normal(coords, facenodes) normal
end
end
end

end
2 changes: 1 addition & 1 deletion test/test_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function reference_normals(::Lagrange{3, RefTetrahedron})
end

# Lagrange{3, Cube}
function reference_normals(::Lagrange{3, RefCube, 1})
function reference_normals(::Lagrange{3, RefCube})
return [Vec{3, Float64}(( 0.0, 0.0, -1.0)),
Vec{3, Float64}(( 0.0, -1.0, 0.0)),
Vec{3, Float64}(( 1.0, 0.0, 0.0)),
Expand Down

0 comments on commit 357e35b

Please sign in to comment.