GemaMesh
The GeMA Mesh Plugin
gmpGemaCellMeshData.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_GEMA_CELL_MESH_DATA_H_
25 #define _GEMA_PLUGIN_GEMA_CELL_MESH_DATA_H_
26 
27 #include "gmpCellMeshData.h"
28 #include "gmpGemaCell.h"
29 
30 #include <gmLuaCell.h>
31 #include <gmStateDump.h>
32 
33 
35 template <template <class> class Vector>
36 struct GMP_GEMAMESH_API_EXPORT GmpGemaCellMeshData : public GmpCellMeshData<Vector>
37 {
40  : GmpCellMeshData<Vector>(mesh)
41  {}
42 
44  virtual ~GmpGemaCellMeshData() { releaseOwnMemory(); }
45 
46  virtual Vector<int>* cellNodesVector() { return &_cellNodeIndices; }
47 
48  virtual void updateCellNodeOffset(GmCell* c, int offset)
49  {
50  assert(offset >= 0 && offset < _cellNodeIndices.size());
51  // This is ugly but we are sure that the cell is a decendent of GmGemaCell and also
52  // that class sizes are independent of the type and size template parameters so we
53  // can get away with accessing the _nodeOffset field as is done and explained in
54  // cellMemory().
55  // TODO: find a better way (without adding methods to GmCell)
57  gc->setOffset(offset);
58  }
59 
60  // See comments on the base class
61  virtual void releaseMemory(bool clearBoundaryData = true)
62  {
63  GmpCellMeshData::releaseMemory(clearBoundaryData);
64  releaseOwnMemory();
65  }
66 
68  int* cellNodesPtr(int offset) { return _cellNodeIndices.iptr(offset); }
69 
71  virtual size_t cellMemory() const
72  {
73  // - The base size of each cell is one id + a pointer to the property list + pointer to the cell node list
74  // - If ghost nodes are allowed, each cell also stores a QVarLengthArray<int> with ghost entries (contributing
75  // with the vector size + the number of ghost nodes)
76  // - The property list has a size equal to the number of cells * the number of property sets
77  // - The node list has a size equal to the number of cells * the number of nodes per cell (different
78  // per cell type).
79  // - If dump aux vectors are different from NULL, they should also be accounted for
80 
81  // In the code bellow we assume that the basic sizeof() of a cell type independs if it is a GmCell
82  // or a GmElement. It is also independent of the cell type or the use of hierarchical elements
88 
89  // Base size for the cell vector
90  size_t size = _cells.usedMemory();
91 
92  // The size for each, independently allocated, cell structure
93  size += _numCells * (_ghostEnabled ? sizeof(GmpGemaGhostCell<GmCell, GmLuaCell, GmpGemaCellMeshData<Vector>, GM_BAR2, 2, 2>) :
95 
96  // Property set indices per cell
97  size += _cellPropertyIndices.usedMemory();
98 
99  // Node indices per cell
100  size += _cellNodeIndices.usedMemory();
101 
102  if(_maxNumGhostNodes > 0) // A mesh can have ghost nodes enabled but no ghost nodes...
103  {
104  for(int i = 0; i<_numCells; i++)
105  {
106  // The cast bellow works since cell class layouts are independent of the element type and number of
107  // nodes (see asserts above). Keep in mind that we are NOT going to call any methods that depend
108  // on the cell type / number of nodes. Those would NOT work with the said cast.
110 
111  size += c->_ghostList.capacity() * sizeof(int);
112  }
113  }
114 
115  // Account for dump vectors
116  if(_cellDumpTypeActiveData)
117  size += _numCells * sizeof(char);
118 
119  if(_cellDumpGhostData)
120  size += _cellDumpGhostDataSize * sizeof(int);
121 
122  return size;
123  }
124 
127  GmStateDump* state, int groupId)
128  {
129  // Adds the buffer item used to store cell nodes before calling the base class
130  // This is needed to make sure that the node data vector is loaded before
131  // the other cell information and so is available when recreating cell objects
133  cndi = new GmStateDumpSDVectorDataItem<Vector<int>>(state->nextIdInGroup(groupId), &_cellNodeIndices,
134  false, state->logger(), false, "CellMeshDataCellNodes");
135  state->addStateItem(cndi, groupId);
136 
137  // Call base class
138  return GmpCellMeshData::addStateGeometryData(simData, mesh, alloc, state, groupId);
139  }
140 
141 
148  Vector<int> _cellNodeIndices;
149 
150 private:
151 
154  {
155  _cellNodeIndices.clear();
156  }
157 };
158 
159 #endif
160 
virtual bool addStateGeometryData(GmSimulationData *simData, GmMesh *mesh, GmpMeshLoaderCellAllocator alloc, GmStateDump *state, int groupId)
Adds to the state dump the items used for storing cell information, together with number os cells by ...
Definition: gmpCellMeshData.cpp:671
void releaseOwnMemory()
Releases memory owned directly by this class, without releasing memory owned by the base class.
Definition: gmpGemaCellMeshData.h:153
An auxiliar class that can be used as the base class for GmpCellBase for Hierarchical elements....
Definition: gmpCellBase.h:323
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: gmpGemaCellMeshData.h:148
GmCell *(* GmpMeshLoaderCellAllocator)(GmCellMesh *mesh, int meshId, GmCellType type, int hindex, int id, int offset)
Typedef for a function that can allocate a single cell of the given type and initialize it with the g...
Definition: gmpMeshLoaderAllocator.h:36
GM_QUAD4
virtual bool addStateGeometryData(GmSimulationData *simData, GmMesh *mesh, GmpMeshLoaderCellAllocator alloc, GmStateDump *state, int groupId)
Add to the state dump item the vectors storing cell node information.
Definition: gmpGemaCellMeshData.h:126
GmpGemaCellMeshData(GmCellMesh *mesh)
Constructor.
Definition: gmpGemaCellMeshData.h:39
int * cellNodesPtr(int offset)
Returns a pointer to vector region where the node indices for the given cell are stored.
Definition: gmpGemaCellMeshData.h:68
GM_HQUADP
int addStateItem(GmValueAccessor *ac, const GmMesh *mesh, bool fixedHint, bool ownership=false, int groupId=-1, QString prefix="")
GM_BAR2
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: gmpCellBase.h:314
Basic implementation for a "Gema cell", adding the information about the offset of its nodes in the g...
Definition: gmpGemaCell.h:37
GM_HEX8
Basic implementation for a GmpGemaGhostCell cell, based on the GmpGhostCellBase class.
Definition: gmpGemaCell.h:98
Declaration of the GmpCellMeshData structure.
Auxiliar structure used to share data between GmpGemaCellMesh and GmpMeshLoader.
Definition: gmpGemaCellMeshData.h:36
virtual size_t cellMemory() const
Returns the approximate memory used for storing mesh cells.
Definition: gmpGemaCellMeshData.h:71
const GmLogCategory & logger() const
int nextIdInGroup(int groupId)
virtual void releaseMemory(bool clearBoundaryData=true)
Releases all the memory DIRECTLY owned by the object.
Definition: gmpCellMeshData.cpp:460
Auxiliar structure used to share data between GmpXxxCellMeshBase and GmpMeshLoader.
Definition: gmpCellMeshData.h:123
Declaration of the GmpGemaCell class.
virtual void releaseMemory(bool clearBoundaryData=true)
Releases all the memory DIRECTLY owned by the object.
Definition: gmpGemaCellMeshData.h:61
ControlSize capacity() const
virtual ~GmpGemaCellMeshData()
Virtual destructor.
Definition: gmpGemaCellMeshData.h:44
int _numCells
The total number of cells.
Definition: gmpCellMeshData.h:178