FemProcess
The GeMA Fem Process Plugin
gmpFemSolver.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_SOLVER_H_
25 #define _GEMA_PLUGIN_FEM_SOLVER_H_
26 
27 #include <QList>
28 
29 #include <gmElementMesh.h>
30 #include <gmElement.h>
31 
32 #include "gmpFemMatrixSet.h"
33 #include "gmpFemVectorSet.h"
34 #include "gmpFemProcessConfig.h"
35 #include "gmpFemSolverOptions.h"
36 #include "gmpFemAssembler.h"
37 #include "gmpFemPhysics.h"
38 
39 class GmNumSolver;
40 class GmLogCategory;
41 class GmSolverMatrix;
43 class GmCellBoundary;
44 class GmMatrixDof;
45 
46 class GmpFemAssembler;
49 
51 class GMP_FEM_PROCESS_API_EXPORT GmpFemSolver : public QObject, public GmGroupDumpItem
52 {
53  Q_OBJECT
54 
55 public:
58  {
59  PRINT_ELEMENT_MATRICES = 0x001,
60  PRINT_ELEMENT_VECTORS = 0x002,
61  PRINT_ELEMENT_DOF_MAPPING = 0x004,
62  PRINT_EQ_MATRIX = 0x008,
63  PRINT_EQ_VECTOR = 0x010,
64  PRINT_GLOBAL_MATRICES = 0x020,
65  PRINT_GLOBAL_VECTORS = 0x040,
66  PRINT_LINEAR_MATRIX = 0x080,
67  PRINT_LINEAR_VECTOR = 0x100,
68  PRINT_LINEAR_RESULT = 0x200,
69  };
70 
71  GmpFemSolver(GmElementMesh* mesh, GmSimulationData* simulation, const QList<GmpFemPhysics*>& physics,
72  GmNumSolver* solver, const GmpFemSolverOptions& options, const GmLogCategory& logger);
73  virtual ~GmpFemSolver(void);
74 
75  virtual bool init();
76  bool run();
77 
78  bool calcLinearResidual(double* rnorm, double* maxNodeDiff, double* avgNodeDiff);
79 
88  void setMatrixCombinerObject(const GmpFemAssemblerMatrixCombiner* combiner) { _matCombiner = combiner; }
89 
98  void setVectorCombinerObject(const GmpFemAssemblerVectorCombiner* combiner) { _vecCombiner = combiner; }
99 
100  bool update(int mode, QString& err);
101 
102  virtual bool addStateItemsToGroup(GmStateDump* state, int groupId);
103  virtual bool stateAboutToBeSaved (GmStateDump* state);
104  virtual bool stateSaved (GmStateDump* state);
105  virtual bool stateAboutToBeLoaded(GmStateDump* state);
106  virtual bool stateLoaded (GmStateDump* state);
107 
108  virtual bool fillStateControlMapData (QVariantMap* map);
109  virtual bool stateControlMapDataLoaded(QVariantMap* map);
110 
115  virtual bool stateLoadedCalcDerivedResultsNonLinear() { return false; }
116 
117 private:
118  Q_DISABLE_COPY(GmpFemSolver)
119 
120 protected slots :
121  virtual void meshChanged();
122 
123 protected:
124 
127  {
132  //---------- Do not add lines bellow here -----------
134  };
135 
136  bool initSolver(GmpFemAssembler::FixedDofMode assemblerMode, bool assemblerReverseMapping, bool enableFastUpdate);
137 
138  virtual bool initElementSets(GmNumSolver* solver);
139  virtual bool initResultAttributes(QString prefix);
140  virtual bool cleanup();
141 
142  GmpFemPhysics::FemResultType prepareMatrices(bool skipFixedBcs = false);
143  GmpFemPhysics::FemResultType saveElementData(int iter);
144  bool solveLinearSystem(bool xFilled);
145 
146  double timeConvert(double val);
147 
148  GmpFemPhysics::FemResultType traverseElements();
149  GmpFemPhysics::FemResultType traverseBoundaryElements();
150  GmpFemPhysics::FemResultType traverseExternalLoads();
151  GmpFemPhysics::FemResultType traverseContactBoundaries();
152  GmpFemPhysics::FemResultType traverseElementsForSaving(FILE* f, int iter);
153 
154  GmpFemPhysics::FemResultType fillElementData (const GmElement* e, int physIndex);
155  GmpFemPhysics::FemResultType fillElementBoundaryData(const GmElement* e, int physIndex, const GmBoundaryCondition* bc,
156  int bcIndex, int bcListIndex, int border, const GmCellBoundary* b);
157  GmpFemPhysics::FemResultType fillContactData(GmMatrixDof& localDofMap, const GmContactBoundaryCondition* cbc, int physIndex, int index1, int index2);
158 
159  bool addFixedForces();
160  virtual bool applyFixedBoundaryConditions(int* numFixed);
161  bool collectFixedBcs(QVector<bool>& fixedRows, QVector<double>& fixedValues, QList<int>& dofIndex);
162 
163  virtual void collectGlobalContactPairs(const GmContactBoundaryCondition* cbc, QList<QPair<int, int> >& contactPairs);
164 
165  void printElementData(const GmElement* e, int ndof, const int* dofMapping, const GmpFemPhysics* p,
166  const GmBoundaryCondition* bc = NULL, const GmContactBoundaryCondition* cbc = NULL,
167  int loadId1 = -1, int id2 = -1);
168  void printGlobalData (bool linear);
169 
170  int _solverId;
177 
178  bool _enabledWarn[NumDisabledWarnings];
179 
181 
183 
187 
192 
193  unsigned _preCount;
194  unsigned _runCount;
195 
196  QVariantMap _controlMap;
197 
200 
201 #ifdef TRACK_PHYSICS_TIME
202  void resetTimeData() { _elapsedTime = 0; }
203  void printTimeData(const GmLogCategory& logger) { gmTimeMsg(logger, QObject::tr(" *** Physics build matrix time: %1 s").arg(_elapsedTime / 1.0e9)); }
204  qint64 _elapsedTime;
205 #endif
206 };
207 
208 #endif
const GmpFemAssemblerVectorCombiner * _vecCombiner
The combiner object used with the assembler to merge data from multiple elemental vectors.
Definition: gmpFemSolver.h:186
unsigned _runCount
Number of times that run() was called.
Definition: gmpFemSolver.h:194
GmpFemVectorSet _vecSet
Set of global/element vectors filled by physics.
Definition: gmpFemSolver.h:188
Definition: gmpFemSolverOptions.h:38
DisabledWarnings
Enums describing the set of warnings that can be disabled by simulation options.
Definition: gmpFemSolver.h:126
Different fixed BC values specified for a single Dof at collectFixedBcs()
Definition: gmpFemSolver.h:131
GmpFemSolverOptions _solverOptions
The set of solver options.
Definition: gmpFemSolver.h:180
GmSimulationData * _simulation
Simulation Data.
Definition: gmpFemSolver.h:172
GmpFemAssembler * _assembler
Assembler used for adding element contributions to vectors and matrices.
Definition: gmpFemSolver.h:184
virtual bool stateLoadedCalcDerivedResultsNonLinear()
Returns the value of the "nonLinearSolver" parameter that will be passed to the calcDerivedResults() ...
Definition: gmpFemSolver.h:115
FemResultType
Result type for local matrix calculation methods.
Definition: gmpFemPhysics.h:49
Fixed BC specified over an invalid Dof warning at collectFixedBcs()
Definition: gmpFemSolver.h:130
virtual bool stateAboutToBeLoaded(GmStateDump *state)
Basic class for the FEM solving process.
Definition: gmpFemSolver.h:51
const GmLogCategory & _logger
Logger for eventual messages.
Definition: gmpFemSolver.h:175
UnitConverter * _timeConv
Unit converter from the currentTimeUnit to the physics unit. Used only by derived solvers.
Definition: gmpFemSolver.h:182
virtual bool addStateItemsToGroup(GmStateDump *state, int groupId)=0
A convenience class that builds a GmVectorSet with the types given by GmpFemVectorTypes and also asso...
Definition: gmpFemVectorSet.h:47
QString tr(const char *sourceText, const char *disambiguation, int n)
A convenience class that builds a GmMatrixSet with the types given by GmpFemMatrixTypes and also asso...
Definition: gmpFemMatrixSet.h:56
Declaration of the GmpFemVectorSet class.
int _solverId
A unique index for this solver object used by the result attribute auto prefix feature.
Definition: gmpFemSolver.h:170
GmNumSolver * _solver
Numeric solver that will be used to solve the set of linear equations.
Definition: gmpFemSolver.h:174
virtual bool stateLoaded(GmStateDump *state)
Declaration of the GmpFemAssembler class.
Basic interface for defining the rules used to combine information from multiple matrices into a sing...
Definition: gmpFemAssemblerCombiner.h:33
const GmpFemAssemblerMatrixCombiner * _matCombiner
The combiner object used with the assembler to merge data from multiple elemental matrices.
Definition: gmpFemSolver.h:185
QList< GmpFemPhysics * > _physicsList
List of physics that will cooperate to generate the system response.
Definition: gmpFemSolver.h:173
GmpFemMatrixSet _matSet
Set of global/element matrices filled by physics.
Definition: gmpFemSolver.h:189
GmElementMesh * _mesh
Mesh with the nodes and cells data.
Definition: gmpFemSolver.h:171
int _iterResAttr
The registered id for the "fem.iter" result attribute.
Definition: gmpFemSolver.h:198
Declaration of the GmpFemPhysics interface class.
Prescribed force over a fixed BC Dof warning at addFixedForces()
Definition: gmpFemSolver.h:129
Prescribed force over an invalid Dof warning at addFixedForces()
Definition: gmpFemSolver.h:128
void setMatrixCombinerObject(const GmpFemAssemblerMatrixCombiner *combiner)
Sets the combiner object that will be used by the assembler to merge elemental data from multiple mat...
Definition: gmpFemSolver.h:88
GmVector _x
State vector.
Definition: gmpFemSolver.h:190
The number of entrie above.
Definition: gmpFemSolver.h:133
QMutex _printMutex
Mutex for serializing calls to printElementData when traversing elements in parallel.
Definition: gmpFemSolver.h:176
Declaration of the GmpFemSolverOptions class.
Basic interface for defining the rules used to combine information from multiple vectors into a singl...
Definition: gmpFemAssemblerCombiner.h:102
A class responsible for assembling the global stiffness matrix, handling multiple physics with possib...
Definition: gmpFemAssembler.h:62
FixedDofMode
Definition: gmpFemAssembler.h:66
void setVectorCombinerObject(const GmpFemAssemblerVectorCombiner *combiner)
Sets the combiner objects that will be used by the assembler to merge elemental data from multiple ve...
Definition: gmpFemSolver.h:98
Declaration of the GmpFemMatrixSet class.
virtual bool stateSaved(GmStateDump *state)
int _iterResErrAttr
The registered id for the "fem.iterErr" result attribute.
Definition: gmpFemSolver.h:199
unsigned _preCount
Number of times that prepareMatrices() was called.
Definition: gmpFemSolver.h:193
Base interface class for FEM Physics type plugins.
Definition: gmpFemPhysics.h:44
arma::vec GmVector
PrintOptions
Flag options used to compose the printOptions constructor parameter.
Definition: gmpFemSolver.h:57
GmVector _r
Residual vector.
Definition: gmpFemSolver.h:191
Declaration of usefull configuration definitions for the plugin library.
virtual bool stateAboutToBeSaved(GmStateDump *state)
QVariantMap _controlMap
Variant map used for storing dump control data for the solver.
Definition: gmpFemSolver.h:196