Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typo in definition of tetrahedron #173

Merged
merged 2 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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