MFEM  v3.2
Finite element discretization library
 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.org.
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  {
34  x = p[0];
35  if (dim > 1)
36  {
37  y = p[1];
38  if (dim > 2)
39  {
40  z = p[2];
41  }
42  }
43  }
44 
45  void Get(double *p, const int dim) const
46  {
47  p[0] = x;
48  if (dim > 1)
49  {
50  p[1] = y;
51  if (dim > 2)
52  {
53  p[2] = z;
54  }
55  }
56  }
57 
58  void Set(const double x1, const double x2, const double x3, const double w)
59  { x = x1; y = x2; z = x3; weight = w; }
60 
61  void Set3w(const double *p) { x = p[0]; y = p[1]; z = p[2]; weight = p[3]; }
62 
63  void Set3(const double x1, const double x2, const double x3)
64  { x = x1; y = x2; z = x3; }
65 
66  void Set3(const double *p) { x = p[0]; y = p[1]; z = p[2]; }
67 
68  void Set2w(const double x1, const double x2, const double w)
69  { x = x1; y = x2; weight = w; }
70 
71  void Set2w(const double *p) { x = p[0]; y = p[1]; weight = p[2]; }
72 
73  void Set2(const double x1, const double x2) { x = x1; y = x2; }
74 
75  void Set2(const double *p) { x = p[0]; y = p[1]; }
76 
77  void Set1w(const double x1, const double w) { x = x1; weight = w; }
78 
79  void Set1w(const double *p) { x = p[0]; weight = p[1]; }
80 };
81 
83 class IntegrationRule : public Array<IntegrationPoint>
84 {
85 private:
86  friend class IntegrationRules;
87 
89  void GaussianRule();
90 
92  void UniformRule();
93 
95  void GrundmannMollerSimplexRule(int s, int n = 3);
96 
97  void AddTriMidPoint(const int off, const double weight)
98  { IntPoint(off).Set2w(1./3., 1./3., weight); }
99 
100  void AddTriPoints3(const int off, const double a, const double b,
101  const double weight)
102  {
103  IntPoint(off + 0).Set2w(a, a, weight);
104  IntPoint(off + 1).Set2w(a, b, weight);
105  IntPoint(off + 2).Set2w(b, a, weight);
106  }
107 
108  void AddTriPoints3(const int off, const double a, const double weight)
109  { AddTriPoints3(off, a, 1. - 2.*a, weight); }
110 
111  void AddTriPoints3b(const int off, const double b, const double weight)
112  { AddTriPoints3(off, (1. - b)/2., b, weight); }
113 
114  void AddTriPoints3R(const int off, const double a, const double b,
115  const double c, const double weight)
116  {
117  IntPoint(off + 0).Set2w(a, b, weight);
118  IntPoint(off + 1).Set2w(c, a, weight);
119  IntPoint(off + 2).Set2w(b, c, weight);
120  }
121 
122  void AddTriPoints3R(const int off, const double a, const double b,
123  const double weight)
124  { AddTriPoints3R(off, a, b, 1. - a - b, weight); }
125 
126  void AddTriPoints6(const int off, const double a, const double b,
127  const double c, const double weight)
128  {
129  IntPoint(off + 0).Set2w(a, b, weight);
130  IntPoint(off + 1).Set2w(b, a, weight);
131  IntPoint(off + 2).Set2w(a, c, weight);
132  IntPoint(off + 3).Set2w(c, a, weight);
133  IntPoint(off + 4).Set2w(b, c, weight);
134  IntPoint(off + 5).Set2w(c, b, weight);
135  }
136 
137  void AddTriPoints6(const int off, const double a, const double b,
138  const double weight)
139  { AddTriPoints6(off, a, b, 1. - a - b, weight); }
140 
141  // add the permutations of (a,a,b)
142  void AddTetPoints3(const int off, const double a, const double b,
143  const double weight)
144  {
145  IntPoint(off + 0).Set(a, a, b, weight);
146  IntPoint(off + 1).Set(a, b, a, weight);
147  IntPoint(off + 2).Set(b, a, a, weight);
148  }
149 
150  // add the permutations of (a,b,c)
151  void AddTetPoints6(const int off, const double a, const double b,
152  const double c, const double weight)
153  {
154  IntPoint(off + 0).Set(a, b, c, weight);
155  IntPoint(off + 1).Set(a, c, b, weight);
156  IntPoint(off + 2).Set(b, c, a, weight);
157  IntPoint(off + 3).Set(b, a, c, weight);
158  IntPoint(off + 4).Set(c, a, b, weight);
159  IntPoint(off + 5).Set(c, b, a, weight);
160  }
161 
162  void AddTetMidPoint(const int off, const double weight)
163  { IntPoint(off).Set(0.25, 0.25, 0.25, weight); }
164 
165  // given a, add the permutations of (a,a,a,b), where 3*a + b = 1
166  void AddTetPoints4(const int off, const double a, const double weight)
167  {
168  IntPoint(off).Set(a, a, a, weight);
169  AddTetPoints3(off + 1, a, 1. - 3.*a, weight);
170  }
171 
172  // given b, add the permutations of (a,a,a,b), where 3*a + b = 1
173  void AddTetPoints4b(const int off, const double b, const double weight)
174  {
175  const double a = (1. - b)/3.;
176  IntPoint(off).Set(a, a, a, weight);
177  AddTetPoints3(off + 1, a, b, weight);
178  }
179 
180  // add the permutations of (a,a,b,b), 2*(a + b) = 1
181  void AddTetPoints6(const int off, const double a, const double weight)
182  {
183  const double b = 0.5 - a;
184  AddTetPoints3(off, a, b, weight);
185  AddTetPoints3(off + 3, b, a, weight);
186  }
187 
188  // given (a,b) or (a,c), add the permutations of (a,a,b,c), 2*a + b + c = 1
189  void AddTetPoints12(const int off, const double a, const double bc,
190  const double weight)
191  {
192  const double cb = 1. - 2*a - bc;
193  AddTetPoints3(off, a, bc, weight);
194  AddTetPoints3(off + 3, a, cb, weight);
195  AddTetPoints6(off + 6, a, bc, cb, weight);
196  }
197 
198  // given (b,c), add the permutations of (a,a,b,c), 2*a + b + c = 1
199  void AddTetPoints12bc(const int off, const double b, const double c,
200  const double weight)
201  {
202  const double a = (1. - b - c)/2.;
203  AddTetPoints3(off, a, b, weight);
204  AddTetPoints3(off + 3, a, c, weight);
205  AddTetPoints6(off + 6, a, b, c, weight);
206  }
207 
208 public:
210 
212  explicit IntegrationRule(int NP) : Array<IntegrationPoint>(NP)
213  {
214  for (int i = 0; i < this->Size(); i++)
215  {
216  (*this)[i].Init();
217  }
218  }
219 
222 
225  IntegrationRule &irz);
226 
228  int GetNPoints() const { return Size(); }
229 
231  IntegrationPoint &IntPoint(int i) { return (*this)[i]; }
232 
234  const IntegrationPoint &IntPoint(int i) const { return (*this)[i]; }
235 
238 };
239 
242 {
243 private:
244  int own_rules, refined;
245 
246  Array<IntegrationRule *> PointIntRules;
247  Array<IntegrationRule *> SegmentIntRules;
248  Array<IntegrationRule *> TriangleIntRules;
249  Array<IntegrationRule *> SquareIntRules;
250  Array<IntegrationRule *> TetrahedronIntRules;
251  Array<IntegrationRule *> CubeIntRules;
252 
253  void AllocIntRule(Array<IntegrationRule *> &ir_array, int Order)
254  {
255  if (ir_array.Size() <= Order)
256  {
257  ir_array.SetSize(Order + 1, NULL);
258  }
259  }
260  bool HaveIntRule(Array<IntegrationRule *> &ir_array, int Order)
261  {
262  return (ir_array.Size() > Order && ir_array[Order] != NULL);
263  }
264 
265  IntegrationRule *GenerateIntegrationRule(int GeomType, int Order);
266  IntegrationRule *PointIntegrationRule(int Order);
267  IntegrationRule *SegmentIntegrationRule(int Order);
268  IntegrationRule *TriangleIntegrationRule(int Order);
269  IntegrationRule *SquareIntegrationRule(int Order);
270  IntegrationRule *TetrahedronIntegrationRule(int Order);
271  IntegrationRule *CubeIntegrationRule(int Order);
272 
273  void DeleteIntRuleArray(Array<IntegrationRule *> &ir_array);
274 
275 public:
278  explicit IntegrationRules(int Ref = 0);
279 
281  const IntegrationRule &Get(int GeomType, int Order);
282 
283  void Set(int GeomType, int Order, IntegrationRule &IntRule);
284 
285  void SetOwnRules(int o) { own_rules = o; }
286 
289 };
290 
293 
296 
297 }
298 
299 #endif
int GetNPoints() const
Returns the number of the points in the integration rule.
Definition: intrules.hpp:228
void Set(const double *p, const int dim)
Definition: intrules.hpp:32
int Size() const
Logical size of the array.
Definition: array.hpp:109
void Get(double *p, const int dim) const
Definition: intrules.hpp:45
Class for integration rule.
Definition: intrules.hpp:83
const IntegrationRule & Get(int GeomType, int Order)
Returns an integration rule for given GeomType and Order.
Definition: intrules.cpp:235
void Set1w(const double *p)
Definition: intrules.hpp:79
~IntegrationRules()
Destroys an IntegrationRules object.
Definition: intrules.cpp:309
Container class for integration rules.
Definition: intrules.hpp:241
void Set(const double x1, const double x2, const double x3, const double w)
Definition: intrules.hpp:58
const IntegrationPoint & IntPoint(int i) const
Returns a const reference to the i-th integration point.
Definition: intrules.hpp:234
void Set3(const double *p)
Definition: intrules.hpp:66
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
Definition: intrules.hpp:231
void SetOwnRules(int o)
Definition: intrules.hpp:285
int dim
Definition: ex3.cpp:47
IntegrationRules IntRules(0)
A global object with all integration rules (defined in intrules.cpp)
Definition: intrules.hpp:292
IntegrationRules(int Ref=0)
Definition: intrules.cpp:207
~IntegrationRule()
Destroys an IntegrationRule object.
Definition: intrules.hpp:237
void Set3w(const double *p)
Definition: intrules.hpp:61
void Set2(const double x1, const double x2)
Definition: intrules.hpp:73
void Set3(const double x1, const double x2, const double x3)
Definition: intrules.hpp:63
void Set2w(const double *p)
Definition: intrules.hpp:71
void SetSize(int nsize)
Change logical size of the array, keep existing entries.
Definition: array.hpp:331
Class for integration point with weight.
Definition: intrules.hpp:25
void Set2(const double *p)
Definition: intrules.hpp:75
IntegrationRules RefinedIntRules(1)
A global object with all refined integration rules.
Definition: intrules.hpp:295
void Set2w(const double x1, const double x2, const double w)
Definition: intrules.hpp:68
IntegrationRule(int NP)
Construct an integration rule with given number of points.
Definition: intrules.hpp:212
void Set(int GeomType, int Order, IntegrationRule &IntRule)
Definition: intrules.cpp:265
void Set1w(const double x1, const double w)
Definition: intrules.hpp:77