meshplex — Simplex meshes for Python

meshplex computes all sorts of interesting points, areas, and volumes in triangular and tetrahedral meshes, with a focus on efficiency. Useful in many contexts, e.g., finite-element and finite-volume computations.

For a quickstart, checkout meshplex’s GitHubPage.

Overview of classes and functions

class meshplex.MeshLine(points, cells)

Class for handling line segment “meshes”.


Computes the volumes of the “cells” in the mesh.


Compute the control volumes of all nodes in the mesh.

class meshplex.MeshTri(points, cells, sort_cells=False)

Class for handling triangular meshes.


All angles in the triangle.


Get the circumradii of all cells


Get the midpoints of the incircles.


Get the inradii of all cells


Computes the curl of a vector field over the mesh. While the vector field is point-based, the curl will be cell-based. The approximation is based on

\[n\cdot curl(F) = \lim_{A\to 0} |A|^{-1} <\int_{dGamma}, F> dr;\]

see Actually, to approximate the integral, one would only need the projection of the vector field onto the edges at the midpoint of the edges.


The control volumes around each vertex.


Set up edge->point and edge->cell relations.

flip_until_delaunay(tol=0.0, max_steps=100)

Flip edges until the mesh is fully Delaunay (up to tol).


The centroid of any volume V is given by

\[c = \int_V x / \int_V 1.\]

The denominator is the control volume. The numerator can be computed by making use of the fact that the control volume around any vertex is composed of right triangles, two for each adjacent cell.

Optionally disregard the contributions from particular cells. This is useful, for example, for temporarily disregarding flat cells on the boundary when performing Lloyd mesh optimization.


The control volumes around each vertex. Optionally disregard the contributions from particular cells. This is useful, for example, for temporarily disregarding flat cells on the boundary when performing Lloyd mesh optimization.


Number of edges where the Delaunay condition is violated.

plot(show_coedges=True, control_volume_centroid_color=None, mesh_color='k', nondelaunay_edge_color=None, boundary_edge_color=None, comesh_color=(0.8, 0.8, 0.8), show_axes=True, cell_quality_coloring=None, show_point_numbers=False, show_edge_numbers=False, show_cell_numbers=False, cell_mask=None, mark_points=None, mark_edges=None, mark_cells=None)

Show the mesh using matplotlib.

plot_vertex(point_id, show_ce_ratio=True)

Plot the vicinity of a point and its covolume/edgelength ratio.

  • point_id (int) – Node ID of the point to be shown.
  • show_ce_ratio (bool, optional) – If true, shows the ce_ratio of the point, too.

2 * inradius / circumradius (min 0, max 1)


Helper method for removing cells along the boundary. The input criterion is a boolean array of length sum(mesh.is_boundary_cell).

This helps, for example, in the following scenario. When points are moving around, flip_until_delaunay() makes sure the mesh remains a Delaunay mesh. This does not work on boundaries where very flat cells can still occur or cells may even ‘invert’. (The interior point moves outside.) In this case, the boundary cell can be removed, and the newly outward node is made a boundary node.


Remove cells and take care of all the dependent data structures. The input argument remove_array can be a boolean array or a list of indices.

save(filename, *args, **kwargs)

Save the mesh to a file.

show(*args, fullscreen=False, **kwargs)

Show the mesh (see plot()).

show_vertex(*args, **kwargs)

Show the mesh around a vertex (see plot_vertex()).


Signed area of a triangle in 2D.

class meshplex.MeshTetra(points, cells, sort_cells=False)

Class for handling tetrahedral meshes.


Get the midpoints of the inspheres.


Compute the control volumes of all points in the mesh.


Displays edge with ce_ratio.

Parameters:edge_id (int) – Edge ID for which to show the ce_ratio.

Get the smallest of the sines of the 6 angles between the faces of each tetrahedron, times a scaling factor that makes sure the value is 1 for the equilateral tetrahedron.


Ratio of incircle and circumcircle ratios times 3. (“Normalized shape ratio”.) Is 1 for the equilateral tetrahedron, and is often used a quality measure for the cell.


For each cell, return the ratio of the volume and the cube of the root-mean-square edge length. (This is cell quality measure used by Stellar <>.)

Reads an unstructured mesh into meshplex format.

Parameters:filenames (str) – The files to read from.
Returns mesh{2,3}d:
 The mesh data.

Transform from meshio to meshplex format.

Parameters:mesh (meshio.Mesh) – The meshio mesh object.
Returns mesh{2,3}d:
 The mesh data.
meshplex.get_signed_simplex_volumes(cells, pts)

Signed volume of a simplex in nD. Note that signing only makes sense for n-simplices in R^n.