pysdic.compute_vertices_neighborhood#
- compute_vertices_neighborhood(connectivity, n_vertices=None, max_distance=1, self_neighborhood=True)[source]#
Compute the neighborhood of each vertex in the mesh, where the neighborhood of a vertex is defined as the set of vertices that are within a specified distance from the vertex in the connectivity of the mesh.
Convenience function that combines the creation of the vertices adjacency graph from the connectivity of the mesh and the computation of the neighborhood of each vertex in the mesh based on the connectivity and a specified maximum distance.
Note
The input
connectivitymust 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 defaultNone.self_neighborhood (
bool, optional) – IfTrue, the neighborhood of each vertex will include the vertex itself (i.e., the vertex will be considered as part of its own neighborhood). IfFalse, the neighborhood of each vertex will not include the vertex itself. By defaultTrue.
- Returns:
A list where each element is a list containing the indices of the neighboring vertices for the corresponding vertex in the mesh.
- Return type:
List[List[
int]]
See also
compute_neighborhood()Compute the neighborhood of each vertex in the graph, where the neighborhood of a vertex is defined as the set of vertices that are within a specified distance from the vertex in the connectivity of the mesh.
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 4mesh with 10 vertices and 4 elements and compute the vertices adjacency matrix from the connectivity.
Quadrangle 4mesh. The neighboring vertices of vertex 1 with max_distance=1 are vertices 0, 1, 2, 4, 5, 6 and 7 since they are within a distance of 1 from vertex 1 in the graph.#1import numpy as np 2from pysdic import compute_vertices_neighborhood 3 4connectivity = np.array([ 5 [0, 1, 4, 5], 6 [1, 2, 5, 6], 7 [2, 3, 6, 7], 8 [6, 7, 8, 9]], dtype=np.int64 9) 10n_vertices = 10 11 12neighborhood = compute_vertices_neighborhood( 13 connectivity=connectivity, 14 n_vertices=n_vertices, 15 max_distance=1, 16 self_neighborhood=True 17) 18 19print(f"vertices neighborhood (length={len(neighborhood)}):") 20subset_1 = neighborhood[1] 21print(f"vertices neighborhood (neighbors of vertex 1 with max_distance=1): {subset_1}")
vertices neighborhood (length=10): vertices neighborhood (neighbors of vertex 1 with max_distance=1): [1, 0, 2, 4, 5, 6]