← Back to Overview
CFD Scientific Computing · OpenFOAM & Python

OpenFOAM Case Generator

A production-ready Python automation pipeline and CLI for external aerodynamics CFD, generating watertight OpenFOAM cases, conformal multi-region meshes, and real-time telemetry from raw STL geometries.

Role / Type

Lead Developer & CFD Pipeline Architect

Timeline / Context

Formula Student (TSAE) & Open Source (2026)

Core Skills & Tools

Python (Stdlib), OpenFOAM, snappyHexMesh, HPC (SLURM/MPI)

GitHub Repo

Visit Repo ↗

1. The Challenge & Engineering Objectives

OpenFOAM is one of the most capable open-source CFD solvers in computational fluid dynamics, but setting up external aerodynamics simulations requires manually configuring dozens of complex, interdependent C++ dictionary files—including blockMeshDict, snappyHexMeshDict, fvSchemes, fvSolution, decomposeParDict, and individual boundary condition vector fields. For Formula Student (FSAE) race teams rapidly iterating through front wings, rear wings, sidepods, and undertrays, this manual workflow creates a severe engineering bottleneck prone to human error, mesh non-orthogonality, and divergence.

To eliminate this friction, I developed OpenFOAM Case Generator—a standalone, zero-dependency Python engineering pipeline that automates the entire external aerodynamics workflow from raw ASCII STL geometry to converged force post-processing using standard OpenFOAM commands.

2. Technical Architecture & Core Innovations

The pipeline is architected around a declarative JSON specification (configs/config.json) and built exclusively with the Python standard library, requiring no external package installations for core case generation or force extraction:

  • Zero-Dependency Core & Streaming STL Ingestion: Implemented a memory-efficient streaming ASCII STL parser that calculates exact 3D bounding boxes, vertex extents, and sanitizes solid headers line-by-line without loading millions of facets into memory.
  • Automated Domain & Boundary Physics: Computes virtual wind tunnel bounds dynamically derived from geometry extents (4L upstream, 8L downstream, 4H ceiling, 4W lateral far-wall). Supports ground-plane snapping, relative ride-height clearances (e.g., 35 mm front wing ground clearance), offset symmetry planes (e.g., x = -0.1185) with automatic domain and wake-box clipping, and moving road boundary conditions (U = U∞) coupled with continuous Spalding wall functions (nutUSpaldingWallFunction) and k-ω SST turbulence closure.
  • Multi-Fidelity Hexahedral Meshing Pipeline: Automatically orchestrates surfaceFeatureExtract (140° included angle), blockMesh background grids, distance-based refinement shells (e.g., 25 mm → Level 4, 80 mm → Level 3), a two-stage wake refinement architecture (nearWakeBox and farWakeBox), prism boundary layer inflation (Fast, Standard, Fine presets), parallel checkMesh quality diagnostics, and bandwidth-optimizing renumberMesh.
  • Numerical Stability & Solver Schemes: Pre-initializes flow fields with potentialFoam before RANS solving; configures SIMPLEC pressure-velocity coupling (consistent true;) with tuned relaxation factors (p = 0.7, U = 0.7), TVD velocity divergence schemes (bounded Gauss limitedLinear 1), and fast GAMG multigrid elliptic pressure solvers.
  • Telemetry, Convergence Automation & Live Dashboard: Supports multi-part force decomposition (e.g., separate front wing, rear wing, and undertray accounting), configurable drag and downforce projection axes, automatic half-car symmetry detection with 2× full-car force projection, a rolling-variation convergence monitor (variation < 0.5%) that dynamically injects stopAt writeNow; for clean auto-stopping, and an interactive 4-page animated live dashboard (read_forces.py --live).
  • Production HPC / SLURM Integration: Generates automated cluster submission scripts (run.sh) configured for high-performance computing clusters (such as the Chulalongkorn University e-Science cluster), featuring Scotch MPI domain decomposition, node-local high-speed scratch disk execution ($TMPDIR / /dev/shm), 15-second background sync loops, and POSIX signal traps (SIGTERM, SIGINT) to safeguard and reconstruct simulation results against cluster preemption.

Key Engineering Takeaway

"Automating CFD isn't just about scripting dictionary files—it requires embedding aerodynamic domain physics directly into computational geometry algorithms. By coupling streaming STL processing with automated multi-box wake refinement, physics-aware boundary conditions, and real-time force convergence monitors, we transformed an error-prone multi-hour manual setup into a deterministic, single-command pipeline."

3. Results, Impact & Practical Deployment

The generator drastically compressed aerodynamic setup times from over 2–3 hours of manual dictionary editing down to under 5 seconds for case generation, allowing engineering teams to focus on aerodynamic innovation rather than software troubleshooting:

  • Production-Proven in Formula Student: Successfully deployed for TSAE / Formula Student aerodynamic evaluations, powering multi-million-cell half-car and component simulations on multi-core HPC clusters.
  • Zero-Fault Automated Execution: Achieved reliable, reproducible meshing and clean convergence across various CAD geometries, validated by an automated regression test suite covering domain mathematics, STL parsing, and force telemetry.
  • Standard-Commands Workflow: Retains complete flexibility by generating native OpenFOAM files and standard command workflows (./Allrun.parallel or direct simpleFoam execution) without vendor lock-in or proprietary binary wrappers.