capytaine.meshes.meshes module¶
This module contains a class to describe the 2D mesh of the surface of a body in a 3D space. Based on meshmagick <https://github.com/LHEEA/meshmagick> by François Rongère.
- class capytaine.meshes.meshes.Mesh(vertices=None, faces=None, name=None, *, quadrature_method=None)[source]¶
Bases:
ClippableMixin
,SurfaceIntegralsMixin
,Abstract3DObject
A class to handle unstructured 2D meshes in a 3D space.
- Parameters:
vertices (array_like of shape (nv, 3)) – Array of mesh vertices coordinates.Each line of the array represents one vertex coordinates
faces (array_like of shape (nf, 4)) – Arrays of mesh connectivities for faces. Each line of the array represents indices of vertices that form the face, expressed in counterclockwise order to ensure outward normals description.
name (str, optional) – The name of the mesh. If None, the mesh is given an automatic name based on its internal ID.
quadrature_method (None or str or Quadpy quadrature, optional) – The method used to compute quadrature points in each cells. By default: None, that is a one-point first order scheme is used.
- property axis_aligned_bbox¶
Get the axis aligned bounding box of the mesh.
- Returns:
(xmin, xmax, ymin, ymax, zmin, zmax)
- Return type:
tuple
- property center_of_mass_of_nodes¶
(Non-weighted) center of mass of the nodes of the mesh.
- clip(*args, inplace=True, name=None, **kwargs)¶
- copy(name=None) Mesh [source]¶
Get a copy of the current mesh instance.
- Parameters:
name (string, optional) – a name for the new mesh
- Returns:
mesh instance copy
- Return type:
- property diameter_of_nodes¶
Maximum distance between two nodes of the mesh.
- extract_faces(id_faces_to_extract, return_index=False, name=None)[source]¶
Extracts a new mesh from a selection of faces ids
- Parameters:
id_faces_to_extract (ndarray) – Indices of faces that have to be extracted
return_index (bool, optional) – Flag to output old indices
name (string, optional) – Name for the new mesh
- Returns:
A new Mesh instance composed of the extracted faces
- Return type:
- extract_lid(plane=Plane(normal=[0. 0. 1.], point=[0. 0. 0.]))[source]¶
Split the mesh into a mesh of the hull and a mesh of the lid. By default, the lid is composed of the horizontal faces on the z=0 plane.
- Parameters:
plane (Plane) – The plane on which to look for lid faces.
- Returns:
hull mesh and lid mesh
- Return type:
2-ple of Mesh
- property faces: ndarray¶
Get the faces connectivity array of the mesh.
- property faces_areas: ndarray¶
Get the array of faces areas of the mesh.
- property faces_centers: ndarray¶
Get the array of faces centers of the mesh.
- property faces_normals: ndarray¶
Get the array of faces normals of the mesh.
- property faces_radiuses: ndarray¶
Get the array of faces radiuses of the mesh.
- flip_normals(*args, inplace=True, name=None, **kwargs)¶
- generate_lid(z=0.0, faces_max_radius=None)[source]¶
Return a mesh of the internal free surface of the body.
- Parameters:
z (float) – Vertical position of the lid. Default: 0.0
faces_max_radius (float) – resolution of the mesh of the lid. Default: mean of hull mesh resolution.
- Returns:
lid of internal surface
- Return type:
- get_face(face_id)[source]¶
Get the face described by its vertices connectivity.
- Parameters:
face_id (int) – Face id
- Returns:
If the face is a triangle, the array has 3 components, else it has 4 (quadrangle)
- Return type:
ndarray
- heal_mesh(*args, inplace=True, name=None, **kwargs)¶
- is_triangle(face_id) bool [source]¶
Returns if a face is a triangle
- Parameters:
face_id (int) – Face id
- mirror(*args, inplace=True, name=None, **kwargs)¶
- property nb_faces: int¶
Get the number of faces in the mesh.
- property nb_quadrangles: int¶
Get the number of quadrangles in the mesh.
- property nb_triangles: int¶
Get the number of triangles in the mesh.
- property nb_vertices: int¶
Get the number of vertices in the mesh.
- property quadrangles_ids: ndarray¶
Get the array of ids of quadrangle shaped faces.
- property quadrature_points¶
- rotate(*args, inplace=True, name=None, **kwargs)¶
- show_matplotlib(ax=None, normal_vectors=False, scale_normal_vector=None, saveas=None, color_field=None, cmap=None, cbar_label=None, **kwargs)[source]¶
Poor man’s viewer with matplotlib.
- Parameters:
ax (matplotlib axis) – The 3d axis in which to plot the mesh. If not provided, create a new one.
normal_vectors (bool) – If True, print normal vector.
scale_normal_vector (array of shape (nb_faces, )) – Scale separately each of the normal vectors.
saveas (str) – File path where to save the image.
color_field (array of shape (nb_faces, )) – Scalar field to be plot on the mesh (optional).
cmap (matplotlib colormap) – Colormap to use for field plotting.
cbar_label (string) – Label for colormap
Other parameters are passed to Poly3DCollection.
- property squared_axis_aligned_bbox¶
Get a squared axis aligned bounding box of the mesh.
- Returns:
(xmin, xmax, ymin, ymax, zmin, zmax)
- Return type:
tuple
Note
This method differs from axis_aligned_bbox() by the fact that the bounding box that is returned is squared but have the same center as the axis_aligned_bbox().
- to_meshmagick()[source]¶
Convert the Mesh object as a Mesh object from meshmagick. Mostly for debugging.
- translate(*args, inplace=True, name=None, **kwargs)¶
- property triangles_ids: ndarray¶
Get the array of ids of triangle shaped faces.
- triangulate_quadrangles(*args, inplace=True, name=None, **kwargs)¶
- property vertices: ndarray¶
Get the vertices array coordinate of the mesh.
- with_normal_vector_going_down(*args, inplace=True, name=None, **kwargs)¶