Mesh structures#
Mesh class#
- class Mesh(vertices, connectivity, element_type=None)[source]#
A Mesh is a collection of vertices (
PointCloud) associated with connectivity information (Connectivity) that defines the elements of the mesh.The vertices are represented as a
PointCloudinstance with shape \((N_v, E)\), where \(N_v\) is the number of vertices (n_vertices) and \(E\) is the embedding dimension (n_dimensions). The connectivity is represented as aConnectivityinstance with shape \((N_e, N_{vpe})\), where \(N_e\) is the number of elements (n_elements), and \(N_{vpe}\) is the number of vertices per element (n_vertices_per_element).The coordinates of a point into the mesh can be accessed by the natural coordinates in the reference element. The number of natural coordinates \((\xi, \eta, \zeta, ...)\) depends on the type of element and is noted as \(K\) (the topological dimension of the element) accessible through the property
n_topological_dimensions.Lets consider a mesh with \(N_{vpe}\) vertices per element, and \(K\) natural coordinates. Lets \(X\) be the coordinates of a point in the mesh. The transformation from natural coordinates to global coordinates is given by:
\[X = \sum_{i=1}^{N_{vpe}} N_i(\xi, \eta, \zeta, ...) X_i\]where \(N_i\) are the shape functions associated with each vertex, and \(X_i\) are the coordinates of the vertices of the element.
See also
pysdic.compute_shape_functions()for more information on shape functions.
If
element_typeis provided, the mesh will enforce that all elements are of the specified type. This allow to use the predefined shape functions and properties associated with that element type. The implemented types are:Element Type
Description
“segment_2”
2-node line element
“segment_3”
3-node line element
“triangle_3”
3-node triangular element
“triangle_6”
6-node triangular element
“quadrangle_4”
4-node quadrilateral element
“quadrangle_8”
8-node quadrilateral element
Warning
Once the mesh is created with a specific
element_type, number of vertices per element and topological dimensions. Please avoid adding or removing vertices or elements that do not conform to the expected structure of the mesh, as this may lead to unintended consequences and errors in the mesh structure. Consider create a copy of the mesh before performing such operations to avoid modifying the original mesh in place, which may lead to unintended consequences if the original mesh is used elsewhere.- Parameters:
vertices (Union[
PointCloud, ArrayLike]) – The vertices of the mesh as aPointCloudinstance with shape \((N_v, E)\), where \(N_v\) is the number of vertices and \(E\) is the embedding dimension.connectivity (Union[
Connectivity, ArrayLike]) – The connectivity of the mesh as aConnectivityinstance with shape (\(N_e\), \(N_{vpe}\)), where \(N_e\) is the number of elements and \(N_{vpe}\) is the number of vertices per element.element_type (Optional[
str], optional) – The expected type of elements in the mesh, by default None. The element type will be set to the connectivity. If provided, must be similar to the connectivity element type.
Instantiate and export Mesh object#
By default, the meshes are created from a set of vertices and connectivity.
The vertices are represented as a pysdic.PointCloud object, and the connectivity is represented as a pysdic.Connectivity object.
Mesh can also use the following methods to instantiate a Mesh object from different file formats.
|
Create a Mesh instance from a |
|
Create a Mesh instance from a NPZ file. |
|
Create a Mesh instance from a VTK file (Only for 3D embedding dimension meshes \(E=3\)). |
The Mesh class provides methods to export the mesh to various file formats.
|
Convert the |
|
Write the |
|
Write the |
Accessing Mesh attributes#
The public attributes of a Mesh object can be accessed using the following properties:
[Get or Set] The connectivity of the mesh in a |
|
[Get or Set] The vertices of the mesh in an |
For easier access to the vertices and connectivity information, the following properties are also available and are equivalent to the corresponding properties of the pysdic.PointCloud and pysdic.Connectivity objects:
[Get or Set] Alias for |
|
[Get or Set] The vertex indices of the mesh elements - alias for |
|
[Get or Set] The element type of the mesh - alias for |
|
[Get] The embedding dimension \(E\) of the mesh - alias for |
|
[Get] The number of elements \(N_e\) in the mesh - alias for |
|
[Get] Alias for |
|
[Get] The topological dimension \(K\) of the elements in the mesh - alias for |
|
[Get] The number of vertices \(N_v\) in the mesh - alias for |
|
[Get] The number of vertices per element \(N_{vpe}\) in the mesh - alias for |
|
[Get or Set] The coordinates of the mesh vertices - alias for |
To ensure the integrity of the mesh, the following properties can be used:
Create a deep copy of the Mesh instance. |
|
Validate the mesh by performing internal checks on vertices and connectivity. |
Add, remove or modify vertices or connectivity of the Mesh objects#
The topology of the mesh can be modified using the following methods:
|
Add new elements to the mesh by appending new connectivity entries. |
|
Add new vertices to the mesh by appending new vertex coordinates. |
Get a boolean mask indicating which vertices are used in the connectivity of the mesh. |
|
|
Filter the connectivity of the mesh by keeping only the elements corresponding to the True values in the mask. |
|
Filter the vertices of the mesh by keeping only the vertices corresponding to the True values in the mask, remove all the elements that are connected to the removed vertices and remap the vertices indices accordingly. |
|
Keep only the specified elements in the mesh by specifying their indices in the connectivity array. |
|
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. |
|
Remove specified elements from the mesh by specifying their indices in the connectivity array. |
|
Remove all unused vertices from the mesh, where unused vertices are defined as vertices that are not referenced in the connectivity of the mesh. |
|
Remove specified vertices from 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. |
Accessing and managing vertices and connectivity properties#
To access and manage the properties of vertices and connectivity, use the Mesh.vertices() and Mesh.connectivity() objects, which provide methods to compute and store properties related to the vertices and connectivity of the mesh.
The vertices and connectivity properties are common to all meshes build on the same set of vertices and connectivity, and they are stored in PointCloud and Connectivity objects, respectively.
The properties can be accessed and managed using the following methods:
# Example of accessing and managing vertices and connectivity properties
from pysdic import Mesh
# Create a simple mesh (this is just an example, replace with actual vertices and connectivity)
vertices = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
connectivity = [[0, 1, 2]]
mesh = Mesh(vertices=vertices, connectivity=connectivity)
# Access vertices properties
intensity = [1, 2, 3] # Example property for vertices
mesh.vertices.set_property('intensity', intensity)
retrieved_intensity = mesh.vertices.get_property('intensity')
# Access connectivity properties
area = [0.5] # Example property for connectivity
mesh.connectivity.set_property('area', area)
retrieved_area = mesh.connectivity.get_property('area')
Precomputed quantities of the mesh#
To perform geometric computations and property interpolations on the mesh, some quantities can be precomputed and stored in the mesh for later use. The precomputed quantities of the mesh are stored in a dictionary, and they can be accessed and managed using the following methods:
Warning
If any modification is made to the vertices or connectivity of the mesh, the precomputed properties may become invalid and should be cleared using Mesh.clear_precomputed() to avoid using outdated properties in subsequent computations.
It is the responsibility of the user to ensure that the precomputed properties are consistent with the current state of the mesh, especially after any modifications to the vertices or connectivity.
|
Get the value of a precomputed property stored in the mesh by its key. |
List all the keys of the precomputed properties that are currently stored in the mesh. |
|
Clear all the precomputed properties stored in the mesh, removing all key-value pairs from the precomputed properties dictionary. |
The method with precompute argument allows to compute a quantity and store it in the precomputed properties of the mesh for later use (or into IntegrationPoints).
Set to True to store the computed quantity in the precomputed properties of the mesh, and set to False to compute the quantity without storing it in the precomputed properties of the mesh.
The precomputed quantities available are :
vertices_adjacency_matrixelements_adjacency_matrixvertices_neighborhoodelements_neighborhood
The mesh can be used to precompute quantities for IntegrationPoints as well such as:
integration_points_neighborhoodshape_functionsshape_function_derivatives
Compute connectivity and adjacency graphs#
The connectivity and adjacency graphs of a mesh can be computed using the following methods, which are based on Breadth-First Search (BFS) techniques. The connectivity graph represents the direct connections between vertices or elements in the mesh, while the adjacency graph represents the distances between vertices or elements in the mesh based on the connectivity.
Compute the neighborhood of each vertex in the mesh, where the neighborhood of a vertex is defined as the set of vertices that are within a specified distance from the vertex in the connectivity of the mesh. |
|
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. |
|
Compute the vertices path distance matrix (adjacency matrix) from the connectivity of the mesh. |
|
Compute the elements adjacency matrix from the connectivity of the mesh. |
Once computed and stored in the precomputed properties of the mesh, the neighborhood and adjacency graphs can be used to compute statistics of a property according to the adjacency (mean, median, std, …), as well as to perform geometric computations and property interpolations on the mesh.
Compute the specified statistics for the given property array defined at the vertices of a mesh based on the neighborhood information for each vertex. |
|
Compute the specified statistics for the given property array defined at the elements of a mesh based on the neighborhood information for each element. |
Mesh geometric computations and interpolations#
Some methods are provided to perform geometric computations and property interpolations on Mesh objects:
|
Compute the shape functions and their first derivatives for the mesh elements at given |
|
Compute the interpolation of a property at given natural coordinates for specified elements in the mesh (convenient method for |
|
Project a property defined at integration points within elements back to the vertices of a mesh using mesh and integration point information (convenient method for |
|
Compute the derivative of a property defined at the nodes of a mesh to given integration points within elements with respect to global coordinates \((x,y,z,...)\) from mesh and integration point information (convenient method for |
Visualize surface meshes#
The package pysdic provides functions to visualize 3D surface meshes using the Pyvista library.
The element_type of the mesh must be set.
Furthermore, before visualizing a mesh with a texture, make sure to have the uvmap defined.
[Get or Set] The UV mapping of each element in the mesh (only for surfacique meshes \(K=2\)). |
|
|
Visualize the mesh using PyVista (only for \(E \leq 3\) embbeded dimension), the mesh must have |