GemaCoreLib
The GeMA Core library
gmIntegrationRule.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_INT_RULE_H_
25 #define _GEMA_INT_RULE_H_
26 
27 #include "gmCoreConfig.h"
28 #include "gmVector.h"
29 #include "gmCellType.h"
30 
31 #include <QString>
32 #include <QMutex>
33 #include <assert.h>
34 
35 
41 {
42  GM_LINE_GIR_KEY = 10000000,
43  GM_QUAD_GIR_KEY = 20000000,
44  GM_TRI_GIR_KEY = 30000000,
45  GM_HEX_GIR_KEY = 40000000,
46  GM_TET_GIR_KEY = 50000000,
47  GM_WEDGE_GIR_KEY = 60000000,
48  GM_PYRA_GIR_KEY = 70000000,
49  GM_INT_GIR_KEY = 80000000,
50 
51  GM_LINE_NIR_KEY = 90000000,
52  GM_QUAD_NIR_KEY = 100000000,
53  GM_TRI_NIR_KEY = 110000000,
54  GM_HEX_NIR_KEY = 120000000,
55  GM_TET_NIR_KEY = 130000000,
56  GM_INT_NIR_KEY = 140000000,
57 
58  GM_LINE_LIR_KEY = 150000000,
59  GM_QUAD_LIR_KEY = 160000000,
60  GM_HEX_LIR_KEY = 170000000,
61 
62  //-----------
63  GM_USER_IR_KEY = 180000000,
64 };
65 
68 {
69  // Please, pretty please, do NOT change the order of the following enum.
70  // For that, and also when adding entries, you MUST update the implementation
71  // for the GmIntegrationRule::makeRuleName() method and for the
72  // GmCellGeometryIntegrationRuleSetDefaultRules and GmCellGeometryIntegrationRuleSet
73  // classes. You will also need to change all instantiation of those template classes.
74  // --------------------------------------
79 
80  // --------------------------------------
81  // --- Do not add rules bellow this line
82  // --------------------------------------
85 };
86 
89 {
90 public:
92  virtual ~GmIntegrationRule() {}
93 
100  virtual bool isValid() const = 0;
101 
103  virtual int numPoints() const = 0;
104 
113  virtual void integrationPoint(int index, GmVector& naturalCoord, double* weight) const = 0;
114 
116  virtual int numNaturalCoord() const = 0;
117 
119  virtual int degree() const = 0;
120 
122  virtual GmIntegrationRuleType ruleType() const = 0;
123 
125  virtual QString ruleName() const = 0;
126 
130  virtual int rulePar(int num) const = 0;
131 
140  virtual int ruleParNumPoints(int num) const = 0;
141 
149  virtual int cacheKey() const = 0;
150 
151  virtual const QVector<int>& closestIntegrationIndex(GmCellType type, int P, int Q, int nodeIndex) const;
152 
153  static GmIntegrationRule* instance(GmCellType type, int P, int Q, GmIntegrationRuleType irType, int rule1 = -1, int rule2 = -1, int rule3 = -1);
154 
155 protected:
157  int makeCacheKey(GmIntegrationRuleCacheKeyBase base, bool closed, int rule1, int rule2 = -1, int rule3 = -1) const
158  {
159  assert(rule1 < 100 && rule2 < 100 && rule3 < 100);
160  assert(base >= 10000000);
161  int key = base + (closed * 1000000) + rule1;
162  if(rule2 != -1) key += rule2 * 100;
163  if(rule3 != -1) key += rule3 * 10000;
164  return key;
165  }
166 
167  QString makeRuleName(GmIntegrationRuleType irType, int rule1, int rule2 = -1, int rule3 = -1) const;
168 
169 private:
174 
177 };
178 
190 template <int N>
192 {
193  static_assert(N >= 1 && N <= 3, "Unexpeced number of tables");
194 
195 public:
196  // See comments on the base class
197  bool isValid() const { return _tables[0]; }
198 
199  // See comments on the base class
200  virtual int numPoints() const { assert(isValid()); return _nip; }
201 
202  virtual void integrationPoint(int index, GmVector& naturalCoord, double* weight) const;
203 
204  // See comments on the base class
205  virtual int numNaturalCoord() const { assert(isValid()); return N; }
206 
207  // See comments on the base class
208  virtual int degree() const { assert(isValid()); return _degree; }
209 
210  // See comments on the base class
211  virtual GmIntegrationRuleType ruleType() const { return _rtype; }
212 
213  // See comments on the base class
214  virtual QString ruleName() const { return makeRuleName(_rtype, _rules[0], _rules[1], _rules[2]); }
215 
216  // See comments on the base class
217  virtual int rulePar(int num) const { assert(num >= 1 && num <= 3); return _rules[num-1]; }
218 
219  // See comments on the base class
220  virtual int ruleParNumPoints(int num) const
221  {
222  assert(num >= 1 && num <= 3);
223  return _tables[num-1] ? _tables[num-1]->size() : -1;
224  }
225 
226  // See comments on the base class
227  virtual int cacheKey() const { return makeCacheKey(_keyBase, _rtype == GM_CLOSED_NEWTON_RULE_TYPE, _rules[0], _rules[1], _rules[2]); }
228 
229 protected:
231  int rule1, const QVector<QPair<double, double>>* table1, int degree1,
232  int rule2 = -1, const QVector<QPair<double, double>>* table2 = NULL, int degree2 = 0,
233  int rule3 = -1, const QVector<QPair<double, double>>* table3 = NULL, int degree3 = 0);
234 
236  int _degree;
237  int _nip;
238  int _rules[3];
239  const QVector<QPair<double, double>>* _tables[3];
241 };
242 
251 template <int N>
253 {
254 public:
255  // See comments on the base class
256  bool isValid() const { return _table; }
257 
258  // See comments on the base class
259  virtual int numPoints() const { assert(isValid()); return _table->size(); }
260 
261  virtual void integrationPoint(int index, GmVector& naturalCoord, double* weight) const;
262 
263  // See comments on the base class
264  virtual int numNaturalCoord() const { assert(isValid()); return N; }
265 
266  // See comments on the base class.
267  virtual int degree() const { assert(isValid()); return _degree; }
268 
269  // See comments on the base class
270  virtual GmIntegrationRuleType ruleType() const { return _rtype; }
271 
272  // See comments on the base class
273  virtual QString ruleName() const { return makeRuleName(_rtype, _rule); }
274 
275  // See comments on the base class
276  virtual int rulePar(int num) const { return (num == 1) ? _rule : -1; }
277 
278  // See comments on the base class
279  virtual int ruleParNumPoints(int num) const { return (num == 1) ? numPoints() : -1; }
280 
281  // See comments on the base class
282  virtual int cacheKey() const { return makeCacheKey(_keyBase, _rtype == GM_CLOSED_NEWTON_RULE_TYPE, _rule); }
283 
284 protected:
286  int rule, const QVector<QPair<GmVector, double>>* table, int degree);
287 
289  int _degree;
290  int _rule;
293 };
294 
297 
303 template <int N>
305 {
306 public:
307  virtual void integrationPoint(int index, GmVector& naturalCoord, double* weight) const;
308 
310 };
311 
312 
313 #endif
314 
virtual QString ruleName() const
Returns the current ruleName adopted by this integration rule.
Definition: gmIntegrationRule.h:214
GmIntegrationRuleType
The type of desired integration rule (Gauss quadrature, Lobatto quadrature, etc)
Definition: gmIntegrationRule.h:67
virtual GmIntegrationRuleType ruleType() const
Returns the type of the integration rule.
Definition: gmIntegrationRule.h:270
Gauss rules.
Definition: gmIntegrationRule.h:75
Base cache key for 3D Newton cotes tetrahedron rules.
Definition: gmIntegrationRule.h:55
Declaration of usefull configuration definitions for the Core library.
const QVector< QPair< GmVector, double > > * _table
The selected rule table or NULL for invalid rules.
Definition: gmIntegrationRule.h:291
virtual int cacheKey() const
Returns an unique integer that can be used to uniquelly represent this kind of integration rule (i....
Definition: gmIntegrationRule.h:282
Declaration of the GmCellType enum.
Nota a rule, the number of rules above.
Definition: gmIntegrationRule.h:83
virtual int rulePar(int num) const
Returns the value of the numbered rule parameter received in the rule constructor (-1 if unused)....
Definition: gmIntegrationRule.h:276
GmIntegrationRuleType _rtype
The rule type.
Definition: gmIntegrationRule.h:288
int _nip
The number of integration points.
Definition: gmIntegrationRule.h:237
virtual QString ruleName() const
Returns the current ruleName adopted by this integration rule.
Definition: gmIntegrationRule.h:273
bool isValid() const
Returns true if this is a valid integration rule object, false if not.
Definition: gmIntegrationRule.h:197
Lobatto rules.
Definition: gmIntegrationRule.h:76
GmIntegrationRuleCacheKeyBase _keyBase
The base cache key.
Definition: gmIntegrationRule.h:292
Base cache key for 3D Gauss tetrahedron rules.
Definition: gmIntegrationRule.h:46
int _degree
The combined rule degree (the minimum of the individual rule degrees)
Definition: gmIntegrationRule.h:236
virtual int numPoints() const
Returns the number of integration points returned by this rule.
Definition: gmIntegrationRule.h:200
GmIntegrationRuleCacheKeyBase
Enumeration used to define global cache keys for integration rules. These values are used by implemen...
Definition: gmIntegrationRule.h:40
Base cache key for 3D Newton triangle interface rules.
Definition: gmIntegrationRule.h:56
Integration rule base classe.
Definition: gmIntegrationRule.h:88
An especialization of the barycentric, single table, integration rule class to treat the case when th...
Definition: gmIntegrationRule.h:304
static QMutex _cipCacheMutex
The mutex protecting _cipCache.
Definition: gmIntegrationRule.h:176
GmIntegrationRuleType _rtype
The rule type.
Definition: gmIntegrationRule.h:235
virtual int ruleParNumPoints(int num) const
Definition: gmIntegrationRule.h:279
virtual int numNaturalCoord() const
Returns the number of natural coordinates used by this integration rule.
Definition: gmIntegrationRule.h:205
Base cache key for 3D Gauss hex rules.
Definition: gmIntegrationRule.h:45
int makeCacheKey(GmIntegrationRuleCacheKeyBase base, bool closed, int rule1, int rule2=-1, int rule3=-1) const
Creates an unique cache key based on the rule type cache key and the rule parameters.
Definition: gmIntegrationRule.h:157
virtual int numPoints() const =0
Returns the number of integration points returned by this rule.
virtual void integrationPoint(int index, GmVector &naturalCoord, double *weight) const
This function returns weights and points to be sampled for the configured integration rule,...
Definition: gmIntegrationRule.cpp:355
virtual bool isValid() const =0
Returns true if this is a valid integration rule object, false if not.
Base cache key for 3D Gauss triangle interface rules.
Definition: gmIntegrationRule.h:49
Base cache key for 3D Newton cotes hex rules.
Definition: gmIntegrationRule.h:54
Base cache key for 2D Gauss quad rules.
Definition: gmIntegrationRule.h:43
virtual int ruleParNumPoints(int num) const
Definition: gmIntegrationRule.h:220
virtual int rulePar(int num) const
Returns the value of the numbered rule parameter received in the rule constructor (-1 if unused)....
Definition: gmIntegrationRule.h:217
Base cache key for 3D Gauss wedge rules.
Definition: gmIntegrationRule.h:47
Base cache key for 2D Newton cotes triangle rules.
Definition: gmIntegrationRule.h:53
virtual int degree() const
Returns the integration degree for this rule (The polynomial degree for which this rule is exact)
Definition: gmIntegrationRule.h:267
Base cache key for 2D Newton cotes quad rules.
Definition: gmIntegrationRule.h:52
QString makeRuleName(GmIntegrationRuleType irType, int rule1, int rule2=-1, int rule3=-1) const
Returns a standard rule name based on rule type and rule parameters.
Definition: gmIntegrationRule.cpp:129
GmIntegrationRuleCacheKeyBase _keyBase
The base cache key.
Definition: gmIntegrationRule.h:240
Declaration of the GmVector class.
Base cache key for user derived classes.
Definition: gmIntegrationRule.h:63
#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
virtual int numPoints() const
Returns the number of integration points returned by this rule.
Definition: gmIntegrationRule.h:259
Base cache key for 2D Gauss triangle rules.
Definition: gmIntegrationRule.h:44
Base cache key for 1D Gauss line rules.
Definition: gmIntegrationRule.h:42
int _rule
The rule number.
Definition: gmIntegrationRule.h:290
The type of rule should be choosed by the default for the target element type.
Definition: gmIntegrationRule.h:84
virtual ~GmIntegrationRule()
Virtual destructor.
Definition: gmIntegrationRule.h:92
GmCellType
Mesh Cell types. Don't change type orders or add types without reading comments below.
Definition: gmCellType.h:30
Base cache key for 2D Lobatto quad rules.
Definition: gmIntegrationRule.h:59
virtual int cacheKey() const
Returns an unique integer that can be used to uniquelly represent this kind of integration rule (i....
Definition: gmIntegrationRule.h:227
Base cache key for 1D Newton cotes line rules.
Definition: gmIntegrationRule.h:51
A helper class used to combine 1, 2 or 3 single "line" integration rule tables into a multi-dimension...
Definition: gmIntegrationRule.h:191
Base cache key for 3D Gauss pyramid rules.
Definition: gmIntegrationRule.h:48
virtual GmIntegrationRuleType ruleType() const
Returns the type of the integration rule.
Definition: gmIntegrationRule.h:211
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition: gmVector.h:34
Base cache key for 3D Lobatto hex rules.
Definition: gmIntegrationRule.h:60
bool isValid() const
Returns true if this is a valid integration rule object, false if not.
Definition: gmIntegrationRule.h:256
Open Newton-Cotes rules.
Definition: gmIntegrationRule.h:78
A helper class used to implement rules based on a single table storing the full natural coordinate + ...
Definition: gmIntegrationRule.h:252
Closed Newton-Cotes rules.
Definition: gmIntegrationRule.h:77
static QMap< QPair< GmCellType, int >, QVector< QVector< int > > > _cipCache
A global cache, keyed by cell type + cacheKey(), storing the list of closest integration points to a ...
Definition: gmIntegrationRule.h:173
virtual void integrationPoint(int index, GmVector &naturalCoord, double *weight) const =0
Given an index from 0 to numPoints() - 1, fills naturalCoord and weight with the position and weigth ...
int _degree
The rule degree.
Definition: gmIntegrationRule.h:289
virtual int degree() const
Returns the integration degree for this rule (The polynomial degree for which this rule is exact)
Definition: gmIntegrationRule.h:208
virtual int numNaturalCoord() const
Returns the number of natural coordinates used by this integration rule.
Definition: gmIntegrationRule.h:264
Base cache key for 1D Lobatto line rules.
Definition: gmIntegrationRule.h:58