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