pysdic.Mesh.keep_vertices#

Mesh.keep_vertices(vertex_indices, force_inplace=False)[source]#

Keep only the specified vertices in the mesh by specifying their indices in the vertices array, remove all the elements that are connected to the removed vertices and remap the vertices indices accordingly.

This method must be used instead of the vertices.keep_points method because it allows keeping only specified vertices in the mesh while ensuring that the connectivity structure is maintained and validated. This method will ensure that the specified vertex indices are compatible with the existing mesh structure and will update the mesh’s vertices accordingly.

Note

The new vertices will be stored in a new vertices object (Copy of the original vertices object with only the kept vertices). The new connectivity will be stored in a new connectivity object (Copy of the original connectivity object with only the remaining elements that are not connected to the removed vertices and with remapped vertex indices). The properties of the kept vertices will be updated to keep only the properties of the kept vertices and stored in the new vertices object.

See also

  • filter_vertices() to filter the vertices of the mesh using a boolean mask.

  • remove_vertices() to remove specified vertices from the mesh.

  • PointCloud for more information on the vertices structure.

  • Connectivity for more information on the connectivity structure and element types.

Parameters:
  • vertex_indices (ArrayLike) – An array of shape (\(R\),) containing the indices of the vertices to keep in the mesh, where \(R\) is the number of vertices to keep.

  • force_inplace (bool, optional) – If True, the vertices will be updated in place, modifying the original vertices object and the connectivity object will be updated in place as well. If False, new vertices and connectivity objects will be created to store the updated vertices and connectivity, leaving the original vertices and connectivity objects unchanged. By default False.

Raises:
  • TypeError – If vertex_indices is not an array-like object or is not an integer array. If force_inplace is not a boolean.

  • ValueError – If vertex_indices does not have the correct shape or contains invalid indices.

Return type:

None

Examples

Create a simple Mesh instance.

1import numpy as np
2from pysdic import Mesh, PointCloud
3
4points = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]])
5connectivity = np.array([[0, 1, 2], [0, 1, 3], [0, 2, 3], [1, 2, 3]])
6mesh3d = Mesh(points, connectivity, element_type="triangle_3")

Remove the first vertex from the mesh and all the elements connected to it, keeping only the remaining vertices and elements.

1vertex_indices = np.array([1, 2, 3])
2mesh3d.keep_vertices(vertex_indices)
3
4print(mesh3d.vertices)
5# Output: PointCloud with 3 points [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
6
7print(mesh3d.connectivity)
8# Output: Connectivity with 1 element [[0, 1, 2]]