Move NekMesh data structures to use SpatialDomains classes
Issue/feature addressed
NekMesh uses a second, lighter mesh datastructure: NodeSharedPtr, EdgeSharedPtr, FaceSharedPtr, ElementSharedPtr, MeshSharedPtr, all built on shared_ptr. This creates a duplicated geometrical inforation that SpatialDomains MeshGraph and Geometry classes already provide. Each NekMesh element creates a hierarchical stucture that SpatialDomains already owns: edge to verts,
face to vertex and internal high-order node curvature. Any exchange with the rest of Nektar++ and using Nektar++ MPI coommunicators is impractical and requires converting the entire mesh between the two representations, hence not suitable for dynamoc AMR.
The costs are a large both from memory and time due to the conversion. Moreover the geom-factors and high-order expansion needs to be generated every time one needs to use them. Specifically cost of the conversion and generation is dominated by reference counting and by mapping data (Xmap, coefficient arrays).
Proposed solution
- Slim down, extend and move the SpatialDomains data-structure to be as the single source of truth for anything geometry.
- Remove completely the NekMesh data-structure, just keeping the templates and some helper functions.
- port all NekMesh modules and pipelines onto Spatial Domains.
- Move all CAD APIs onto SpatialDomains
Implementation SpatialDomains
SpatialDomains
MeshGraph as the single owner
Ownership across the library is by pooled unique_ptr held once in MeshGraph,
with raw observer pointers everywhere else, so no per-entity reference counting
is paid. This MR extends that model to cover the entities the generator creates:
CreateCurveNode()allocates aPointGeomfrom the object pool, stores it inm_nodeSetand returns an observer pointer, giving the generator a one-call idiom that cannot leak or double-own.AddCurveNode/AddCurveNodesadopt nodes produced byMakeOrder.AddCurvedEdge/AddCurvedFaceadopt aCurveUniquePtrand file it under its ownm_curveID.
Insertion is also hardened. AddGeom now routes every shape through a common
InsertGeomChecked helper that asserts on duplicate IDs; previously a duplicate
silently overwrote the existing entry, which masked genuine duplicate-face bugs
during the port. AddGeom additionally accepts a base Geometry and dispatches
on GetShapeType() through unique_ptr_objpool_cast, so callers holding a base
pointer no longer need to downcast before inserting - necessary now that the
ported modules work generically. BulkAddGeom move-inserts a whole vector in a
single pass for the generator's output, avoiding repeated rehashing.
Two lookup paths are re-keyed for the same reason: m_faceToElMap moves from
int to Geometry2D *, removing a global-ID round trip on a hot path in
GetElementsFromFace and PopulateFaceToElMap; GetNumElements() takes an
optional dimension so callers can count entities of a dimension other than the
mesh dimension; and GetGeometry3D(id) is added to mirror the existing
GetGeometry2D(id).
Uniform curvature access
NekMesh used separate high-order nodes for edges and faces (edgeNode and faceNode) can also be duplicated.
Now in SpatialDomains they are stored as 'PointGeom' through the 'Curve'.
Curvature was previously reachable only through the concrete type:
SegGeom::GetCurve() and Geometry2D::GetCurve(). High-order information can now be read and written through
a base pointer at any dimension, which helps for 'MakeOrder'. CurveUniquePtr and CurveMap are relocated
from MeshGraph.h into library/SpatialDomains/Curve.hpp, next to the type they
describe, so that curvature can be modified without the full m_graph dependency.
MakeOrder() elevation moved into the geometry
MakeOrder(order, pointsType) moves from the NekMesh element classes onto
Geometry, with per-shape implementations for segments, triangles,
quadrilaterals, tetrahedra, prisms, pyramids* and hexahedra. The signature is the
interesting part: it returns
std::pair<CurveUniquePtr, std::vector<PointGeomUniquePtr>> - the newly created
curve and the newly created interior nodes. These can be created without actually being stored in graph.
The geometry sets its own m_curve to keep the new curve, but hands ownership back to the
caller, which can be finally stored into MeshGraph through AddCurvedEdge()/AddCurvedFace(),
AddCurveNodes. Geometries create the curve; and needs to be asigned to the graph to be owned.
We also fix an accuracy issue that the old NekMesh had, where every edgesnodes were coppied but not evaluated. Now the all nodes come form PhysEvaluate on the parent element. This imposes an ordering contract - edges must be elevated before faces - which is asserted rather than assumed. Edge orientation is determined explicitly, so there is a consistent for the face-local direction.
Connectivity-only construction (ElementLite/ResetLit)
From the NekMesh consgtruction which was lighter we moved to Geom, which had both Xmap and runs FillGeom() with all GeomFactors.
This was heavy, so first GeomFactors was moved to MultiDomains and then we can construct a simple geometry without the maps and memory heavy nodes. This is the memory-footprint change. Each 2D and 3D geometry gains a constructor
taking explicit edge and vertex arrays together with a skipSetUp flag,
complemented by SetVertex, SetEdge and SetFace and skipping the Setup 'skipSetUp'.
The mapping data is created then through the Geometry::FillGeom() now checks
m_setupState and calls v_Setup() on demand so a geometry built in the lite
form becomes fully functional the moment anything actually needs it.
Because the bulk of a meshing pipelines only creates and modifies connectivity,
this means the generator no longer allocates the memory expensive part of the Geom for
the vast majority of the elements it handles, while solvers or HO-splitting opearators call
FillGeom on everything - see identical behaviour.
CAD system
The CADSystem hierarchy moves from /NekMesh/CADSystem into
/SpatialDomains/CADSystem and is re-namespaced to
all the abstract layer are retained (CADSystem, CADObject,
CADCurve, CADSurf, CADVert), with OCE and CFI backend.
NEKTAR_USE_MESHGEN, so a standard build gains no new external dependency.
MeshGraph holds the CADSystemSharedPtr and owns the CAD-mesh association. The
association is deliberately not stored on the geometries to avoid circular dependencies and unnecessary memory footprint.
Hence, we create hash maps on for the geometries - m_faceToCADSurf, m_edgeToCADSurf,
m_edgeToCADCurve, m_vertToCADSurf (surface plus UV), m_vertToCADCurve
and m_vertToCADVert.
Vertex associations are unique per mesh entity: SetVertToCADSurf and
SetVertToCADCurve overwrite the entry with a matching CAD id rather than
appending, so repeated projection or smoothing passes converge rather than
growing the tables without bound. GetVertToCADSurfUV and GetVertToCADCurveT
provide id-based lookup with an assertion if empty, and ClearVertToCADSurf /
ClearVertToCADCurve reset the CAD-mesh connectivity.
NekMesh - Porting, new and depreciated functionalities
Practically, every module of NekMesh has been refactored and ported to using SpatialDomain Geometries. The structure of edgeNodes, faceNodes, m_elLInk and m_mesh->m_element[] for example are substituted with meshGraph properties. A current status can be seen below :
Core
-
Module- populates MeshGraph, not ProcessEdge/ProcessFace, no edgeSet and faceSet -
MeshElements/Mesh- becomes a wraper around MeshGraph, which owns the mesh -
MeshElements/Element- creates ElementLite SpatialDomains geometry (no Xmap, coeff,etc) The element types become very light compared to the old NekMesh elements. SpatialDomains elements do the heavy lifting. -
MeshElements/Line- only MakeOrder and GetNumNodes left for all. Rest is in the SpatialDomain::Geometry classes -
MeshElements/Triangle -
MeshElements/Quadrilateral -
MeshElements/Tetrahedron -
MeshElements/Pyramid -
MeshElements/Prism -
MeshElements/Hexahedrons -
MeshElements/Node- retired, usePointGeom -
MeshElements/Point- retired usePointGeom -
MeshElements/Edge- retired, useSegGeom -
MeshElements/Face- retired, useTriGeom/QuadGeom -
MeshElements/Composite- retired, we useCompositeMap -
MeshElements/HOAlignment- retired
IO
-
InputGmsh -
InputStar -
InputNekpp- use Nektar++ module -
InputCGNS- crucial -
InputPly -
InputSwan -
InputNek- not crucial -
InputNek5000- not crucial -
InputSem- not crucial -
InputStarTec- not crucial -
InputVtk- not crucial -
OutputGmsh -
OutputNekpp -
OutputStdOut -
OutputSTL
Industrial Pipeline
-
ProcessProjectCAD -
ProcessBL -
ProcessBLOld- depreciated - all elements now in ProcessBL -
ProcessJac -
ProcessLinear -
ProcessPerAlign -
ProcessCheckConnectivity- new in this MR, added to catch the duplicate-entity errors the port exposed -
VarOpti- not yet, see below removedProcessLinkCheck
Other Process Modules
-
ProcessCombine -
ProcessExtractSurf -
ProcessExtrude -
ProcessRevolve -
ProcessScale -
ProcessCurve -
ProcessCurvedEdges -
ProcessCyl -
ProcessDetectSurf -
ProcessScalar- same as scale ? -
ProcessSpherigon -
ProcessTetSplit- h-adaptation will have this -
ProcessOptiExtract -
ProcessInsertSurface removedProcessExtractTetPrismInterfaceremovedProcessLinkCheck
MeshGen
All modules related to the internal mesh generation InputMCF - NEKTAR_USE_MESHGEN:
-
Octree -
Octant -
ProcessLoadOctree -
CurveMesh -
SurfaceMesh -
FaceMesh -
2DGenerator -
OptimiseFunctions -
VolumeMesh -
TetMesh -
BLMesh -
2DGenerator -
TriangleInterface -
TetGenInterface -
VarOpti
The variational optimizer VarOpti - @dmoxey
-
ProcessVarOpti -
PreProcessing -
NodeOpti -
NodeOptiCAD -
ElUtil
CAD Engines
-
CADSystem -
CADObject -
CADVert -
CADCurve -
CADSurf -
OCEModules -
CFI- @dmoxey do we keep it - we cannot really test at the momemnt.
Miscellaneous
PointGeom gains Angle() and IsNodeClose(), used by the ported connectivity for PerAlign.
Tests
Suggested reviewers
Please suggest any people who would be appropriate to review your code.
Notes
Please add any other information that could be useful for reviewers.
Checklist
- Functions and classes, or changes to them, are documented.
- User guide/documentation is updated.
- Changelog is updated.
- Suitable tests added for new functionality.
- Contributed code is correctly formatted. (See the contributing guidelines).
- License added to any new files.
- No extraneous files have been added (e.g. compiler output or test data files).