Skip to content

Commit e3664a1

Browse files
committed
update some tests
1 parent 03b5271 commit e3664a1

2 files changed

Lines changed: 24 additions & 23 deletions

File tree

test/test_jit_expression.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,11 @@ def test_facet_expression(compile_args):
299299
consts = np.array([], dtype=dtype)
300300
entity_index = np.array([0], dtype=np.intc)
301301
quad_perm = np.array([0], dtype=np.dtype("uint8"))
302-
tangents = np.array([coords[1] - coords[2], coords[2] - coords[0], coords[0] - coords[1]])
303-
midpoints = np.array(
304-
[
305-
coords[1] + (coords[2] - coords[1]) / 2,
306-
coords[0] + (coords[2] - coords[0]) / 2,
307-
coords[1] + (coords[1] - coords[0]) / 2,
308-
]
309-
)
302+
303+
edges = basix.topology(basix.CellType.triangle)[1]
304+
tangents = np.array([coords[j] - coords[i] for i, j in edges])
305+
midpoints = np.array([(coords[i] + coords[j]) / 2 for i, j in edges])
306+
310307
for i, (tangent, midpoint) in enumerate(zip(tangents, midpoints)):
311308
# normalize tangent
312309
tangent /= np.linalg.norm(tangent)
@@ -329,7 +326,7 @@ def test_facet_expression(compile_args):
329326
assert np.isclose(np.linalg.norm(output), 1)
330327

331328
# Check that facet normal is pointing out of the cell
332-
assert np.dot(midpoint - coords[i], output) > 0
329+
assert max(np.dot(midpoint - c, output) for c in coords) > 0
333330

334331

335332
def test_facet_geometry_expressions(compile_args):
@@ -518,11 +515,12 @@ def test_mixed_mesh_expression(compile_args):
518515

519516
# Define exact normals
520517
face_normal = np.array([0.0, 0.0, 1.0])
521-
e0 = coords[2] - coords[1]
522-
e1 = coords[0] - coords[2]
523-
e2 = coords[1] - coords[0]
524-
edges = np.array([e0, e1, e2])
518+
topology = basix.cell.topology(basix.CellType.triangle)
519+
edges = np.array([coords[j] - coords[i] for i, j in topology[1]])
525520
edge_normals = np.cross(edges, face_normal)[:, :2]
521+
for i, orient in enumerate(basix.cell.facet_orientations(basix.CellType.triangle)):
522+
if orient == 1:
523+
edge_normals[i] *= -1
526524
norms = np.linalg.norm(edge_normals, axis=1, keepdims=True)
527525
edge_normals_normalized = edge_normals / norms
528526

@@ -554,7 +552,6 @@ def test_mixed_mesh_expression(compile_args):
554552
@pytest.mark.parametrize("facet_perm", [0, 1], ids=["no_perm", "perm"])
555553
@pytest.mark.parametrize("local_index", [0, 1, 2], ids=["facet0", "facet1", "facet2"])
556554
def test_expression_facet_perm(compile_args, facet_perm, local_index):
557-
558555
c_el = basix.ufl.element("Lagrange", "triangle", 1, shape=(2,))
559556
mesh = ufl.Mesh(c_el)
560557
expr = ufl.SpatialCoordinate(mesh)
@@ -586,10 +583,10 @@ def test_expression_facet_perm(compile_args, facet_perm, local_index):
586583
entity_index = np.array([local_index], dtype=np.intc)
587584

588585
# Perm 0, means that global facet is ordered as
589-
# 1----2
586+
# 0----1
590587
# and quadrature point is not reflected
591588
# Perm 1, means that global facet is ordered as
592-
# 2----1
589+
# 1----0
593590
# and quadrature point should be reflected
594591
quad_perm = np.array([facet_perm], dtype=np.uint8)
595592

@@ -606,8 +603,13 @@ def test_expression_facet_perm(compile_args, facet_perm, local_index):
606603
ffi.NULL,
607604
)
608605

606+
edges = basix.topology(basix.CellType.triangle)[1]
607+
609608
ordered_points = points * (facet_perm == 0) + (1 - points) * (facet_perm == 1)
610-
facet = np.delete(coords, local_index, axis=0)[:, :2]
609+
facet = [coords[i][:2] for i in edges[local_index]]
611610
edge = facet[1] - facet[0]
611+
print(local_index, facet)
612612
exact_value = facet[0] + ordered_points * edge
613-
np.testing.assert_allclose(output, exact_value)
613+
print(output)
614+
print(exact_value)
615+
np.testing.assert_allclose(output, exact_value, 1e-10)

test/test_jit_forms.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ def lagrange_triangle_symbolic(order, corners=((1, 0), (2, 0), (0, 1)), fun=lamb
618618
# vertices
619619
eval_points = [S(c) for c in corners]
620620
# edges
621-
for e in [(1, 2), (0, 2), (0, 1)]:
621+
for e in basix.topology(basix.CellType.triangle)[1]:
622622
p0 = corners[e[0]]
623623
p1 = corners[e[1]]
624624
if order > 3:
@@ -722,7 +722,7 @@ def lagrange_tetrahedron_symbolic(
722722
# vertices
723723
eval_points = [S(c) for c in corners]
724724
# edges
725-
for e in [(2, 3), (1, 3), (1, 2), (0, 3), (0, 2), (0, 1)]:
725+
for e in basix.topology(basix.CellType.tetrahedron)[1]:
726726
p0 = corners[e[0]]
727727
p1 = corners[e[1]]
728728
if order > 3:
@@ -738,7 +738,7 @@ def lagrange_tetrahedron_symbolic(
738738
for i in range(1, order)
739739
]
740740
# face
741-
for f in [(1, 2, 3), (0, 2, 3), (0, 1, 3), (0, 1, 2)]:
741+
for f in basix.topology(basix.CellType.tetrahedron)[2]:
742742
p0 = corners[f[0]]
743743
p1 = corners[f[1]]
744744
p2 = corners[f[2]]
@@ -1173,8 +1173,7 @@ def test_derivative_domains(compile_args):
11731173

11741174

11751175
@pytest.mark.parametrize("dtype", ["float64"])
1176-
@pytest.mark.parametrize("permutation", [[0], [1]])
1177-
def test_mixed_dim_form(compile_args, dtype, permutation):
1176+
def test_mixed_dim_form(compile_args, dtype, permutation, local_index):
11781177
"""Test that the local element tensor corresponding to a mixed-dimensional form is correct.
11791178
The form involves an integral over a facet of the cell. The trial function and a coefficient f
11801179
are of codim 0. The test function and a coefficient g are of codim 1. We compare against another

0 commit comments

Comments
 (0)