1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
<p align="center">
<a href="https://github.com/nschloe/meshplex"><img alt="meshplex" src="https://nschloe.github.io/meshplex/meshplex-logo.svg" width="60%"></a>
<p align="center">Fast tools for simplex meshes.</p>
</p>
[](https://pypi.org/project/meshplex/)
[](https://pypi.org/project/meshplex/)
[](https://github.com/nschloe/meshplex)
[](https://pypistats.org/packages/meshplex)
[](https://discord.gg/hnTJ5MRX2Y)
[](https://readthedocs.org/projects/meshplex/?badge=latest)
[](https://github.com/nschloe/meshplex/actions?query=workflow%3Aci)
[](https://codecov.io/gh/nschloe/meshplex)
[](https://lgtm.com/projects/g/nschloe/meshplex)
[](https://github.com/psf/black)
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.
meshplex is used in [optimesh](https://github.com/nschloe/optimesh) and
[pyfvm](https://github.com/nschloe/pyfvm).
### Quickstart
meshplex can compute the following data:
```python
import meshplex
# create a simple Mesh instance
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")
# triangle volumes, heights
print(mesh.cell_volumes)
print(mesh.signed_cell_volumes)
print(mesh.cell_heights)
# circumcenters, centroids, incenters
print(mesh.cell_circumcenters)
print(mesh.cell_centroids)
print(mesh.cell_incenters)
# 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)
# removes some cells
mesh.remove_cells([0])
```
For triangular meshes (`MeshTri`), meshplex also has some mesh manipulation routines:
<!--pytest-codeblocks: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://nschloe.github.io/meshplex/pacman.png" width="30%">
<!--pytest-codeblocks: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://nschloe.github.io/meshplex/tetra.png" width="30%">
<!--pytest-codeblocks: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,
)
```
### Installation
meshplex is [available from the Python Package
Index](https://pypi.org/project/meshplex/), so simply type
```
pip install meshplex
```
to install.
### License
This software is available under the [GPLv3
license](https://www.gnu.org/licenses/gpl-3.0.en.html) as well as a commercial
license. If you'd like to use this software commercially, please contact the
author.
|