FemProcess
The GeMA Fem Process Plugin
Loading...
Searching...
No Matches
gmpFemAssembler.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_FEM_ASSEMBLER_H_
25#define _GEMA_PLUGIN_FEM_ASSEMBLER_H_
26
27#include <QList>
28#include <QVector>
29#include <QHash>
30#include <gmElementMesh.h>
31#include <gmElementDof.h>
32#include <gmElement.h>
33#include <gmThreadLocalBuffer.h>
34
35#include "gmpFemProcessConfig.h"
36
37class GmpFemPhysics;
38class GmpFemMatrixSet;
39class GmpFemVectorSet;
40class GmpFemLocker;
41
42class GmStateVar;
43class GmLogCategory;
44class GmSolverMatrix;
45
48
51
53
54// Enable the define below to force validation of internal structures after assembler initialization
55// #define ENABLE_ASSEMBLER_TESTS
56
57
62class GMP_FEM_PROCESS_API_EXPORT GmpFemAssembler
63{
64public:
65
71
78
80 {
81 NODES_ADDED = 0x001,
82 DOFS_ADDED = 0x002,
83 DOFS_REMOVED = 0x004,
84 ELEMENTS_ADDED = 0x008,
85 ELEMENTS_REMOVED = 0x010,
86
87 FIXED_BCS_UPDATE = 0x020,
88 FIXED_BCS_CHANGED = 0x040,
89 FIXED_BCS_ALL = 0x080,
90 FIXED_BCS_KEEPOLD = 0x100,
91
92 FULL_UPDATE = 0x4000,
93 SAVE_MAPPING_INFO = 0x8000,
94 };
95
98
99 bool init(GmpFemMatrixSet* matSet, GmpFemVectorSet* vecSet, FixedDofMode fixedMode,
100 GhostDofMode ghostMode, bool enableFastUpdate, bool createReverseMapping,
101 int numThreads, QString& err);
102 bool update(int mode, QString& err);
103
107 void setBcWarningMode(bool warnOnFixedInvalidDof, bool warnOnFixedDofConflict)
108 {
109 _warnOnFixedInvalidDof = warnOnFixedInvalidDof;
110 _warnOnFixedDofConflict = warnOnFixedDofConflict;
111 }
112
113 void setPartitions(int npart);
114
116 int numDof() const { return _nMatrixDof; }
117
122 int numTotalDof() const { return _nTotalDof; }
123
124 // Returns the number of fixed degrees of freeedom handled by the assembler. Equal to numTotalDof() - numDof()
125 int numFixedDof() const { return _nTotalDof - _nMatrixDof; }
126
127 int numElementDof(const GmElement* e, int physicsIndex) const;
128
130 int maxElementDof() const { return _elemIndexMap.size(); }
131
132 int dofIndex (int node, int dof) const;
133 int fillIndexMap(const GmElement* e, int physicsIndex, int* indexMap, const GmElementDof*& dofMap);
134
136 double dofFixedValue(int index) { assert(index < 0); return _fixedValues[abs(index+1)]; }
137
138 GmStateVar* stateVar (int globalIndex);
139 int svGroupId(int globalIndex);
140
142 const QVector<QPair<GmStateVar*, GmValueAccessor*> >& stateVars() const { return _stateVars; }
143
145 Unit timeUnit() const { return _timeUnit; }
146
147 bool beginAssembly();
148 bool endAssembly(bool discardData = false);
149 const int* addElementData(const GmElement* e, int physicsIndex,
150 const GmpFemAssemblerMatrixCombiner* matCombiner,
151 const GmpFemAssemblerVectorCombiner* vecCombiner);
152 bool addLocalMatrixData (GmMatrixDof& localDofMap,
153 const GmpFemAssemblerMatrixCombiner* matCombiner,
154 const GmpFemAssemblerVectorCombiner* vecCombiner);
155
156 void saveResultData(const GmVector& data, double lambda = 1.0);
157 void saveResultData(const GmVector& data, int baseDof, GmValueAccessor* ac, double lambda = 1.0);
158 void saveResultDataToFixedDofs(const GmVector& data, int baseDof, GmValueAccessor* ac, bool clearFree);
159
160 void loadResultData(GmVector& data);
161 void loadFixedData(GmVector& data);
162
163 const QVector<int>& remapInfo() const;
164 void remapData(GmVector& data, double newValue = 0.0) const;
165 void remapData(const GmVector& oldData, GmVector& newData, double newValue = 0.0) const;
166
168 bool fastUpdate() const { return _dofUnitList; }
169
170private:
171 Q_DISABLE_COPY(GmpFemAssembler)
172
173
175 {
179 int _dofMap[GM_MAX_DOF];
180
183
190
202 };
203
204 bool addMappedMatrixData(int ndof, const int* indexMap, const GmDofMap* dofMap,
205 const GmpFemAssemblerMatrixCombiner* matCombiner,
206 const GmpFemAssemblerVectorCombiner* vecCombiner);
207
208 bool initSparseLayout(GmSparseMatrixLayoutBuilder* layoutBuilder);
209
210 void cleanup();
211 bool initTranslationStructures(bool enableFastUpdate, bool createReverseMapping, QString& err);
212 bool initTemplateAssociations(const GmElementDofMap* nodeDofMap, const QHash<int, GmElementDofMap>& fixedNodeDofMap, QString& err);
213 void initDofToNodeIndex(int firstNode);
214 void initUpdateDofPhysicsList();
215
216 GmElementDofMap* createNodeDofMap (GmElementDofMap* physicsDofMapList, int* maxElemDof, size_t* dofsSum);
217 bool fillFixedDofMap (QHash<int, GmElementDofMap>& fixedDofMap, const GmElementDofMap* fullNodeDofMap,
218 const QHash<int, GmElementDofMap>* partialNodeDofMap, QString& err);
219 bool fillBcNodeDofMap (const QVector<GmpFemPhysics*>& physicsList, QMap<QPair<int, int>, double>& fixedData,
220 bool saveNonConstantPhysics, QString& err);
221 bool fillUnitMap (const QVector<GmpFemPhysics*>& physicsList, GmElementDofMap* physicsDofMapList, QString& err);
222 int fecthNodeTemplate(const GmElementDofMap& nodeDofMap, const GmElementDofMap& fixedNodeDofMap, int node, QString& err);
223 int fecthDofStatevar (int dof);
224 void fillFixedData(double* data, int size);
225
226 bool updateFixedBcValues(QString& err);
227 bool updateTranslationStructures(const QVector<GmpFemPhysics*>& physList, const QList<QList<int> >& elementLists,
228 bool nodesAdded, int updateFixedMode, bool updateUnits, QString& err);
229
230 QHash<int, GmElementDofMap> createUpdateNodeDofMap(const QVector<GmpFemPhysics*>& physList, const QList<QList<int> >& elementLists,
231 GmElementDofMap* physicsDofMapList, int* maxElemDof, size_t* dofsSum);
232
233 int updateNodeTemplate(int node, const GmElementDofMap& addedDofMap, const GmElementDofMap& newFixedDofMap,
234 bool useOldFixedDofMap, int* nFreeAdded, int* nFixedAdded, QString& err);
235
236 int extendedDofIndex(int node, int dof) const;
237
238 bool saveNodeDofInfo(QVector<QPair<int, int> >& map, QString& err) const;
239 bool buildRemapInfo(const QVector<QPair<int, int> >& oldMap, QString& err);
240
245 int tgi(int node) const { return _mesh->toLinearGhostIndex(node); }
246
248 int nodeIndex(int node) const { return _nodeIndex[tgi(node)]; }
249
251 void setNodeIndex(int node, int baseIndex) { _nodeIndex[tgi(node)] = baseIndex; }
252
254 void incNodeIndex(int node, int offset) { _nodeIndex[tgi(node)] += offset; }
255
257 int nodeTemplateIndex(int node) const { return _nodeTemplateIndex[tgi(node)]; }
258
260 void setNodeTemplateIndex(int node, int templateIndex) { _nodeTemplateIndex[tgi(node)] = templateIndex; }
261
263 const TemplateData& nodeTemplate(int node) const { return _templateList.at(nodeTemplateIndex(node)); }
264
272
274
277
280
282 int _nt;
291 unsigned char* _nodeTemplateIndex;
296
301
306
309
312
318
323
328
331
336
343
344#if defined ENABLE_TESTS || defined ENABLE_ASSEMBLER_TESTS
345 void validateInternalStructure() const;
346#endif
347};
348
349#endif
A class responsible for assembling the global stiffness matrix, handling multiple physics with possib...
Definition gmpFemAssembler.h:63
int _maxNodeDofs
The maximum number of dofs for a node. Might over estimate if number of node dofs are reduced over ti...
Definition gmpFemAssembler.h:286
QVector< GmpFemPhysics * > _nonConstantDofPhysics
A list with the set of physics that should be queried when updating dofs if _updateDofMode == FAST_UP...
Definition gmpFemAssembler.h:311
unsigned char * _nodeTemplateIndex
A vector storing for each mesh node its dof template index.
Definition gmpFemAssembler.h:291
GmpFemMatrixSet * _matSet
The matrix set used together with the assembler
Definition gmpFemAssembler.h:270
int * _nodeIndex
A vector storing for each mesh node its base index in the matrix.
Definition gmpFemAssembler.h:289
QVector< double > _oldFixedValues
A vector storing the values in _fixedValues before the last call to update()
Definition gmpFemAssembler.h:293
bool _hasRemapInfo
Is remap info available (The last call to update included the SAVE_MAPPING_INFO flag)?...
Definition gmpFemAssembler.h:335
UpdateMode
Definition gmpFemAssembler.h:80
GmTLBuffer< int, true > _elemIndexMap
An auxiliar vector used by addElementMatrix, with size equal to the biggest local matrix number of do...
Definition gmpFemAssembler.h:305
QMap< QPair< GmElementDofMap, GmElementDofMap >, int > _templateCache
A map keyed by both the node dof mapping and the fixed dof mapping, storing the equivalent template i...
Definition gmpFemAssembler.h:317
QMap< int, int > _dofToSvCache
A map keyed by dof number storing the corresponding entry in _stateVars. This map holds values outsid...
Definition gmpFemAssembler.h:322
int numDof() const
Returns the number of degrees of freedom of the global assembled matrix.
Definition gmpFemAssembler.h:116
QVector< QPair< GmStateVar *, GmValueAccessor * > > _stateVars
A list storing pairs of state vars and accessors to them for every different state var that provides ...
Definition gmpFemAssembler.h:300
bool _warnOnFixedDofConflict
Should the assembler emmit a warning for conflicting fixed BC values?
Definition gmpFemAssembler.h:269
int nodeIndex(int node) const
Returns the base node index of the given node. Node can be a ghost node index if ghost support is ena...
Definition gmpFemAssembler.h:248
GmpFemAssemblerVectorAdder * _debugVecAdder
The configured adder object used to assemble vectors in "single debug" mode.
Definition gmpFemAssembler.h:279
Unit _timeUnit
The time unit used by all the physics.
Definition gmpFemAssembler.h:330
FixedDofMode
Definition gmpFemAssembler.h:67
@ NO_DOF_HANDLING
No fixed dof handling. The full matrix will be generated.
Definition gmpFemAssembler.h:68
@ REMOVE_DOF
Fixed dofs are removed from the matrix.
Definition gmpFemAssembler.h:69
const QVector< GmpFemPhysics * > & _physicsList
List of physics that will cooperate to generate the global matrix.
Definition gmpFemAssembler.h:266
FixedDofMode _fixedDofMode
How does the assembler treats fixed degrees of freedom.
Definition gmpFemAssembler.h:267
QVector< double > _fixedValues
A vector storing the values of the fixed dofs with size equal to _nTotalDof - _nMatrixDof.
Definition gmpFemAssembler.h:292
QVector< GmpFemPhysics * > _nonConstantFixedValuesPhysics
A list with the set of physics whose fixed boundary condition values are not constant.
Definition gmpFemAssembler.h:308
GmpFemLocker * _locker
The locker object used when adding values to the global matrices/vectors in multiple threads.
Definition gmpFemAssembler.h:273
size_t _elemDofsSum
A sum of the number of local matrix entries for the whole set of elements. When update() is called,...
Definition gmpFemAssembler.h:287
double dofFixedValue(int index)
Returns the fixed dof value associated to a negative index in an entry in the vector returned by fill...
Definition gmpFemAssembler.h:136
Unit * _dofUnitList
A vector keyed by dof number, with size equal to GM_MAX_DOF, storing the corresponding dof unit....
Definition gmpFemAssembler.h:327
QVector< int > _remapInfo
The remap vector storing information on how to translate values from a vector prior to an update() ca...
Definition gmpFemAssembler.h:342
const TemplateData & nodeTemplate(int node) const
Returns the node template. Node can be a ghost node index if ghost support is enabled.
Definition gmpFemAssembler.h:263
GmElementMesh * _mesh
The mesh.
Definition gmpFemAssembler.h:265
GmpFemAssemblerMatrixAdder * _debugMatAdder
The configured adder object used to assemble matrices in "single debug" mode.
Definition gmpFemAssembler.h:278
GmpFemAssemblerVectorAdder * _vecAdder
The configured adder object used to assemble vectors.
Definition gmpFemAssembler.h:276
QHash< int, int > _fixedNodeIndex
Map determining the base index of a node in the _fixedValues vector.
Definition gmpFemAssembler.h:294
int nodeTemplateIndex(int node) const
Returns the node template index. Node can be a ghost node index if ghost support is enabled.
Definition gmpFemAssembler.h:257
int _nTotalDof
The total number of degrees of freedom of the system, including fixed ones.
Definition gmpFemAssembler.h:285
void incNodeIndex(int node, int offset)
Updates the base node index of the given node by adding the given value. Node can be a ghost node ind...
Definition gmpFemAssembler.h:254
const QVector< QPair< GmStateVar *, GmValueAccessor * > > & stateVars() const
Returns the vector storing the set of state variables/accesors to them in use by the assembler.
Definition gmpFemAssembler.h:142
int _nMatrixDof
The number of degrees of freedom of the assembled matrix.
Definition gmpFemAssembler.h:284
QVector< int > _dofNode
A reverse vector mapping, storing for each dof in the assembled matrix the node it belongs to,...
Definition gmpFemAssembler.h:290
int _nthreads
The number of threads configured for the assembler. Can be any value >= -1.
Definition gmpFemAssembler.h:281
Unit timeUnit() const
Returns the unit in which time is handled by the physics.
Definition gmpFemAssembler.h:145
int _nt
The number of threads that should be used by the assembler in OMP operations.
Definition gmpFemAssembler.h:282
int _nNodes
The number of nodes in _nodeIndex & _nodeTemplateIndex. Will be equal to _mesh->numNodes() or _mesh->...
Definition gmpFemAssembler.h:288
bool _warnOnFixedInvalidDof
Should the assembler emmit a warning fixed BCs for invalid dofs?
Definition gmpFemAssembler.h:268
void setBcWarningMode(bool warnOnFixedInvalidDof, bool warnOnFixedDofConflict)
Updates the flags controlling wheter warnings should be emmited or not when invalid fixed dofs are fo...
Definition gmpFemAssembler.h:107
QVector< TemplateData > _templateList
A list with node metadata information for every node template type.
Definition gmpFemAssembler.h:295
GmpFemVectorSet * _vecSet
The vector set used together with the assembler.
Definition gmpFemAssembler.h:271
int numTotalDof() const
Returns the total number of the system degrees of freedom, including fixed ones. This value will be e...
Definition gmpFemAssembler.h:122
GhostDofMode
Definition gmpFemAssembler.h:73
@ AUTO_GHOST_SUPPORT
Equal to GHOST_SUPPORT if there is ANY state var in the mesh with ghost support. Equal to NO_GHOST_SU...
Definition gmpFemAssembler.h:76
@ GHOST_SUPPORT
The assembler will support dofs in ghost nodes.
Definition gmpFemAssembler.h:74
@ NO_GHOST_SUPPORT
The assembler will not support dofs in ghost nodes.
Definition gmpFemAssembler.h:75
bool _ghostEnabled
Should the assembler handle ghost nodes?
Definition gmpFemAssembler.h:283
bool fastUpdate() const
Returns whether the assembler was initialized with the fast update option turned on or off.
Definition gmpFemAssembler.h:168
void setNodeTemplateIndex(int node, int templateIndex)
Updates the template index of the given node. Node can be a ghost node index if ghost support is enab...
Definition gmpFemAssembler.h:260
void setNodeIndex(int node, int baseIndex)
Updates the base node index of the given node. Node can be a ghost node index if ghost support is ena...
Definition gmpFemAssembler.h:251
GmpFemAssemblerMatrixAdder * _matAdder
The configured adder object used to assemble matrices.
Definition gmpFemAssembler.h:275
int maxElementDof() const
Returns the maximum number of degrees of freedom used by a physics/element type.
Definition gmpFemAssembler.h:130
int tgi(int node) const
Translate Ghost Index - An auxiliary function that given a mesh node index, whose value might be a gh...
Definition gmpFemAssembler.h:245
Interface for an object responsible for assemblying local matrices into global matrices....
Definition gmpFemAssemblerAdder.h:43
Basic interface for defining the rules used to combine information from multiple matrices into a sing...
Definition gmpFemAssemblerCombiner.h:34
Interface for an object responsible for assemblying local vectors into global vectors....
Definition gmpFemAssemblerAdder.h:65
Basic interface for defining the rules used to combine information from multiple vectors into a singl...
Definition gmpFemAssemblerCombiner.h:103
A lock manager to be used by GmpFemAssemblerMatrixAdder and GmpFemAssemblerVectorAdder objects when w...
Definition gmpFemLocker.h:39
A convenience class that builds a GmMatrixSet with the types given by GmpFemMatrixTypes and also asso...
Definition gmpFemMatrixSet.h:59
Base interface class for FEM Physics type plugins.
Definition gmpFemPhysics.h:45
A convenience class that builds a GmVectorSet with the types given by GmpFemVectorTypes and also asso...
Definition gmpFemVectorSet.h:50
#define GM_MAX_DOF
quint64 GmElementDofMap
arma::vec GmVector
Declaration of useful configuration definitions for the plugin library.
Struct storing node metadata information.
Definition gmpFemAssembler.h:175
int _nFreeDof
The number of "free" degrees of freedom in _dofMap (values >= 0 && < MAX_DOF)
Definition gmpFemAssembler.h:182
QVector< int > _sv
List of indices in _stateVars for every non -1 value in _dofMap, organized so that the _ndof "free" d...
Definition gmpFemAssembler.h:189
QVector< int > _svOffset
Vector with size equal to _sv, storing the offset of this degree of freedom inside the state variable...
Definition gmpFemAssembler.h:201