pysdic.compute_elements_adjacency_matrix#

compute_elements_adjacency_matrix(connectivity, max_distance=None)[source]#

Compute the elements path distance matrix (adjacency matrix) from the connectivity of the mesh, where the distance between two elements is defined as the minimum number of elements that must be traversed to go from one element to another.

Convenience function that combines the creation of the elements adjacency graph from the connectivity of the mesh and the computation of the adjacency matrix from the elements adjacency graph.

Note

  • The input connectivity must be integral-array like.

Warning

No tests are performed to check if the input connectivity is valid (e.g., if the connectivity contains invalid vertex indices, …). The behavior of the function is undefined in that case.

Parameters:
  • connectivity (ArrayLike) – An array of shape \((N_e, N_{vpe})\) defining the connectivity of the elements in the mesh, where each row contains the indices of the nodes that form an element.

  • max_distance (Optional[Integral], optional) – The maximum distance to consider between elements. If the distance between two elements exceeds this value, the corresponding entry in the adjacency matrix will be set to -1. If None, there is no maximum distance and all distances will be computed. By default None.

Returns:

A square array of shape (\(N_e\), \(N_e\)) representing the path distance matrix between elements.

Return type:

numpy.ndarray

Raises:
  • TypeError – If max_distance is not an integer or None.

  • ValueError – If max_distance is a negative integer. If the connectivity array is not 2D.

See also

compute_adjacency_matrix()

Compute the adjacency matrix from the adjacency graph of the elements, where the distance between two elements is defined as the minimum number of elements that must be traversed to go from one element to another.

create_elements_adjacency_graph()

Create the elements adjacency graph from the connectivity of the mesh, where two elements are neighbors if they share a common vertex.

Examples

Create a simple quadrangle 4 mesh with 10 vertices and 4 elements and compute the elements adjacency matrix from the connectivity.

../_images/graph_mesh.png

Quadrangle 4 mesh.#

 1import numpy as np
 2from pysdic import compute_elements_adjacency_matrix
 3
 4connectivity = np.array([
 5    [0, 1, 4, 5],
 6    [1, 2, 5, 6],
 7    [2, 3, 6, 7],
 8    [6, 7, 8, 9]]
 9, dtype=np.int64)
10n_elements = connectivity.shape[0] # 4 elements
11
12adjacency_matrix = compute_elements_adjacency_matrix(connectivity=connectivity)
13
14print(f"elements adjacency matrix with shape: {adjacency_matrix.shape}")
15print(adjacency_matrix)
elements adjacency matrix with shape: (4, 4)
[[ 0  1  2  2]
 [ 1  0  1  2]
 [ 2  1  0  1]
 [ 2  2  1  0]]