15. 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 2-dimensional integer array with all non-negative 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 array_like) – Data to initialize the Connectivity. The data should be 2-dim 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 non-typed Connectivity will result.
- Raises:
ValueError – If
nplex
is provided and the specifieddata
do not match the specified plexitude.
Notes
The Connectivity class has no knowledge about the geometrical meaning of the element types. In most cases the use of its subclass
Elems
is therefore more appropriate.Empty Connectivities with
nelems==0
andnplex > 0
can be useful, but a Connectivity withnplex==0
generally is not.See also
Elems
a subclass that holds geometrical information about the element types and is used to create
Mesh
geometries.
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 1-dim 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])
- listDegenerate()[source]¶
Return a list with the numbers of the degenerate elements.
- Returns:
int array – A 1-dim 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 non-degenerate elements.
- Returns:
int array – A 1-dim int array holding the row indices of the non-degenerate 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]])
- 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:
1-dim 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:
1-dim 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:
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:
1-dim 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 (1-dim 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[10-7] 4
- inverse(expand=None)[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(expand=True) array([[ 0, 1, 2], [-1, 0, 1], [-1, 0, 2], [-1, -1, -1], [-1, 1, 2]]) >>> Connectivity([[0,1,2],[0,1,4],[0,4,2]]).inverse(expand=False) Varray([[0, 1, 2], [0, 1], [0, 2], [], [1, 2]]) >>> Connectivity().inverse() Varray([])
- nParents()[source]¶
Return the number of elements connected to each node.
- Returns:
1-dim 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 array_like) – 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]), array([2, 3, 2, 2]))
- hits(nodes)[source]¶
Count the nodes from a list connected to the elements.
- Parameters:
- 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', *, exclude=None, 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.
exclude (bool array or int index, optional) –
Node selector. If provided (with
kind=='e'
) this defines by a bool flag array or int index numbers a list of nodes that are not to be considered connectors between elements.This option is only useful in the case kind == ‘e’. If you want to exclude elements for the ‘n’ case, remove those elements from the Connectivity before calling adjacency().
mask (bool array or int index, optional) –
This is like exclude, but specifies the nodes that should be considered connectors instead of the ones that should be excluded.
This argument can not be used together with
exclude
. Its use is deprecated.
- 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]]) >>> Connectivity([[0,1],[0,2],[1,3],[0,5]]).adjacency('e',exclude=[0,4]) Adjacency([[ 2], [-1], [ 0], [-1]]) >>> Connectivity([[0,1],[0,2],[1,3],[0,5]]).adjacency('e',mask=[1,2,3,5]) Adjacency([[ 2], [-1], [ 0], [-1]]) >>> Connectivity([[0,1],[0,2],[1,3],[0,5]]).adjacency( ... 'e',mask=[False,True,True,True,False,True]) Adjacency([[ 2], [-1], [ 0], [-1]]) >>> 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]]) >>> Connectivity([[0,1,],[2,3]]).adjacency('e') Adjacency([], shape=(2, 0))
- 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]]) >>> Connectivity([[0,1],[0,2],[1,3],[0,5]]).adjacentElements([0,1,2]) array([[ 1, 2, 3], [-1, 0, 3], [-1, -1, 0]]) >>> Connectivity([[0,1],[0,2],[1,3],[0,5]]).adjacentElements([1,2,3]) array([[ 0, 3], [-1, 0], [ 0, 1]]) >>> Connectivity([[0,1],[0,2],[1,3],[0,5]]).adjacentElements([0,2]) array([[ 1, 2, 3], [-1, -1, 0]]) >>> Connectivity([[0,1],[0,2],[1,3],[0,5]]).adjacentElements([2]) array([[0]]) >>> Connectivity([[0,1],[0,2],[1,3],[0,5]]).adjacentElements(1) array([[0, 3]])
- 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]]) >>> 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 non-negative, 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:
- 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 array_like) – An object that can be converted to a 1-dim or 2-dim 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 plex-3 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. Each element may generate multiple instances of the intermediate level.
- Parameters:
selector (int array_like) – An object that can be converted to a 1-dim or 2-dim 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.
permutations (str or None) –
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 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 resulting tables.
See however
mesh.Mesh.getBorder()
for an application where aninverse operation is possible, because the border only contains
unique rows.
See also
mesh.Mesh.combine()
, which is an almost inverse operationfor 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, 3, 1], [1, 3, 0], [2, 4, 1]]), Connectivity([[0, 1], [2, 0], [0, 3], [1, 2], [3, 2]])) >>> Connectivity([[0,1,2,3]]).insertLevel( ... [[0,1,2],[1,2,3],[0,1,1],[0,0,1],[1,0,0]]) (Connectivity([[1, 2, 0, 0, 0]]), Connectivity([[0, 1, 1], [0, 1, 2], [1, 2, 3]]))
- 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 node 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 plex-2 connections.
Creates a Connectivity table with a plex-2 (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 plex-2 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 array_like) – List of element numbers. If not specified, all elements are considered.
- Returns:
int array – A 1-dim 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:
- 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]])
- chain(disconnect=None, return_conn=False)[source]¶
Reorder the elements into simply connected chains.
Chaining the elements involves reordering them such that the first node of the next element is equal to the last node of the previous. This is especially useful in converting line elements to continuous curves or polylines. It will work with any plexitude though, and only look at the first and last node of the elements in the chaining process.
- Parameters:
disconnect (int array_like | str, optional) – List of node numbers where the resulting chains should be split. None of the resulting chains will have any of the listed node numbers as an interior node. A chain may start and end at such a node. A special value ‘branch’ will set the disconnect array to all the nodes owned by more than two elements. This will split all chains at branching points.
return_conn (bool) – If True, also return the list of Connectivities corresponding with the chains.
- Returns:
chains (list of int arrays) – A list of tables with the same column length as those in
conn
, and having two columns. The first column contains the original element numbers of a chain, 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). The list of chains is sorted in order of decreasing length.conn (list of
Connectivity
instances, optional) – Only returned ifreturn_conn
is True: a list a Connectivity tables of plexitudenplex
corresponding to each chain. The elements in each Connectivity are ordered to form a continuous connected segment, i.e. the last node of each element in the table is equal to the first node of the following element (if any).
See also
chained
return only the chained Connectivities
Examples
>>> Connectivity([[0,1],[1,2],[0,4],[4,2]]).chain() [array([[ 0, 1], [ 1, 1], [ 3, -1], [ 2, -1]])] >>> Connectivity([[0,1],[1,2],[0,4]]).chain() [array([[ 1, -1], [ 0, -1], [ 2, 1]])] >>> Connectivity([[0,1],[0,2],[0,3],[5,4]]).chain() [array([[ 0, -1], [ 1, 1]]), array([[3, 1]]), array([[2, 1]])] >>> Connectivity([[0,1],[0,2],[0,3],[5,4]]).chain(disconnect='branch') [array([[3, 1]]), array([[2, 1]]), array([[1, 1]]), array([[0, 1]])] >>> Connectivity([[0,1],[0,2],[0,3],[5,4]]).chain(return_conn=True) ([array([[ 0, -1], [ 1, 1]]), array([[3, 1]]), array([[2, 1]])], [Connectivity([[1, 0], [0, 2]]), Connectivity([[5, 4]]), Connectivity([[0, 3]])]) >>> Connectivity([[0,1,2],[2,0,3],[0,3,1],[4,5,2]]).chain() [array([[ 1, -1], [ 0, -1], [ 2, 1]]), array([[3, 1]])] >>> Connectivity([[0,1,2],[2,0,3],[0,3,1],[4,5,2]]).chain( ... disconnect=[0]) [array([[0, 1], [1, 1]]), array([[3, 1]]), array([[2, 1]])]
- chained(disconnect=None)[source]¶
Return the Connectivities of the chained elements.
This is a convenience method calling
chain()
with thereturn_conn=True
parameter and only returning the second return value. It is equivalent with:self.chain(disconnect, return_conn=True)[1]
Examples
>>> Connectivity([[0,1],[1,2],[0,4],[4,2]]).chained() [Connectivity([[0, 1], [1, 2], [2, 4], [4, 0]])]
>>> Connectivity([[0,1],[1,2],[0,4]]).chained() [Connectivity([[4, 0], [0, 1], [1, 2]])]
>>> Connectivity([[0,1],[0,2],[0,3],[4,5]]).chained() [Connectivity([[1, 0], [0, 2]]), Connectivity([[4, 5]]), Connectivity([[0, 3]])]
>>> Connectivity([[0,1],[0,2],[0,3],[5,4]]).chained(disconnect='branch') [Connectivity([[5, 4]]), Connectivity([[0, 3]]), Connectivity([[0, 2]]), Connectivity([[0, 1]])] >>> Connectivity([[0,1,2],[2,0,3],[0,3,1],[4,5,2]]).chained() [Connectivity([[1, 3, 0], [0, 1, 2], [2, 0, 3]]), Connectivity([[4, 5, 2]])] >>> Connectivity([[0,1,2],[2,0,3],[0,3,1],[4,5,2]],).chained( ... disconnect=[0]) [Connectivity([[0, 1, 2], [2, 0, 3]]), Connectivity([[4, 5, 2]]), Connectivity([[0, 3, 1]])]
- 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 array_like, 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 array_like, 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]]