Skip to main content

Block Mesh processing library for OpenFOAM

Project description

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:
    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.2.tar.gz (588.1 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for pybmesh-1.0.2.tar.gz
Algorithm Hash digest
SHA256 71cbfcab9922fb77943a25b2939be973c01ceebf6e8618c1c2c10a5d3787af27
MD5 fecd258e1026efbe5fcf79af26e436ec
BLAKE2b-256 631f6950a00e02364049fd3ad36ee8fafa778b9a3f5e05462a3f66dfd29f9b6d

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