pysdic.fem.compute_elements_distance_matrix#
- compute_elements_distance_matrix(connectivity_array, *, max_distance=None, sparse=False)[source]#
Compute the shortest path distances between all the pairs of elements of a mesh, where two elements are neighbors (distance 1) if they share at least one vertex.
Convenience function that combines
pysdic.fem.assemble_elements_adjacency_graph()andpysdic.fem.compute_distance_matrix().Note
Input
connectivity_arraywill be converted tonumpy.int64.
Warning
The dense output has shape \((N_{e}, N_{e})\). 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.
max_distance (Optional[Integral], optional (default:
None)) – The maximum distance to compute. Pairs of elements 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 elements is returned (seepysdic.fem.compute_distance_matrix()).
- Returns:
distance_matrix – A symmetric matrix of shape \((N_{e}, N_{e})\) containing the distances between the elements (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_elements_adjacency_graphElements adjacency graph of a mesh.
Examples
Create a simple
'quadrangle_4'mesh with 10 vertices and 4 elements and compute the elements distance matrix.
'quadrangle_4'mesh.#1import numpy 2from pysdic.fem import compute_elements_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_elements_distance_matrix(connectivity_array) 11 12print(f"elements distance matrix (shape={distance_matrix.shape}):") 13print(distance_matrix)
elements distance matrix (shape=(4, 4)): [[0 1 2 2] [1 0 1 1] [2 1 0 1] [2 1 1 0]]