GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
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 below this line
82 // --------------------------------------
85};
86
89{
90public:
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
155protected:
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
169private:
174
177};
178
190template <int N>
192{
193 static_assert(N >= 1 && N <= 3, "Unexpeced number of tables");
194
195public:
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
229protected:
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
237 int _nip;
238 int _rules[3];
239 const QVector<QPair<double, double>>* _tables[3];
241};
242
251template <int N>
253{
254public:
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
284protected:
286 int rule, const QVector<QPair<GmVector, double>>* table, int degree);
287
290 int _rule;
293};
294
297
303template <int N>
305{
306public:
307 virtual void integrationPoint(int index, GmVector& naturalCoord, double* weight) const;
308
310};
311
312
313#endif
314
Integration rule base classe.
Definition gmIntegrationRule.h:89
virtual int rulePar(int num) const =0
Returns the value of the numbered rule parameter received in the rule constructor (-1 if unused)....
virtual QString ruleName() const =0
Returns the current ruleName adopted by this integration rule.
virtual ~GmIntegrationRule()
Virtual destructor.
Definition gmIntegrationRule.h:92
virtual int degree() const =0
Returns the integration degree for this rule (The polynomial degree for which this rule is exact)
virtual int numNaturalCoord() const =0
Returns the number of natural coordinates used by this integration rule.
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 ruleParNumPoints(int num) const =0
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 =0
Given an index from 0 to numPoints() - 1, fills naturalCoord and weight with the position and weigth ...
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
static QMutex _cipCacheMutex
The mutex protecting _cipCache.
Definition gmIntegrationRule.h:176
virtual GmIntegrationRuleType ruleType() const =0
Returns the type of the integration rule.
virtual int cacheKey() const =0
Returns an unique integer that can be used to uniquelly represent this kind of integration rule (i....
virtual bool isValid() const =0
Returns true if this is a valid integration rule object, false if not.
A helper class used to combine 1, 2 or 3 single "line" integration rule tables into a multi-dimension...
Definition gmIntegrationRule.h:192
GmIntegrationRuleType _rtype
The rule type.
Definition gmIntegrationRule.h:235
virtual int numNaturalCoord() const
Returns the number of natural coordinates used by this integration rule.
Definition gmIntegrationRule.h:205
GmIntegrationRuleCacheKeyBase _keyBase
The base cache key.
Definition gmIntegrationRule.h:240
virtual int numPoints() const
Returns the number of integration points returned by this rule.
Definition gmIntegrationRule.h:200
int _nip
The number of integration points.
Definition gmIntegrationRule.h:237
virtual void integrationPoint(int index, GmVector &naturalCoord, double *weight) const
Given an index from 0 to numPoints() - 1, fills naturalCoord and weight with the position and weigth ...
bool isValid() const
Returns true if this is a valid integration rule object, false if not.
Definition gmIntegrationRule.h:197
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
virtual GmIntegrationRuleType ruleType() const
Returns the type of the integration rule.
Definition gmIntegrationRule.h:211
virtual int degree() const
Returns the integration degree for this rule (The polynomial degree for which this rule is exact)
Definition gmIntegrationRule.h:208
int _degree
The combined rule degree (the minimum of the individual rule degrees)
Definition gmIntegrationRule.h:236
virtual QString ruleName() const
Returns the current ruleName adopted by this integration rule.
Definition gmIntegrationRule.h:214
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
An especialization of the barycentric, single table, integration rule class to treat the case when th...
Definition gmIntegrationRule.h:305
A helper class used to implement rules based on a single table storing the full natural coordinate + ...
Definition gmIntegrationRule.h:253
int _degree
The rule degree.
Definition gmIntegrationRule.h:289
int _rule
The rule number.
Definition gmIntegrationRule.h:290
bool isValid() const
Returns true if this is a valid integration rule object, false if not.
Definition gmIntegrationRule.h:256
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
virtual QString ruleName() const
Returns the current ruleName adopted by this integration rule.
Definition gmIntegrationRule.h:273
GmIntegrationRuleType _rtype
The rule type.
Definition gmIntegrationRule.h:288
virtual int degree() const
Returns the integration degree for this rule (The polynomial degree for which this rule is exact)
Definition gmIntegrationRule.h:267
GmIntegrationRuleCacheKeyBase _keyBase
The base cache key.
Definition gmIntegrationRule.h:292
virtual int numNaturalCoord() const
Returns the number of natural coordinates used by this integration rule.
Definition gmIntegrationRule.h:264
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
virtual int ruleParNumPoints(int num) const
Definition gmIntegrationRule.h:279
const QVector< QPair< GmVector, double > > * _table
The selected rule table or NULL for invalid rules.
Definition gmIntegrationRule.h:291
virtual GmIntegrationRuleType ruleType() const
Returns the type of the integration rule.
Definition gmIntegrationRule.h:270
virtual int numPoints() const
Returns the number of integration points returned by this rule.
Definition gmIntegrationRule.h:259
Declaration of the GmCellType enum.
GmCellType
Mesh Cell types. Don't change type orders or add types without reading comments below.
Definition gmCellType.h:31
Declaration of useful configuration definitions for the Core library.
#define GMC_API_EXPORT
Macro for controlling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_L...
Definition gmCoreConfig.h:35
GmIntegrationRuleCacheKeyBase
Enumeration used to define global cache keys for integration rules. These values are used by implemen...
Definition gmIntegrationRule.h:41
@ GM_QUAD_NIR_KEY
Base cache key for 2D Newton cotes quad rules.
Definition gmIntegrationRule.h:52
@ GM_HEX_LIR_KEY
Base cache key for 3D Lobatto hex rules.
Definition gmIntegrationRule.h:60
@ GM_TRI_GIR_KEY
Base cache key for 2D Gauss triangle rules.
Definition gmIntegrationRule.h:44
@ GM_LINE_NIR_KEY
Base cache key for 1D Newton cotes line rules.
Definition gmIntegrationRule.h:51
@ GM_HEX_GIR_KEY
Base cache key for 3D Gauss hex rules.
Definition gmIntegrationRule.h:45
@ GM_TET_NIR_KEY
Base cache key for 3D Newton cotes tetrahedron rules.
Definition gmIntegrationRule.h:55
@ GM_WEDGE_GIR_KEY
Base cache key for 3D Gauss wedge rules.
Definition gmIntegrationRule.h:47
@ GM_TRI_NIR_KEY
Base cache key for 2D Newton cotes triangle rules.
Definition gmIntegrationRule.h:53
@ GM_TET_GIR_KEY
Base cache key for 3D Gauss tetrahedron rules.
Definition gmIntegrationRule.h:46
@ GM_INT_GIR_KEY
Base cache key for 3D Gauss triangle interface rules.
Definition gmIntegrationRule.h:49
@ GM_QUAD_GIR_KEY
Base cache key for 2D Gauss quad rules.
Definition gmIntegrationRule.h:43
@ GM_LINE_GIR_KEY
Base cache key for 1D Gauss line rules.
Definition gmIntegrationRule.h:42
@ GM_USER_IR_KEY
Base cache key for user derived classes.
Definition gmIntegrationRule.h:63
@ GM_INT_NIR_KEY
Base cache key for 3D Newton triangle interface rules.
Definition gmIntegrationRule.h:56
@ GM_HEX_NIR_KEY
Base cache key for 3D Newton cotes hex rules.
Definition gmIntegrationRule.h:54
@ GM_QUAD_LIR_KEY
Base cache key for 2D Lobatto quad rules.
Definition gmIntegrationRule.h:59
@ GM_LINE_LIR_KEY
Base cache key for 1D Lobatto line rules.
Definition gmIntegrationRule.h:58
@ GM_PYRA_GIR_KEY
Base cache key for 3D Gauss pyramid rules.
Definition gmIntegrationRule.h:48
GmIntegrationRuleType
The type of desired integration rule (Gauss quadrature, Lobatto quadrature, etc)
Definition gmIntegrationRule.h:68
@ GM_CLOSED_NEWTON_RULE_TYPE
Closed Newton-Cotes rules.
Definition gmIntegrationRule.h:77
@ GM_AUTO_RULE_TYPE
The type of rule should be choosed by the default for the target element type.
Definition gmIntegrationRule.h:84
@ GM_NUM_RULE_TYPES
Nota a rule, the number of rules above.
Definition gmIntegrationRule.h:83
@ GM_GAUSS_RULE_TYPE
Gauss rules.
Definition gmIntegrationRule.h:75
@ GM_LOBATTO_RULE_TYPE
Lobatto rules.
Definition gmIntegrationRule.h:76
@ GM_OPEN_NEWTON_RULE_TYPE
Open Newton-Cotes rules.
Definition gmIntegrationRule.h:78
GmSingleTableIntegrationRule< N > GmBarycentricSingleTableIntegrationRule
An alias for GmSingleTableIntegrationRule used for barycentric coordianate based classes.
Definition gmIntegrationRule.h:296
Declaration of the GmVector class.
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition gmVector.h:34