Compute 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.
meshplex is used in optimesh and pyfvm.
import numpy
import meshplex
# create a simple MeshTri instance
points = numpy.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]])
cells = numpy.array([[0, 1, 2]])
mesh = meshplex.MeshTri(points, cells)
# or read it from a file
# mesh = meshplex.read('pacman.msh')
# triangle volumes
print(mesh.cell_volumes)
# circumcenters, centroids, incenters
print(mesh.cell_circumcenters)
print(mesh.cell_centroids)
print(mesh.cell_incenters)
# circumradius, inradius, cell quality, angles
print(mesh.circumradius)
print(mesh.inradius)
print(mesh.cell_quality) # d * inradius / circumradius (min 0, max 1)
print(mesh.angles)
# control volumes, centroids
print(mesh.control_volumes)
print(mesh.control_volume_centroids)
# covolume/edge length ratios
print(mesh.ce_ratios)
# flip edges until the mesh is Delaunay
mesh.flip_until_delaunay()
# show the mesh
mesh.show()
meshplex works much the same way with tetrahedral meshes.
(For mesh creation, check out this list).
meshplex is available from the Python Package Index, so simply type
pip3 install --user meshplex
to install.
To run the meshplex unit tests, check out this repository and type
pytest
To create a new release
-
bump the
__version__
number, -
publish to PyPi and GitHub:
make publish
meshplex is published under the MIT license.