HPC Gmsh
Treat Gmsh as a geometry-plus-meshing stack. Choose the modeling kernel first, then make topology, sizing, and structured-meshing decisions explicit before exporting downstream.
Start
- Read
references/modeling-kernels-and-geometry.mdbefore creating or repairing a Gmsh model — covers GEO versus OpenCASCADE selection, boolean operations, extrusions, transformations, CAD/STL import, embedded and compound entities, synchronization rules. - Read
references/physical-groups-and-entity-tagging.mdwhen solver handoff depends on boundary or region tags — covers export behavior, physical group stability after booleans, downstream solver requirements matrix. - Read
references/algorithm-selection-guide.mdwhen choosing 2D or 3D meshing algorithms — covers MeshAdapt, Delaunay, Frontal-Delaunay, HXT, parallel meshing, optimization, element order, subdivision. - Read
references/mesh-size-and-field-control.mdwhen choosing mesh sizes — covers the full size determination hierarchy, all field types (Distance, Threshold, Box, Ball, Cylinder, BoundaryLayer, MathEval, AutomaticMeshSizeField, etc.), combining fields, size callbacks. - Read
references/boundary-layer-and-refinement-recipes.mdwhen boundary layers, distance-based refinement, or CFD-specific mesh recipes are needed — covers BL parameters, y+ estimation, fan points, wake refinement, complete 2D CFD recipe. - Read
references/transfinite-and-recombine-playbook.mdwhen the mesh should be structured, swept, or recombined — covers TransfiniteCurve/Surface/Volume syntax with grading, Recombine, structured extrusion with Layers, periodic meshes, high-order, complete hex workflow. - Read
references/cli-and-python-api-playbook.mdwhen choosing between.geo, CLI, and the Python API — covers complete CLI flag reference, Python API patterns for geometry, meshing, fields, partitioning, periodic meshes, CAD import. - Read
references/import-export-and-solver-handoff.mdwhen importing CAD/STL or exporting meshes — covers all output formats, MSH4.1/MSH2 format details, element type table, downstream handoff recipes for FEniCS, OpenFOAM, Elmer, SU2, ABAQUS, Code_Aster, mesh partitioning. - Read
references/error-recovery.mdwhen meshing or geometry construction fails — covers diagnostic commands, recovery decision tree, geometry/meshing failure recovery sequences, reporting template. - Read
references/error-pattern-dictionary.mdfor fast matching of specific Gmsh failure signatures — 14 patterns covering wrong kernel, missing physical groups, transfinite incompatibility, synchronize missing, boolean tag instability, 3D boundary recovery, negative Jacobians, periodic mismatch, and more.
Scenario Recipes
Load the relevant recipe when the task involves:
references/algorithm-selection-guide.md— 2D/3D algorithm selection matrices, parallel meshing, optimization passes, element order, subdivision for all-quad/all-hexreferences/boundary-layer-and-refinement-recipes.md— BoundaryLayer field setup, y+ targeting, fan points, distance+threshold refinement, box/ball/cylinder refinement, MathEval sizing, complete 2D CFD airfoil recipe, 3D BL strategiesreferences/transfinite-and-recombine-playbook.md— structured hex/quad meshing, TransfiniteCurve grading (Progression, Bump), periodic mesh setup (affine transforms), extruded mesh with Layers, high-order elementsreferences/import-export-and-solver-handoff.md— STEP/IGES/BREP/STL import and healing, MSH4.1/MSH2/VTK/SU2/CGNS/MED format details, downstream solver physical group requirements, mesh partitioning with Metis
Work Sequence
- Choose one modeling path and stay consistent:
- GEO kernel for simple scripted primitives, explicit point/curve control, and hybrid discrete models
- OpenCASCADE for CAD-style solids, booleans (fuse/cut/fragment), fillets, pipes, lofts, and STEP/IGES import
- Build clean topology before tuning mesh size:
- create all geometry
- perform all boolean operations
- call
synchronize() - inspect entities and boundaries
- Define physical groups after geometry is finalized:
- physical groups encode solver-facing semantics (inlet, outlet, walls, fluid, solid)
- use
getBoundary()andgetEntitiesInBoundingBox()to identify surfaces after booleans - if physical groups are defined, only tagged elements are exported (use
Mesh.SaveAll = 1to override)
- Select the meshing algorithm:
- 2D default: Delaunay (5) for speed, Frontal-Delaunay (6) for quality, MeshAdapt (1) for robustness
- 3D default: Delaunay (1) for robustness, HXT (10) for parallel speed
- embedded entities and size fields require Delaunay or HXT
- Configure mesh sizing:
- start coarse and uniform, then add local refinement one field at a time
- disable
MeshSizeFromPoints,MeshSizeFromCurvature,MeshSizeExtendFromBoundarywhen fields are authoritative - combine multiple fields with
Minand set asBackground Field
- Use structured meshing only where topology supports it:
- transfinite requires 3- or 4-sided surfaces with compatible node counts on opposite edges
- extrusion with
Layersproduces structured hex/prism - recombine converts tris to quads (use Blossom algorithm + smoothing for quality)
- Optimize and validate before export:
- optimize tets:
gmsh.model.mesh.optimize("Netgen") - high-order:
setOrder(2)thenoptimize("HighOrder") - check quality:
getElementQualities(tags, "minSICN")
- optimize tets:
- Export in the format matching the downstream solver:
- verify physical groups are present in the output
- verify element types and mesh dimension match solver expectations
Guardrails
- Do not mix GEO kernel and OpenCASCADE in the same model.
- Do not define physical groups before
synchronize()— entity tags may be stale. - Do not rely on raw entity tags staying stable after boolean operations — use
BooleanFragments+ the output map. - Do not force transfinite or recombine settings onto incompatible topology.
- Do not use
Mesh.SaveAll = 1with MSH2 if physical group info is needed — MSH2 discards it. - Do not treat export format or mesh version as an afterthought — the receiving solver decides what metadata matters.
- Do not add multiple competing size fields without combining them through a
Minfield. - Do not use embedded entities with algorithms other than Delaunay or HXT — they will be silently ignored.
- Do not skip
optimize("HighOrder")aftersetOrder(2)— curved elements on complex geometry will have negative Jacobians. - Do not mesh 3D without first verifying the 2D surface mesh is valid — 3D boundary recovery depends on it.
Additional References
Load these on demand:
references/modeling-kernels-and-geometry.md— GEO versus OpenCASCADE, boolean operations, extrusions, transformations, CAD/STL import, embedded/compound entitiesreferences/physical-groups-and-entity-tagging.md— physical group syntax, export behavior, downstream solver requirementsreferences/algorithm-selection-guide.md— 2D and 3D algorithm matrices, parallel meshing, optimization, element orderreferences/mesh-size-and-field-control.md— complete field reference (Distance, Threshold, Box, Ball, Cylinder, BoundaryLayer, MathEval, AutomaticMeshSizeField), size hierarchy, callbacksreferences/boundary-layer-and-refinement-recipes.md— BL setup, y+ targeting, wake refinement, complete CFD recipesreferences/transfinite-and-recombine-playbook.md— structured meshing, periodic meshes, high-order, hex workflowreferences/cli-and-python-api-playbook.md— all CLI flags, Python API patterns, .geo scripting referencereferences/import-export-and-solver-handoff.md— format details, element types, solver handoff recipes, partitioningreferences/error-pattern-dictionary.md— 14 failure patterns with symptoms, diagnosis, and fixesreferences/error-recovery.md— diagnostic commands, recovery decision tree, reporting template
Reusable Templates
Use assets/templates/ when a concrete starting point is faster than building from scratch:
minimal_rectangle_2d.geo— simplest OCC rectangle with physical groupsocc_box_python.py— 3D box with boundary extraction via Python APIparametric_cylinder_in_box.geo— parametric external flow geometry with distance-based refinementairfoil_bl_2d.py— 2D airfoil with boundary layer, wake refinement, and fan pointsperiodic_channel_hex.py— structured hex channel with periodic BCs (DNS/LES)step_import_mesh.py— STEP import, healing, physical groups, parallel meshinggmsh-batch-mesh.sh— minimal batch meshing scriptgmsh-mesh-slurm.sh— SLURM-submitted batch meshing
Outputs
Summarize:
- chosen modeling kernel and why
- physical groups and their intended downstream meaning
- meshing algorithm (2D and 3D) and why
- mesh-size strategy: fields used, MeshSizeMin/Max, background field
- structured-meshing or recombine choices if any
- element order and optimization passes
- export format and the exact failure class if the workflow is being repaired
- mesh statistics: element counts by type, minimum quality metric
Scan to join WeChat group