GemaCoreLib
The GeMA Core library
gmCellMesh.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_CELL_MESH_H_
25 #define _GEMA_CELL_MESH_H_
26 
27 #include "gmMesh.h"
28 #include "gmCell.h"
29 #include <assert.h>
30 #include <float.h>
31 
32 class GmCellAccessor;
33 class GmPropertySet;
34 class GmCellBoundary;
35 class GmCellGroupSet;
36 class GmCellMeshTopology;
37 
40 {
41 public:
42  GmCellMesh(GmSimulationData* simulation, QString id, QString description, const GmLogCategory& logger);
43  virtual ~GmCellMesh();
44 
46  virtual int numCells() const = 0;
47 
49  virtual int numActiveCells() const = 0;
50 
56  virtual const GmCell* cell(int cellIndex) const = 0;
57 
59  virtual GmCell* cell(int cellIndex) = 0;
60 
78  virtual const GmCellMeshTopology* topology(bool create = true) const { Q_UNUSED(create); return NULL; }
79 
85  virtual void clearTopology() {}
86 
95  virtual const int* numCellTypes() const = 0;
96 
105  virtual const int* numActiveCellTypes() const = 0;
106 
111  virtual int maxNumCellNodes() const = 0;
112 
125  virtual int maxNumCellGhostNodes() const { return 0; }
126 
142  virtual int maxTotalNumCellNodes() const { return maxNumCellNodes(); }
143 
151  virtual void ghostNodesUpdated(int nghost, int ntotal) { Q_UNUSED(nghost); Q_UNUSED(ntotal); }
152 
159  virtual void activeCellUpdated(GmCellType type, bool active) = 0;
160 
161  virtual bool isValid(QList<int>* nonValidIds = NULL, double tol = 1e-3) const;
162 
163  virtual bool isQualityGT(double minQuality) const;
164 
165  virtual void qualityHistogram(QVector<int>& hist, int nbins = 10) const;
166 
172  virtual double edgeMinLength() { return edgeStatistics()->_edgeMinLength; }
173 
179  virtual double edgeMaxLength() { return edgeStatistics()->_edgeMaxLength; }
180 
186  virtual double cellBboxMinLength() { return bboxStatistics()->_bboxMinLength; }
187 
193  virtual double cellBboxMaxLength() { return bboxStatistics()->_bboxMaxLength; }
194 
195  void clearCellStatistics();
196 
197  void printQualityHistogram(bool activeOnly = true) const;
198 
205  virtual QStringList cellGroupIds() const { return QStringList(); }
206 
214  virtual int numCellsInGroup(int groupIndex) const { Q_UNUSED(groupIndex); assert(0); return 0; }
215 
224  virtual const GmCell* cellInGroup(int groupIndex, int cellIndex) const { Q_UNUSED(groupIndex); Q_UNUSED(cellIndex); assert(0); return NULL; }
225 
227  virtual GmCell* cellInGroup(int groupIndex, int cellIndex) { Q_UNUSED(groupIndex); Q_UNUSED(cellIndex); assert(0); return NULL; }
228 
229 
234  virtual const QMap<QString, GmCellBoundary*>& cellBoundaryGroups() const = 0;
235 
243  virtual const QList<GmPropertySet*>& propertySets() const = 0;
244 
253  virtual int propertySetIndex(QString id) const = 0;
254 
255  virtual GmValueInfo* cellPropertyInfo (QString id) const;
256  virtual GmCellAccessor* cellPropertyAccessor(QString id, Unit desiredUnit, const GmLogCategory& logger) const;
257 
258  virtual QStringList cellAttributeIds() const;
259 
260  virtual GmValueInfo* cellAttributeInfo (QString id) const;
261  virtual GmCellAccessor* cellAttributeAccessor(QString id, Unit desiredUnit, const GmLogCategory& logger) const;
262  virtual GmCellAccessor* cellAttributeAccessor(QString id, int snum, bool locked, Unit desiredUnit, const GmLogCategory& logger) const;
263 
299  virtual int addCells(int* numCellTypes) { Q_UNUSED(numCellTypes); return -1; }
300 
305  virtual QList<int> addedCells() const { return QList<int>(); }
306 
310  virtual void clearAddedCells() {}
311 
320  virtual int addCellGroup(QString groupName) { Q_UNUSED(groupName); return -1; }
321 
330  virtual bool addCellsToGroup(int groupId, const QVector<int>& cellIds) { Q_UNUSED(groupId); Q_UNUSED(cellIds); return false; }
331 
342  virtual bool addCellsToGroup(int groupId, const QVector<QPair<int, int>>& cellIds) { Q_UNUSED(groupId); Q_UNUSED(cellIds); return false; }
343 
344  virtual bool addCellAttributeSet(GmValueInfo* info);
345  virtual void removeCellAttributeSet(QString id);
346  virtual void clearCellAttributeSets();
347  virtual void clearCellAttributeSetsData();
348 
349 
350  virtual bool saveState (GmValueSet::SaveStateMode mode, const GmLogCategory& logger);
351  virtual bool saveCellAttributeState (QString id, GmValueSet::SaveStateMode mode, const GmLogCategory& logger);
352  virtual int numCellAttributeStates (QString id) const;
353  virtual QString cellAttributeStateTag (QString id, int snum) const;
354  virtual double cellAttributeStateTime (QString id, int snum) const;
355  virtual void setCellAttributeStateTag (QString id, int snum, QString tag);
356  virtual void setCellAttributeStateTime(QString id, int snum, double time);
357 
358  virtual void printParameters(const GmLogCategory& logger);
359  virtual void printValues (const GmLogCategory& logger, int options = GM_PRINT_DEFAULT);
360 
362  virtual size_t cellMemory() const = 0;
363 
365  virtual size_t cellGroupsMemory() const = 0;
366 
368  virtual size_t cellBoundariesMemory() const = 0;
369 
370 
374  const QList<GmValueSet*>& cellValueSets() const { return _cellAttributesData; }
375 
376  const GmCellGroupSet* cellGroupSet(const QList<int>& groupIdList, bool disjoint);
377  void clearCellGroupSetsData(bool keepMeshSet);
378 
379 protected:
380  virtual bool addStateAccessorData (GmStateDump* state, int groupId);
381  virtual bool fillDumpControlMapData (QVariantMap* map, const GmLogCategory& logger);
382  virtual bool dumpControlMapDataLoaded(QVariantMap* map, const GmLogCategory& logger);
383 
384 private:
385 
386  // Structure collecting mesh edge statistics
388  {
389  double _edgeMinLength;
390  double _edgeMaxLength;
391 
392  GmCellEdgeStatistics() : _edgeMinLength(DBL_MAX), _edgeMaxLength(-DBL_MAX) {}
393  };
394 
395  // Structure collecting mesh bbox statistics
397  {
398  double _bboxMinLength;
399  double _bboxMaxLength;
400 
401  GmCellBboxStatistics() : _bboxMinLength(DBL_MAX), _bboxMaxLength(-DBL_MAX) {}
402  };
403 
404  GmCellEdgeStatistics* edgeStatistics();
405  GmCellBboxStatistics* bboxStatistics();
406 
407  void computeEdgeLength (GmCellEdgeStatistics* stat);
408  void computeCellBboxLength(GmCellBboxStatistics* stat);
409 
412 
414 
418 };
419 
420 
422 template <class T> class GmForeachCellHelperClass
423 {
424 public:
426  GmForeachCellHelperClass(const T* container, bool activeOnly)
427  {
428  _control = 1;
429  _n = container->numCells();
430  for(_index = 0; activeOnly && _index<_n && !container->cell(_index)->active(); _index++);
431  }
432 
434  void inc(const T* container, bool activeOnly) { for(_index++; activeOnly && _index<_n && !container->cell(_index)->active(); _index++); }
435 
436  int _index;
437  int _n;
438  int _control;
439 };
440 
458 #define GmForeachCellHelper(variable, container, contType, cellType, activeOnly) \
459 for(GmForeachCellHelperClass<contType> it(container, activeOnly); it._control && it._index<it._n; it.inc(container, activeOnly), it._control ^= 1) \
460  for(variable = (cellType*)container->cell(it._index); it._control; it._control = 0)
461 
462 
478 #define GmForeachActiveCell(variable, mesh) GmForeachCellHelper(variable, mesh, GmCellMesh, GmCell, true)
479 
481 #define GmForeachCell(variable, mesh, activeOnly) GmForeachCellHelper(variable, mesh, GmCellMesh, GmCell, activeOnly)
482 
483 
484 #endif
485 
Auxiliar class used to store the definition of a value. It can be used to store informations about st...
Definition: gmValueInfo.h:126
virtual void clearTopology()
If the mesh suppports the topology capability (hasCapability("topology") returns true),...
Definition: gmCellMesh.h:85
Interface storing property descriptions and values.
Definition: gmPropertySet.h:37
double _edgeMinLength
Minimun edge length in the whole mesh.
Definition: gmCellMesh.h:389
QMutex _meshStatsMutex
Mutex protecting the creation of the statistics objects.
Definition: gmCellMesh.h:417
int _index
The current index.
Definition: gmCellMesh.h:436
Interface for helping managing mesh cell groups and returning the elements in their union.
Definition: gmCellGroupSet.h:34
virtual void clearAddedCells()
Method called by the assembler to clear the internal list used to track added cells....
Definition: gmCellMesh.h:310
virtual QStringList cellGroupIds() const
Returns a list with the names of the available cell groups.
Definition: gmCellMesh.h:205
The GmStateDump class presents a higher level of abstraction over GmMemoryDump, storing accessor data...
Definition: gmStateDump.h:52
Helper class for the GmForeachActiveXxxx() family of macros.
Definition: gmCellMesh.h:422
void inc(const T *container, bool activeOnly)
Increments the iterator.
Definition: gmCellMesh.h:434
int _n
The number of cells in the container (either a mesh or a cell group set)
Definition: gmCellMesh.h:437
QList< GmCellGroupSet * > _cellGroups
A list with GmCellGroupSet objects used for traversing elements in a mesh group of cells.
Definition: gmCellMesh.h:413
virtual const GmCell * cellInGroup(int groupIndex, int cellIndex) const
Returns a cell present in the group referenced by groupIndex.
Definition: gmCellMesh.h:224
virtual int addCellGroup(QString groupName)
Adds a new (empty) cell group to the mesh.
Definition: gmCellMesh.h:320
This class stores a set of cell edges or cell faces that together form a piece of the boundary of a m...
Definition: gmCellBoundary.h:43
Base interface for mesh cells.
Definition: gmCell.h:81
QMap< QString, int > _cellAttributesMap
Map translating ids from attributes into their position in _cellAttributesData.
Definition: gmCellMesh.h:410
virtual double cellBboxMinLength()
Definition: gmCellMesh.h:186
virtual double edgeMaxLength()
Definition: gmCellMesh.h:179
const QList< GmValueSet * > & cellValueSets() const
Returns a list with the mesh cell value sets. This is a very specialized function....
Definition: gmCellMesh.h:374
virtual bool addStateAccessorData(GmStateDump *state, int groupId)
Adds to 'state' accessors for all the data stored on state variables or node attributes associated wi...
Definition: gmMesh.cpp:683
QAtomicPointer< GmCellEdgeStatistics > _meshEdgeStats
Atomic pointer to the mesh edge statistics object.
Definition: gmCellMesh.h:415
virtual double cellBboxMaxLength()
Definition: gmCellMesh.h:193
Auxiliar class used to store the complete set of simulation data.
Definition: gmSimulationData.h:51
virtual bool saveState(GmValueSet::SaveStateMode mode, const GmLogCategory &logger)
Simmilar to saveNodeValueState(), saves the current state of all values that support state saving....
Definition: gmMesh.cpp:467
virtual int numCellsInGroup(int groupIndex) const
Returns the number of cells present in the group referenced by groupIndex.
Definition: gmCellMesh.h:214
virtual QList< int > addedCells() const
If the mesh supports mesh edition (hasCapability("addCells") returns true), this function should retu...
Definition: gmCellMesh.h:305
virtual void printValues(const GmLogCategory &logger, int options=GM_PRINT_DEFAULT)
Asks the mesh to print all of its node and cell data using the provided logger and requested options.
Definition: gmMesh.cpp:833
virtual int maxNumCellGhostNodes() const
Returns the maximum number of ghost nodes in a mesh cell.
Definition: gmCellMesh.h:125
Declaration of the GmMesh interface class.
virtual bool addCellsToGroup(int groupId, const QVector< QPair< int, int >> &cellIds)
Adds the set of cells in the given list to the cell group.. The set of added cells is given by a vect...
Definition: gmCellMesh.h:342
The GmCellAccessor class is a proxy object to a value accesor implementing a more convenient interfac...
Definition: gmCellAccessor.h:66
Base interface class for CellMesh type plugins.
Definition: gmCellMesh.h:39
int _control
The controls flag used to allow breaking inside the inner loop.
Definition: gmCellMesh.h:438
virtual const GmCellMeshTopology * topology(bool create=true) const
If the mesh suppports the topology capability (hasCapability("topology") returns true),...
Definition: gmCellMesh.h:78
virtual bool dumpControlMapDataLoaded(QVariantMap *map, const GmLogCategory &logger)
Sanity checks + processing of the dump control data map after a load operation.
Definition: gmMesh.cpp:743
virtual void printParameters(const GmLogCategory &logger)
Asks the mesh to print all of its parameters using the provided logger.
Definition: gmMesh.cpp:780
virtual void ghostNodesUpdated(int nghost, int ntotal)
Informs the mesh that the number of ghost nodes / total num nodes in a cell was updated to the given ...
Definition: gmCellMesh.h:151
Definition: gmCellMesh.h:396
virtual int maxTotalNumCellNodes() const
Returns the maximum total number of nodes (normal + ghost) in a cell mesh.
Definition: gmCellMesh.h:142
#define GMC_API_EXPORT
Macro for controling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_LI...
Definition: gmCoreConfig.h:35
Base interface class for mesh topological queries.
Definition: gmCellMeshTopology.h:32
virtual bool fillDumpControlMapData(QVariantMap *map, const GmLogCategory &logger)
Fills the dump control data map with mesh data prior to a save operation On errors,...
Definition: gmMesh.cpp:727
double _bboxMinLength
Minimun length of a cell bounding box diagonal in the whole mesh.
Definition: gmCellMesh.h:398
virtual int addCells(int *numCellTypes)
Adds new cells to the mesh, WHITHOUT initializing their nodes or attributes.
Definition: gmCellMesh.h:299
double _edgeMaxLength
Maximum edge length in the whole mesh.
Definition: gmCellMesh.h:390
virtual double edgeMinLength()
Definition: gmCellMesh.h:172
GmCellType
Mesh Cell types. Don't change type orders or add types without reading comments below.
Definition: gmCellType.h:30
Class representing a category with multiple logging levels.
Definition: gmLog.h:58
double _bboxMaxLength
Maximun length of a cell bounding box diagonal in the whole mesh.
Definition: gmCellMesh.h:399
SaveStateMode
Initialization mode for calls to saveState()
Definition: gmValueSet.h:59
GmForeachCellHelperClass(const T *container, bool activeOnly)
Constructor. Positions the iterator on the first active cell.
Definition: gmCellMesh.h:426
Declaration of the GmCell class.
virtual bool addCellsToGroup(int groupId, const QVector< int > &cellIds)
Adds the set of cells in the given list to the cell group. Assumes that the intersection of the given...
Definition: gmCellMesh.h:330
Definition: gmCellMesh.h:387
QList< GmValueSet * > _cellAttributesData
List with set of values for cell attributes.
Definition: gmCellMesh.h:411
Base interface class for Mesh type plugins.
Definition: gmMesh.h:44
QAtomicPointer< GmCellBboxStatistics > _meshBboxStats
Atomic pointer to the mesh bbox statistics object.
Definition: gmCellMesh.h:416
A tag to request that the options should be filled with the default.
Definition: gmPrintUtils.h:68
virtual GmCell * cellInGroup(int groupIndex, int cellIndex)
Non const version of cellInGroup() const.
Definition: gmCellMesh.h:227