pysdic.Mesh#
The pysdic.Mesh combines \(N_v\) vertices (a pysdic.PointCloud) and \(N_e\) elements (a pysdic.Connectivity). It gives access to the finite element tools of pysdic.fem directly on the mesh (interpolation, derivatives, normals, ray casting, neighborhoods, …).
Mesh class#
- class Mesh(vertices, connectivity, *, element_type=None)[source]#
Bases:
LockableMixin,JsonSerializerMixin,NpzSerializerMixin,Hdf5SerializerMixinA mesh: \(N_v\) vertices (a
pysdic.PointCloudof shape \((N_v, E)\)) and \(N_e\) elements (apysdic.Connectivityof shape \((N_e, N_{vpe})\)) whose indices refer to these vertices.A point inside an element is located by its natural coordinates \(\Xi = (\xi, \eta, \zeta, ...)\) in the reference element. There are \(K\) natural coordinates, the topological dimension of the element (
n_topological_dimensions). The global coordinates of the point are given by the shape functions \(N_i\) of the element:\[X = \sum_{i=1}^{N_{vpe}} N_i(\Xi) X_i\]where \(X_i\) are the coordinates of the vertices of the element.
See also
pysdic.fem.compute_shape_functions()for the shape functions.The element types implemented in
pysdic.femare listed inpysdic.Connectivity. An element type is required for the operations that use shape functions and for the meshio and VTK exports.Important
The mesh always satisfies \(0 \leq\) index \(< N_v\) for all the vertex indices of the elements. The setters of
pysdic.Mesh(vertices,connectivity,coordinates,elements, …) check it.mesh.verticesandmesh.connectivityreturn the internal objects, so that properties can be read and set directly (mesh.vertices["u"] = ...). Their number of vertices and elements cannot be changed through them (the methods that change it return new objects). Their coordinates and elements can be set through them (mesh.connectivity.elements = ...), but this bypasses the check of the vertex indices: prefer the setters ofpysdic.Mesh, or callvalidate().Note
A mesh can be locked by an object of the package that owns it (for example an SDIC analysis, see
pysdic.core.lockable.LockableMixin). Its vertices and its connectivity are locked with it: the settersvertices,connectivity,coordinates,elementsandelement_typeof the mesh, and the setters ofmesh.verticesandmesh.connectivity, then raise aRuntimeErrorexplaining why. The properties (and theuvmap) can always be modified. A copy (copy) is always unlocked.- Parameters:
vertices (Union[
pysdic.PointCloud, ArrayLike]) – The vertices of the mesh, as apysdic.PointCloudor an array of shape \((N_v, E)\). A given point cloud is copied (with its properties).connectivity (Union[
pysdic.Connectivity, ArrayLike]) – The elements of the mesh, as apysdic.Connectivityor an integer array of shape \((N_e, N_{vpe})\). A given connectivity is copied (with its properties and element type).element_type (Optional[str], optional (default:
None)) – The type of the elements. If the connectivity already has an element type, both must be the same.
Notes
The methods never modify the mesh in place: the methods that change the vertices or the elements (
filter_connectivity(),filter_vertices(),remove_unused_vertices(), …) return a new mesh, and the current one is unchanged. The new mesh never shares its point cloud, connectivity or properties with the current one.
Instantiation#
The Mesh class can be instantiated in several ways:
From the coordinates of the vertices and the elements with the constructor (
Mesh(vertices, elements, element_type=...)).From other libraries:
meshio(from_meshio()),pyvista(from_pyvista()) orvtk(from_vtk(),from_vtk_file()).With the mesh creation functions (see Geometry).
|
Create a mesh from a |
|
Create a mesh from a |
|
Create a mesh from a VTK dataset with a single cell type ( |
|
Create a mesh from a legacy VTK file ( |
Implemented methods and attributes#
The following sections provide an overview of the attributes and methods defined
in the pysdic.Mesh class.
Attributes#
[Get/Set] The elements of the mesh, a |
|
[Get/Set] The coordinates of the vertices, a read-only array of shape \((N_v, E)\) (shortcut for |
|
[Get/Set] The type of the elements (shortcut for |
|
[Get/Set] The vertex indices of the elements, a read-only array of shape \((N_e, N_{vpe})\) (shortcut for |
|
[Get] The dimension \(E\) of the space. |
|
[Get] The number of elements \(N_e\). |
|
[Get] The topological dimension \(K\) of the elements, or |
|
[Get] The number of vertices \(N_v\). |
|
[Get] The number of vertices per element \(N_{vpe}\). |
|
[Get/Set] The UV coordinates of the vertices of each element (only for surface meshes, \(K = 2\)). |
|
[Get/Set] The vertices of the mesh, a |
Structure methods#
|
Create a copy of the mesh (with the same element type). |
|
Return a new mesh with additional elements (appended after the current ones). |
|
Return a new mesh with additional vertices (appended after the current ones, so the current indices are unchanged). |
|
Keep only the elements selected by a boolean mask. |
|
Keep only the elements with the given indices (in their original order). |
|
Remove the elements with the given indices. |
|
Keep only the vertices selected by a boolean mask. |
|
Keep only the vertices with the given indices (in their original order). |
|
Remove the vertices with the given indices. |
Get the vertices used by at least one element. |
|
|
Remove the vertices that are not used by any element (the indices of the elements are renumbered). |
Get the degenerated elements, i.e. the elements using the same vertex at least twice. |
|
|
Remove the degenerated elements (see |
Checks#
|
Validate the integrity of the mesh. |
Check that integration points are consistent with the mesh. |
Operations at integration points#
Interpolate, differentiate and project the properties of the mesh at integration points (see pysdic.IntegrationPoints).
|
Compute the shape functions of the elements of the mesh at integration points. |
|
Compute the shape function matrix \(\mathcal{N}\) of the mesh at integration points, such that the values of a property at the points are \(\mathcal{N} U\), with \(U\) the values at the vertices. |
|
Compute the Jacobian matrices \(\frac{\partial X}{\partial \Xi}\) of the mapping from the reference element to the mesh, at integration points. |
Compute the global coordinates of integration points. |
|
|
Interpolate a property defined at the vertices of the mesh at integration points. |
|
Compute the derivatives of a property defined at the vertices of the mesh with respect to the global coordinates, at integration points. |
|
Project a property defined at integration points to the vertices of the mesh. |
|
Compute the linear strain tensor of a displacement field at integration points. |
Geometry of the elements#
Compute the center of each element of the mesh, the image of the center of the reference element. |
|
Compute the area of each element of a surface mesh (\(K = 2\)). |
|
Compute the unit normal of each element of a 3D surface mesh (\(K = 2\), \(E = 3\)), at the center of the element. |
|
Compute the unit normal at each vertex of a 3D surface mesh (\(K = 2\), \(E = 3\)), as the mean of the normals of the elements weighted by their areas. |
|
Compute the unit normal of a 3D surface mesh (\(K = 2\), \(E = 3\)) at integration points. |
|
|
Compute the first intersection of rays with a 3D surface mesh (\(K = 2\), \(E = 3\)). |
|
Locate points in a 2D surface mesh (\(K = 2\), \(E = 2\)): compute the element containing each point and its natural coordinates. |
Adjacency and neighborhoods#
Assemble the vertices adjacency graph of the mesh: two vertices are neighbors if they belong to the same element. |
|
Assemble the elements adjacency graph of the mesh: two elements are neighbors if they share at least one vertex. |
|
|
Compute the neighborhood of each vertex of the mesh, i.e. the vertices within a given distance (two vertices are at distance 1 if they belong to the same element). |
|
Compute the neighborhood of each element of the mesh, i.e. the elements within a given distance (two elements are at distance 1 if they share a vertex). |
Compute, for each element of the mesh, the integration points located in the elements of its neighborhood. |
Conversion and visualization#
Export to other libraries (the meshio, pyvista and vtk methods require the corresponding optional packages).
|
Convert the mesh to a |
|
Convert the mesh to a |
|
Convert the mesh to a |
|
Save the mesh to a legacy VTK file ( |
|
Visualize the mesh with PyVista (only for \(E \leq 3\)). |
Serialization methods#
The pysdic.Mesh is converted to a flat dictionary with to_dict (and created back with
from_dict). It inherits the file methods of the serialization mixins
(see Core Tools).
|
Convert the mesh to a flat dictionary. |
|
Create a mesh from a flat dictionary. |
|
Serialize the object to a JSON file. |
|
Deserialize a JSON file to an object of the class. |
|
Serialize the object to an HDF5 file. |
|
Deserialize an object from an HDF5 file. |
|
Serialize the object to an NPZ file. |
|
Deserialize an object from an NPZ file. |