# 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](https://visualstudio.microsoft.com/visual-cpp-build-tools/)
### Linux
Install GCC and related build tools via your package manager:
```bash
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:**
```python
from pybmesh import Point
p = Point(0, 0, 0)
```
- **1D - Lines, Arcs, and Circles:**
```python
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:**
```python
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:**
```python
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:
```python
from pybmesh import translate, rotate, syme, scale, fuse
```
- **Translate a mesh (with copy):**
```python
translated = translate(surface, (2, 0, 0))
```
- **Rotate 90° about the Z-axis (with copy):**
```python
rotated = rotate(surface, center=(0,0,0), axis=(0,0,1), angle=90)
```
- **Reflect (symmetry) across the XY-plane (with copy):**
```python
reflected = syme(surface, plane='xy')
```
- **Scale a mesh (with copy):**
```python
scaled = scale(surface, sx=2, sy=1, sz=1)
```
- **Fuse two meshes:**
```python
fused = fuse(surface, translated)`
```
### Extruding Meshes
Create higher-dimensional meshes via extrusion:
- **Linear Extrusion:**
```python
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:**
```python
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:**
Use `getBoundaries` from `pybmesh.meshmanip` to extract faces, edges, or nodes from a mesh.
- **Submesh Extraction:**
Use `extract_point` and `extract_element` functions for obtaining submeshes based on criteria.
- **Assembly and Export:**
Combine mesh components using `MeshComponent` and `MeshAssembly`, and export meshes using VTK writers (e.g., in `FoamSave.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:
```python
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).
Raw data
{
"_id": null,
"home_page": "https://gitlab.com/alexis.sauvageon/pybmesh.git",
"name": "pybmesh",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "mesh, geometry, openfoam",
"author": "Alexis Sauvageon",
"author_email": "Alexis Sauvageon <alexis.sauvageon@arep.fr>",
"download_url": "https://files.pythonhosted.org/packages/a1/f2/85fbdb47ba64d7fb7b7cf82577002c3ebd8301b06624fe064c7f5e00bf34/pybmesh-1.0.3.tar.gz",
"platform": null,
"description": "\n# PyBMesh\n\n**Homepage:** https://gitlab.com/alexis.sauvageon/pybmesh\n\n**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).\n\n## Prerequisites\n\n- **C Compiler** (GCC or Clang) \n- **C++ Compiler** (GCC or MSVC 14.0+)\n\n### Windows \nMicrosoft Visual C++ 14.0 or greater is required. Get it with \"Microsoft C++ Build Tools\": \n[Download Microsoft C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/)\n\n### Linux \nInstall GCC and related build tools via your package manager:\n```bash\nsudo apt-get update\nsudo apt-get install build-essential\n```\n\n## Installation\n\nInstall PyBMesh from pypi.org using pip:\n`pip install pybmesh` \n\nOr clone the repository and install with:\n`python pip install -e .` \n\n## Module Structure\nA high-level view of the project layout:\n\n\n\n +-- examples/ # Example scripts illustrating common meshing workflows.\n +-- LICENSE # MIT License.\n +-- pybmesh/ # Main package.\n \u00a6 +-- cython/ # Cython modules for performance-critical tasks.\n \u00a6 +-- geom/ # Definitions for 0D (points), 1D (lines, arcs, circles), 2D (surfaces), and 3D (volumes) elements.\n \u00a6 +-- io/ # I/O routines for VTK conversion and mesh writing.\n \u00a6 +-- utils/ # Utility modules including mesh manipulation tools (fusion, extrusion, boundary extraction).\n +-- pyproject.toml # Build configuration.\n +-- README.md # This documentation.\n +-- ressources/ # other useful files.\n +-- tests/ # Unit tests for verifying functionality.\n\n## Quick Tutorial\n\n### Creating Basic Mesh Elements\n\nPyBMesh provides classes for each mesh dimension:\n\n- **0D - Points:** \n```python\nfrom pybmesh import Point\np = Point(0, 0, 0)\n```\n \n- **1D - Lines, Arcs, and Circles:** \n```python\nfrom pybmesh import Point, Line, Arc, Circle\np1 = Point(0, 0, 0)\np2 = Point(1, 0, 0)\nline = Line(p1, p2, n=10)\n\n# Create an arc using a center and boundary points:\narc = Arc.from_center_2points(center=p1.coords[0], pA=p2.coords[0],\n pB=Point(0, 1, 0).coords[0], n=10)``\n```\n\n\n- **2D - Surfaces:**\n \n```python\nfrom pybmesh import Surface\np3 = Point(1, 1, 0)\np4 = Point(0, 1, 0)\nsurface = Surface(p1, p2, p3, p4, n=1, quad=True)` \n```\n \n- **3D - Volumes:**\n \n```python\nfrom pybmesh import Volume, translate\nsurface2 = surface.copy()\nsurface2.translate(0, 0, 1)\nvolume = Volume(surface, surface2, n=10)\n```\n \n\n### Mesh Manipulation\n\nThe `pybmesh.utils.meshtools` module offers several functions for transforming and combining meshes:\n\n```python\nfrom pybmesh import translate, rotate, syme, scale, fuse\n```\n\n- **Translate a mesh (with copy):**\n```python\ntranslated = translate(surface, (2, 0, 0))\n```\n\n- **Rotate 90\u00b0 about the Z-axis (with copy):**\n```python\nrotated = rotate(surface, center=(0,0,0), axis=(0,0,1), angle=90)\n```\n\n- **Reflect (symmetry) across the XY-plane (with copy):**\n```python\nreflected = syme(surface, plane='xy')\n```\n\n- **Scale a mesh (with copy):**\n```python\nscaled = scale(surface, sx=2, sy=1, sz=1)\n```\n\n- **Fuse two meshes:**\n```python\nfused = fuse(surface, translated)` \n```\n\n### Extruding Meshes\n\nCreate higher-dimensional meshes via extrusion:\n\n- **Linear Extrusion:**\n \n```python\nfrom pybmesh.meshmanip import extrudeLinear\nvector_line = Line(Point(0,0,0), Point(0,0,1), n=1)\nextruded_surface = extrudeLinear(line, vector_line)` \n```\n\n- **Rotational Extrusion:**\n```python\nfrom pybmesh.meshmanip import extrudeRotational\nrot_extruded = extrudeRotational(line, pA=(0,0,0), pB=(0,0,1), angle=45, n=10)` \n```\n\n### Additional Tools\n\n- **Boundary Extraction:** \n Use `getBoundaries` from `pybmesh.meshmanip` to extract faces, edges, or nodes from a mesh.\n \n- **Submesh Extraction:** \n Use `extract_point` and `extract_element` functions for obtaining submeshes based on criteria.\n \n- **Assembly and Export:** \n Combine mesh components using `MeshComponent` and `MeshAssembly`, and export meshes using VTK writers (e.g., in `FoamSave.py`).\n \n\n## Examples\n\nThe `examples/` directory contains scripts that illustrate various workflows:\n\n- **Lines.py:** Demonstrates creation and manipulation of 1D elements.\n- **Surfaces.py:** Shows surface generation from curves and transfinite techniques.\n- **Volumes.py:** Illustrates volume creation by interpolating between surfaces.\n- **Extrude_Exemples.py:** Provides examples of linear and rotational extrusion.\n- **Extract_Boundaries.py & Extract_submeshes.py:** Demonstrate boundary and submesh extraction.\n- **FoamSave.py:** Exports meshes to VTK files for CFD applications.\n- **MeshComponent.py & MeshAssembly.py:** Show how to build a complete mesh from components.\n\n## Help and Documentation\n\nFor complete descriptions of classes and functions, use Python's built-in help. \nFor example, to view details about the `Volume` class:\n```python\nfrom pybmesh import Volume\nhelp(Volume)` \n```\nThis will print a full explanation of the constructor, methods, and usage examples.\n\n## License\n\nPyBMesh is released under the BSD 3-Clause License(LICENSE).\n",
"bugtrack_url": null,
"license": null,
"summary": "Block Mesh processing library for OpenFOAM",
"version": "1.0.3",
"project_urls": {
"Homepage": "https://gitlab.com/alexis.sauvageon/pybmesh.git"
},
"split_keywords": [
"mesh",
" geometry",
" openfoam"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "a1f285fbdb47ba64d7fb7b7cf82577002c3ebd8301b06624fe064c7f5e00bf34",
"md5": "436619985e9cda366f712aebeac71f5d",
"sha256": "3c2d46fdc1cd673798f8adcf1ace4d8c8afbb44c03c7a5b7fe28e628a23aeb86"
},
"downloads": -1,
"filename": "pybmesh-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "436619985e9cda366f712aebeac71f5d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 593524,
"upload_time": "2025-10-23T09:51:43",
"upload_time_iso_8601": "2025-10-23T09:51:43.838615Z",
"url": "https://files.pythonhosted.org/packages/a1/f2/85fbdb47ba64d7fb7b7cf82577002c3ebd8301b06624fe064c7f5e00bf34/pybmesh-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-23 09:51:43",
"github": false,
"gitlab": true,
"bitbucket": false,
"codeberg": false,
"gitlab_user": "alexis.sauvageon",
"gitlab_project": "pybmesh",
"lcname": "pybmesh"
}