pysdic.compute_vertices_adjacency_matrix#

compute_vertices_adjacency_matrix(connectivity, n_vertices=None, max_distance=None)[source]#

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

Convenience function that combines the creation of the vertices adjacency graph from the connectivity of the mesh and the computation of the adjacency matrix from the vertices 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.

  • n_vertices (Optional[Integral], optional) – The total number of vertices in the mesh. If not provided, it will be inferred from the connectivity array.

  • max_distance (Optional[Integral], optional) – The maximum distance to consider between vertices. If the distance between two vertices 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_v\), \(N_v\)) representing the path distance matrix between vertices.

Return type:

numpy.ndarray

See also

compute_adjacency_matrix()

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

create_vertices_adjacency_graph()

Create the vertices adjacency graph from the connectivity of the mesh, where two vertices are neighbors if there is an element in the mesh containing both vertices.

Examples

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

../_images/graph_mesh.png

Quadrangle 4 mesh.#

 1import numpy as np
 2from pysdic import compute_vertices_adjacency_matrix
 3
 4connectivity = np.array([[0, 1, 4, 5], [1, 2, 5, 6], [2, 3, 6, 7], [6, 7, 8, 9]])
 5n_vertices = 10
 6
 7adjacency_matrix = compute_vertices_adjacency_matrix(
 8    connectivity=connectivity,
 9    n_vertices=n_vertices
10)
11
12print(f"vertices adjacency matrix with shape: {adjacency_matrix.shape}")
13extracted_subset = adjacency_matrix[1, :]
14print(f"vertices adjacency matrix (distances from vertex 1 to all vertices): {extracted_subset}")
vertices adjacency matrix with shape: (10, 10)
vertices adjacency matrix (distances from vertex 1 to all vertices): [1, 0, 1, 2, 1, 1, 1, 2, 3, 3]