11. connectivity
— A class and functions for handling nodal connectivity.¶
This module defines a specialized array class for representing nodal connectivity. This is e.g. used in mesh models, where geometry is represented by a set of numbered points (nodes) and the geometric elements are described by refering to the node numbers. In a mesh model, points common to adjacent elements are unique, and adjacency of elements can easily be detected from common node numbers.

class
connectivity.
Connectivity
(data=[], dtyp=None, copy=False, nplex=0, eltype=None)[source]¶ A class for handling element to node connectivity.
A connectivity object is a 2dimensional integer array with all nonnegative values. Each row of the array defines an element by listing the numbers of its lower entity types. A typical use is a
Mesh
object, where each element is defined in function of its nodes. While in a Mesh the word ‘node’ will normally refer to a geometrical point, here we will use ‘node’ for the lower entity whatever its nature is. It doesn’t even have to be a geometrical entity.Note
The current implementation limits a Connectivity object to numbers that are smaller than 2**31. That is however largely sufficient for all practical cases.
In a row (element), the same node number may occur more than once, though usually all numbers in a row are different. Rows containing duplicate numbers are called degenerate elements. Rows containing the same node sets, albeit different permutations thereof, are called duplicates.
Parameters:  data (int arraylike) – Data to initialize the Connectivity. The data should be 2dim with
shape
(nelems,nplex)
, wherenelems
is the number of elements andnplex
is the plexitude of the elements.  dtyp (float datatype, optional) – It not provided, the datatype of
data
is used.  copy (bool, optional) – If True, the data are copied. The default setting will try to use
the original data if possible, e.g. if
data
is a correctly shaped and typednumpy.ndarray
.  nplex (int, optional) – The plexitude of the data. This can be specified to force a check on
the plexitude of the data, or to set the plexitude for an empty
Connectivity.
If an
eltype
is specified, the plexitude of the element type will override this value.  eltype (str or
elements.ElementType
subclass, optional) – The element type associated with the Connectivity. It can be either a subclass of:class:elements.ElementType or thename
of such a subclass. If not provided, a nontyped Connectivity will result. If that is used to create aMesh
, the proper element type will have to be specified at Mesh creation time. If the Connectivity will be used for other purposes, the element type may not be needed or not be important.
Raises: ValueError
– Ifnplex
is provided and the specifieddata
do not match the specified plexitude.Notes
Empty Connectivities with
nelems==0
andnplex > 0
can be useful, but a Connectivity withnplex==0
generally is not.Examples
>>> Connectivity([[0,1,2],[0,1,3],[0,3,2],[0,5,3]]) Connectivity([[0, 1, 2], [0, 1, 3], [0, 3, 2], [0, 5, 3]])
>>> Connectivity(np.array([],dtype=at.Int).reshape(0,3)) Connectivity([], shape=(0, 3))

nelems
()[source]¶ Return the number of elements in the Connectivity table.
Returns: int – The number of rows in the table. Examples
>>> Connectivity([[0,1,2],[0,1,3],[0,3,2],[0,5,3]]).nelems() 4

maxnodes
()[source]¶ Return an upper limit for number of nodes in the Connectivity.
Returns: int – The highest node number plus one. See also
nnodes()
 the actual number of nodes in the table
Examples
>>> Connectivity([[0,1,2],[0,1,3],[0,3,2],[0,5,3]]).maxnodes() 6

nnodes
()[source]¶ Return the actual number of nodes in the Connectivity.
This returns the count of the unique node numbers.
See also
maxnodes()
 the highest node number + 1
Examples
>>> Connectivity([[0,1,2],[0,1,3],[0,3,2],[0,5,3]]).nnodes() 5

nplex
()[source]¶ Return the plexitude of the elements in the Connectivity table.
Examples
>>> Connectivity([[0,1,2],[0,1,3],[0,3,2],[0,5,3]]).nplex() 3

testDegenerate
()[source]¶ Flag the degenerate elements (rows).
A degenerate element is a row which contains at least two equal values.
Returns: bool array – A 1dim bool array with length self.nelems()
, holding True values for the degenerate rows.Examples
>>> Connectivity([[0,1,2],[0,1,1],[0,3,2]]).testDegenerate() array([False, True, False], dtype=bool)

listDegenerate
()[source]¶ Return a list with the numbers of the degenerate elements.
Returns: int array – A 1dim int array holding the row indices of the degenerate elements. Examples
>>> Connectivity([[0,1,2],[0,1,1],[0,3,2]]).listDegenerate() array([1])

listNonDegenerate
()[source]¶ Return a list with the numbers of the nondegenerate elements.
Returns: int array – A 1dim int array holding the row indices of the nondegenerate elements. Examples
>>> Connectivity([[0,1,2],[0,1,1],[0,3,2]]).listNonDegenerate() array([0, 2])

removeDegenerate
()[source]¶ Remove the degenerate elements from a Connectivity table.
Returns: Connectivity – A Connectivity object with the degenerate elements removed. Examples
>>> Connectivity([[0,1,2],[0,1,1],[0,3,2]]).removeDegenerate() Connectivity([[0, 1, 2], [0, 3, 2]])

reduceDegenerate
(target=None, return_indices=False)[source]¶ Reduce degenerate elements to lower plexitude elements.
This will try to reduce the degenerate elements of the Connectivity to a lower plexitude. This is only possible if an element type was set in the Connectivity. This function uses the data of the Element database in
elements
to reduce certain element types to other types depending on the kind of degeneracy.Parameters:  target (str, optional) – Target element name. If provided, only reductions to that element type are performed. Else, all the target element types for which a reduction scheme is available, will be tried.
 return_indices (bool, optional) – If True, also returns the indices of the elements in the input Connectivity that are contained in each of the parts.
Returns:  conn (list of Connectivity objects) – A list of Connectivities of which the first one contains
the originally nondegenerate elements, the next one(s) contain
the reduced elements (per reduced element type) and the last one
contains elements that could not be reduced (may be absent).
In the following cases a list with only the original is returned:
 there are no degenerate elements in the Connectivity;
 the Connectivity does not have an element type;
 the element type of the Connectivity does not have any reduction scheme defined.
 ind (list of indices, optional) – Only returned if
return_indices
is True: the indices of the elements ofself
contained in each item inconn
.
Note
If the Connectivity is part of a
Mesh
, you should use themesh.Mesh.splitDegenerate()
method instead, as that will preserve the property numbers in the resulting Meshes.The resulting reduced Connectivities may still be degenerate for their own element type.
See also
mesh.Mesh.splitDegenerate()
 split mesh in nondegenerate and reduced
Examples
>>> Connectivity([[0,1,2],[0,1,3]],eltype='line3').reduceDegenerate() [Connectivity([[0, 1, 2], [0, 1, 3]], eltype='line3')] >>> C = Connectivity([[0,1,2],[0,1,1],[0,3,2]],eltype='line3') >>> C.reduceDegenerate() [Connectivity([[0, 1, 2], [0, 3, 2]], eltype='line3'), Connectivity([[0, 1]], eltype='line2')] >>> C = Connectivity([[0,1,2],[0,1,1],[0,3,2],[1,1,1],[0,0,2]],eltype='line3') >>> C.reduceDegenerate() [Connectivity([[0, 1, 2], [0, 3, 2]], eltype='line3'), Connectivity([[1, 1], [0, 2], [0, 1]], eltype='line2')]
>>> C.reduceDegenerate(return_indices=True) ([Connectivity([[0, 1, 2], [0, 3, 2]], eltype='line3'), Connectivity([[1, 1], [0, 2], [0, 1]], eltype='line2')], [array([0, 2]), array([3, 4, 1])])

findDuplicate
(permutations='all')[source]¶ Find duplicate rows in the Connectivity.
Parameters: permutations (str) – Defines which permutations of the row data are allowed while still considering the rows equal. Possible values are:
 ’none’: no permutations are allowed: rows must match the same date at the same positions.
 ’roll’: rolling is allowed. Rows that can be transformed into each other by rolling are considered equal;
 ’all’: any permutation of the same data will be considered an equal row. This is the default.
Returns: V ( Varray
) – A Varray where each row contains a list of the row numbers from a that are considered equal. The entries in each row are sorted and the rows are sorted according to their first element.Notes
This is like
arraytools.equalRows()
but has a different default value forpermutations
.Examples
>>> C = Connectivity([[0,1,2],[0,1,3],[0,1,2],[2,0,1],[2,1,0]]) >>> C.findDuplicate() Varray([[0, 2, 3, 4], [1]]) >>> C.findDuplicate(permutations='roll') Varray([[0, 2, 3], [1], [4]]) >>> C.findDuplicate(permutations='none') Varray([[0, 2], [1], [3], [4]])

listDuplicate
(permutations='all')[source]¶ Return a list with the numbers of the duplicate elements.
Returns: 1dim int array – The indices of the unique rows in the Connectivity array. Examples
>>> C = Connectivity([[0,1,2],[0,1,3],[0,1,2],[2,0,1],[2,1,0]]) >>> C.listDuplicate() array([2, 3, 4]) >>> C.listDuplicate(permutations='roll') array([2, 3]) >>> C.listDuplicate(permutations='none') array([2])

listUnique
(permutations='all')[source]¶ Return a list with the numbers of the unique elements.
Returns: 1dim int array – The indices of the unique rows in the Connectivity array. See also
findDuplicate()
 find duplicate rows
listDuplicate()
 list duplicate rows
removeDuplicate()
 remove duplicate rows
Examples
>>> C = Connectivity([[0,1,2],[0,1,3],[0,1,2],[2,0,1],[2,1,0]]) >>> C.listUnique() array([0, 1]) >>> C.listUnique(permutations='roll') array([0, 1, 4]) >>> C.listUnique(permutations='none') array([0, 1, 3, 4])

removeDuplicate
(permutations='all')[source]¶ Remove duplicate elements from a Connectivity list.
By default, duplicates are elements that consist of the same set of nodes, in any particular order. Setting permutations to ‘none’ will only remove the duplicate rows that have matching values at matching positions.
Returns: Connectivity – A new Connectivity with the duplicate elements removed. Examples
>>> C = Connectivity([[0,1,2],[0,1,3],[0,1,2],[2,0,1],[2,1,0]]) >>> C.removeDuplicate() Connectivity([[0, 1, 2], [0, 1, 3]]) >>> C.removeDuplicate(permutations='roll') Connectivity([[0, 1, 2], [0, 1, 3], [2, 1, 0]]) >>> C.removeDuplicate(permutations='none') Connectivity([[0, 1, 2], [0, 1, 3], [2, 0, 1], [2, 1, 0]])

reorder
(order='nodes')[source]¶ Reorder the elements of a Connectivity in a specified order.
This does not actually reorder the elements itself, but returns an index with the order of the rows (elements) in the Connectivity table that meets the specified ordering requirements.
Parameters: order (str or list of ints) – Specifies how to reorder the elements. It is either one of the special string values defined below, or else it is an index with length equal to the number of elements. The index should be a permutation of the numbers in
range(self.nelems()
. Each value gives the number of the old element that should be placed at this position. Thus, the order values are the old element numbers on the position of the new element number.order
can also take one of the following predefined values, resulting in the corresponding renumbering scheme being generated: ’nodes’: the elements are renumbered in order of their appearance in the inverse index, i.e. first are the elements connected to node 0, then the as yet unlisted elements connected to node 1, etc.
 ’random’: the elements are randomly renumbered.
 ’reverse’: the elements are renumbered in reverse order.
Returns: 1dim int array – Int array with a permutation of arange(self.nelems()
, such that taking the elements in this order will produce a Connectivity reordered as requested. In case an explicit order was specified as input, this order is returned after checking that it is indeed a permutation ofrange(self.nelems()
.Examples
>>> A = Connectivity([[1,2],[2,3],[3,0],[0,1]]) >>> A[A.reorder('reverse')] Connectivity([[0, 1], [3, 0], [2, 3], [1, 2]]) >>> A[A.reorder('nodes')] Connectivity([[0, 1], [3, 0], [1, 2], [2, 3]]) >>> A[A.reorder([2,3,0,1])] Connectivity([[3, 0], [0, 1], [1, 2], [2, 3]])

renumber
(start=0)[source]¶ Renumber the nodes to a consecutive integer range.
The node numbers in the table are changed thus that they form a consecutive integer range starting from the specified value.
Parameters: start (int) – Lowest node number to be used in the renumbered Connectivity. Returns:  elems (Connectivity) – The renumbered Connectivity
 oldnrs (1dim int array) – The sorted list of unique (old) node numbers. The new
node numbers are assigned in order of increasing old node numbers,
thus the old node number for new node number
i
can be found at positioni  start
.
Examples
>>> e,n = Connectivity([[0,2],[1,4],[4,2]]).renumber(7) >>> print(e) [[ 7 9] [ 8 10] [10 9]] >>> print(n) [0 1 2 4]
Find the old node number of new node 10 >>> n[107] 4

inverse
(expand=True)[source]¶ Return the inverse index of a Connectivity table.
Returns: int array – The inverse index of the Connectivity, as computed by arraytools.inverseIndex()
.Examples
>>> Connectivity([[0,1,2],[0,1,4],[0,4,2]]).inverse() array([[ 0, 1, 2], [1, 0, 1], [1, 0, 2], [1, 1, 1], [1, 1, 2]], dtype=int32) >>> Connectivity([[0,1,2],[0,1,4],[0,4,2]]).inverse(expand=False) Varray([[0, 1, 2], [0, 1], [0, 2], [], [1, 2]])

nParents
()[source]¶ Return the number of elements connected to each node.
Returns: 1dim int array – The number of elements connected to each node. The length of the array is equal to the highest node number + 1. Unused node numbers will have a count of zero. Examples
>>> Connectivity([[0,1,2],[0,1,4],[0,4,2]]).nParents() array([3, 2, 2, 0, 2])

connectedTo
(nodes, return_ncon=False)[source]¶ Check if the elements are connected to the specified nodes.
Parameters:  nodes (int or int arraylike) – One or more node numbers to check for connections in the table.
 return_ncon (bool, optional) – If True, also return the number of connections for each element.
Returns:  connections (int array) – The numbers of the elements that contain at least one of the specified nodes.
 ncon (int array, optional) – The number of connections for each connected element.
This is only provided if
return_ncon
is True.
Examples
>>> A = Connectivity([[0,1,2],[0,1,3],[0,3,2],[1,2,3]]) >>> print(A.connectedTo(2)) [0 2 3] >>> A.connectedTo([0,1,3],True) (array([0, 1, 2, 3], dtype=int32), array([2, 3, 2, 2]))

hits
(nodes)[source]¶ Count the nodes from a list connected to the elements.
Parameters: nodes (int or list of ints) – One or more node numbers. Returns: int array (nelems,) – An int array holding the number of nodes from the specified input that are contained in each of the elements. Notes
This information can also be got from meth:connectedTo. This method however expands the results to the full element set, making it apt for use in selector expressions like
self[self.hits(nodes) >= 2]
.Examples
>>> A = Connectivity([[0,1,2],[0,1,3],[0,3,2],[1,2,3]]) >>> A.hits(2) array([1, 0, 1, 1]) >>> A.hits([0,1,3]) array([2, 3, 2, 2])

adjacency
(kind='e', mask=None)[source]¶ Create a table of adjacent items.
This creates an element adjacency table or node adjacency table An element i is said to be adjacent to element j, if the two elements have at least one common node. A node i is said to be adjacent to node j, if there is at least one element containing both nodes.
Parameters:  kind ('e' or 'n') – Select element (‘e’) or node (n’) adjacency table. Default is element adjacency.
 mask (bool array or int index, optional) –
Node selector. If provided (with
kind=='e'
) this defines by a bool flag array or int index numbers the list of nodes that are to be considered connectors between elements. The default is to consider all nodes as connectors.This option is only useful in the case kind == ‘e’. If you want to use an element mask for the ‘n’ case, just apply the (element) mask beforehand by using
self[mask].adjacency('n')
.
Returns: Adjacency
object – An Adjacency array with shape (nr,nc), where row i holds a sorted list of all the items that are adjacent to item i, padded with 1 values to create an equal list length for all items.Examples
>>> Connectivity([[0,1],[0,2],[1,3],[0,5]]).adjacency('e') Adjacency([[ 1, 2, 3], [1, 0, 3], [1, 1, 0], [1, 0, 1]], dtype=int32) >>> Connectivity([[0,1],[0,2],[1,3],[0,5]]).adjacency('e',mask=[1,2,3,5]) Adjacency([[ 2], [1], [ 0], [1]], dtype=int32) >>> Connectivity([[0,1],[0,2],[1,3],[0,5]]).adjacency('n') Adjacency([[ 1, 2, 5], [1, 0, 3], [1, 1, 0], [1, 1, 1], [1, 1, 1], [1, 1, 0]]) >>> Connectivity([[0,1,2],[0,1,3],[2,4,5]]).adjacency('n') Adjacency([[1, 1, 2, 3], [1, 0, 2, 3], [ 0, 1, 4, 5], [1, 1, 0, 1], [1, 1, 2, 5], [1, 1, 2, 4]]) >>> Connectivity([[0,1,2],[0,1,3],[2,4,5]])[[0,2]].adjacency('n') Adjacency([[1, 1, 1, 2], [1, 1, 0, 2], [ 0, 1, 4, 5], [1, 1, 1, 1], [1, 1, 2, 5], [1, 1, 2, 4]])

adjacentElements
(els, mask=None)[source]¶ Compute adjacent elements.
This creates an element adjacency table or node adjacency table An element i is said to be adjacent to element j, if the two elements have at least one common node. A node i is said to be adjacent to node j, if there is at least one element containing both nodes.
Parameters:  else (int or list of ints) – The element number(s) for which to compute the adjacent elements
 mask (bool array or int index, optional) –
Node selector. If provided (with
kind=='e'
) this defines by a bool flag array or int index numbers the list of nodes that are to be considered connectors between elements. The default is to consider all nodes as connectors.This option is only useful in the case kind == ‘e’. If you want to use an element mask for the ‘n’ case, just apply the (element) mask beforehand by using
self[mask].adjacency('n')
.
Returns: Adjacency
object – An Adjacency array with shape (nr,nc), where row i holds a sorted list of all the items that are adjacent to item i, padded with 1 values to create an equal list length for all items.Examples
>>> Connectivity([[0,1],[0,2],[1,3],[0,5]]).adjacentElements([0,1,2,3]) array([[ 1, 2, 3], [1, 0, 3], [1, 1, 0], [1, 0, 1]], dtype=int32) >>> Connectivity([[0,1],[0,2],[1,3],[0,5]]).adjacentElements([0,1,2]) array([[ 1, 2, 3], [1, 0, 3], [1, 1, 0]], dtype=int32) >>> Connectivity([[0,1],[0,2],[1,3],[0,5]]).adjacentElements([1,2,3]) array([[ 0, 3], [1, 0], [ 0, 1]], dtype=int32) >>> Connectivity([[0,1],[0,2],[1,3],[0,5]]).adjacentElements([0,2]) array([[ 1, 2, 3], [1, 1, 0]], dtype=int32) >>> Connectivity([[0,1],[0,2],[1,3],[0,5]]).adjacentElements([2]) array([[0]], dtype=int32) >>> Connectivity([[0,1],[0,2],[1,3],[0,5]]).adjacentElements(1) array([[0, 3]], dtype=int32)

frontGenerator
(startat=0, frontinc=1, partinc=1)[source]¶ Generator function returning the frontal elements.
This is a generator function and is normally not used directly, but via the
frontWalk()
method.Parameters: see
frontWalk()
.Returns: int array – Int array with a value for each element. On the initial call, all values are 1, except for the elements in the initial front, which get a value 0. At each call a new front is created with all the elements that are connected to any of the current front and which have not yet been visited. The new front elements get a value equal to the last front’s value plus the frontinc
. If the front becomes empty and a new starting front is created, the front value is extra incremented withpartinc
.Examples
>>> C = Connectivity([[2,8,7],[2,3,8],[3,9,8],[4,10,9],[5,6,11], ... [6,12,11]]) >>> C.adjacentElements([0]) array([[1, 2]], dtype=int32) >>> for p in C.frontGenerator(): print(p) [ 0 1 1 1 1 1] [ 0 1 1 1 1 1] [ 0 1 1 2 1 1] [ 0 1 1 2 4 1] [0 1 1 2 4 5] >>> A = C.adjacency() >>> for p in A.frontGenerator(): print(p) [ 0 1 1 1 1 1] [ 0 1 1 1 1 1] [ 0 1 1 2 1 1] [ 0 1 1 2 4 1] [0 1 1 2 4 5]

frontWalk
(startat=0, frontinc=1, partinc=1, maxval=1)[source]¶ Walks through the elements by their node front.
A frontal walk is executed starting from the given element(s). A number of steps is executed, each step advancing the front over a given number of single pass increments. The step number at which an element is reached is recorded and returned.
Parameters:  startat (int or list of ints) – Initial element number(s) in the front.
 frontinc (int) – Increment for the front number on each frontal step.
 partinc (int) – Increment for the front number when the front gets empty and a new part is started.
 maxval (int) – Maximum frontal value. If negative (default) the walk will continue until all elements have been reached. If nonnegative, walking will stop as soon as the frontal value reaches this maximum.
Returns: int array – An array of ints specifying for each element in which step the element was reached by the walker.
Examples
>>> C = Connectivity([[2,8,7],[2,3,8],[3,9,8],[4,10,9],[5,6,11], ... [6,12,11]]) >>> print(C.frontWalk()) [0 1 1 2 4 5]

front
(startat=0, add=False)[source]¶ Returns the elements of the first node front.
Parameters:  startat (int or list od ints) – Element number(s) or a list of element numbers. The list of elements to find the next front for.
 add (bool, optional) – If True, the startat elements wil be included in the return value. The default (False) will only return the elements in the next front line.
Returns: int array – A list of the elements that are connected to any of the nodes that are part of the startat elements.
Notes
This is equivalent to the first step of a
frontWalk()
with the same startat elements, and could thus also be obtained fromwhere(self.frontWalk(startat,maxval=1) == 1)[0]
.Here however another implementation is used, which is more efficient for very large models: it avoids the creation of the large array as returned by frontWalk.
Examples
>>> C = Connectivity([[2,8,7],[2,3,8],[3,9,8],[4,10,9],[5,6,11], ... [6,12,11]]) >>> print(C.front([2])) [0 1 3]

selectNodes
(selector)[source]¶ Return a
Connectivity
containing subsets of the nodes.Parameters: selector (int arraylike) – An object that can be converted to a 1dim or 2dim int array. Examples are a tuple of local node numbers, or a list of such tuples all having the same length. Each row of selector holds a list of the local node numbers that should be retained in the new Connectivity table. As an example, if the Connectivity is plex3 representing triangles, a selector [[0,1],[1,2],[2,0]] would extract the edges of the triangle. Returns: Connectivity
– A new Connectivity object with shape(self.nelems*selector.nelems,selector.nplex)
. Duplicate elements created by the selector are retained. If the selector has an eltype (for example if it is a Connectivity itself), the returned Connectivity will have the same eltype.Examples
>>> Connectivity([[0,1,2],[0,2,1],[0,3,2]]).selectNodes([[0,1],[0,2]]) Connectivity([[0, 1], [0, 2], [0, 2], [0, 1], [0, 3], [0, 2]])

insertLevel
(selector, permutations='all')[source]¶ Insert an extra hierarchical level in a Connectivity table.
A Connectivity table identifies higher hierarchical entities in function of lower ones. This method inserts an extra level in the hierarchy. For example, if you have volumes defined in function of points, you can insert an intermediate level of edges, or faces. Multiple intermediate level entities may be created from each element.
Parameters:  selector (int arraylike) –
An object that can be converted to a 1dim or 2dim int array. Examples are a tuple of local node numbers, or a list of such tuples all having the same length. Each row of selector holds a list of the local node numbers that should be retained in the new Connectivity table.
If the Connectivity has an element type, selector can also be a single integer specifying one of the hierarchical levels of element entities (See the Element class). In that case the selector is constructed automatically from self.eltype.getEntities(selector).
 permutations (str) –
Defines which permutations of the row data are allowed while still considering the rows equal. Equal rows in the intermediate level are collapsed into single items. Possible values are:
 ’none’: no permutations are allowed: rows must match the same date at the same positions.
 ’roll’: rolling is allowed. Rows that can be transformed into each other by rolling are considered equal;
 ’all’: any permutation of the same data will be considered an equal row. This is the default.
Returns:  hi (
Connectivity
) – A Connecivity defining the original elements in function of the intermediate level ones.  lo (
Connectivity
) – A Connectivity defining the intermediate level items in function of the lowest level ones (the original nodes). If theselector
has aneltype
attribute, thenlo
will inherit the sameeltype
value.  The resulting node numbering of the created intermediate entities
 (the lo return value) respects the numbering order of the original
 elements and the applied the selector, but in case of collapsing
 duplicate rows, it is undefined which of the collapsed sequences is
 returned.
 Because the precise order of the data in the collapsed rows is lost,
 it is in general not possible to restore the exact original table
 from the two result tables.
 See however
mesh.Mesh.getBorder()
for an application where an  inverse operation is possible, because the border only contains
 unique rows.
 See also
mesh.Mesh.combine()
, which is an almost inverse operation  for the general case, if the selector is complete.
 The resulting rows may however be permutations of the original.
Examples
>>> Connectivity([[0,1,2],[0,2,1],[0,3,2]]). insertLevel([[0,1],[1,2],[2,0]]) (Connectivity([[0, 1, 2], [2, 1, 0], [3, 4, 2]]), Connectivity([[0, 1], [1, 2], [2, 0], [0, 3], [3, 2]])) >>> Connectivity([[0,1,2,3]]). insertLevel([[0,1,2],[1,2,3],[0,1,1],[0,0,1],[1,0,0]]) (Connectivity([[0, 1, 2, 2, 2]]), Connectivity([[0, 1, 2], [1, 2, 3], [0, 1, 1]]))
 selector (int arraylike) –

combine
(lo)[source]¶ Combine two hierarchical Connectivity levels to a single one.
self and lo are two hierarchical Connectivity tables, representing higher and lower level respectively. This means that the elements of self hold numbers which point into lo to obtain the lowest level items.
In the current implementation, the plexitude of lo should be 2!
As an example, in a structure of triangles, hi could represent triangles defined by 3 edges and lo could represent edges defined by 2 vertices. This method will then result in a table with plexitude 3 defining the triangles in function of the vertices.
This is the inverse operation of
insertLevel()
with a selector which is complete. The algorithm only works if all vertex numbers of an element are unique.Examples
>>> hi,lo = Connectivity([[0,1,2],[0,2,1],[0,3,2]]). insertLevel([[0,1],[1,2],[2,0]]) >>> hi.combine(lo) Connectivity([[0, 1, 2], [0, 2, 1], [0, 3, 2]])

resolve
()[source]¶ Resolve the connectivity into plex2 connections.
Creates a Connectivity table with a plex2 (edge) connection between any two nodes that are connected to a common element.
There is no point in resolving a plexitude 2 structure. Plexitudes lower than 2 can not be resolved.
Returns a plex2 Connectivity with all connections between node pairs. In each element the nodes are sorted.
Examples
>>> print([ i for i in combinations(range(3),2) ]) [(0, 1), (0, 2), (1, 2)] >>> Connectivity([[0,1,2],[0,2,1],[0,3,2]]).resolve() Connectivity([[0, 1], [0, 2], [0, 3], [1, 2], [2, 3]])
Return the list of nodes shared by all elements in elist
Parameters: elist (int arraylike) – List of element numbers. If not specified, all elements are considered. Returns: int array – A 1dim int array with the list of nodes that are common to all elements in the specified list. This array may be empty. Examples
>>> a = Connectivity([[0,1,2],[0,2,1],[0,3,2]]) >>> a.sharedNodes() array([0, 2]) >>> a.sharedNodes([0,1]) array([0, 1, 2])

replic
(n, inc)[source]¶ Repeat a Connectivity with increasing node numbers.
Parameters:  n (int) – Number of copies to make.
 inc (int) – Increment in node numbers for each copy.
Returns: Connectivity – A Connectivity with the concatenation of
n
replicas ofself
, where the first replica is identical to self and each next one has its node numbers increased byinc
.Examples
>>> Connectivity([[0,1,2],[0,2,3]]).replic(2,4) Connectivity([[0, 1, 2], [0, 2, 3], [4, 5, 6], [4, 6, 7]])

extrude
(nnod, degree)[source]¶ Extrude a Connectivity to a higher level Connectivity.
This method is only available if the Connectivity has an element type and the element type is extrudable. See
elements
for more details.Parameters:  nnod (int) – Node increment for each new node plane. It should be higher than the highest node number in self.
 degree (int) – Number of node planes to add. This is also the degree of the extrusion. Currently it is limited to 1 or 2.
 extrusion adds degree planes of nodes, each with a node (The) –
 nnod, to the original Connectivity and then selects (increment) –
 target nodes from it as defined by the (the) –
 value. (self.eltype.extruded[degree]) –
Returns: Connectivity – A Connectivity for the extruded element.
Examples
>>> from pyformex.elements import Line2,Line3 >>> a = Connectivity([[0,1],[1,2]],eltype=Line2).extrude(3,1) >>> print(a) [[0 1 4 3] [1 2 5 4]] >>> print(a.eltype.name()) quad4 >>> a = Connectivity([[0,1,2],[0,2,3]],eltype=Line3).extrude(4,2) >>> print(a) [[ 0 2 10 8 1 6 9 4 5] [ 0 3 11 8 2 7 10 4 6]] >>> print(a.eltype.name()) quad9

static
connect
(clist, nodid=None, bias=None, loop=False)[source]¶ Connect nodes from multiple Connectivity objects.
Parameters:  clist (list of Connectivity objects) – The Connectivities to connect.
 nodid (int arraylike, optional) – List of node indices, same length as
clist
. This specifies which node of the elements will be used in the connect operation.  bias (int arraylike, optional) – List of element bias values, same length as
clist
. If provided, then element looping will start at this number instead of at zero.  loop (bool) – If False (default), new element generation will stop as soon as the shortest Connectivity runs out of elements. If set to True, the shorter lists will wrap around until all elements of all Connectivities have been used.
Returns: Connectivity – A Connectivity with plexitude equal to the number of Connectivities in
clist
. Each element of the new Connectivity consist of a node from the corresponding element of each of the Connectivities inclist
. By default this will be the first node of that element, but anodid
list may be given to specify the node index to be used for each of the Connectivities. Finally, a list of bias values may be given to specify an offset in element number for the subsequent Connectivities. If loop==False, the length of the Connectivity will be the minimum length of the Connectivities inclist
, each minus its respective bias. If loop=True, the length will be the maximum length in of the Connectivities inclist
.Examples
>>> a = Connectivity([[0,1],[2,3],[4,5]]) >>> b = Connectivity([[10,11,12],[13,14,15]]) >>> c = Connectivity([[20,21],[22,23]]) >>> print(Connectivity.connect([a,b,c])) [[ 0 10 20] [ 2 13 22]] >>> print(Connectivity.connect([a,b,c],nodid=[1,0,1])) [[ 1 10 21] [ 3 13 23]] >>> print(Connectivity.connect([a,b,c],bias=[1,0,1])) [[ 2 10 22]] >>> print(Connectivity.connect([a,b,c],bias=[1,0,1],loop=True)) [[ 2 10 22] [ 4 13 20] [ 0 10 22]]
 data (int arraylike) – Data to initialize the Connectivity. The data should be 2dim with
shape
11.1. Functions defined in module connectivity¶

connectivity.
connectedLineElems
(elems, disconnect=None, return_indices=False)[source]¶ Partition a collection of line segments into connected polylines.
Parameters:  elems (intr array with shape (nelems,nplex)) – An 2dim int array where each row holds the vertex numbers of a
single line segment. This can e.g.be the
elems
Connectivity table of aMesh
with eltype ‘line2’ (nplex=2). But it will work as well for higher order elements like ‘line3’  disconnect (int arraylike, optional) – List of vertex numbers where the resulting polylines should be split. None of the resulting polylines will have any of the listed vertex numbers as an interior vertex. A polyline may start and end at such a vertex.
 return_indices (bool) – If True, also return indices identifying the original elements contained in each of the resulting polylines.
Returns:  conn (list of Connectivity objects) – A list a Connectivity tables of plexitude
nplex
. The line elements in each Connectivity are ordered to form a continuous connected segment, i.e. the last vertex of each line element in the table is equal to the first vertex of the following element (if any). The list of connectivity tables is sorted in order of decreasing length.  ind (list of int arrays, optional) – Only returned if
return_indices
is True: a list of tables with the same column length as those inconn
, and having always two columns. The first column contains the original element number of the entries, and the second column a value +1 or 1 depending on whether the element traversal in the connected segment is in the original direction (+1) or the reverse (1).
Notes
A practical application of the use of the
disconnect
paraemter is to enforce splitting of the resulting polylines at branching points. Branching points can be detected by checking the number of parents.# M is a Mesh of some 'line.' type split = where(M.elems.nParents() > 2)[0] lines = connectedLineElems(M.elems,disconnect=split)
Using
disconnect=None
would allow polylines to continue over the branch points.Obviously, from the input elems table and the second return value, the first return value could be reconstructed:
first = [ where(i[:,1:] > 0, elems[i[:,0]], elems[i[:,0],::1]) for i in second ]
But since the construction of the first list is required by the algorithm, it is returned anyway.
Examples
>>> connectedLineElems([[0,1],[1,2],[0,4],[4,2]]) [Connectivity([[0, 1], [1, 2], [2, 4], [4, 0]])]
>>> connectedLineElems([[0,1],[1,2],[0,4]]) [Connectivity([[2, 1], [1, 0], [0, 4]])]
>>> connectedLineElems([[0,1],[0,2],[0,3],[4,5]]) [Connectivity([[1, 0], [0, 2]]), Connectivity([[4, 5]]), Connectivity([[0, 3]])]
>>> connectedLineElems([[0,1],[0,2],[0,3],[4,5]]) [Connectivity([[1, 0], [0, 2]]), Connectivity([[4, 5]]), Connectivity([[0, 3]])]
>>> connectedLineElems([[0,1],[0,2],[0,3],[4,5]],return_indices=True) ([Connectivity([[1, 0], [0, 2]]), Connectivity([[4, 5]]), Connectivity([[0, 3]])], [array([[ 0, 1], [ 1, 1]], dtype=int32), array([[3, 1]], dtype=int32), array([[2, 1]], dtype=int32)]) >>> connectedLineElems([[0,1,2],[2,0,3],[0,3,1],[4,5,2]]) [Connectivity([[3, 0, 2], [2, 1, 0], [0, 3, 1]]), Connectivity([[4, 5, 2]])] >>> connectedLineElems([[0,1,2],[2,0,3],[0,3,1],[4,5,2]], ... disconnect=[0]) [Connectivity([[0, 1, 2], [2, 0, 3]]), Connectivity([[4, 5, 2]]), Connectivity([[0, 3, 1]])]
 elems (intr array with shape (nelems,nplex)) – An 2dim int array where each row holds the vertex numbers of a
single line segment. This can e.g.be the