Skip to main content

Block Mesh processing library for OpenFOAM

Project description

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).

Installation

Install PyBMesh 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:
    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:

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).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybmesh-1.0.0.tar.gz (542.5 kB view details)

Uploaded Source

File details

Details for the file pybmesh-1.0.0.tar.gz.

File metadata

  • Download URL: pybmesh-1.0.0.tar.gz
  • Upload date:
  • Size: 542.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for pybmesh-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e08644de078332b44bd07c68873a78ad7333ad3119bf287418eb78e7337be481
MD5 321b6fb460c735d7fba29a0d5827ee51
BLAKE2b-256 a4e98318c082e628fadef848bfc523e6a13b038dbddb559fb34541aac960a228

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page