This section describes the ongoing redesign of NekMesh relative to the master branch. It is
intended as an orientation guide for developers who know the old code base and need
to understand what has moved, what has been ported, and what is temporarily
disabled. The subsequent sections of this document describe the design as it now
stands.
Historically NekMesh maintained its own mesh data structures (Node, Edge, Face, Element,
Composite) which duplicated, but were not interoperable with, the SpatialDomains geometry
objects (PointGeom, SegGeom, TriGeom/QuadGeom, TetGeom, PrismGeom, …) used by the
solvers. Every NekMesh run therefore ended in a translation step: the NekMesh representation
was converted into geometry objects (or serialised to XML) before it could be used. This had
three consequences:
Duplication. Connectivity, curvature and high-order node handling were implemented twice, in two conventions that had to be kept in sync.
Cost. Large industrial meshes were held twice in memory, and the conversion between representations dominated the runtime of several modules.
No pipelining. Because NekMesh objects were not geometry objects, a mesh
could not be handed straight to a solver, nor could a solver-side MeshGraph be fed
back into a process module.
The redesign removes the duplication by making SpatialDomains the single mesh
representation: NekMesh now operates directly on a MeshGraph. This enables an
in-memory, MPI-parallel meshing pipeline (mesh → process → solve) without file
round-trips.
Table 18.1 maps each of the old NekMesh structures onto its replacement. The rest of this section explains each entry in turn.
| Was | Is now | Note |
| | | owned by the graph, passed by raw pointer |
|
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| same hashing, non-owning |
|
|
| dimensions live with the graph |
|
|
| see the CAD subsection below |
| (no equivalent) |
| owns geometry not yet in the graph |
| (no equivalent) |
| explicit, deterministic IDs on creation |
SpatialDomains-based ones.
The changes fall into four groups, in decreasing order of impact on calling code:
Representation. Nodes, edges, faces and elements are now geometry objects.
Any code that dereferenced node->m_x or iterated el->GetVertexList() must be
rewritten against the Geometry interface.
Ownership. The MeshGraph owns every entity through unique_ptr_objpool;
everybody else holds raw pointers. Shared-pointer reference counting no longer
keeps entities alive, so lifetime is now explicit.
Identity. Entities are addressed by global ID within the graph’s maps rather than by pointer identity within a set, and IDs can be pinned at creation.
Grouping. Composites are replaced by a geometry-to-tag map, one per dimension.
The central change is in MeshElements/Mesh.h. The old Mesh class owned m_node,
m_vertexSet, m_element, m_composite and friends. The new Mesh owns essentially one
thing:
1class Mesh 2{ 3public: 4 /// Mesh graph shared ptr storing the geometry info 5 SpatialDomains::MeshGraphSharedPtr m_meshGraph; 6 /// Array by dimension of maps of all elements and boundary 7 /// surfaces to their tags. 8 std::array<GeomTagMap, 4> m_elementTags; 9 /// Map of element edges / faces. 10 EdgeMap m_edgeSet; 11 FaceMap m_faceSet; 12 ... 13 /// Information handed from one module to another. 14 ModuleContext &GetContext(); 15private: 16 ModuleContext m_context; 17};
Taking each member in turn:
m_meshGraph — the MeshGraph owns the mesh. Geometry objects are held
by the graph in per-shape maps (m_pointGeoms, m_segGeoms, m_triGeoms, …) of
unique_ptr_objpool, keyed by global ID; everything else refers to them by raw
pointer. This replaces both m_node/m_vertexSet and m_element. Ownership is
transferred explicitly through the new MeshGraph API:
AddGeom<T>(id, geom) — hand a single entity to the graph. The
type-dispatched overload for T = Geometry switches on GetShapeType() and
downcasts, so a module holding a generic Geometry need not know the
concrete shape.
BulkAddGeom<T>(vector) — move a whole batch in at once, which
avoids repeated map rehashing when a module creates many entities (e.g.
boundary-layer splitting).
ExtractGeom<T>(id, erase) — take ownership back out of the graph,
optionally erasing the map entry. This is how a module temporarily removes
entities it is about to replace.
GetGeomMap<T>() / SetGeomMap<T>() — read or wholesale-replace a shape’s
map; the latter is used when renumbering.
Insertion goes through InsertGeomChecked, which asserts that the ID is not already
present, so a duplicate global ID is now a hard error rather than silent corruption of the
mesh.
m_elementTags — composites replaced by tags. m_elementTags[dim] is a
unordered_map<Geometry*, int> (GeomTagMap) associating each geometry of that
dimension with its composite/tag. The old CompositeMap was the inverse relation — tag
→ list of elements — which meant a linear search to answer "which composite is this
element in?", the question modules actually ask. Boundary membership is now a single
lookup, Mesh::IsBoundary(geom, dim). Note that an entity carries a single int tag
rather than a vector<int>. The counting helpers follow: GetNumEntities() has become
GetNumTaggedEntities().
m_edgeSet, m_faceSet — connectivity lookup. These retain their old purpose (find
the existing edge/face defined by a given set of vertex IDs, so that neighbouring elements
share it rather than duplicating it) and their old hashing, but they are now non-owning
maps to geometry pointers:
1typedef std::unordered_map<std::pair<int,int>, 2 SpatialDomains::SegGeom*, EdgeHash, EdgeKey> EdgeMap; 3typedef std::unordered_map<std::array<int,4>, 4 SpatialDomains::Geometry2D*, FaceHash, FaceKey> FaceMap;
EdgeHash/EdgeKey hash an edge on its two vertex IDs irrespective of order;
FaceHash/FaceKey do the same for the (up to) four vertex IDs of a face via the sort4
sorting network. A face key is a fixed array<int,4>, with triangles using the fourth slot
as a sentinel.
What disappeared. Node, Edge, Face, Point, Composite, HOAlignment and Pyramid
are commented out of library/NekMesh/CMakeLists.txt (the files remain on disk for
reference only). m_expDim and m_spaceDim move to MeshGraph::GetMeshDimension()
and GetSpaceDimension(). m_cad moves into SpatialDomains. The auxiliary members
m_vertexNormals, m_spherigonSurfs, m_faceLabels, m_condition and m_fields are
not carried over as members: those still needed are now module-to-module payloads held
in the ModuleContext described below, rather than fields on Mesh that every module
pays for and no module owns. (The Condition type itself is still declared in
Mesh.h.)
NekMesh.cpp builds a pipeline of modules and runs them in sequence, and some of them need
to hand something to a later one that is not mesh data: vertex normals read from a .ply
file and consumed by the spherigon module, the octree built by loadoctree and
used by surface meshing, the coarse elements ProcessBL keeps so that a boundary
layer can later be regenerated. Historically each of these was a member of Mesh
(m_vertexNormals, m_octree, m_macroElements, …), which put single-module concerns
in the one class every module includes, and gave the payload no clear owner or
lifetime.
ModuleContext (NekMesh/Module/ModuleContext.h), reached through Mesh::GetContext(),
is a store keyed on the payload’s own type:
1// Producer, in the module that has the information: 2m_mesh->GetContext().Get<VertexNormals>().normals[vert] = {nx, ny, nz}; 3 4// Consumer, in a module that may or may not be given it: 5if (VertexNormals *vn = m_mesh->GetContext().TryGet<VertexNormals>()) 6{ 7 ... 8}
Set<T> replaces a payload, Get<T> constructs one if absent or stale, TryGet<T> returns
nullptr in that case instead, and Remove<T> drops one. The distinction matters to a
consumer that must tell “nothing was supplied” from “something was supplied and is
empty”, which a size() == 0 test cannot do. The key is std::type_index, so
there are no string names to keep in sync and a typo is a compile error; entries
are held as shared_ptr<void>, which (unlike unique_ptr<void> or std::any)
retains the concrete deleter, so the payload type need only be complete where it is
used.
The payload types themselves are small structs declared next to the context:
VertexNormals and SpherigonSurfs (Module/SurfaceHints.h) and MacroElements
(Module/MacroElements.h), the last of which wraps an EntityHolder — a plain owning
container of unique pointers, one vector per geometry type, for entities that must stay alive
while not part of the graph.
Staleness.
A payload that refers to mesh entities is invalidated when those entities may have gone.
Module::RemoveOrphanedEntities() calls ModuleContext::Invalidate(), which bumps a
generation counter; TryGet<T> compares generations and reports a payload stored before the
last invalidation as absent. This is deliberately coarse — “the mesh changed, discard” —
because testing whether a particular entity survived would cost more than rebuilding the
payload. Renumbering, by contrast, is deliberately not an invalidation: keying a payload
on geometry pointers rather than on global IDs is precisely what lets it survive
one.
Not every payload wants that, and the trait PayloadFollowsEntities<T> says so. It defaults
to true_type, the safe answer, and is specialised for the octree:
1template <> struct PayloadFollowsEntities<Octree> : std::false_type {};
because the octree is built from the CAD, not from mesh entities, and would otherwise be
thrown away the first time a module tidied up the graph — during mesh generation, before
anything had used it. The check is an if constexpr in TryGet<T>, so an exempt payload
costs nothing.
When to use it rather than SpatialDomains.
The question to ask is whether the payload must react to the destruction of an individual
entity. CAD associations must — a link from a geometry to the CAD curve it sits on has to
disappear with that geometry — so they live in SpatialDomains as CADAssociation, whose
Remove() is called from the geometry destructor. Everything for which the coarse “mesh
changed” answer is enough belongs in the context, where it stays out of SpatialDomains and
out of Mesh.
Element used to be the mesh element: it owned m_vertex, m_edge, m_face and
m_volumeNodes, and held m_geom as a lazily-built by-product for output. That relationship
is now inverted. The geometry object is the element, and Element is reduced to
a shape-level helper that builds and queries it. Its remaining state is just m_id,
m_dim, m_conf, m_tag, m_taglist, m_curveType, m_boundaryLinks and m_geom;
the four node/edge/face containers and the m_edgeLink/m_faceLink boundary
back-pointers are gone, the latter being expressed by the m_elementTags lookup
instead.
The factory signature reflects the inversion. It used to construct an Element from
nodes,
1// old 2typedef LibUtilities::NekFactory<LibUtilities::ShapeType, Element, 3 ElmtConfig, std::vector<NodeSharedPtr>, std::vector<int>> 4 ElementFactory;
whereas it now produces a SpatialDomains::Geometry* directly:
1// new 2typedef LibUtilities::NekFactoryBase< 3 LibUtilities::ShapeType, SpatialDomains::Geometry, 4 SpatialDomains::Geometry *, 5 std::vector<SpatialDomains::PointGeom *> &, 6 SpatialDomains::MeshGraphSharedPtr &, EdgeMap &, FaceMap &, 7 ElmtConfig &, std::set<int> *, std::unordered_set<int> *, 8 std::unordered_set<int> *, ElmtIds *> ElementFactory;
Reading the argument list left to right:
ShapeType selects the shape-level implementation, as before, but the product type
is now SpatialDomains::Geometry — hence NekFactoryBase, which allows the
created type and the returned type to differ.
vector<PointGeom*> is the vertex list, in the NekMesh node ordering described
in section 18.3.2.
MeshGraphSharedPtr is the graph the new entity (and any edges and faces created
along the way) is registered with, so creation and ownership happen in one step
rather than two.
EdgeMap/FaceMap are consulted first for every edge and face of the new element:
an entity already present is reused, and only a genuinely new one is constructed
and inserted. This is where inter-element connectivity is established.
ElmtConfig carries the order and the curvature/face-node flags, as before.
The three pointer-to-set arguments are optional bookkeeping outputs; each may be
nullptr if the caller does not want it.
vertIDs collects the global IDs of the vertices used, so a caller can distinguish
true vertices from high-order nodes.
curveNodeIDs collects the global IDs of the points consumed as curve
(high-order) nodes.
naiveTriIDs records triangular faces that were created standalone by
Triangle.cpp, i.e. without a parent 3D element to fix their orientation. When
a prism or tet later adopts such a face, it finds it in this set and re-sets
the face’s vertices and edges to its own orientation (and regenerates the face
curvature), instead of inheriting the arbitrary alignment the face was born
with.
ElmtIds* lets the caller pin explicit global IDs for the element and for each of its edges
and faces:
1struct ElmtIds 2{ 3 std::vector<int> edges; ///< edge ids, indexed by local edge 4 std::vector<int> faces; ///< face ids, indexed by local face 5 int elmt; ///< element id 6};
Passing nullptr falls back to an automatic ID taken from the current size of the
relevant map, which is adequate when building a mesh from scratch but not when a
module inserts elements into an existing mesh. Pinning is what lets a module place new
entities at chosen IDs and so produce reproducible output — notably the same result in
serial and in parallel — and it is used together with the consolidateIDs<T>()
renumbering described below.
The convenience wrapper CreateElementLite() covers the common case — a linear element
with automatic IDs and no filters:
1SpatialDomains::Geometry *CreateElementLite( 2 LibUtilities::ShapeType type, 3 std::vector<SpatialDomains::PointGeom *> &nodeList, 4 SpatialDomains::MeshGraphSharedPtr &meshGraph, 5 EdgeMap &edgeMap, FaceMap &faceMap);
Two free functions, GetCurvedNodesTri() and GetCurvedNodesQuad(), assemble the full
high-order node list of a 2D entity from its vertices, edge curves and interior face nodes, in the
NekMesh ordering of section 18.3.3.
MakeOrderOrder elevation has moved down into SpatialDomains. The new Geometry::MakeOrder(order,
pType) returns the curve and the newly created interior points,
1std::pair<CurveUniquePtr, std::vector<PointGeomUniquePtr>> 2 MakeOrder(int order, const LibUtilities::PointsType pType);
and is implemented per shape (SegGeom, TriGeom, QuadGeom, TetGeom, PrismGeom, HexGeom).
Two properties are new: the implementation no longer requires a MeshGraph, and elevation
proceeds bottom-up — edge curves are generated first, face curves are filled from the edge
curves, and volume nodes last — so that shared entities are curved exactly once and
consistently. Two supporting additions are Geometry::GetNumFacets() / GetFacet(i), which
give dimension-generic access to a geometry’s sub-entities (vertices in 1D, edges in 2D, faces in
3D), and Geometry::ResetLite(), a cheap reset that invalidates a geometry without
rebuilding its mapping data. Consistent v_Reset/FillGeom behaviour across all shapes is
what allows a mesh to be handed on to a solver in-memory after a module has modified
it.
The tables below give the idiom for each of the operations that modules perform most often,
as written on master and as written now. They are grouped by theme: traversal and access
(table 18.2), creation, ownership and identity (table 18.3), and CAD, evaluation and pipeline
(table 18.4). graph below abbreviates m_mesh->m_meshGraph.
| Operation | Before | Now |
| Loop over all elements |
| |
| Loop over boundary elements |
|
|
| Loop over a composite |
| filter |
| Test boundary membership | element had a non-empty
|
|
| Mesh / space dimension |
|
|
| Element vertices |
|
|
| Element edges / faces |
|
|
| Vertex coordinates |
|
|
| Find shared edge / face |
|
|
| Neighbours of a face |
|
|
| Recover concrete shape |
|
|
| Identify a shape | Same |
|
| Describe an element’s order and curvature | Same |
|
| Vertex node ordering | Same | the collapsed-point, prism and pyramid rules of section 18.3.2 are unchanged, as is the high-order ordering of section 18.3.3 |
SD abbreviates SpatialDomains. Rows marked Same
are unchanged from master and are listed because they remain in common use.
| Operation | Before | Now |
| Create a vertex |
|
|
| Create an element |
| same factory,
but → |
| Register an element |
| done inside the factory,
via |
| Remove an element | erase from |
|
| Keep an entity alive off-graph | reference counting did it implicitly | park it in an |
| Entity ID |
|
|
| Choose IDs on creation | not possible; assigned on insertion | pass an |
| Renumber after edits | reassign |
|
| Composite / tag of an entity |
|
|
| Edge / face curvature |
|
|
| Register a module | Same |
|
| Declare and read options | Same |
|
| Report to the user | Same |
|
| Assert | Same |
|
master.
| Operation | Before | Now |
| Reach the CAD model |
|
|
| Fetch a CAD entity |
|
|
| Project a point to a surface | Same |
|
| Query a CAD entity | Same |
|
| Build geometry for evaluation |
| the entity is the geometry; no conversion step |
| Geometric factors / Jacobian | Same |
|
| Integrate over an element | Same |
|
| Refresh after moving nodes | rebuild the element’s geometry |
|
| Elevate order |
|
|
A separate point, easily missed: geometry objects carry no CAD back-pointer. m_parentCAD is
commented out in SegGeom, TriGeom and QuadGeom, and PointGeom has no equivalent of the
old Node::SetCADSurf / GetCADSurfInfo. The association is instead held by the MeshGraph
in a set of maps from mesh entity to CAD entity (SpatialDomains/MeshGraph.h):
Get/SetFaceToCADSurf(Geometry*);
Get/SetEdgeToCADSurf(Geometry1D*) and
Get/SetEdgeToCADCurve(Geometry1D*);
Get/SetVertToCADSurf(PointGeom*), with GetVertToCADSurfUV(vert,
cadId) for the parameter pair;
Get/SetVertToCADCurve(PointGeom*), with GetVertToCADCurveT(vert,
cadId);
Get/SetVertToCADVert(PointGeom*).
Table 18.5 gives the translation used when porting CurveMesh, which is representative of the
mesh generation modules generally.
| Before | Now |
| | |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| no equivalent; see the note below |
graph abbreviates m_mesh->m_meshGraph and
pt a PointGeom*.
The whole CAD abstraction has been lifted out of library/NekMesh/CADSystem into
library/SpatialDomains/CADSystem, so that geometry objects themselves — not just
NekMesh — can carry a CAD association:
the interface (CADObject, CADSystem, CADCurve, CADSurf, CADVert);
the OpenCASCADE backend CADSystem/OCE, including OpenCascade.h,
TransfiniteSurface and GeoParser.hpp, a boost::spirit parser for the .geo
format;
the CFI backend CADSystem/CFI, which additionally gains CADElementCFI.
SpatialDomains/MeshGraph.h now includes CADSystem/CADSystem.h directly. The
corresponding NekMesh sources are commented out of the NekMesh build, and NekMesh gains
a dependency on SpatialDomains.
ProcessProjectCAD has been substantially rewritten on top of this (CAD reconstruction): it
now keys its work off PointGeom* and Geometry3D* rather than nodes and elements,
and separates the association stages into LinkVertexToCAD, LinkEdgeToCAD and
LinkFaceToCAD, with boost::geometry R-trees for proximity search and a lockedNodes set
recording vertices whose CAD projection failed (these are linearised rather than curved).
HOSurfaceMesh has been reworked in step with it, for both quadrilateral and triangular face
nodes.
Because the mesh is now a MeshGraph, modules can be run under MPI on a partitioned mesh.
Mesh::m_comm holds the communicator, and the ported modules test m_comm->GetSize() > 1
to switch on the parallel path, exchanging the entities they have modified across ranks (for
example via GatherUnion of cleared edge/face IDs and AllReduce on the iteration
termination flag in ProcessLinear). At present:
ProcessLinear runs in parallel, with an extract configuration option to write
out the invalid elements it finds (per-rank).
ProcessBL runs in parallel, and now handles hexahedra and mixed element
orientations in 2D and 3D.
Parallel HDF5 output is supported and HDF5 is enabled by default;
MeshGraphIOHDF5 gained parallel writing of curve data, composites and domains.
The port is incomplete by design: modules are being brought over to the new
data structure one at a time, and those not yet converted are commented out of
library/NekMesh/CMakeLists.txt rather than deleted. Table 18.6 summarises the state at
the time of writing.
| Kind | Ported | Not yet ported (disabled) |
| Input |
|
|
| Process |
|
|
| Output |
|
|
| Generation | — |
|
MeshGraph-based data structure.
Disabled modules are commented out of the build, not removed.
ProcessCheckConnectivity is a new module which verifies the connectivity of all elements
and reports orphaned geometry — a useful consistency check while modules are being
ported.
Coincident vertices are no longer removed by default.
Element tags are a single int (m_elementTags) rather than a vector<int>.
Geometry IDs are consolidated after modules that create or destroy entities (see
the consolidateIDs<T>() template in ProcessBL.h), which renumbers a shape’s
geometry map and the associated curve map so that IDs remain contiguous and
deterministic.
Module gained m_order and m_nummode members (both -1 for the non-uniform
case).