Metadata-Version: 2.4
Name: meshplex
Version: 0.21.13
Summary: Fast tools for simplex meshes
Author-email: Nico Schlömer <nico.schloemer@gmail.com>
License-Expression: LicenseRef-Proprietary
Project-URL: Homepage, https://github.com/meshpro/meshplex
Project-URL: Issues, https://github.com/meshpro/meshplex/issues
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: meshio<8,>=4
Requires-Dist: npx>=0.0.7
Requires-Dist: numpy>=2
Requires-Dist: stonefish-license-manager>=0.6
Provides-Extra: all
Requires-Dist: matplotlib; extra == "all"
Requires-Dist: scipy; extra == "all"
Requires-Dist: vtk; extra == "all"
Provides-Extra: plot
Requires-Dist: matplotlib; extra == "plot"
Requires-Dist: vtk; extra == "plot"
Requires-Dist: stonefish-runtime>=0.4.6

<p align="center">
  <a href="https://github.com/nschloe/meshplex"><img alt="meshplex" src="https://raw.githubusercontent.com/meshpro/meshplex/assets/meshplex-logo.svg" width="60%"></a>
  <p align="center">Fast tools for simplex meshes.</p>
</p>

[![PyPi Version](https://img.shields.io/pypi/v/meshplex.svg?style=flat-square)](https://pypi.org/project/meshplex/)
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/meshplex.svg?style=flat-square)](https://pypi.org/project/meshplex/)
[![GitHub stars](https://img.shields.io/github/stars/nschloe/meshplex.svg?style=flat-square&logo=github&label=Stars&logoColor=white)](https://github.com/nschloe/meshplex)
[![PyPi downloads](https://img.shields.io/pypi/dm/meshplex.svg?style=flat-square)](https://pypistats.org/packages/meshplex)

Compute all sorts of interesting points, areas, and volumes in simplex
(triangle, tetrahedral, n-simplex) meshes of any dimension, with a focus on
efficiency. Useful in many contexts, e.g., finite-element and finite-volume
computations.

### Installation

Install meshplex [from PyPI](https://pypi.org/project/meshplex/) with

```
pip install meshplex
```

For full usage of meshplex, you require a license. Licenses for personal and
academic use can be purchased
[here](https://buy.stripe.com/5kA3eV8t8af83iE9AE). For more info, see
[here](https://github.com/meshpro).

### Quickstart

meshplex can compute the following data:

```python
import meshplex

# create a simple Mesh instance
# (could be tetrahedra or even higher dimensional simplices)
points = [[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]]
cells = [[0, 1, 2]]
mesh = meshplex.Mesh(points, cells)
# or read it from a file
# mesh = meshplex.read("pacman.vtk")

# simplex volumes, heights
print(mesh.cell_volumes)
print(mesh.signed_cell_volumes)
print(mesh.cell_heights)
print(mesh.volume)
print(mesh.surface_area)

# centers of any kind
print(mesh.cell_circumcenters)
print(mesh.cell_centroids)
print(mesh.cell_incenters)
print(mesh.cell_monge_points)
print(mesh.cell_nagel_points)
print(mesh.cell_spieker_centers)
print(mesh.cell_lemoine_points)
print(mesh.center_of_gravity)

# circumradius, inradius, cell quality
print(mesh.cell_circumradius)
print(mesh.cell_inradius)
print(mesh.q_radius_ratio)  # d * inradius / circumradius (min 0, max 1)

# control volumes, centroids
print(mesh.control_volumes)
print(mesh.control_volume_centroids)

# covolume/edge length ratios
print(mesh.ce_ratios)

# count Delaunay violations
print(mesh.num_delaunay_violations)

# get all boundary angles in radians
print(mesh.outside_boundary_angles_radians)

# removes some cells
mesh.remove_cells([0])
```

For triangular meshes (`MeshTri`), meshplex also has some mesh manipulation routines:

<!--pytest.mark.skip-->

```python
mesh.show()  # show the mesh
mesh.angles  # compute angles
mesh.flip_until_delaunay()  # flips edges until the mesh is Delaunay
```

For a documentation of all classes and functions, see
[readthedocs](https://meshplex.readthedocs.io/).

(For mesh creation, check out
[this list](https://github.com/nschloe/awesome-scientific-computing#meshing)).

### Plotting

#### Triangles

<img src="https://raw.githubusercontent.com/meshpro/meshplex/assets/pacman.png" width="30%">

<!--pytest.mark.skip-->

```python
import meshplex

mesh = meshplex.read("pacman.vtk")
mesh.show(
    # 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=False,
)
```

#### Tetrahedra

<img src="https://raw.githubusercontent.com/meshpro/meshplex/assets/tetra.png" width="30%">

<!--pytest.mark.skip-->

```python
import numpy as np
import meshplex

# Generate tetrahedron
points = np.array(
    [
        [1.0, 0.0, -1.0 / np.sqrt(8)],
        [-0.5, +np.sqrt(3.0) / 2.0, -1.0 / np.sqrt(8)],
        [-0.5, -np.sqrt(3.0) / 2.0, -1.0 / np.sqrt(8)],
        [0.0, 0.0, np.sqrt(2.0) - 1.0 / np.sqrt(8)],
    ]
) / np.sqrt(3.0)
cells = [[0, 1, 2, 3]]

# Create mesh object
mesh = meshplex.MeshTetra(points, cells)

# Plot cell 0 with control volume boundaries
mesh.show_cell(
    0,
    # barycenter_rgba=(1, 0, 0, 1.0),
    # circumcenter_rgba=(0.1, 0.1, 0.1, 1.0),
    # circumsphere_rgba=(0, 1, 0, 1.0),
    # incenter_rgba=(1, 0, 1, 1.0),
    # insphere_rgba=(1, 0, 1, 1.0),
    # face_circumcenter_rgba=(0, 0, 1, 1.0),
    control_volume_boundaries_rgba=(1.0, 0.0, 0.0, 1.0),
    line_width=3.0,
)
```
