TopologyArray#
- class sigmaepsilon.mesh.topoarray.TopologyArray(*topo, cuts: Iterable | None = None, force_numpy: bool = True)[source]#
A class to handle complex topologies. It is a subclass of the JaggedArray class from the Neumann library and is compatible with Numpy universal functions.
- Parameters:
*topo (Iterable) – One or more 2d arrays definig topologies for polygonal cells.
cuts (Iterable, Optional) – An iterable that tells how to unflatten an 1d array into a 2d jagged shape. Only if topology is provided as a 1d array. Default is None.
force_numpy (bool, Optional) – Forces dense inputs to be NumPy arrays in the background. Default is True.
Examples
The following could be the definiton for a mesh consisting from two line cells, one with 3 nodes and another with 2:
>>> import numpy as np >>> from sigmaepsilon.mesh import TopologyArray >>> data = np.array([0, 1, 2, 3, 4]) >>> TopologyArray(data, cuts=[3, 2]) TopologyArray([[0, 1, 2], [3, 4]])
The same mesh defined in another way:
>>> topo1 = np.array([0, 1, 2]) >>> topo2 = np.array([3, 4]) >>> TopologyArray(topo1, topo2) TopologyArray([[0, 1, 2], [3, 4]])
Let assume we have two 4-noded quadrilaterals as well:
>>> topo3 = np.array([[5, 6, 7, 8],[6, 7, 9, 10]]) >>> TopologyArray(topo1, topo2, topo3) TopologyArray([[0, 1, 2], [3, 4], [5, 6, 7, 8], [6, 7, 9, 10]])
Since the TopologyArray class is a subclass of JaggedArray, we can easily transform it to a CSR matrix, or an Awkward array:
>>> TopologyArray(topo1, topo2, topo3).to_csr() >>> TopologyArray(topo1, topo2, topo3).to_ak() <Array [[0, 1, 2], [3, 4, ... [6, 7, 9, 10]] type='4 * var * int32'>
To get the unique indices in a mesh, you can simply use NumPy:
>>> t = TopologyArray(topo1, topo2, topo3) >>> np.unique(t) array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
You can also combine different topologies into one object by stacking:
>>> t1 = TopologyArray(topo1, topo2) >>> t2 = TopologyArray(topo3) >>> np.vstack([t1, t2]) TopologyArray([[0, 1, 2], [3, 4], [5, 6, 7, 8], [6, 7, 9, 10]])
See also