MFEM  v3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
intrules.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.googlecode.com.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 #ifndef MFEM_INTRULES
13 #define MFEM_INTRULES
14 
15 #include "../config/config.hpp"
16 #include "../general/array.hpp"
17 
18 namespace mfem
19 {
20 
21 /* Classes for IntegrationPoint, IntegrationRule, and container class
22  IntegrationRules. Declares the global variable IntRules */
23 
26 {
27 public:
28  double x, y, z, weight;
29 
30  void Init() { x = y = z = weight = 0.0; }
31 
32  void Set(const double *p, const int dim)
33  { x = p[0]; if (dim > 1) { y = p[1]; if (dim > 2) z = p[2]; } }
34 
35  void Get(double *p, const int dim) const
36  { p[0] = x; if (dim > 1) { p[1] = y; if (dim > 2) p[2] = z; } }
37 
38  void Set(const double x1, const double x2, const double x3, const double w)
39  { x = x1; y = x2; z = x3; weight = w; }
40 
41  void Set3w(const double *p) { x = p[0]; y = p[1]; z = p[2]; weight = p[3]; }
42 
43  void Set3(const double x1, const double x2, const double x3)
44  { x = x1; y = x2; z = x3; }
45 
46  void Set3(const double *p) { x = p[0]; y = p[1]; z = p[2]; }
47 
48  void Set2w(const double x1, const double x2, const double w)
49  { x = x1; y = x2; weight = w; }
50 
51  void Set2w(const double *p) { x = p[0]; y = p[1]; weight = p[2]; }
52 
53  void Set2(const double x1, const double x2) { x = x1; y = x2; }
54 
55  void Set2(const double *p) { x = p[0]; y = p[1]; }
56 
57  void Set1w(const double x1, const double w) { x = x1; weight = w; }
58 
59  void Set1w(const double *p) { x = p[0]; weight = p[1]; }
60 };
61 
63 class IntegrationRule : public Array<IntegrationPoint>
64 {
65 private:
66  friend class IntegrationRules;
67 
69  void GaussianRule();
70 
72  void UniformRule();
73 
75  void GrundmannMollerSimplexRule(int s, int n = 3);
76 
77  void AddTriMidPoint(const int off, const double weight)
78  { IntPoint(off).Set2w(1./3., 1./3., weight); }
79 
80  void AddTriPoints3(const int off, const double a, const double b,
81  const double weight)
82  {
83  IntPoint(off + 0).Set2w(a, a, weight);
84  IntPoint(off + 1).Set2w(a, b, weight);
85  IntPoint(off + 2).Set2w(b, a, weight);
86  }
87 
88  void AddTriPoints3(const int off, const double a, const double weight)
89  { AddTriPoints3(off, a, 1. - 2.*a, weight); }
90 
91  void AddTriPoints3b(const int off, const double b, const double weight)
92  { AddTriPoints3(off, (1. - b)/2., b, weight); }
93 
94  void AddTriPoints3R(const int off, const double a, const double b,
95  const double c, const double weight)
96  {
97  IntPoint(off + 0).Set2w(a, b, weight);
98  IntPoint(off + 1).Set2w(c, a, weight);
99  IntPoint(off + 2).Set2w(b, c, weight);
100  }
101 
102  void AddTriPoints3R(const int off, const double a, const double b,
103  const double weight)
104  { AddTriPoints3R(off, a, b, 1. - a - b, weight); }
105 
106  void AddTriPoints6(const int off, const double a, const double b,
107  const double c, const double weight)
108  {
109  IntPoint(off + 0).Set2w(a, b, weight);
110  IntPoint(off + 1).Set2w(b, a, weight);
111  IntPoint(off + 2).Set2w(a, c, weight);
112  IntPoint(off + 3).Set2w(c, a, weight);
113  IntPoint(off + 4).Set2w(b, c, weight);
114  IntPoint(off + 5).Set2w(c, b, weight);
115  }
116 
117  void AddTriPoints6(const int off, const double a, const double b,
118  const double weight)
119  { AddTriPoints6(off, a, b, 1. - a - b, weight); }
120 
121  // add the permutations of (a,a,b)
122  void AddTetPoints3(const int off, const double a, const double b,
123  const double weight)
124  {
125  IntPoint(off + 0).Set(a, a, b, weight);
126  IntPoint(off + 1).Set(a, b, a, weight);
127  IntPoint(off + 2).Set(b, a, a, weight);
128  }
129 
130  // add the permutations of (a,b,c)
131  void AddTetPoints6(const int off, const double a, const double b,
132  const double c, const double weight)
133  {
134  IntPoint(off + 0).Set(a, b, c, weight);
135  IntPoint(off + 1).Set(a, c, b, weight);
136  IntPoint(off + 2).Set(b, c, a, weight);
137  IntPoint(off + 3).Set(b, a, c, weight);
138  IntPoint(off + 4).Set(c, a, b, weight);
139  IntPoint(off + 5).Set(c, b, a, weight);
140  }
141 
142  void AddTetMidPoint(const int off, const double weight)
143  { IntPoint(off).Set(0.25, 0.25, 0.25, weight); }
144 
145  // given a, add the permutations of (a,a,a,b), where 3*a + b = 1
146  void AddTetPoints4(const int off, const double a, const double weight)
147  {
148  IntPoint(off).Set(a, a, a, weight);
149  AddTetPoints3(off + 1, a, 1. - 3.*a, weight);
150  }
151 
152  // given b, add the permutations of (a,a,a,b), where 3*a + b = 1
153  void AddTetPoints4b(const int off, const double b, const double weight)
154  {
155  const double a = (1. - b)/3.;
156  IntPoint(off).Set(a, a, a, weight);
157  AddTetPoints3(off + 1, a, b, weight);
158  }
159 
160  // add the permutations of (a,a,b,b), 2*(a + b) = 1
161  void AddTetPoints6(const int off, const double a, const double weight)
162  {
163  const double b = 0.5 - a;
164  AddTetPoints3(off, a, b, weight);
165  AddTetPoints3(off + 3, b, a, weight);
166  }
167 
168  // given (a,b) or (a,c), add the permutations of (a,a,b,c), 2*a + b + c = 1
169  void AddTetPoints12(const int off, const double a, const double bc,
170  const double weight)
171  {
172  const double cb = 1. - 2*a - bc;
173  AddTetPoints3(off, a, bc, weight);
174  AddTetPoints3(off + 3, a, cb, weight);
175  AddTetPoints6(off + 6, a, bc, cb, weight);
176  }
177 
178  // given (b,c), add the permutations of (a,a,b,c), 2*a + b + c = 1
179  void AddTetPoints12bc(const int off, const double b, const double c,
180  const double weight)
181  {
182  const double a = (1. - b - c)/2.;
183  AddTetPoints3(off, a, b, weight);
184  AddTetPoints3(off + 3, a, c, weight);
185  AddTetPoints6(off + 6, a, b, c, weight);
186  }
187 
188 public:
190 
192  explicit IntegrationRule(int NP) : Array<IntegrationPoint>(NP)
193  {
194  for (int i = 0; i < this->Size(); i++)
195  (*this)[i].Init();
196  }
197 
200 
202  int GetNPoints() const { return Size(); }
203 
205  IntegrationPoint &IntPoint(int i) { return (*this)[i]; }
206 
208  const IntegrationPoint &IntPoint(int i) const { return (*this)[i]; }
209 
212 };
213 
216 {
217 private:
218  int own_rules, refined;
219 
220  Array<IntegrationRule *> PointIntRules;
221  Array<IntegrationRule *> SegmentIntRules;
222  Array<IntegrationRule *> TriangleIntRules;
223  Array<IntegrationRule *> SquareIntRules;
224  Array<IntegrationRule *> TetrahedronIntRules;
225  Array<IntegrationRule *> CubeIntRules;
226 
227  void AllocIntRule(Array<IntegrationRule *> &ir_array, int Order)
228  {
229  if (ir_array.Size() <= Order)
230  ir_array.SetSize(Order + 1, NULL);
231  }
232  bool HaveIntRule(Array<IntegrationRule *> &ir_array, int Order)
233  {
234  return (ir_array.Size() > Order && ir_array[Order] != NULL);
235  }
236 
237  IntegrationRule *GenerateIntegrationRule(int GeomType, int Order);
238  IntegrationRule *PointIntegrationRule(int Order);
239  IntegrationRule *SegmentIntegrationRule(int Order);
240  IntegrationRule *TriangleIntegrationRule(int Order);
241  IntegrationRule *SquareIntegrationRule(int Order);
242  IntegrationRule *TetrahedronIntegrationRule(int Order);
243  IntegrationRule *CubeIntegrationRule(int Order);
244 
245  void DeleteIntRuleArray(Array<IntegrationRule *> &ir_array);
246 
247 public:
250  explicit IntegrationRules(int Ref = 0);
251 
253  const IntegrationRule &Get(int GeomType, int Order);
254 
255  void Set(int GeomType, int Order, IntegrationRule &IntRule);
256 
257  void SetOwnRules(int o) { own_rules = o; }
258 
261 };
262 
265 
268 
269 }
270 
271 #endif
int GetNPoints() const
Returns the number of the points in the integration rule.
Definition: intrules.hpp:202
void Set(const double *p, const int dim)
Definition: intrules.hpp:32
int Size() const
Logical size of the array.
Definition: array.hpp:108
void Get(double *p, const int dim) const
Definition: intrules.hpp:35
Class for integration rule.
Definition: intrules.hpp:63
const IntegrationRule & Get(int GeomType, int Order)
Returns an integration rule for given GeomType and Order.
Definition: intrules.cpp:194
void Set1w(const double *p)
Definition: intrules.hpp:59
~IntegrationRules()
Destroys an IntegrationRules object.
Definition: intrules.cpp:259
Container class for integration rules.
Definition: intrules.hpp:215
void Set(const double x1, const double x2, const double x3, const double w)
Definition: intrules.hpp:38
const IntegrationPoint & IntPoint(int i) const
Returns a const reference to the i-th integration point.
Definition: intrules.hpp:208
void Set3(const double *p)
Definition: intrules.hpp:46
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
Definition: intrules.hpp:205
void SetOwnRules(int o)
Definition: intrules.hpp:257
IntegrationRules IntRules(0)
A global object with all integration rules (defined in intrules.cpp)
Definition: intrules.hpp:264
IntegrationRules(int Ref=0)
Definition: intrules.cpp:166
~IntegrationRule()
Destroys an IntegrationRule object.
Definition: intrules.hpp:211
void Set3w(const double *p)
Definition: intrules.hpp:41
void Set2(const double x1, const double x2)
Definition: intrules.hpp:53
void Set3(const double x1, const double x2, const double x3)
Definition: intrules.hpp:43
void Set2w(const double *p)
Definition: intrules.hpp:51
void SetSize(int nsize)
Change logical size of the array, keep existing entries.
Definition: array.hpp:293
Class for integration point with weight.
Definition: intrules.hpp:25
void Set2(const double *p)
Definition: intrules.hpp:55
IntegrationRules RefinedIntRules(1)
A global object with all refined integration rules.
Definition: intrules.hpp:267
void Set2w(const double x1, const double x2, const double w)
Definition: intrules.hpp:48
IntegrationRule(int NP)
Construct an integration rule with given number of points.
Definition: intrules.hpp:192
void Set(int GeomType, int Order, IntegrationRule &IntRule)
Definition: intrules.cpp:217
void Set1w(const double x1, const double w)
Definition: intrules.hpp:57