pysdic.compute_elements_neighborhood#

compute_elements_neighborhood(connectivity, max_distance=1, self_neighborhood=True)[source]#

Compute the neighborhood of each element in the mesh, where the neighborhood of an element is defined as the set of elements that are within a specified distance from the element in the connectivity of the mesh.

Convenience function that combines the creation of the elements adjacency graph from the connectivity of the mesh and the computation of the neighborhood of each element in the mesh based on the connectivity and a specified maximum distance.

Note

  • The input connectivity must 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.

  • max_distance (Optional[Integral], optional) – The maximum distance to consider between elements. If the distance between two elements 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 default None.

  • self_neighborhood (bool, optional) – If True, the neighborhood of each element will include the element itself (i.e., the element will be considered as part of its own neighborhood). If False, the neighborhood of each element will not include the element itself. By default True.

Returns:

A list where each element is a list containing the indices of the neighboring elements for the corresponding element in the mesh.

Return type:

List[List[int]]

See also

compute_neighborhood()

Compute the neighborhood of each element in the graph, where the neighborhood of an element is defined as the set of elements that are within a specified distance from the element in the connectivity of the mesh.

create_elements_adjacency_graph()

Create the elements adjacency graph from the connectivity of the mesh, where two elements are neighbors if they share a common vertex in the mesh.

Examples

Create a simple quadrangle 4 mesh with 10 vertices and 4 elements and compute the elements adjacency matrix from the connectivity.

../_images/graph_mesh.png

Quadrangle 4 mesh. The neighboring elements of element 0 with max_distance=1 are elements 0, 1 since they are within a distance of 1 from element 0 in the graph.#

 1import numpy as np
 2from pysdic import compute_elements_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]]
 9)
10
11neighborhood = compute_elements_neighborhood(
12    connectivity=connectivity, max_distance=1, self_neighborhood=True
13)
14
15print(f"elements neighborhood (length={len(neighborhood)}):")
16subset_1 = neighborhood[0]
17print(f"elements neighborhood (neighbors of element 0 with max_distance=1): {subset_1}")
elements neighborhood (length=10):
elements neighborhood (neighbors of element 0 with max_distance=1): [0, 1]