Skip to content

Commit

Permalink
wrap sub_entity_type (#888)
Browse files Browse the repository at this point in the history
* wrap sub_entity_type

* update pyi

* the other pyi too

* ,
  • Loading branch information
mscroggs authored Dec 5, 2024
1 parent 4c5ca5b commit 92c54d2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions basix/_basixcpp.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ def restriction(arg0: PolysetType, arg1: CellType, arg2: CellType, /) -> Polyset

def sobolev_space_intersection(arg0: SobolevSpace, arg1: SobolevSpace, /) -> SobolevSpace: ...

def sub_entity_type(arg: CellType, dim: int, index: int, /) -> CellType: ...

def sub_entity_connectivity(arg: CellType, /) -> list[list[list[list[int]]]]: ...

def sub_entity_geometry(arg0: CellType, arg1: int, arg2: int, /) -> Annotated[ArrayLike, dict(dtype='float64', )]: ...
Expand Down
2 changes: 2 additions & 0 deletions python/basix/_basixcpp.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,8 @@ def sobolev_space_intersection(arg0: SobolevSpace, arg1: SobolevSpace, /) -> Sob

def subentity_types(arg: CellType, /) -> list[list[CellType]]: ...

def sub_entity_type(arg: CellType, dim: int, index: int, /) -> CellType: ...

def sub_entity_connectivity(arg: CellType, /) -> list[list[list[list[int]]]]: ...

def sub_entity_geometry(arg0: CellType, arg1: int, arg2: int, /) -> Annotated[ArrayLike, dict(dtype='float64', )]: ...
Expand Down
15 changes: 15 additions & 0 deletions python/basix/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from basix._basixcpp import geometry as _geometry
from basix._basixcpp import subentity_types as _sut
from basix._basixcpp import sub_entity_connectivity as _sec
from basix._basixcpp import sub_entity_type as _set
from basix._basixcpp import topology as _topology

__all__ = [
Expand All @@ -31,6 +32,20 @@
]


def sub_entity_type(celltype: CellType, dim: int, index: int) -> CellType:
"""Cell type of a sub-entity.
Args:
celltype: cell type.
dim: dimension of the sub-entity.
index: index of the sub-entity
Returns:
The cell type of the sub-entity.
"""
return _set(celltype, dim, index)


def sub_entity_connectivity(celltype: CellType) -> list[list[list[list[int]]]]:
"""Numbers of entities connected to each sub-entity of the cell.
Expand Down
2 changes: 2 additions & 0 deletions python/wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ NB_MODULE(_basixcpp, m)
m.def("topology", &cell::topology);
m.def("geometry", [](cell::type celltype)
{ return as_nbarrayp(cell::geometry<double>(celltype)); });
m.def("sub_entity_type", [](cell::type celltype, int dim, int index)
{ return cell::sub_entity_type(celltype, dim, index); });
m.def("sub_entity_connectivity", &cell::sub_entity_connectivity);
m.def("sub_entity_geometry",
[](cell::type celltype, int dim, int index)
Expand Down
11 changes: 11 additions & 0 deletions test/test_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,14 @@ def test_sub_entity_connectivity(cell):
else:
for i in topology[dim][n]:
assert i in topology[dim2][n2]


def test_sub_entity_type():
cell_type = basix.CellType.tetrahedron
for i in range(4):
assert basix.cell.sub_entity_type(cell_type, 0, i) == basix.CellType.point
for i in range(6):
assert basix.cell.sub_entity_type(cell_type, 1, i) == basix.CellType.interval
for i in range(4):
assert basix.cell.sub_entity_type(cell_type, 2, i) == basix.CellType.triangle
assert basix.cell.sub_entity_type(cell_type, 3, 0) == basix.CellType.tetrahedron

0 comments on commit 92c54d2

Please sign in to comment.