pysdic.Mesh.add_connectivity#

Mesh.add_connectivity(new_connectivity, force_inplace=False)[source]#

Add new elements to the mesh by appending new connectivity entries.

This method is an extension of the connectivity.concatenate method that allows adding new elements to the mesh while ensuring that the connectivity structure is maintained and validated. This method will ensure that the new connectivity is compatible with the existing mesh structure and will update the mesh’s connectivity accordingly.

Note

The new elements will be added to the end of the existing connectivity object and store in a new connectivity object (Copy of the original connectivity object with the new connectivity concatenated). The properties of the new elements will be initialized with NaN values and stored in the new connectivity object.

See also

  • add_vertices() to add new vertices to the mesh.

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

Parameters:
  • new_connectivity (Union[Connectivity, ArrayLike]) – An array of shape (\(P\), \(N_{vpe}\)) containing the connectivity of the new elements to add, where \(P\) is the number of new elements and \(N_{vpe}\) is the number of vertices per element.

  • force_inplace (bool, optional) – If True, the new connectivity will be concatenated to the existing connectivity in place, modifying the original connectivity object. If False, a new connectivity object will be created to store the combined connectivity, leaving the original connectivity object unchanged. By default False.

Raises:
  • TypeError – If new_connectivity is not a Connectivity instance or a numpy array. If force_inplace is not a boolean.

  • ValueError – If new_connectivity 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]])
5elements = np.array([[0, 1, 2]])
6mesh3d = Mesh(points, elements, element_type="triangle_3")

Add some properties to the elements.

1element_property = np.array([10.0]).reshape(-1, 1) # Shape (1, 1)
2mesh3d.connectivity["my_element_property"] = element_property

Add new elements to the mesh.

1new_elements = np.array([[0, 1, 2], [1, 2, 0]])
2mesh3d.add_elements(new_elements)
3
4print(mesh3d.connectivity)
5# Output: Connectivity with 3 elements [[0, 1, 2], [0, 1, 2], [1, 2, 0]]
6
7print(mesh3d.connectivity["my_element_property"])
8# Output: [[10.], [nan], [nan]]