pysdic.create_vertices_adjacency_graph#
- create_vertices_adjacency_graph(connectivity, n_vertices=None)[source]#
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.
Note that the function is indepedent of the geometry of the element, thus two vertices will be considered as neighbors if they are part of the same element, regardless of the shape of the element (e.g., triangle, quadrilateral, tetrahedron, hexahedron, …).
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.
- Returns:
A list of sets representing the adjacency list of the graph, where each index corresponds to a vertex and each set at that index contains the neighboring vertex indices.
- Return type:
List[Set[Integral]]
See also
create_elements_adjacency_graph()Create the elements adjacency graph from the connectivity of the mesh.
Examples
Create a simple
quadrangle 4mesh with 10 vertices and 4 elements and compute the vertices adjacency graph from the connectivity.
Quadrangle 4mesh. The neighboring vertices of vertex 1 are vertices 0, 2, 4, 5 and 6 since they are part of the same elements in the mesh (elements 0 and 1).#1import numpy as np 2from pysdic import create_vertices_adjacency_graph 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) 9n_vertices = 10 10 11adjacency_graph = create_vertices_adjacency_graph( 12 connectivity=connectivity, 13 n_vertices=n_vertices 14) 15 16print(f"vertices adjacency graph with length: {len(adjacency_graph)}") 17subset_1 = adjacency_graph[1] 18print(f"vertices adjacency graph (neighbors of vertex 1): {subset_1}")
vertices adjacency graph with length: 10 vertices adjacency graph (neighbors of vertex 1): {np.int64(0), np.int64(2), np.int64(4), np.int64(5), np.int64(6)}