8. adjacency — A class for storing and handling adjacency tables.

This module defines a specialized array class for representing adjacency of items of a single type. This is e.g. used in mesh models, to store the adjacent elements.

class adjacency.Adjacency(data=[], dtyp=None, copy=False, normalize=True)[source]

A class for storing and handling adjacency tables.

An adjacency table defines a neighbouring relation between elements of a single collection. The nature of the relation is not important, but should be a binary relation: two elements are either related or they are not.

Typical applications in pyFormex are the adjacency tables for storing elements connected by a node, or by an edge, or by a node but not by an edge, etcetera.

Conceptually the adjacency table corresponds with a graph. In graph theory however the data are usually stored as a set of tuples (a,b) indicating a connection between the elements a and b. In pyFormex elements are numbered consecutively from 0 to nelems-1, where nelems is the number of elements. If the user wants another numbering, he can always keep an array with the actual numbers himself. Connections between elements are stored in an efficient two-dimensional array, holding a row for each element. This row contains the numbers of the connected elements. Because the number of connections can be different for each element, the rows are padded with an invalid elements number (-1).

A normalized Adjacency is one where all rows do not contain duplicate nonnegative entries and are sorted in ascending order and where no column contains only -1 values. Also, since the adjacency is defined within a single collection, no row should contain a value higher than the maximum row index.

Parameters
  • data (int array_like) – Data to initialize the Connectivity. The data should be 2-dim with shape (nelems,ncon), where nelems is the number of elements and ncon is the maximum number of connections per element.

  • dtyp (float datatype, optional) – Can be provided to force a specific int data type. If not, 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 typed numpy.ndarray.

  • normalize (bool, optional) – If True (default) the Adjacency will be normalized at creation time.

  • allow_self (bool, optional) – If True, connections of elements with itself are allowed. The default (False) will remove self-connections when the table is normalized.

Warning

The allow_self parameter is currently inactive.

Examples

>>> A = Adjacency([[1,2,-1],
...                [3,2,0],
...                [1,-1,3],
...                [1,2,-1],
...                [-1,-1,-1]])
>>> print(A)
[[-1  1  2]
 [ 0  2  3]
 [-1  1  3]
 [-1  1  2]
 [-1 -1 -1]]
>>> A.nelems()
5
>>> A.maxcon()
3
>>> Adjacency([[]])
Adjacency([], shape=(1, 0))