FemProcess
The GeMA Fem Process Plugin
gmpFemMatrixSet.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_MATRIX_SET_H_
25 #define _GEMA_PLUGIN_FEM_MATRIX_SET_H_
26 
27 #include "gmpFemProcessConfig.h"
28 #include "gmpFemVectorSet.h"
29 
30 #include <gmMatrixSet.h>
31 #include <gmSolverMatrix.h>
32 
33 class GmNumSolver;
34 class GmSolverMatrix;
35 
37 
40 {
45  //---------------------------------------
46  // No changing bellow this line
47  //---------------------------------------
48  GmpFemMatrix_NumTypes
49 };
50 
51 
56 class GMP_FEM_PROCESS_API_EXPORT GmpFemMatrixSet : public GmMatrixSet
57 {
58 public:
60  ~GmpFemMatrixSet();
61 
68  {
72  };
73 
74  void clear();
75 
76  bool initTypes (const GmNumSolver* solver, GmpFemMatrixMode mode, int numMatrices, ...);
77  bool adjustSizes(int globalNumDofs, int maxElemDofs, bool sparseLayoutChanged);
78 
83  void setNumThreads(int nthreads) { assert(_nthreads >= -1); _nthreads = nthreads; }
84 
85  void setTransposedDofVector(GmpFemMatrixTypes type, GmpFemVectorTypes vectorType);
86 
87  void clearGlobalMatrices(bool keepSparseLayout);
88 
89  bool supportsBatchInsert() const;
90  bool beginBatchInsert(size_t expectedEntries = 0);
91  bool endBatchInsert(bool discardData);
92 
93  bool supportsSparseLayouts() const;
94  GmSparseMatrixLayoutBuilder* layoutBuilder() const;
95  bool emptyLayout() const;
96 
98  bool supportsParallelAdd() const { return _parallelSupport; }
99 
101  bool needsLocking() const { return _needsLock; }
102 
110  {
111  assert((_mode == MATRIX_MATCH_MODE && index(type) >= 0) || (_mode != MATRIX_MATCH_MODE && type == GmpFemMatrix_Eq));
112  return _globalMatrices[tindex(type)]._data;
113  }
114 
117  {
118  assert(_mode == MATRIX_MATCH_MODE && index >= 0 && index < _nMatrices);
119  return _globalMatrices[index]._data;
120  }
121 
133  {
134  assert((_mode == MATRIX_MATCH_MODE && index(type) >= 0) || (_mode != MATRIX_MATCH_MODE && type == GmpFemMatrix_Eq));
135  return _globalMatrices[tindex(type)]._transposed;
136  }
137 
145  int transposedDofVectorFromIndex(int index) const
146  {
147  assert(_mode == MATRIX_MATCH_MODE && index >= 0 && index < _nMatrices);
148  return _globalMatrices[index]._transposed;
149  }
150 
157  {
158  assert(_mode != MATRIX_SINGLE_MODE && index(type) >= 0);
159  return (_mode == MATRIX_MATCH_MODE) ? _globalMatrices[index(type)]._data : _printMatrices[index(type)];
160  }
161 
166  {
167  assert(_mode != MATRIX_SINGLE_MODE && index >= 0 && index < _nMatrices);
168  return (_mode == MATRIX_MATCH_MODE) ? _globalMatrices[index]._data : _printMatrices[index];
169  }
170 
172  GmpFemMatrixMode mode() const { return _mode; }
173 
176 
177 
178 protected:
179 
181  int tindex(GmpFemMatrixTypes type) const { return (_mode == MATRIX_MATCH_MODE) ? index(type) : 0; }
182 
185  int _nthreads;
186 
188  bool _needsLock;
189 
192  {
195 
197  GmpFemMatrixTypeData() { _data = NULL; _transposed = -1; }
198 
200  ~GmpFemMatrixTypeData() { delete _data; }
201  };
202 
208 
213 };
214 
215 
216 #endif
217 
The M matrix in the general equation M u" + C u' + K u = f.
Definition: gmpFemMatrixSet.h:44
GmpFemVectorTypes
Predefined names for vectors used in finite element solvers together with control procedures.
Definition: gmpFemVectorSet.h:32
GmpFemMatrixTypeData()
Constructor.
Definition: gmpFemMatrixSet.h:197
int transposedDofVectorFromIndex(int index) const
Returns the registered vector type for storing transposed values when reducing a matrix due to fixed ...
Definition: gmpFemMatrixSet.h:145
Set stores one global matrix per local matrix.
Definition: gmpFemMatrixSet.h:69
GmpFemMatrixTypes
Predefined names for matrices used in finite element solvers together with control procedures.
Definition: gmpFemMatrixSet.h:39
GmSolverMatrix * globalMatrixFromIndex(int index) const
Returns a global matrix identified by its index in the set. Can NOT be used for "single" or "single d...
Definition: gmpFemMatrixSet.h:116
The equivalent matrix when merging values into a single global matrix.
Definition: gmpFemMatrixSet.h:41
bool supportsParallelAdd() const
Returns true if the solver matrices support parallel assembling (supportedParallelAddMode() !...
Definition: gmpFemMatrixSet.h:98
const GmNumSolver * _solver
The solver used to create global matrices.
Definition: gmpFemMatrixSet.h:184
int index(int type) const
int _nthreads
The configured number of threads that should be used by sparse matrices in batch mode/layout operatio...
Definition: gmpFemMatrixSet.h:185
Set stores a single "equivalent" global matrix.
Definition: gmpFemMatrixSet.h:70
GmpFemMatrixMode mode() const
Returns the mode defining the global matrices stored by the set.
Definition: gmpFemMatrixSet.h:172
int transposedDofVector(GmpFemMatrixTypes type) const
Returns the registered vector type for storing transposed values when reducing a matrix due to fixed ...
Definition: gmpFemMatrixSet.h:132
Aux structure storing the matrix associated with a matrix type.
Definition: gmpFemMatrixSet.h:191
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.
GmSolverMatrix * _data
The data matrix.
Definition: gmpFemMatrixSet.h:193
bool _parallelSupport
Do solver matrices support parallel assembling ?
Definition: gmpFemMatrixSet.h:187
bool needsLocking() const
Returns true if the solver matrices needs external locking for parallel assembling (supportedParallel...
Definition: gmpFemMatrixSet.h:101
GmpFemMatrixTypes femTypeFromIndex(int index) const
Given a matrix index, returns its type as a GmpFemMatrixTypes. Equivalent to GmMatrixSet::typeFromInd...
Definition: gmpFemMatrixSet.h:175
GmSolverMatrix ** _printMatrices
Vector with debug global matrices associated to element local matrices when _mode equals MATRIX_SINGL...
Definition: gmpFemMatrixSet.h:212
The C matrix in the general equation M u" + C u' + K u = f (u" = d2u/dt2)
Definition: gmpFemMatrixSet.h:43
The K matrix in the general equation M u" + C u' + K u = f (u' = du/dt)
Definition: gmpFemMatrixSet.h:42
GmSolverMatrix * globalMatrix(GmpFemMatrixTypes type) const
Returns a global matrix identified by its type in the set.
Definition: gmpFemMatrixSet.h:109
bool adjustSizes(int maxNodes)
bool initTypes(int numMatrices, va_list typeList)
GmpFemMatrixTypeData * _globalMatrices
Vector storing data for global matrices. Will store one data set per included type in the matrix set ...
Definition: gmpFemMatrixSet.h:207
Set stores an "equivalent" global matrix + another matrix per local matrix for debug purposes.
Definition: gmpFemMatrixSet.h:71
GmSolverMatrix * globalDebugPrintMatrixFromIndex(int index) const
Returns the auxiliar matrix used for storing global matrices matching local ones for debug printing p...
Definition: gmpFemMatrixSet.h:165
bool _needsLock
Do solver matrices needs external locking for parallel assembling ?
Definition: gmpFemMatrixSet.h:188
GmpFemMatrixMode _mode
The mode defining how many global matrices are stored.
Definition: gmpFemMatrixSet.h:183
void setNumThreads(int nthreads)
Sets the number of threads used by sparse matrices in batch/layout operations. Default is the number ...
Definition: gmpFemMatrixSet.h:83
GmpFemMatrixMode
Control mode specifying if the matrix set should have one global matrix per local matrix (MATCH_MODE)...
Definition: gmpFemMatrixSet.h:67
Declaration of usefull configuration definitions for the plugin library.
~GmpFemMatrixTypeData()
Destructor.
Definition: gmpFemMatrixSet.h:200
void clear()
int typeFromIndex(int index) const
int tindex(GmpFemMatrixTypes type) const
Returns the index in _globalMatrices for the given type, accounting for the selected matrix mode.
Definition: gmpFemMatrixSet.h:181
GmSolverMatrix * globalDebugPrintMatrix(GmpFemMatrixTypes type) const
Returns the auxiliar matrix used for storing global matrices matching local ones for debug printing p...
Definition: gmpFemMatrixSet.h:156
int _transposed
The type of the associated transposed dofs vector or -1 if no vector was associated with this type.
Definition: gmpFemMatrixSet.h:194