A Python library to read, write, and modify OpenFOAM polyMesh meshes in memory. It focuses on mesh topology and geometry: boundary inspection, connectivity builders, in-place mesh edits, scaling, and diagnostics for manually specified cyclic patch pairs.
Detailed guides live under docs/.
- Read and write ASCII or binary
constant/polyMesh(points, faces, owner, neighbour, boundary) - Query mesh topology via
PolyMesh(cells, faces, boundaries, adjacency) - Build compact cell–face and cell–point connectivity arrays
- Compute geometrial properties (face areas and centroids)
- Modify meshes in place (merge cells, boundary edits, point scaling, and more)
- Diagnostics (currently only checking of cyclic/periodic patch pairs)(diagnostics)
- Python 3.8+
- NumPy, Numba
transformations(cyclic diagnostics)
Clone the repository and install from the project root:
pip install .Editable install while developing:
pip install -e .Point PolyMesh at a case directory (the folder that contains constant/polyMesh):
from pypolymesh import PolyMesh
# Can read and auto-detect both binary and ascii, by default expects int32 and float64
mesh = PolyMesh("path/to/case")
# Display some information - many intuitive methods under PolyMeesh class
print(mesh.n_points, mesh.n_cells, mesh.n_faces, mesh.n_boundaries)
print(list(mesh.boundary.keys())[:5])
# Inspect one boundary patch
patch = "inlet"
print(mesh.boundary[patch])
face_ids = mesh.boundary_faces(patch)
print("first face points:", mesh.face_points(face_ids[0]))
# Scale coordinates (topology arrays are unchanged)
mesh.scale((0.001, 0.001, 0.001)) # mm -> m, for example
# Write mesh back under a new case path in ASCII Format
mesh.write("path/to/output_case", mode="ascii")See Getting started for dtypes, verbosity, and write options.
| Guide | Description |
|---|---|
| Getting started | Install, load/save, core properties |
| Connectivity and geometry | Cell–face/point lists, areas, ordered VTK-style points |
| Mesh modification | Edits, scaling, current vs original indices |
| Diagnostics | Cyclic / periodic patch pair checks |
| Visualization | Plotly primitives (in development) |
API details are also available in module and class docstrings.
Run tests from the repository root:
python -m unittest discover -s tests -v- Mesh modification features are experimental
- The
pypolymesh.visualizationpackage is under active development and is not yet a supported end-user plotting API.