pysdic.fem.compute_vertices_distance_matrix#
- compute_vertices_distance_matrix(connectivity_array, *, n_vertices=None, max_distance=None, sparse=False)[source]#
Compute the shortest path distances between all the pairs of vertices of a mesh, where two vertices are neighbors (distance 1) if they belong to the same element.
Convenience function that combines
pysdic.fem.assemble_vertices_adjacency_graph()andpysdic.fem.compute_distance_matrix().Note
Input
connectivity_arraywill be converted tonumpy.int64.
Warning
The dense output has shape \((N_{v}, N_{v})\). For large meshes, use
sparse=Truewith a smallmax_distance.- Parameters:
connectivity_array (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 vertices that form an element.
n_vertices (Optional[Integral], optional (default:
None)) – The total number of vertices \(N_{v}\) in the mesh. If not provided, it will be inferred as the maximum vertex index inconnectivity_arrayplus one.max_distance (Optional[Integral], optional (default:
None)) – The maximum distance to compute. Pairs of vertices farther thanmax_distanceare considered unreachable. If None, all the distances are computed.sparse (bool, optional (default:
False)) – If True, a sparse matrix storing only the distances between distinct reachable vertices is returned (seepysdic.fem.compute_distance_matrix()).
- Returns:
distance_matrix – A symmetric matrix of shape \((N_{v}, N_{v})\) containing the distances between the vertices (see
pysdic.fem.compute_distance_matrix()for the dense and sparse conventions).- Return type:
Union[numpy.ndarray, scipy.sparse.csr_matrix]
See also
pysdic.fem.compute_distance_matrixDistance matrix of an adjacency graph.
pysdic.fem.assemble_vertices_adjacency_graphVertices adjacency graph of a mesh.
Examples
Create a simple
'quadrangle_4'mesh with 10 vertices and 4 elements and compute the vertices distance matrix.
'quadrangle_4'mesh.#1import numpy 2from pysdic.fem import compute_vertices_distance_matrix 3 4connectivity_array = numpy.array([ 5 [0, 1, 4, 5], 6 [1, 2, 5, 6], 7 [2, 3, 6, 7], 8 [6, 7, 8, 9]]) 9 10distance_matrix = compute_vertices_distance_matrix(connectivity_array) 11 12print(f"vertices distance matrix (shape={distance_matrix.shape})") 13print(f"distances from vertex 1: {distance_matrix[1]}")
vertices distance matrix (shape=(10, 10)) distances from vertex 1: [1 0 1 2 1 1 1 2 2 2]