Skip to content

Commit

Permalink
Fix typo in definition of tetrahedron (#173)
Browse files Browse the repository at this point in the history
* fix cell typo

* Add test
  • Loading branch information
mscroggs authored Jun 27, 2023
1 parent 05adfee commit 79ef1d4
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
61 changes: 61 additions & 0 deletions test/test_cell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import ufl
import pytest


def test_interval():
cell = ufl.interval
assert cell.num_vertices() == 2
assert cell.num_edges() == 1
assert cell.num_faces() == 0


def test_triangle():
cell = ufl.triangle
assert cell.num_vertices() == 3
assert cell.num_edges() == 3
assert cell.num_faces() == 1


def test_quadrilateral():
cell = ufl.quadrilateral
assert cell.num_vertices() == 4
assert cell.num_edges() == 4
assert cell.num_faces() == 1


def test_tetrahedron():
cell = ufl.tetrahedron
assert cell.num_vertices() == 4
assert cell.num_edges() == 6
assert cell.num_faces() == 4


def test_hexahedron():
cell = ufl.hexahedron
assert cell.num_vertices() == 8
assert cell.num_edges() == 12
assert cell.num_faces() == 6



@pytest.mark.parametrize("cell", [ufl.interval])
def test_cells_1d(cell):
assert cell.num_facets() == cell.num_vertices()
assert cell.num_ridges() == 0
assert cell.num_peaks() == 0


@pytest.mark.parametrize("cell", [ufl.triangle, ufl.quadrilateral])
def test_cells_2d(cell):
assert cell.num_facets() == cell.num_edges()
assert cell.num_ridges() == cell.num_vertices()
assert cell.num_peaks() == 0


@pytest.mark.parametrize("cell", [ufl.tetrahedron, ufl.hexahedron, ufl.prism, ufl.pyramid])
def test_cells_2d(cell):
assert cell.num_facets() == cell.num_faces()
assert cell.num_ridges() == cell.num_edges()
assert cell.num_peaks() == cell.num_vertices()


8 changes: 7 additions & 1 deletion ufl/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def peak_types(self) -> typing.Tuple[AbstractCell, ...]:
"interval": [tuple("vertex" for i in range(2)), ("interval", )],
"triangle": [tuple("vertex" for i in range(3)), tuple("interval" for i in range(3)), ("triangle", )],
"quadrilateral": [tuple("vertex" for i in range(4)), tuple("interval" for i in range(4)), ("quadrilateral", )],
"tetrahedron": [tuple("vertex" for i in range(4)), tuple("interval" for i in range(4)),
"tetrahedron": [tuple("vertex" for i in range(4)), tuple("interval" for i in range(6)),
tuple("triangle" for i in range(4)), ("tetrahedron", )],
"hexahedron": [tuple("vertex" for i in range(8)), tuple("interval" for i in range(12)),
tuple("quadrilateral" for i in range(6)), ("hexahedron", )],
Expand Down Expand Up @@ -251,20 +251,26 @@ def has_simplex_facets(self) -> bool:

def num_sub_entities(self, dim: int) -> int:
"""Get the number of sub-entities of the given dimension."""
if dim < 0:
return 0
try:
return self._num_cell_entities[dim]
except IndexError:
return 0

def sub_entities(self, dim: int) -> typing.Tuple[AbstractCell, ...]:
"""Get the sub-entities of the given dimension."""
if dim < 0:
return ()
try:
return self._sub_entities[dim]
except IndexError:
return ()

def sub_entity_types(self, dim: int) -> typing.Tuple[AbstractCell, ...]:
"""Get the unique sub-entity types of the given dimension."""
if dim < 0:
return ()
try:
return self._sub_entity_types[dim]
except IndexError:
Expand Down

0 comments on commit 79ef1d4

Please sign in to comment.