18.5 Mesh generation from CAD

This section describes the strategy of the mesh generator — the path from a CAD model to a curved tetrahedral mesh, which runs when NekMesh is given a .mcf file. It is built only when NEKTAR_USE_MESHGEN is on. The intention is to record the order things happen in, the invariant each stage establishes for the next, and where the numbers that are not derived from the user’s input come from, so that a failure can be attributed to a stage rather than hunted for.

18.5.1 The pipeline

InputMCF reads the configuration and then runs, in order:

  1. Load the CAD (CADSystemOCE::LoadCAD). The model is read through OpenCASCADE, its faces are sewn into a single shell, and vertices, curves and surfaces are enumerated. Establishes: every CAD curve is bounded by exactly two CAD surfaces, checked by CADSystem::CheckClosed. Without that the model is not a closed solid and no later stage can work.

  2. Build the octree (Octree::Process). Samples the curvature of every curve and surface and turns it into a target element size, δ, at every point in space. Establishes: a function Octree::Query(x) giving the element size wanted at any point, bounded below by MinDelta, above by MaxDelta, and varying no faster than maxGradation per unit distance.

  3. Mesh the curves (CurveMesh). Each CAD curve is divided into segments whose lengths follow the octree. Establishes: a sequence of mesh vertices and edges along every CAD curve, shared between the two surfaces that curve bounds, and each edge associated with the curve it lies on.

  4. Mesh the surfaces (FaceMesh). Each CAD surface is triangulated in its own (u,v) parameter plane by Triangle, using the curve meshes as its boundary, then refined against the octree and improved by alternating diagonal swaps and smoothing. Establishes: a triangulation of the whole boundary in which the only edges shared between two faces are the curve-mesh edges of step 3 — checked by FaceMesh::CheckEdgeOwnership.

  5. Build the boundary layer, if one was asked for (BLMesh). Prisms are extruded inwards from the nominated surfaces, thinning locally where they would otherwise invert. The surfaces the layer slides along are then re-triangulated against their new boundary.

  6. Mesh the volume (TetMesh). The surface triangulation — or, with a boundary layer, the inner face of the prism layer together with the surfaces not in it — is handed to TetGen as a piecewise linear complex and filled with tetrahedra. Establishes, before handing over, that every edge of that triangulation is used by exactly two triangles (TetMesh::CheckManifold); TetGen requires a watertight manifold boundary and aborts without explanation otherwise.

  7. Curve the mesh (HOSurfaceMesh). Interior nodes are added to the surface elements at the requested polynomial order and projected onto the CAD.

18.5.2 Where the failures come from

Nearly every failure of this pipeline is a failure of step 2 showing up later. The octree is bounded below by MinDelta, which the user chooses; where the curvature of the geometry asks for something smaller, the request is clamped and the feature is meshed flatter than it is. A face meshed flat enough passes through whatever is on the other side of it, and the symptom is a surface mesh that is not a manifold (caught in step 6) or one that intersects itself (caught by TetGen, which reports it as its exit code 3). Octree::ReportClamping warns when the clamp is widespread for this reason, and reducing MinDelta is usually the answer.

18.5.3 Units

Inside OpenCASCADE every length is in millimetres; outside it, in the mesh and in everything the user writes in a .mcf, the unit is the metre. A STEP file carries its own unit in its header and is converted on the way in, so a model drawn in millimetres and one drawn in metres produce the same mesh from the same .mcf. Every quantity crossing that boundary is converted through SpatialDomains::CADUnits, which also handles the quantities that convert the other way, such as curvature.

18.5.4 Numbers that are not the user’s

The parameters a .mcf sets — MinDelta, MaxDelta, EPS, the boundary layer thickness and progression — are documented in the user guide. The constants below are chosen inside the generator, and are collected here because each one is a decision rather than a derivation:

18.5.5 What is checked, and when

Each of these turns a failure that used to be silent, or a crash inside a third-party library, into a message naming the geometry responsible. They run in pipeline order: