toponetx.Cell#

class toponetx.Cell(elements: Collection, regular: bool = True, **kwargs)[source]#

Bases: Atom[tuple[Hashable]]

Class representing a 2D cell.

A 2D cell is an elementary building block used to build a 2D cell complex, whether regular or non-regular.

Parameters:
elementsiterable of hashable objects

An iterable that contains hashable objects representing the nodes of the cell. The order of the elements is important and defines the cell up to cyclic permutation.

regularbool, optional

A boolean indicating whether the cell satisfies the regularity condition. The default value is True. A 2D cell is regular if and only if there is no repetition in the boundary edges that define the cell. By default, the cell is assumed to be regular unless otherwise specified. Self-loops are not allowed in the boundary of the cell. If a cell violates the cell complex regularity condition, a ValueError is raised.

**kwargskeyword arguments, optional

Attributes belonging to the cell can be added as key-value pairs. Both the key and value must be hashable.

Attributes:
boundary

Boundary.

is_regular

Check if a cell is regular.

Methods

clone()

Clone the Cell with all attributes.

is_homotopic_to(cell)

Check if self is homotopic to input cell.

is_valid_cell(elements[, regular])

Check if a 2D cell defined by a list of elements is valid.

reverse()

Reverse the sequence of nodes that defines the cell.

sign(edge)

Compute the sign of the given edge with respect to this cell.

update(attributes)

Update the attributes of the atom.

Notes

  • A cell is defined as an ordered sequence of nodes (n_1, …, n_k), where each two consecutive nodes (n_i, n_{i+1}) define an edge in the boundary of the cell. Note that the last edge (n_k, n_1) is also included in the boundary of the cell. For instance, if a Cell is defined as c = Cell((1, 2, 3)), then c.boundary will return [(1, 2), (2, 3), (3, 1)], which consists of three edges.

  • When a cell is created, its boundary is automatically created as a set of edges that encircle the cell.

Examples

>>> cell1 = tnx.Cell((1, 2, 3))
>>> cell2 = tnx.Cell((1, 2, 4, 5), weight=1)
>>> cell3 = tnx.Cell(("a", "b", "c"))
>>> # create geometric cell:
>>> v0 = (0, 0)
>>> v1 = (1, 0)
>>> v2 = (1, 1)
>>> v3 = (0, 1)
# create the cell with the vertices and edges
>>> cell = tnx.Cell([v0, v1, v2, v3], type="square")
>>> cell["type"]
>>> list(cell.boundary)
[((0, 0), (1, 0)), ((1, 0), (1, 1)), ((1, 1), (0, 1)),
((0, 1), (0, 0))]
__init__(elements: Collection, regular: bool = True, **kwargs) None[source]#

Methods

__init__(elements[, regular])

clone()

Clone the Cell with all attributes.

is_homotopic_to(cell)

Check if self is homotopic to input cell.

is_valid_cell(elements[, regular])

Check if a 2D cell defined by a list of elements is valid.

reverse()

Reverse the sequence of nodes that defines the cell.

sign(edge)

Compute the sign of the given edge with respect to this cell.

update(attributes)

Update the attributes of the atom.

Attributes

boundary

Boundary.

is_regular

Check if a cell is regular.

elements

name

property boundary#

Boundary.

A 2d cell is characterized by its boundary edges.

Returns:
Iterable[tuple[int, int]]

Iterator of tuple representing boundary edges given in cyclic order.

Examples

For a cell [1,2,3,4,5], the boundary is the edges that define that cell :

(1,2), (2,3), (3,4), (4,5) and (5,1).

clone() Self[source]#

Clone the Cell with all attributes.

The clone method by default returns an independent shallow copy of the cell and attributes. That is, if an attribute is a container, that container is shared by the original and the copy. Use Python’s copy.deepcopy for new containers.

Returns:
Cell

A copy of this cell.

is_homotopic_to(cell) bool[source]#

Check if self is homotopic to input cell.

Parameters:
celltuple, list or Cell

The cell to check for homotopy.

Returns:
bool

Return True is self is homotopic to input cell and False otherwise.

property is_regular: bool#

Check if a cell is regular.

Returns:
bool

True if the Cell is regular, and False otherwise.

static is_valid_cell(elements: Sequence, regular: bool = False) bool[source]#

Check if a 2D cell defined by a list of elements is valid.

Parameters:
elementsSequence

List of elements defining the cell.

regularbool, default=False

Indicates if the cell is regular.

Returns:
bool

True if the cell is valid, False otherwise.

reverse()[source]#

Reverse the sequence of nodes that defines the cell.

Returns:
Cell

New cell with the new reversed elements.

sign(edge) Literal[-1, 1][source]#

Compute the sign of the given edge with respect to this cell.

This takes an edge as input and computes the sign of the edge with respect to the cell.

If the edge is in the boundary of the cell, then the sign is 1 if the edge is in the counterclockwise direction around the cell and -1 if it is in the clockwise direction.

If the edge is not in the boundary of the cell, a KeyError is raised.

Parameters:
edgeIterable

The edge whose sign should be computed.

Returns:
{1, -1}

1: if the edge is in the counterclockwise direction around the cell. -1: if the edge is in the clockwise direction around the cell.

Raises:
KeyError

If the input edge is not in the boundary of the cell.

ValueError

If the input edge is not valid.

TypeError

If the input edge is not iterable.

update(attributes: dict) None#

Update the attributes of the atom.

Parameters:
attributesdict

The attributes to be updated.