24#ifndef _UIBHM_TOPOLOGY_H_
25#define _UIBHM_TOPOLOGY_H_
44#define GMP_UIBHM_SIDE_BITS 4
47#define GM_UIBHM_SIDE_MASK (~(~0u >> GMP_UIBHM_SIDE_BITS))
50#define GMP_UIBHM_MAX_SIDE_VALUE ((1 << GMP_UIBHM_SIDE_BITS) - 1)
53#define GMP_UIBHM_BORDER_SIDE GMP_UIBHM_MAX_SIDE_VALUE
56#define GMP_UIBHM_MID_SIDE (GMP_UIBHM_MAX_SIDE_VALUE - 1)
59#define GMP_UIBHM_MAX_NUM_SIDES GMP_UIBHM_MID_SIDE
64#define GMP_UIBHM_CELL_BITS (32 - GMP_UIBHM_SIDE_BITS)
67#define GM_UIBHM_CELL_MASK (~GM_UIBHM_SIDE_MASK)
70#define GMP_UIBHM_MAX_NUM_CELLS (1 << GMP_UIBHM_CELL_BITS)
76#define GMP_UIBHM_INVALID_VALUE (~0u)
82#define GMP_UIBHM_INTERFACE_BORDER (GMP_UIBHM_INVALID_VALUE << 1)
108 BasicCheckWarn = FirstWarnOption,
116 virtual bool init(
bool buildEdgeMap, CheckOptions extraChecks) = 0;
117 virtual bool addNewCells() = 0;
118 virtual bool cellIsIndexed(
int cellId) = 0;
170template <
class Geometry>
179 using HSVT =
typename Geometry::template VectorType<HalfSide>;
182 using IVT =
typename Geometry::template VectorType<int>;
187 UibhmTopology(
typename Geometry::NodeData* nodeData,
typename Geometry::CellData* cellData,
189 : Geometry(nodeData, cellData, pcr), _nhalf(0), _lastAddedCells(0), _hasOffset(false), _needsEH(false),
190 _extraChecks(BasicCheck), _checking(0), _checkLogger(logger) {}
192 virtual bool init(
bool buildEdgeMap, CheckOptions extraChecks);
193 virtual bool addNewCells();
202 size_t usedMemory()
const;
229 *cellId = hsCell(hs);
231 assert(*cellId >= 0 && *cellId < this->numCells());
232 assert(*side >= 0 && *side < this->numSides(*cellId));
251 if constexpr(Geometry::IsHybrid)
252 lhs = (_hasOffset ? _Of[cellId] : this->co(cellId)) + side;
254 lhs = cellId * this->_typeTemplate->numSides() + side;
255 assert(lhs >= 0 && lhs < _nhalf);
263 hsBreak(hs, &cellId, &side);
264 return linearHs(cellId, side);
284 HalfSide o = oppositeHs(cellId, side);
293 assert(hsIsValid(hs));
303 assert(hsIsValid(hs));
311 void fillBorderKind(
int cellId,
int side,
bool* isExtBorder,
bool* isInterfaceBorder)
313 HalfSide o = oppositeHs(cellId, side);
321 assert(cellId >= 0 && cellId < this->numCells());
322 return hsMake(cellId, 0);
329 hsBreak(hs, &cellId, &side);
330 return hsMake(cellId, (side + 1) % this->numSides(cellId));
337 hsBreak(hs, &cellId, &side);
338 int ncs = this->numSides(cellId);
339 return hsMake(cellId, (side + ncs - 1) % ncs);
348 assert(this->solid());
350 hsBreak(hf, &cellId, &face);
351 assert(faceEdge >= 0 && faceEdge < this->tt(cellId)->numFaceVertices(face));
352 return hsMake(cellId, this->tt(cellId)->adjacentFaces(face)[faceEdge]);
366 bool doAddNewCells();
368 int buildOffsetTable();
369 int updateOffsetTable(
int numAddedCells);
371 bool buildOppositeTable();
372 bool updateOppositeTable(
int numAddedCells);
373 template <
class Key,
class MakeKey>
bool oppositeTableTraverseCells(MakeKey makeKey,
int first,
int last, QMap <Key, HalfSide>& adjMap);
375 bool buildVertexHalfSideTable();
376 bool updateVertexHalfSideTable(
int numAddedCells,
QVector<HalfSide>& borderToIntBorderList);
377 void vertexHalfSideTableTraverseCells(
int first,
int last,
const QSet<int>& oldCells =
QSet<int>());
379 bool buildEdgeHalfFaceMap();
380 bool updateEdgeHalfFaceMap(
int numAddedCells);
381 bool edgeHalfFaceMapTraverseCells(
int first,
int last);
383 bool adjustSolidInterfaceElementBorders();
384 bool updateSolidInterfaceElementBorders(
int numAddedCells,
QVector<HalfSide>& borderToIntBorderList);
385 bool solidInterfaceElementBordersTraverseCells(
int first,
int last,
QVector<HalfSide>& borderToIntBorderList);
387 bool buildSurfaceBordersTable();
388 bool updateSurfaceBordersTable(
int numAddedCells);
390 bool buildSolidBordersTable();
391 bool updateSolidBordersTable(
int numAddedCells);
400 BSIterator* borderSurfaceIterator(
int borderIndex);
403 bool numNodesDifferentFromNumEdges()
const;
405 bool checkLimits(
int ncells);
407 template <
class Key>
bool checkOppositeMap(
const QMap<Key, int>& countMap);
408 bool fullNodeCheck();
411 bool logFindFaceEdgeError(
int cellId,
int face,
int v1,
int v2,
bool bidir =
false);
412 bool logFindNodeIndexError(
int cellId,
int v);
451 bool operator<(
const struct V3& other)
const
453 return (v[0] < other.v[0]) ||
454 (v[0] == other.v[0] && v[1] < other.v[1]) ||
455 (v[0] == other.v[0] && v[1] == other.v[1] && v[2] < other.v[2]);
457 bool operator==(
const struct V3& other)
const
459 return v[0] == other.v[0] && v[1] == other.v[1] && v[2] == other.v[2];
466 bool operator<(
const struct V4& other)
const
468 return (v[0] < other.v[0]) ||
469 (v[0] == other.v[0] && v[1] < other.v[1]) ||
470 (v[0] == other.v[0] && v[1] == other.v[1] && v[2] < other.v[2]) ||
471 (v[0] == other.v[0] && v[1] == other.v[1] && v[2] == other.v[2] && v[3] < other.v[3]);
473 bool operator==(
const struct V4& other)
const
475 return v[0] == other.v[0] && v[1] == other.v[1] && v[2] == other.v[2] && v[3] == other.v[3];
482 assert(vertexList.
size() == 2);
489 assert(vertexList.
size() > 2);
491 return V3{ vertexList[0], vertexList[1], vertexList[2] };
497 assert(vertexList.
size() > 2 && vertexList.
size() <= 4);
499 return V4{ vertexList[0], vertexList[1], vertexList[2], vertexList.
size() == 4 ? vertexList[3] : -1};
Auxiliar structure used to share data between GmpCellMesh and GmpMeshLoader. All fields are public si...
Definition gmpCellMeshData.h:121
Auxiliar interface used to share node data between the mesh implementation and GmpMeshLoader....
Definition gmpNodeMeshData.h:53
The basic class for topological queries using the UibhmTopology structure. Implements the GmCellMeshT...
Definition uibhmQuery.h:37
A helper queue class implemented over a QVector with amortized O(1) enqueue and dequeue operations....
Definition uibhmQueue.h:38
The UibhmQuery especialization for solid meshes.
Definition uibhmQuery.h:132
The UibhmQuery especialization for surface meshes.
Definition uibhmQuery.h:80
Interface for accessing the "exported" functions of a UibhmTopology class instance,...
Definition uibhmTopology.h:94
virtual ~UibhmTopologyBase()
Virtual destructor.
Definition uibhmTopology.h:114
CheckOptions
Check options for mesh initialization.
Definition uibhmTopology.h:99
@ FullCheck
Simple check + check the correctness of the nodeAdjacentCells() query, ensuring that non strange elem...
Definition uibhmTopology.h:102
@ SimpleCheckWarn
Same as SimpleCheck but init() and addNewCells() do not fail on errors.
Definition uibhmTopology.h:109
@ FullCheckWarn
Same as FullCheck but init() and addNewCells() do not fail on errors.
Definition uibhmTopology.h:110
@ SimpleCheck
Check opposite consistency & orientation.
Definition uibhmTopology.h:101
@ BasicCheck
Performs only basic checks during the creation of the structure.
Definition uibhmTopology.h:100
Definition uibhmTopology.h:172
QVector< HalfSide > _B
The border table with one entry per border "curve" (2d) or "surface" (3d). It stores only one half-si...
Definition uibhmTopology.h:560
int linearHs(HalfSide hs) const
Returns the linear half-side index used to index the opposite table.
Definition uibhmTopology.h:260
static int hsCell(HalfSide hs)
Extracts the cellId from the half-side index.
Definition uibhmTopology.h:221
HalfSide nextHs(HalfSide hs) const
Returns the index of the next half side in the cell associated with the given half side.
Definition uibhmTopology.h:326
void hsBreak(HalfSide hs, int *cellId, int *side) const
Breaks the half-side into its components. In debug mode, checks their validity as actual cells and si...
Definition uibhmTopology.h:227
int _checking
A flag set to 0 during query time, 1 when building the structure and 2 if an error was found while bu...
Definition uibhmTopology.h:573
quint32 HalfSide
The integer type used to represent a half-side index.
Definition uibhmTopology.h:176
HalfSide radialHf(HalfSide hf, int faceEdge) const
Given a half face (this method should NOT be used for surface meshes) and the local index of an edge ...
Definition uibhmTopology.h:362
void fillBorderKind(int cellId, int side, bool *isExtBorder, bool *isInterfaceBorder)
Given a (cellId, side) pair fills isExtBorder with the result of isNonInterfaceBorderHs() and isInter...
Definition uibhmTopology.h:311
HalfSide prevHs(HalfSide hs) const
Returns the index of the previous half side in the cell associated with the given half side.
Definition uibhmTopology.h:334
HalfSide adjacentHf(HalfSide hf, int faceEdge) const
Given a half face (this method should NOT be used for surface meshes) and the local index of an edge ...
Definition uibhmTopology.h:346
const GmLogCategory & _checkLogger
The logger used for check messages.
Definition uibhmTopology.h:574
QMap< size_t, HalfSide > _EH
The edge half-face map. Indexed by edge id, it stores one of its incident half-faces....
Definition uibhmTopology.h:570
bool isNonInterfaceBorderHs(int cellId, int side) const
Returns true if the given (cell, side) pair corresponds to a border half-side that IS NOT an internal...
Definition uibhmTopology.h:282
static bool hsIsValid(HalfSide hs)
Returns true for a standard half-side. Returns false for special half-sides used to represent borders...
Definition uibhmTopology.h:238
bool isBorderHs(int cellId, int side) const
Returns true if the given (cell, side) pair corresponds to a border half-side.
Definition uibhmTopology.h:274
UibhmTopology(typename Geometry::NodeData *nodeData, typename Geometry::CellData *cellData, const GmPCR *pcr, const GmLogCategory &logger)
Basic constructor. The internal structure is built by a required call to init() that returns true or ...
Definition uibhmTopology.h:187
HalfSide oppositeHs(int cellId, int side) const
Returns the opposite half-side to the given (cell, side) pair.
Definition uibhmTopology.h:268
bool _hasOffset
Do we have a built offset table? Equal to (!_Of.isEmpty()). Stored since linearHs() is called quite o...
Definition uibhmTopology.h:509
HSVT _O
The opposite table with _nhalf entries. For a half-side index 'hs', _O[linearHs(hs)] stores the half_...
Definition uibhmTopology.h:522
HalfSide oppositeHs(HalfSide hs) const
Returns the opposite half-side to the given half-side.
Definition uibhmTopology.h:271
HalfSide firstHs(int cellId) const
Returns the index of the first half side for the given cell.
Definition uibhmTopology.h:319
static V4 makeSolidKey4(QVarLengthArray< int, 10 > &vertexList)
Creates a map key from up to 4 face vertices. vertexList is sorted as a side effect.
Definition uibhmTopology.h:495
CheckOptions _extraChecks
Should we perfrom extra checks on the mesh data to ensure that the mesh is adequate for the topology?
Definition uibhmTopology.h:572
IVT _Of
The side offset table. ONLY EXISTS for hybrid meshes and even though might be empty for surface meshe...
Definition uibhmTopology.h:536
HSVT _VH
The vertex half-side table with numNodes() entries. Each entry stores one half-side that contains tha...
Definition uibhmTopology.h:553
int _nhalf
The number of half-sides in the mesh (either half-edges or half-faces)
Definition uibhmTopology.h:507
int _lastAddedCells
The number of mesh cells added to the topology when the structure was built / last updated.
Definition uibhmTopology.h:508
static V3 makeSolidKey3(QVarLengthArray< int, 10 > &vertexList)
Creates a map key from the 3 face vertices with smaller index. vertexList is sorted as a side effect.
Definition uibhmTopology.h:487
bool _needsEH
Did the user asked for the EH map? Needed for the special case when the mesh is initialized empty and...
Definition uibhmTopology.h:510
virtual bool cellIsIndexed(int cellId)
Returns true if the cell already was indexed by the topological structure by the last call to init() ...
Definition uibhmTopology.h:196
static bool hsIsMidElement(HalfSide hs)
Returns true if the given half-side represents a special hs used to store the element for a quadratic...
Definition uibhmTopology.h:243
static int hsSide(HalfSide hs)
Extracts the side from the half-side index.
Definition uibhmTopology.h:224
static size_t makeSurfaceKey(QVarLengthArray< int, 10 > &vertexList)
Creates a map key from two vertices.
Definition uibhmTopology.h:480
typename Geometry::template VectorType< int > IVT
Let IVT be the same vector type used by Geometry storing an integer.
Definition uibhmTopology.h:182
static HalfSide hsMake(int cellId, int side)
Creates a half-side index from a cellId and side components.
Definition uibhmTopology.h:205
typename Geometry::template VectorType< HalfSide > HSVT
Let HSVT be the same vector type used by Geometry storing a half-side value.
Definition uibhmTopology.h:179
int linearHs(int cellId, int side) const
Returns the linear half-side index used to index the opposite table for the given (cell,...
Definition uibhmTopology.h:248
bool isInterfaceBorderHs(HalfSide hs) const
Returns true if the given (valid) half-side is a border half-side that IS part of an internal hole ar...
Definition uibhmTopology.h:301
bool isBorderHs(HalfSide hs) const
Returns true if the given (valid) half-side is a border half-side.
Definition uibhmTopology.h:277
static HalfSide hsMakeSpecial(int id, int side)
Creates a half-side index to represent a border or a mid surface/volume node.
Definition uibhmTopology.h:213
bool isNonInterfaceBorderHs(HalfSide hs) const
Returns true if the given (valid) half-side is a border half-side that IS NOT an internal hole artifi...
Definition uibhmTopology.h:291
Declaration of useful configuration definitions for the plugin library.
#define GMP_GEMAMESH_CELL_ID_BITS
The number of bits effectivelly used to encode the cell id inside a 32 bits integer,...
Definition gmpGemaMeshConfig.h:49
The internal context returned by borderSurfaceIterator() and consumed by nextBorderSurface()
Definition uibhmTopology.h:395
QVector< bool > _visited
A vector to store which half-faces where already visited, initialized with false.
Definition uibhmTopology.h:397
UibhmQueue< HalfSide > _queue
A queue with the set of half-faces to process.
Definition uibhmTopology.h:396
Definition uibhmTopology.h:449
Definition uibhmTopology.h:464
Declaration of the UibhmQueue helper class.
#define GMP_UIBHM_CELL_BITS
The number of bits effectivelly used to encode the cell id inside a 32 bits half-side integer.
Definition uibhmTopology.h:64
#define GM_UIBHM_CELL_MASK
Mask with 1 on bits representing the cell id part (least significant bits up to the side mask).
Definition uibhmTopology.h:67
#define GMP_UIBHM_MAX_NUM_SIDES
The maximum number of sides (keeping in mind the special values used for borders and mid nodes).
Definition uibhmTopology.h:59
#define GMP_UIBHM_BORDER_SIDE
The special side value used to specify that a half-side is at the border.
Definition uibhmTopology.h:53
#define GMP_UIBHM_MID_SIDE
The special side value used to specify that the half-side stores only a cell id (for mid nodes)
Definition uibhmTopology.h:56
#define GMP_UIBHM_INTERFACE_BORDER
The value used to represent both the side and the cell for a border half-side origintaed from interfa...
Definition uibhmTopology.h:82
#define GMP_UIBHM_MAX_NUM_CELLS
The maximum number of allowed cells.
Definition uibhmTopology.h:70