GemaMesh
The GeMA Mesh Plugin
Loading...
Searching...
No Matches
gmpNodeMesh.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_NODE_MESH_H_
25#define _GEMA_PLUGIN_NODE_MESH_H_
26
27#include <gmGhostNodeAccessor.h>
28#include <gmLuaMesh.h>
30#include <gmPCR.h>
31#include <gmSimulationData.h>
32#include <gmModelData.h>
33
34#include "gmpNodeMeshData.h"
35#include "gmpCellMeshData.h"
36
37#include "gmpMeshLoader.h"
38#include "gmpDataDump.h"
39#include "gmpNodeDataDump.h"
40
41#include <unitConverter.h>
42#include <luaTable.h>
43#include <luaStackBalancer.h>
44
45#include <assert.h>
46
47
69template <class Mesh, template <class> class Vector>
70class GmpNodeMesh: public Mesh
71{
72public:
74 GmpNodeMesh(GmSimulationData* simulation, QString id, QString description, const GmLogCategory& logger)
75 : Mesh(simulation, id, description, logger), _pcr(NULL), _ownPcr(false)
76 {
77 }
78
80 virtual ~GmpNodeMesh()
81 {
82 clearNodeValueSets();
83 if(_ownPcr)
84 {
85 assert(_pcr);
86 simulationData()->modelData()->removePcrObject(_pcr->id(), true);
87 }
88 }
89
90 // Comments on the base class
91 virtual const char* pluginName() const { return "GemaMesh"; }
92
93 // Comments on the base class
94 virtual const char* pluginType() const { if constexpr(std::is_same<Vector<int>, GmSingleVector<int>>::value) return "nodes"; else return "nodesd"; }
95
96 // Comments on the base class
97 virtual bool hasCapability(QString capabilityName) const
98 {
99 // This implementation has a caveat: If this function is called before loadPrivateData() is called
100 // on the mesh, it will return no support for ghost nodes, regardless of mesh configuration.
101 // This should not be a problem since it can not happen in a normal control flow.
102 return (capabilityName == "addNodes" || (capabilityName == "ghostNodes" && _nd._ghostEnabled) ||
103 capabilityName == "clear" || capabilityName == "stateDump");
104 }
105
106 // Comments on the base class
107 virtual bool useDualVectors() const { if constexpr(std::is_same<Vector<int>, GmSingleVector<int>>::value) return false; else return true; }
108
109 // Comments on the base class
110 virtual void pushProxy(lua_State* L, const GmLogCategory& logger) { LuaProxy::pushObject(L, new GmLuaMesh(this, logger)); }
111
117 virtual bool loadPrivateData(LuaTable& table)
118 {
119 // Check if the mesh should support ghost nodes or not. This parameter is read here, and not
120 // in the mesh loader, because this information is needed in the call to initCellData()
121 bool ghostSupport = table.getField("useGhostNodes").toBool();
122 bool ok;
123
124 // Setup cell data for derived meshes. Might update ghostSupport.
125 GmpCellMeshData<Vector>* cd = initCellData(table, &ghostSupport, &ok);
126 if(!ok)
127 return false;
128
129 // Setup ghost support
130 _nd._ghostEnabled = ghostSupport;
131
132 // Load mesh data. The call will fill _pcr and _ownPcr
133 // We will take its ownership of the PCR object if it was created
134 // by the loader
136 return loader->loadMeshData(table, this, &_nd, cd, &_pcr, &_ownPcr);
137 }
138
139 // Comments on the base class
140 virtual GmValueInfo* nodeCoordInfo() const { return _nd._coordInfo; }
141
142 // Comments on the base class
143 virtual GmValueAccessor* nodeCoordAccessor(Unit desiredUnit, const GmLogCategory& logger) const
144 {
145 bool compatibleUnits;
146 UnitConverter* conv = Unit::converter(_nd._coordInfo->unit(), desiredUnit, &compatibleUnits);
147 if(!compatibleUnits) // Conv can be NULL with compatible units if no conversion is needed
148 {
149 gmInfoMsg(logger, QObject::tr("Could not create an accessor for mesh coordinates due to incompatible units.\n"
150 "Data unit = '%1'. Requested unit = '%2'.")
151 .arg(_nd._coordInfo->unit().name(), desiredUnit.name()));
152 return NULL;
153 }
154
155 if(_nd._ghostEnabled)
156 {
157 // Accessors own converters so no sharing is possible
158 UnitConverter* gconv = Unit::converter(_nd._coordInfo->unit(), desiredUnit, &compatibleUnits);
159 GmValueAccessor* ac = const_cast<GmpNodeMeshData<Vector>&>(_nd).coordAc(logger, conv, desiredUnit.name());
160 GmValueAccessor* gac = const_cast<GmpNodeMeshData<Vector>&>(_nd).ghostAc(logger, gconv, desiredUnit.name());
161 return new GmGhostNodeAccessor(ac, gac);
162 }
163 else
164 return const_cast<GmpNodeMeshData<Vector>&>(_nd).coordAc(logger, conv, desiredUnit.name());
165 }
166
167 // See comments on the base interface class
168 virtual int numNodes() const { assert(_nd._numNodes >= 0); return _nd._numNodes; }
169
170 // See comments on the base interface class
171 virtual int numGhostNodes() const { assert(_nd._numGhostNodes >= 0); return _nd._numGhostNodes; }
172
173 // Comments on the base class
174 virtual const QMap<QString, GmNodeSet*>& nodeSets() const { return _nd._nodeSets; }
175
176 // See comments on the base interface class
177 virtual int addNodes(int numNodes) { return _nd.addNodes(this, false, numNodes, true, _pcr); }
178
179 // See comments on the base interface class
180 virtual int addGhostNodes(int numNodes) { return _nd._ghostEnabled ? _nd.addNodes(this, true, numNodes, true, _pcr) : -1; }
181
182 // See comments on the base interface class
183 virtual void clear() { _nd.clear(this); _pcr->clear(); }
184
185 // See comments on the base interface class
186 virtual size_t nodeMemory() const { return _nd.nodeMemory(); }
187
188 // See comments on the base interface class
189 virtual size_t nodeSetsMemory() const { return _nd.nodeSetsMemory(); }
190
191 // See comments on the base interface class
192 virtual GmPCR* pcrObject() const { return _pcr; }
193
194protected:
195
205 virtual GmpCellMeshData<Vector>* initCellData(LuaTable& table, bool* ghostSupport, bool* ok)
206 {
207 Q_UNUSED(table); Q_UNUSED(ghostSupport);
208 *ok = true;
209 return NULL;
210 }
211
213 virtual GmpMeshLoader<Vector>* meshLoader() { return new GmpMeshLoader<Vector>(simulationData(), logger()); }
214
215 //---------------------------------------
216 // State dump control functions
217 //---------------------------------------
218
219 // See comments on the base class and on the enum definition
220 virtual int controlMapStateItemType() { return GMP_GEMA_MESH_DUMP_ITEM; }
221
222 // See comments on the base GmMesh class
223 virtual bool addStateGeometryData(GmStateDump* state, int groupId)
224 {
225 return Mesh::addStateGeometryData(state, groupId) &&
226 _nd._dumper->addStateGeometryData(state, groupId) &&
227 _pcr->addStateGeometryData(state, groupId);
228 }
229
230 // See comments on the base GmMesh class
231 virtual bool fillDumpControlMapData(QVariantMap* map, const GmLogCategory& logger)
232 {
233 return Mesh::fillDumpControlMapData(map, logger) &&
234 _nd._dumper->fillDumpControlMapData(this, map, logger) &&
235 _pcr->fillDumpControlMapData(map, logger);
236 }
237
238 // See comments on the base GmMesh class
239 virtual bool dumpControlMapDataLoaded(QVariantMap* map, const GmLogCategory& logger)
240 {
241 return Mesh::dumpControlMapDataLoaded(map, logger) &&
242 _nd._dumper->dumpControlMapDataLoaded(this, map, logger) &&
243 _pcr->dumpControlMapDataLoaded(map, logger);
244 }
245
247
249 bool _ownPcr;
250};
251
252
253#endif
254
virtual void clear()=0
QString id() const
Auxiliar structure used to share data between GmpCellMesh and GmpMeshLoader. All fields are public si...
Definition gmpCellMeshData.h:121
Auxiliary class used to load mesh data from a Lua file.
Definition gmpMeshLoader.h:58
Auxiliar interface used to share node data between the mesh implementation and GmpMeshLoader....
Definition gmpNodeMeshData.h:53
Basic class for a plugin mesh. Implements the needed functions for a GmMesh interface,...
Definition gmpNodeMesh.h:71
GmPCR * _pcr
PCR object. Not stored inside _nd since that class does not have access to the model data for correct...
Definition gmpNodeMesh.h:248
GmpNodeMesh(GmSimulationData *simulation, QString id, QString description, const GmLogCategory &logger)
Constructor. Will be called by the plugin loading code.
Definition gmpNodeMesh.h:74
virtual GmpCellMeshData< Vector > * initCellData(LuaTable &table, bool *ghostSupport, bool *ok)
Virtual function that should be overridden for derived classes that need to load cells....
Definition gmpNodeMesh.h:205
GmpNodeMeshData< Vector > _nd
The complete node data.
Definition gmpNodeMesh.h:246
virtual ~GmpNodeMesh()
Destructor.
Definition gmpNodeMesh.h:80
virtual bool loadPrivateData(LuaTable &table)
See behaviour comments on the base class. When inheriting from this class, the idea is that this func...
Definition gmpNodeMesh.h:117
bool _ownPcr
Do we own the PCR object? (will be true if the object was instanced internally)
Definition gmpNodeMesh.h:249
virtual GmpMeshLoader< Vector > * meshLoader()
Returns the mesh loader used to load mesh data. This function should be replaced for using a custom m...
Definition gmpNodeMesh.h:213
static void pushObject(lua_State *L, Base *obj)
QVariant getField(const char *name, LuaEnv::StackOption opt=LuaEnv::STACK_AUTO)
QString name() const
static UnitConverter * converter(const Unit &srcUnit, const Unit &dstUnit, bool *compatible=NULL)
Declaration of the GmpCellMeshData structure.
Declaration of the GmpDataDump interface class.
@ GMP_GEMA_MESH_DUMP_ITEM
Node mesh dump type.
Definition gmpDataDump.h:34
Declaration of the GmpMeshLoader class.
Implementation of the GmpNodeDataDump class.
Declaration of the GmpNodeMeshData class.
void clear()
QString tr(const char *sourceText, const char *disambiguation, int n)
bool toBool() const const