24#ifndef _GEMA_PLUGIN_CELL_BASE_H_
25#define _GEMA_PLUGIN_CELL_BASE_H_
38#include <QVarLengthArray>
54#define GM_CELLBASE_ACTIVE_MASK (~(~0u >> 1))
59#define GM_CELLBASE_MESH_MASK ((~(~0u >> GMP_GEMAMESH_CELL_MESH_BITS)) >> 1)
62#define GM_CELLBASE_CELL_MASK (~(GM_CELLBASE_ACTIVE_MASK | GM_CELLBASE_MESH_MASK))
64static_assert((GM_CELLBASE_ACTIVE_MASK | GM_CELLBASE_MESH_MASK | GM_CELLBASE_CELL_MASK) == ~0u,
"Invalid masks");
65static_assert((GM_CELLBASE_ACTIVE_MASK & GM_CELLBASE_MESH_MASK) == 0,
"Invalid masks");
66static_assert((GM_CELLBASE_ACTIVE_MASK & GM_CELLBASE_CELL_MASK) == 0,
"Invalid masks");
67static_assert((GM_CELLBASE_MESH_MASK & GM_CELLBASE_CELL_MASK) == 0,
"Invalid masks");
72static inline bool GmpCellIsActive(
int cellId) {
return !(cellId & GM_CELLBASE_ACTIVE_MASK); }
75static inline int GmpCellMakeActive(
int cellId) {
return cellId & (~GM_CELLBASE_ACTIVE_MASK); }
78static inline int GmpCellMakeInactive(
int cellId) {
return cellId | GM_CELLBASE_ACTIVE_MASK; }
81static inline int GmpCellSetActiveFlag(
int cellId,
bool active) {
return active ? GmpCellMakeActive(cellId) : GmpCellMakeInactive(cellId); }
88static inline int GmpCellIndex(
int cellId) {
return (cellId & GM_CELLBASE_CELL_MASK); }
91static inline int GmpCellUpdateMeshIndex(
int id,
int oldId) {
return (
id & ~GM_CELLBASE_MESH_MASK) | (oldId & GM_CELLBASE_MESH_MASK); }
94static inline int GmpCellEncodeId(
int cellIndex,
int meshIndex,
bool active)
131template <
class Base,
class Proxy,
class CellMeshData, GmCellType T,
int N>
class GmpCell :
public Base
137 assert(N == geometry().numNodes());
138 _cellId = GmpCellEncodeId(cellId, meshId,
true);
143 virtual int cellId()
const {
return GmpCellIndex(
_cellId); }
146 virtual GmCellMesh* mesh()
const {
return CellMeshData::mesh(GmpCellMeshIndex(
_cellId)); }
149 virtual bool active()
const {
return GmpCellIsActive(
_cellId); }
152 virtual void setActive(
bool active)
154 if(active == this->active())
168 virtual int numNodes()
const {
return N; }
171 virtual int nodeIndex(
int localIndex)
const
173 assert(localIndex >= 0 && localIndex < N);
178 virtual void nodes(
int* nodeList,
bool ghost)
const
180 Q_UNUSED(ghost); assert(!ghost);
185 virtual bool setNodes(
const int* nodeList)
191 for(
int i = 0; i < N; i++)
193 int node = nodeList[i];
194 if(node < 0 || node >= nnodes)
200 if(
meshData()->cellIsTopologyIndexed(cellId()))
209 virtual int propertyIndex(
int propertySet)
const
211 assert(propertySet >= 0 && propertySet < mesh()->propertySets().size());
212 return meshData()->cellPropertiesPtr(cellId())[propertySet];
216 virtual bool setProperties(
const int* propList,
int nprop)
219 assert(nprop == mesh()->propertySets().size());
221 memcpy(
meshData()->cellPropertiesPtr(cellId()), propList, nprop*
sizeof(
int));
239 id = GmpCellUpdateMeshIndex(
id,
_cellId);
241 _cellId = GmpCellSetActiveFlag(
id, active());
264template <
class Base,
class Proxy,
class CellMeshData, GmCellType T,
int N>
class GmpGhostCell
265 :
public GmpCell<Base, Proxy, CellMeshData, T, N>
270 :
GmpCell<Base, Proxy, CellMeshData, T, N>(meshId, cellId,
offset) {}
276 virtual int addGhostNode(
int globalIndex)
279 if(index < 0 || index >= mesh()->numGhostNodes())
289 virtual void setGhostNodes(
int* ghostNodes,
int numNodes)
296 virtual void removeGhostNode(
int localIndex)
298 assert(localIndex >= N && localIndex < N + (
int)
_ghostList.
size());
303 virtual int nodeIndex(
int localIndex)
const
305 assert(localIndex >= 0 && localIndex < N + (
int)
_ghostList.
size());
306 return localIndex < N ? GmpCell<Base, Proxy, CellMeshData, T, N>::nodeIndex(localIndex) :
_ghostList[localIndex-N];
310 virtual void nodes(
int* nodeList,
bool ghost)
const
389#define STD_TEMPLATE_PARS(X) X<GmCell, GmLuaCell, GmpCellMeshData<GmSingleVector>, GM_BAR2, 2>
391static_assert(
sizeof(
GmCell) ==
sizeof(
GmElement),
"Unexpected cell base class size");
392static_assert(
sizeof(
GmCell) ==
sizeof(
GmHElement),
"Unexpected cell base class size");
393static_assert(
sizeof(STD_TEMPLATE_PARS(
GmpCell)) ==
sizeof(GmpCell <GmElement, GmLuaElement, GmpCellMeshData<GmSingleVector>,
GM_BAR2, 2>),
"Unexpected cell size");
394static_assert(
sizeof(STD_TEMPLATE_PARS(
GmpCell)) ==
sizeof(GmpCell <GmCell, GmLuaCell, GmpCellMeshData<GmSingleVector>,
GM_HEX8, 8>),
"Unexpected cell size");
399static_assert(
sizeof(STD_TEMPLATE_PARS(
GmpCell)) == 16,
"Unexpected cell size value");
400static_assert(
sizeof(STD_TEMPLATE_PARS(
GmpGhostCell)) == 32,
"Unexpected cell size value");
409template <
template<
class,
class,
class, GmCellType,
int>
class T,
class Base,
class Proxy,
class CellMeshData>
410GmCell* GmpCellFactory(
void* addr,
int meshId,
GmCellType type,
int hindex,
int id,
int offset)
414 assert(hindex == -1);
417 static_assert(std::is_base_of<STD_TEMPLATE_PARS(
GmpGhostCell), STD_TEMPLATE_PARS(T)>::value ||
418 std::is_base_of<STD_TEMPLATE_PARS(
GmpCell), STD_TEMPLATE_PARS(T)>::value,
419 "Expecting T to inherit from GmpCell or from GmpGhostCell");
422 static_assert(
sizeof(Base) ==
sizeof(
GmCell),
"Unexpected cell base class size");
425#error Create Cell macro already defined
429#define CREATE_CELL(type, nn) new (addr) T<Base, Proxy, CellMeshData, type, nn>(meshId, id, offset)
434 case GM_BAR2:
return CREATE_CELL(GM_BAR2, 2);
435 case GM_BAR3:
return CREATE_CELL(GM_BAR3, 3);
436 case GM_BAR3D2:
return CREATE_CELL(GM_BAR3D2, 2);
437 case GM_BAR3D3:
return CREATE_CELL(GM_BAR3D3, 3);
438 case GM_QUAD4:
return CREATE_CELL(GM_QUAD4, 4);
439 case GM_QUAD8:
return CREATE_CELL(GM_QUAD8, 8);
440 case GM_QUAD9:
return CREATE_CELL(GM_QUAD9, 9);
441 case GM_QUAD3D4:
return CREATE_CELL(GM_QUAD3D4, 4);
442 case GM_QUAD3D8:
return CREATE_CELL(GM_QUAD3D8, 8);
443 case GM_TRI3:
return CREATE_CELL(GM_TRI3, 3);
444 case GM_TRI6:
return CREATE_CELL(GM_TRI6, 6);
445 case GM_TRI3D3:
return CREATE_CELL(GM_TRI3D3, 3);
446 case GM_TRI3D6:
return CREATE_CELL(GM_TRI3D6, 6);
447 case GM_INT2DL4:
return CREATE_CELL(GM_INT2DL4, 4);
448 case GM_INT2DL6:
return CREATE_CELL(GM_INT2DL6, 6);
449 case GM_INT2DQ6:
return CREATE_CELL(GM_INT2DQ6, 6);
451 case GM_HEX8:
return CREATE_CELL(GM_HEX8, 8);
452 case GM_HEX20:
return CREATE_CELL(GM_HEX20, 20);
453 case GM_HEX27:
return CREATE_CELL(GM_HEX27, 27);
454 case GM_TET4:
return CREATE_CELL(GM_TET4, 4);
455 case GM_TET10:
return CREATE_CELL(GM_TET10, 10);
456 case GM_INT3DL8:
return CREATE_CELL(GM_INT3DL8, 8);
457 case GM_INT3DL12:
return CREATE_CELL(GM_INT3DL12, 12);
458 case GM_INT3DQ16:
return CREATE_CELL(GM_INT3DQ16, 16);
460 case GM_INT3DL6:
return CREATE_CELL(GM_INT3DL6, 6);
461 case GM_INT3DL9:
return CREATE_CELL(GM_INT3DL9, 9);
462 case GM_INT3DQ12:
return CREATE_CELL(GM_INT3DQ12, 12);
464 case GM_WEDGE6:
return CREATE_CELL(GM_WEDGE6, 6);
465 case GM_WEDGE15:
return CREATE_CELL(GM_WEDGE15, 15);
466 case GM_PYRA5:
return CREATE_CELL(GM_PYRA5, 5);
467 case GM_PYRA13:
return CREATE_CELL(GM_PYRA13, 13);
477template <
template<
class,
class,
class, GmCellType,
int>
class T,
class Base,
class Proxy,
class CellMeshData>
481 return sizeof(T<Base, Proxy, CellMeshData, GM_BAR2, 2>);
485template <
template<
class,
class,
class, GmCellType,
int>
class T,
class CellMeshData>
486GmCell* GmpHElementFactory(
void* addr,
int meshId,
GmCellType type,
int hindex,
int id,
int offset)
491#if GMP_GEMAMESH_MAX_HTYPES != 3
492#error Unexpected value for GMP_GEMAMESH_MAX_HTYPES
496#error Create Cell macro already defined
500#define CREATE_CELL(i, type, nn) new (addr) T<GmpHElementBase<i>, GmLuaHElement, CellMeshData, type, nn>(meshId, id, offset)
505 if (hindex == 0)
return CREATE_CELL(0, GM_HQUADP, 4);
506 else if(hindex == 1)
return CREATE_CELL(1, GM_HQUADP, 4);
507 else if(hindex == 2)
return CREATE_CELL(2, GM_HQUADP, 4);
511 if (hindex == 0)
return CREATE_CELL(0, GM_DGQUAD, 4);
512 else if(hindex == 1)
return CREATE_CELL(1, GM_DGQUAD, 4);
513 else if(hindex == 2)
return CREATE_CELL(2, GM_DGQUAD, 4);
517 if (hindex == 0)
return CREATE_CELL(0, GM_HHEXP, 8);
518 else if(hindex == 1)
return CREATE_CELL(1, GM_HHEXP, 8);
519 else if(hindex == 2)
return CREATE_CELL(2, GM_HHEXP, 8);
523 if (hindex == 0)
return CREATE_CELL(0, GM_DGHEX, 8);
524 else if(hindex == 1)
return CREATE_CELL(1, GM_DGHEX, 8);
525 else if(hindex == 2)
return CREATE_CELL(2, GM_DGHEX, 8);
537template <
template<
class,
class,
class, GmCellType,
int>
class T,
class CellMeshData>
virtual void ghostNodesUpdated(int nghost, int ntotal)
virtual void activeCellUpdated(GmCellType type, bool active)=0
virtual int numNodes() const=0
static int clearGhostFlag(int nodeIndex)
static int setGhostFlag(int nodeIndex)
bool resize(ControlSize newSize, GmPODGrowT grow=Grow)
void remove(ControlSize index, ControlSize numValues)
Class for storing cell data, without ghost nodes support.
Definition gmpCell.h:132
GmpCell(int meshId, int cellId, int offset)
Constructs a cell given its id, associated mesh id and node offset in the mesh data structure.
Definition gmpCell.h:135
int offset() const
Returns the offset in the global mesh cell nodes vector for this cell. Not part of the GmCell API and...
Definition gmpCell.h:249
int _nodeOffset
Index in the mesh data for the first node for this cell.
Definition gmpCell.h:259
int _cellId
The cell index inside the mesh. MSB is used to control if the cell is active or not.
Definition gmpCell.h:258
CellMeshData * meshData() const
Returns the mesh data object associated with this cell's mesh.
Definition gmpCell.h:256
void replaceCellId(int id, bool keepActiveFlag)
Updates the cell id. For those who really know what they are doing. This function is a very specific ...
Definition gmpCell.h:237
void setOffset(int offset)
Updates the cell offset. Not part of the GmCell API and should NOT be marked as virtual.
Definition gmpCell.h:252
static GmpCellMeshDataBase * meshData(int meshId)
Returns the mesh data pointer associated with the given mesh id.
Definition gmpCellMeshData.h:94
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
Auxiliar structure used to share data between GmpCellMesh and GmpMeshLoader. All fields are public si...
Definition gmpCellMeshData.h:121
Adds ghost node support to GmpCell.
Definition gmpCell.h:266
GmpGhostCell(int meshId, int cellId, int offset)
Constructs a cell given its id, associated mesh id and node offset in the mesh data structure.
Definition gmpCell.h:269
GmPODVector< int, uint32_t, GmPODVectorFastGrow< uint32_t > > _ghostList
List storing cell ghost nodes. Uses a GmPODVector with size control based on a 32 bits value giving a...
Definition gmpCell.h:344
void replaceGhostNodes(int *ghostNodes, int numNodes)
Replaces the full set of ghost nodes of the cell. Unlike setGhostNodes(), does NOT calls GmCellMesh::...
Definition gmpCell.h:322
An auxiliar class that can be used as the base class for GmpCell for Hierarchical elements....
Definition gmpCell.h:355
static void pushObject(lua_State *L, Base *obj)
size_t GmPODVectorTightGrow(size_t s, size_t a)
Declaration of the GmpCellMeshData structure.
#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
#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
#define GMP_GEMAMESH_MAX_NUM_CELLS
The maximum number of allowed cells.
Definition gmpGemaMeshConfig.h:55