GemaMesh
The GeMA Mesh Plugin
Loading...
Searching...
No Matches
gmpCellMeshData.h
Go to the documentation of this file.
1/************************************************************************
2**
3** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4** All rights reserved.
5**
6** This file is part of the "GeMA" software. It's use should respect
7** the terms in the license agreement that can be found together
8** with this source code.
9** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11** A PARTICULAR PURPOSE.
12**
13************************************************************************/
14
24#ifndef _GEMA_PLUGIN_CELL_MESH_DATA_H_
25#define _GEMA_PLUGIN_CELL_MESH_DATA_H_
26
27#include "gmpGemaMeshConfig.h"
28#include "gmpCellAllocator.h"
29#include "uibhmTopology.h"
30
32
33
34class GmPropertySet;
35class GmCellBoundary;
36class GmCellMesh;
37class GmElementMesh;
38class GmCell;
39class GmLuaCell;
41class GmValueInfo;
43class GmLogCategory;
44
45template <template <class> class> class GmpCellDataDump;
46template <class, class, class, GmCellType, int> class GmpCell;
47template <class, class, class, GmCellType, int> class GmpGhostCell;
48
52class GMP_GEMAMESH_API_EXPORT GmpCellMeshDataBase
53{
54public:
57 {
58 _meshId = newMeshId(mesh, this);
59 _hierarchicalIndex = -1;
60 }
61
63 ~GmpCellMeshDataBase() { _meshTable[_meshId] = NULL; _meshDataTable[_meshId] = NULL; }
64
66 bool hierarchicalElements() const { return _hierarchicalIndex >= 0; }
67
69 bool setHierarchicalIndex(int p, int q)
70 {
71 assert(p > 0 && p <= GM_MAX_ORTHOGONAL_POL_ORDER && q > 0 && q <= GM_MAX_ORTHOGONAL_POL_ORDER);
72 _hierarchicalIndex = hierarchicalOrderIndex(p, q);
73 return (_hierarchicalIndex >= 0);
74 }
75
76 static int hierarchicalOrderIndex(int P, int Q);
77
81 static inline int hierarchicalPOrder(int index) { assert(index >= -1 && index < _hTableNumUsedSlots); return index == -1 ? 0 : _hTable[index].first; }
82
86 static inline int hierarchicalQOrder(int index) { assert(index >= -1 && index < _hTableNumUsedSlots); return index == -1 ? 0 : _hTable[index].second; }
87
88 static int newMeshId(GmCellMesh* mesh, GmpCellMeshDataBase* data);
89
91 static inline GmCellMesh* mesh(int meshId) { assert(meshId >= 0 && meshId < GMP_GEMAMESH_MAX_NUM_MESHES); return _meshTable[meshId]; }
92
94 static inline GmpCellMeshDataBase* meshData(int meshId) { assert(meshId >= 0 && meshId < GMP_GEMAMESH_MAX_NUM_MESHES); return _meshDataTable[meshId]; }
95
97 int _meshId;
98
103
108};
109
110
111
119template <template <class> class Vector>
120class GMP_GEMAMESH_API_EXPORT GmpCellMeshData : public GmpCellMeshDataBase
121{
122public:
123
124 // CellPrototype and GhostCellPrototype can be used to cast a GmCell* into the "real"
125 // implementation class. This derives from the fact that we know that the cell is a
126 // subclass of GmpCell or GmpGhostCell and that the memory layout is independent of
127 // the template parameters. Of course the casted object can not be used to call any
128 // virtual functions. It can only be used to access attributes or call non virtual
129 // functions like offset(). See comments on the "IMPORTANT considerations:" comment
130 // on gmpCell.h, just above the GmpCellFactory() function definition.
131 // Not needing this casts would be nice, but that is difficult to achieve without
132 // adding virtual functions to GmCell that would be tied to implementation details
133 // of how our data is structured, like the offset field. That information does not
134 // belong in GmCell since it might not even exist in another mesh implementation!
135 using CellPrototype = GmpCell <GmCell, GmLuaCell, GmpCellMeshData<Vector>, GM_BAR2, 2>;
137
139
141
142 void clear(GmCellMesh* mesh);
143 void releaseMemory(bool clearBoundaryData = true);
144
146 GmCell* cell(int cellId) const { return (GmCell*)_cells.iptr(cellId * _cellSize); }
147
151 int* cellPropertiesPtr(int cellId) { assert(_propertySets.size() > 0); return _cellPropertyIndices.iptr(cellId * _propertySets.size()); }
152
154 int* cellNodesPtr(int offset) { return _cellNodeIndices.iptr(offset); }
155
157 int addCells(GmCellMesh* mesh, int* addedCellsByType, bool allocCells,
158 bool updateValueSets, GmPCR* pcr, const GmLogCategory& logger)
159 {
160 assert(addedCellsByType);
161 return addCellsImpl(mesh, addedCellsByType, 0, 0, allocCells, updateValueSets, pcr, logger);
162 }
163
165 int addCells(GmCellMesh* mesh, int numCells, int numCellNodes, GmPCR* pcr, const GmLogCategory& logger)
166 {
167 return addCellsImpl(mesh, NULL, numCells, numCellNodes, false, false, pcr, logger);
168 }
169
170 bool reorderCells(GmPCR* pcr, const QMap<int, int>& partOrigToLocOrder, const QVector<int>& partLocToOrigOrder);
171 void adjustCellIncidences(GmPCR* pcr, bool ghostSupport);
172
173 bool checkAndCollectStatistics(GmCellMesh* mesh, int* addedCellsByType, int* nAddedCells,
174 int* nAddedNodes, int* maxNumCellNodes, bool* hasSolidElements,
175 const GmLogCategory& logger);
176
177 void destroyCellsInRange(int first);
178
179 void updateCellNodeOffset(GmCell* c, int offset);
180
181 int addCellGroup(QString groupName);
182 bool addCellsToGroup(int groupId, const QVector<int>& cellIds);
183 bool addCellsToGroup(int groupId, const QVector<QPair<int, int>>& cellIds);
184
186 bool cellIsTopologyIndexed(int cellId) const { return _topology && _topology->cellIsIndexed(cellId); }
187
188 bool buildTopologyStructure(const GmCellMesh* mesh, GmpNodeMeshData<Vector>* nodeData,
189 GmSimulationData* simData, const GmLogCategory& logger);
190 void clearTopology();
191 bool topologyMeshChanged();
192
193 size_t cellMemory() const;
194 size_t cellGroupsMemory() const;
195 size_t cellBoundariesMemory() const;
196
197private:
198 int addCellsImpl(GmCellMesh* mesh, int* addedCellsByType, int numCells, int numCellNodes,
199 bool allocCells, bool updateValueSets, GmPCR* pcr, const GmLogCategory& logger);
200
201 bool resizeGaussValueSets (GmElementMesh* emesh, int* addedCellsByType, int offset = 0);
202 void restoreGaussValueSets(GmElementMesh* emesh, int oldNumCells);
203
204public:
207
208 GmpCellAllocator _cellAllocator;
209
214
219 Vector<char> _cells;
220
228
235 Vector<int> _cellNodeIndices;
236
241
244
246 int _cellsByType[GM_NUM_CELL_TYPES];
247
249 int _activeCellsByType[GM_NUM_CELL_TYPES];
250
253
256
259
262
265
268
273
278
283
289
291};
292
293#endif
A helper class to implement state dump operations for a GmpCellMeshData<Vector> object.
Definition gmpCellDataDump.h:43
Class for storing cell data, without ghost nodes support.
Definition gmpCell.h:132
A non template base class for GmpCellMeshData storing the needed static attributes to controll the gl...
Definition gmpCellMeshData.h:53
GmpCellMeshDataBase(GmCellMesh *mesh)
Constructor.
Definition gmpCellMeshData.h:56
bool hierarchicalElements() const
Returns true if the mesh uses hierarchical elements, false otherwise.
Definition gmpCellMeshData.h:66
static GmpCellMeshDataBase * meshData(int meshId)
Returns the mesh data pointer associated with the given mesh id.
Definition gmpCellMeshData.h:94
static int _hTableNumUsedSlots
The number of used entries in _hTable.
Definition gmpCellMeshData.h:105
static int hierarchicalPOrder(int index)
Returns the P order for hierarchical elements associated with the given index (returned by hierarchic...
Definition gmpCellMeshData.h:81
static int hierarchicalQOrder(int index)
Returns the Q order for hierarchical elements associated with the given index (returned by hierarchic...
Definition gmpCellMeshData.h:86
~GmpCellMeshDataBase()
Destructor. Clears our entry in the global _meshTable and _meshDataTable.
Definition gmpCellMeshData.h:63
bool setHierarchicalIndex(int p, int q)
Sets the hierarchical index for this mesh from the given P & Q element orders. Returns false if not p...
Definition gmpCellMeshData.h:69
static GmCellMesh * mesh(int meshId)
Returns the mesh pointer associated with the given mesh id.
Definition gmpCellMeshData.h:91
int _hierarchicalIndex
The hierarchical order index in _hTable if this mesh has hierarchical elements or -1 if elements are ...
Definition gmpCellMeshData.h:102
Auxiliar structure used to share data between GmpCellMesh and GmpMeshLoader. All fields are public si...
Definition gmpCellMeshData.h:121
UibhmTopologyBase::CheckOptions _topoCheckOptions
Etxra check options when building the topology.
Definition gmpCellMeshData.h:288
int _numConstructed
The number of cells in _cells that where effectively in-place constructed (by a call to _cellAllocato...
Definition gmpCellMeshData.h:227
int * cellPropertiesPtr(int cellId)
Returns a pointer to the vector region where the property indices for the given cell are stored....
Definition gmpCellMeshData.h:151
int _numCells
The total number of cells.
Definition gmpCellMeshData.h:205
int * cellNodesPtr(int offset)
Returns a pointer to the vector region where the node indices for the given cell are stored.
Definition gmpCellMeshData.h:154
Vector< int > _cellPropertyIndices
A vector with size equal to _numCells * _propertySets.size() continuously storing the cell's property...
Definition gmpCellMeshData.h:243
int _cellSize
The allocator function used to instance cell object in-place on the _cells vector.
Definition gmpCellMeshData.h:213
GmCell * cell(int cellId) const
Returns a pointer to the given cell object.
Definition gmpCellMeshData.h:146
bool _topoBuildError
Set to true if we tried, unsuccessfully, to build _topology. Reset when the mesh is changed.
Definition gmpCellMeshData.h:286
QMap< QString, GmCellBoundary * > _boundaryGroups
A map with the definition of each boundary group associated with the mesh. Map entries are instances ...
Definition gmpCellMeshData.h:282
int _maxNumGhostNodes
The maximum number of ghost nodes among mesh cells.
Definition gmpCellMeshData.h:261
QList< GmPropertySet * > _propertySets
The list of property sets "indexed" by every cell. The order of property sets in this list is the sam...
Definition gmpCellMeshData.h:240
QStringList _cellGroupIds
A list with available cell group names.
Definition gmpCellMeshData.h:267
Vector< int > _cellNodeIndices
The list of cell nodes storing, in order, the set of all cell nodes. Its size is equal to the sum of ...
Definition gmpCellMeshData.h:235
QList< int * > _cellGroupCells
A list with a vector of cell Ids for each cell group. Its size should be equal to _cellGroupIds....
Definition gmpCellMeshData.h:277
GmpCellDataDump< Vector > * _dumper
The object responsible for state dump operations.
Definition gmpCellMeshData.h:290
QList< int > _numCellsInGroup
A list with the number of cells in each cell group. Its size should be equal to _cellGroupIds....
Definition gmpCellMeshData.h:272
int addCells(GmCellMesh *mesh, int *addedCellsByType, bool allocCells, bool updateValueSets, GmPCR *pcr, const GmLogCategory &logger)
See comments on addCellsImpl()
Definition gmpCellMeshData.h:157
GmCellMeshTopology * _topoQuery
The query object, if already built.
Definition gmpCellMeshData.h:285
Vector< char > _cells
The cell vector. Size equal to _numCells * _cellSize. Since the type and size of a cell is only known...
Definition gmpCellMeshData.h:219
bool _hasSolidElements
Set to true if there is at least one solid element in _cellsByType.
Definition gmpCellMeshData.h:255
bool _topoBuildEdgeMap
Should we build the edge map when building the topology?
Definition gmpCellMeshData.h:287
bool cellIsTopologyIndexed(int cellId) const
Returns true if the mesh has a topology structure and the cell has already been added to that structu...
Definition gmpCellMeshData.h:186
bool _singleCellType
If set to true, the mesh has only one cell type and other types can NOT be added to it.
Definition gmpCellMeshData.h:252
int _maxTotalNumNodes
The maximum number of nodes (common + ghost) among mesh cells.
Definition gmpCellMeshData.h:264
int addCells(GmCellMesh *mesh, int numCells, int numCellNodes, GmPCR *pcr, const GmLogCategory &logger)
See comments on addCellsImpl()
Definition gmpCellMeshData.h:165
int _numActiveCells
The total number of active cells in the mesh.
Definition gmpCellMeshData.h:206
UibhmTopologyBase * _topology
The topology structure, if already built.
Definition gmpCellMeshData.h:284
int _maxNumNodes
The maximum number of nodes among mesh cell types in use by the mesh.
Definition gmpCellMeshData.h:258
Adds ghost node support to GmpCell.
Definition gmpCell.h:266
Auxiliar interface used to share node data between the mesh implementation and GmpMeshLoader....
Definition gmpNodeMeshData.h:53
Interface for accessing the "exported" functions of a UibhmTopology class instance,...
Definition uibhmTopology.h:94
CheckOptions
Check options for mesh initialization.
Definition uibhmTopology.h:99
GM_BAR2
GM_NUM_CELL_TYPES
#define GM_MAX_ORTHOGONAL_POL_ORDER
Declaration of the GmpCellAllocator type.
GmCell *(* GmpCellAllocator)(void *addr, int meshId, GmCellType type, int hindex, int id, int offset)
Typedef for a function that can construct a single cell of the given type, placing it at the provided...
Definition gmpCellAllocator.h:36
Declaration of useful configuration definitions for the plugin library.
#define GMP_GEMAMESH_MAX_HTYPES
The maximum number of distinct hierarchical type orders that can be used simmultaneously....
Definition gmpGemaMeshConfig.h:63
#define GMP_GEMAMESH_MAX_NUM_MESHES
The maximum number of allowed meshes.
Definition gmpGemaMeshConfig.h:52
Declaration of the UibhmTopology familiy of classes.