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.

as_set_of_faces()[source]
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)
compute_quadrature(method)[source]
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:

Mesh

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:

Mesh

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

extract_one_face(id_face)[source]
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)
static from_set_of_faces(set_of_faces)[source]
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:

Mesh

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)
heal_normals(**kwargs)[source]
heal_triangles(**kwargs)[source]
is_triangle(face_id) bool[source]

Returns if a face is a triangle

Parameters:

face_id (int) – Face id

join_meshes(*, name=None)[source]
lowest_lid_position(omega_max, *, g=9.81)[source]
merge_duplicates(**kwargs)[source]
merged()[source]

Dummy method to be generalized for collections of meshes.

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.

path_to_leaf()[source]

Dummy method to be generalized for collection of meshes.

property quadrangles_ids: ndarray

Get the array of ids of quadrangle shaped faces.

property quadrature_points
remove_degenerated_faces(**kwargs)[source]
remove_unused_vertices(**kwargs)[source]
rotate(*args, inplace=True, name=None, **kwargs)
show(**kwargs)[source]
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.

show_vtk(**kwargs)[source]

Shows the mesh in the vtk viewer

sliced_by_plane(plane: Plane)[source]
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().

symmetrized(plane)[source]
to_meshmagick()[source]

Convert the Mesh object as a Mesh object from meshmagick. Mostly for debugging.

translate(*args, inplace=True, name=None, **kwargs)
tree_view(**kwargs)[source]

Dummy method to be generalized for collections of meshes.

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)