Gmsh Mesh Generation

Category: Open-Source CAE | Revised 2026-10-02
CAE visualization for gmsh meshing theory - technical simulation diagram
Gmsh Mesh Generation

Theory: how meshes are made in Gmsh

Overview

🙋

Gmsh is a free mesher. What can it do compared with commercial pre-processors?

🎓

It covers the essentials of meshing: importing geometry, controlling element size, defining physical groups and exporting in many formats. Using OpenCASCADE as its geometry kernel, Gmsh reads STEP and IGES CAD and builds shapes by Boolean operations. Element size can be set per point and varied by distance or curvature with size fields, and boundary layers (BoundaryLayer field) and structured grids (Transfinite) are available. Its hallmark is that every operation can be scripted in .geo files or the Python API, ideal for parametric studies and automatic remeshing inside optimisation. Conformal contact between assembly parts and large-scale automatic hexahedral meshing, however, are often easier in commercial tools.

Estimating element count

$$ N \approx \int_A \frac{dA}{\tfrac{\sqrt{3}}{4}\,h(\mathbf{x})^2},\qquad h(d) = h_{\min} + (h_{\max}-h_{\min})\,\frac{d - d_{\min}}{d_{\max} - d_{\min}}\quad (d_{\min} \le d \le d_{\max}) $$

h is element size, A area and d distance from, say, a hole edge. The estimate assumes near-equilateral triangles; the Threshold field varies size linearly between d_min and d_max.

Coffee Break Trivia

A mesher going since 1997

Gmsh was started around 1997 by Christophe Geuzaine and Jean-François Remacle in Belgium for their own research. Development continues centred on UCLouvain and the University of Liège, and it is released under the GPL. Software begun for research is now the standard entry point for many open-source solvers.

Worked examples

Element counts are numerical area-integral estimates for equilateral triangles, not counts from a Gmsh-generated mesh. Matching hole-edge spacing does not guarantee stress accuracy; check size transitions, curved geometry, element quality and convergence.

Example: 100 mm square plate with a central 10 mm hole (2D triangles)

Meshing approachElement sizeElements (estimate)vs uniform 0.5 mm
Uniform fine0.5 mm≈ 91,650100%
Uniform coarse5 mm≈ 9171.0%
Size field (0.5 mm at hole edge → 5 mm at 20 mm)0.5–5 mm≈ 1,7251.9%

With the size field, 63 elements still line the hole as in the uniform 0.5 mm mesh, keeping the resolution needed for the stress concentration, while element count falls about fiftyfold. In 3D, halving size multiplies elements by 8, so size fields pay off even more.

🙋

I set up a size field but the mesh around the hole isn't refined. What's missing?

🎓

Three causes are common. First, the field isn't set as the background field: defining it isn't enough — specify which field to use with Background Field = n. Second, other size settings take precedence: point sizes (MeshSize), curvature-based sizing and propagation from boundaries combine, so setting Mesh.MeshSizeFromPoints, Mesh.MeshSizeFromCurvature and Mesh.MeshSizeExtendFromBoundary to 0 lets the field alone govern. Third, the Distance field points at the wrong entity — the hole curve's tag may change when geometry changes. OpenCASCADE renumbers entities, so retrieve them, for example by bounding box, rather than hard-coding tags; then geometry edits won't break the script.

Getting started

  1. Install Gmsh, build a simple shape in the GUI, mesh it, save as .geo and read the script.
  2. Import a STEP file and name boundary-condition faces and material regions with physical groups.
  3. Refine only stress-concentration areas with Distance and Threshold size fields.
  4. Export in the solver's format and check element count and quality (Gamma, SICN).
  5. Parameterise dimensions with the Python API and remesh automatically as parameters change.
Coffee Break Trivia

“Adding a physical group made faces disappear”

People new to physical groups in Gmsh are often surprised when elements vanish from the exported mesh. The rule: with no physical groups Gmsh writes every element, but with even one it writes only elements belonging to physical groups. Creating only face groups for boundary conditions therefore exports no volume elements — an empty mesh. Always give volumes (all bodies in 3D) a physical group too, or set Mesh.SaveAll = 1 to write everything.

Common mistakes

Mistakes and fixes

MistakeEffectFix
No background field setSize field ignoredSet Background Field
Physical groups on faces onlyNo volume elements exportedTag volumes too
Hard-coded entity tagsBreaks on geometry changeRetrieve by bounding box etc.
Wrong output formatSolver can't read itCheck format and version
Second-order mid-side nodesOff the curved surfaceHigh-order mesh optimisation
🙋

I'd like to learn related topics.

Frequently asked questions

What is Gmsh?

An open-source finite element mesh generator developed by researchers at UCLouvain in Belgium and elsewhere. It imports CAD (e.g. STEP via OpenCASCADE) and generates 2D and 3D triangle, quadrilateral, tetrahedral and hexahedral meshes. It is driven by .geo scripts or Python/C++ APIs and feeds many solvers, including CalculiX, Code_Aster, Elmer, FEniCS and OpenFOAM.

How do I refine only where needed?

Use size fields (Mesh Fields). A Distance field measures distance from, say, a hole edge, and a Threshold field varies element size with that distance — for example 0.5 mm at distance 0 rising to 5 mm at 20 mm. For a 100 mm square plate with a hole this needs about 1,700 elements versus about 92,000 for a uniform 0.5 mm mesh, with 63 equally fine elements around the hole.

What should I watch when passing meshes to a solver?

Assign physical groups. If any physical group exists, Gmsh writes only entities that belong to one. Give named physical groups to faces carrying boundary conditions and to material regions, and choose an output format the solver expects (.msh version, .inp, .unv, etc.). With second-order elements, also check that mid-side nodes lie on curved boundaries.

References and scope of verification

Numbers are educational reference calculations under the stated assumptions. Sources document theory and setup, not proof that these numerical values were reproduced in each package. Engineering decisions require validation for the actual conditions.

Related Simulators

Experience the theory firsthand with the interactive simulator for this field

All Simulators

Related fields

Structural AnalysisFluid Analysis (CFD)Thermal Analysis
Rate this article
Thank you for your feedback!
Helpful
More details
Report error
Helpful
0
More details
0
Report error
0