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., finiteelement and finitevolume computations.
For a quickstart, checkout meshplex’s GitHubPage.
Overview of classes and functions¶

class
meshplex.
MeshLine
(node_coords, cells)¶ Class for handling line segment “meshes”.

create_cell_volumes
()¶ Computes the volumes of the “cells” in the mesh.

create_control_volumes
()¶ Compute the control volumes of all nodes in the mesh.

show_vertex_function
(u)¶


class
meshplex.
MeshTri
(nodes, cells, sort_cells=False)¶ Class for handling triangular meshes.

angles
¶ All angles in the triangle.

ce_ratios_per_interior_edge
¶

cell_barycenters
¶ See cell_centroids().

cell_centroids
¶ The centroids (barycenters, midpoints of the circumcircles) of all triangles.

cell_circumcenters
¶

cell_circumradius
¶ Get the circumradii of all cells

cell_incenters
¶ Get the midpoints of the incircles.

cell_inradius
¶ Get the inradii of all cells

cell_partitions
¶

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

compute_curl
(vector_field)¶ Computes the curl of a vector field over the mesh. While the vector field is pointbased, the curl will be cellbased. The approximation is based on
\[n\cdot curl(F) = \lim_{A\to 0} A^{1} <\int_{dGamma}, F> dr;\]see https://en.wikipedia.org/wiki/Curl_(mathematics). Actually, to approximate the integral, one would only need the projection of the vector field onto the edges at the midpoint of the edges.

control_volumes
¶ The control volumes around each vertex.

create_edges
()¶ Set up edgenode and edgecell relations.

edge_gid_to_edge_list
¶

edges_cells
¶

face_partitions
¶

flip_interior_edges
(is_flip_interior_edge)¶

flip_until_delaunay
()¶ Flip edges until the mesh is fully Delaunay.

get_control_volume_centroids
(cell_mask=None)¶ 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.

get_control_volumes
(cell_mask=None)¶ 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.

is_boundary_facet
¶

is_boundary_node
¶

is_interior_node
¶

mark_boundary
()¶

num_delaunay_violations
()¶ 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_node_numbers=False, show_cell_numbers=False, cell_mask=None, show_edge_numbers=False)¶ Show the mesh using matplotlib.

plot_vertex
(node_id, show_ce_ratio=True)¶ Plot the vicinity of a node and its covolume/edgelength ratio.
Parameters:  node_id (int) – Node ID of the node to be shown.
 show_ce_ratio (bool, optional) – If true, shows the ce_ratio of the node, too.

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_cell_areas
¶ Signed area of a triangle in 2D.

surface_areas
¶

update_values
()¶ Update all computes entities around the mesh.


class
meshplex.
MeshTetra
(node_coords, cells)¶ Class for handling tetrahedral meshes.

cell_barycenters
¶ See cell_centroids().

cell_centroids
¶ The centroids (barycenters, midpoints of the circumcircles) of all tetrahedra.

cell_circumcenters
¶

cell_circumradius
¶

cell_incenters
¶ Get the midpoints of the inspheres.

cell_inradius
¶

control_volumes
¶ Compute the control volumes of all nodes in the mesh.

create_cell_face_relationships
()¶

create_face_edge_relationships
()¶

get_ce_ratios
()¶ Covolumeedge length ratios.

mark_boundary
()¶

num_delaunay_violations
()¶

q_min_sin_dihedral_angles
¶ 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.

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

q_vol_rms_edgelength3
¶ For each cell, return the ratio of the volume and the cube of the rootmeansquare edge length. (This is cell quality measure used by Stellar <https://people.eecs.berkeley.edu/~jrs/stellar>.)

show
()¶

show_edge
(edge_id)¶ Displays edge with ce_ratio.
Parameters: edge_id (int) – Edge ID for which to show the ce_ratio.


meshplex.
read
(filename)¶ Reads an unstructured mesh into meshplex format.
Parameters: filenames (str) – The files to read from. 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 nsimplices in R^n.