pysdic.fem.compute_vertices_neighborhood#
- compute_vertices_neighborhood(connectivity_array, *, n_vertices=None, max_distance=1, self_neighborhood=True)[source]#
Compute the neighborhood of each vertex of a mesh, i.e. the vertices within a given distance, 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_neighborhood().Note
Input
connectivity_arraywill be converted tonumpy.int64.
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_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 (Integral, optional (default:
1)) – The maximum distance of the vertices in the neighborhood. With 1, only the vertices sharing an element are included.self_neighborhood (bool, optional (default:
True)) – If True, the neighborhood of each vertex includes the vertex itself.
- Returns:
neighborhood – A symmetric boolean sparse matrix of shape \((N_{v}, N_{v})\), where the neighborhood of vertex \(i\) is
neighborhood[i].indices(sorted).- Return type:
See also
pysdic.fem.compute_neighborhoodNeighborhood of each node 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 neighborhood of each vertex.
'quadrangle_4'mesh. The neighborhood of vertex 1 with max_distance=1 contains vertices 0, 1, 2, 4, 5 and 6.#1import numpy 2from pysdic.fem import compute_vertices_neighborhood 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 10neighborhood = compute_vertices_neighborhood(connectivity_array, max_distance=1) 11 12print(f"vertices neighborhood (shape={neighborhood.shape})") 13print(f"neighborhood of vertex 1: {neighborhood[1].indices}")
vertices neighborhood (shape=(10, 10)) neighborhood of vertex 1: [0 1 2 4 5 6]