PyBMesh
Homepage: https://gitlab.com/alexis.sauvageon/pybmesh
PyBMesh is a Python library for generating, manipulating, and exporting meshes using VTK. It supports a wide range of mesh types - from points (0D) to volumes (3D) - and provides advanced tools such as extrusion (both linear and rotational), mesh fusion, and boundary extraction. PyBMesh is designed to help users create high-quality meshes for computational simulations and CFD applications (e.g., for OpenFOAM).
Prerequisites
- C Compiler (GCC or Clang)
- C++ Compiler (GCC or MSVC 14.0+)
Windows
Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools":
Download Microsoft C++ Build Tools
Linux
Install GCC and related build tools via your package manager:
sudo apt-get update
sudo apt-get install build-essential
Installation
Install PyBMesh from pypi.org using pip:
pip install pybmesh
Or clone the repository and install with:
python pip install -e .
Module Structure
A high-level view of the project layout:
+-- examples/ # Example scripts illustrating common meshing workflows.
+-- LICENSE # MIT License.
+-- pybmesh/ # Main package.
¦ +-- cython/ # Cython modules for performance-critical tasks.
¦ +-- geom/ # Definitions for 0D (points), 1D (lines, arcs, circles), 2D (surfaces), and 3D (volumes) elements.
¦ +-- io/ # I/O routines for VTK conversion and mesh writing.
¦ +-- utils/ # Utility modules including mesh manipulation tools (fusion, extrusion, boundary extraction).
+-- pyproject.toml # Build configuration.
+-- README.md # This documentation.
+-- ressources/ # other useful files.
+-- tests/ # Unit tests for verifying functionality.
Quick Tutorial
Creating Basic Mesh Elements
PyBMesh provides classes for each mesh dimension:
- 0D - Points:
from pybmesh import Point
p = Point(0, 0, 0)
- 1D - Lines, Arcs, and Circles:
from pybmesh import Point, Line, Arc, Circle
p1 = Point(0, 0, 0)
p2 = Point(1, 0, 0)
line = Line(p1, p2, n=10)
# Create an arc using a center and boundary points:
arc = Arc.from_center_2points(center=p1.coords[0], pA=p2.coords[0],
pB=Point(0, 1, 0).coords[0], n=10)``
- 2D - Surfaces:
from pybmesh import Surface
p3 = Point(1, 1, 0)
p4 = Point(0, 1, 0)
surface = Surface(p1, p2, p3, p4, n=1, quad=True)`
- 3D - Volumes:
from pybmesh import Volume, translate
surface2 = surface.copy()
surface2.translate(0, 0, 1)
volume = Volume(surface, surface2, n=10)
Mesh Manipulation
The pybmesh.utils.meshtools module offers several functions for transforming and combining meshes:
from pybmesh import translate, rotate, syme, scale, fuse
- Translate a mesh (with copy):
translated = translate(surface, (2, 0, 0))
- Rotate 90° about the Z-axis (with copy):
rotated = rotate(surface, center=(0,0,0), axis=(0,0,1), angle=90)
- Reflect (symmetry) across the XY-plane (with copy):
reflected = syme(surface, plane='xy')
- Scale a mesh (with copy):
scaled = scale(surface, sx=2, sy=1, sz=1)
- Fuse two meshes:
fused = fuse(surface, translated)`
Extruding Meshes
Create higher-dimensional meshes via extrusion:
- Linear Extrusion:
from pybmesh.meshmanip import extrudeLinear
vector_line = Line(Point(0,0,0), Point(0,0,1), n=1)
extruded_surface = extrudeLinear(line, vector_line)`
- Rotational Extrusion:
from pybmesh.meshmanip import extrudeRotational
rot_extruded = extrudeRotational(line, pA=(0,0,0), pB=(0,0,1), angle=45, n=10)`
Additional Tools
-
Boundary Extraction:
UsegetBoundariesfrompybmesh.meshmanipto extract faces, edges, or nodes from a mesh. -
Submesh Extraction:
Useextract_pointandextract_elementfunctions for obtaining submeshes based on criteria. -
Assembly and Export:
Combine mesh components usingMeshComponentandMeshAssembly, and export meshes using VTK writers (e.g., inFoamSave.py).
Examples
The examples/ directory contains scripts that illustrate various workflows:
- Lines.py: Demonstrates creation and manipulation of 1D elements.
- Surfaces.py: Shows surface generation from curves and transfinite techniques.
- Volumes.py: Illustrates volume creation by interpolating between surfaces.
- Extrude_Exemples.py: Provides examples of linear and rotational extrusion.
- Extract_Boundaries.py & Extract_submeshes.py: Demonstrate boundary and submesh extraction.
- FoamSave.py: Exports meshes to VTK files for CFD applications.
- MeshComponent.py & MeshAssembly.py: Show how to build a complete mesh from components.
Help and Documentation
For complete descriptions of classes and functions, use Python's built-in help.
For example, to view details about the Volume class:
from pybmesh import Volume
help(Volume)`
This will print a full explanation of the constructor, methods, and usage examples.
License
PyBMesh is released under the BSD 3-Clause License(LICENSE).
Release files for pybmesh 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pybmesh-1.0.4.tar.gz | 598.8 kB | Details |
Release files / pybmesh-1.0.4.tar.gz
| Download URL | pybmesh-1.0.4.tar.gz |
|---|---|
| Size | 598.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cb465e29dd8afaeeef8724fe5d9a7ca462ad7ebca6f1e0b1354f492f94cd6a90
|
|
BLAKE2b-256 checksum How to use checksums |
0daa590c58647856c8b1adc5f981c199a92af4e7a4fdf5bf337d4bdb11a6dff1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.2
|