LifeV
QuadratureRule.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  @file
29  @brief File for the definition of the QuadratureRule class.
30 
31  @author Jean-Frederic Gerbeau
32  Samuel Quinodoz <samuel.quinodoz@epfl.ch>
33  @date 01-06-2010
34 
35  @contributor Samuel Quinodoz <samuel.quinodoz@epfl.ch>
36  @mantainer Samuel Quinodoz <samuel.quinodoz@epfl.ch>
37  */
38 
39 
40 #ifndef QUADRULE_H
41 #define QUADRULE_H
42 
43 #include <lifev/core/LifeV.hpp>
44 
45 #include <lifev/core/mesh/ElementShapes.hpp>
46 
47 #include <lifev/core/fem/QuadraturePoint.hpp>
48 
49 #include <iostream>
50 #include <fstream>
51 #include <cstdarg>
52 
53 namespace LifeV
54 {
55 
56 
57 //! QuadratureRule - The basis class for storing and accessing quadrature rules.
58 /*!
59 
60  <b> Definition of a quadrature rule </b>
61 
62  To define a quadrature rule, several constructors have been defined for this class. Besides the classical constructors, one is provided with an arbitrary number of arguements (indicated by "..."). Its usage is quite simple: first of all, one defines the standard arguements (name...) but also the number of quadrature points and their dimension. After that, one add the coordinates and weights of the quadrature points in the order: coordinates for the first point, weight for the first point, coordinates of the second point, weight of the second point,...
63 
64 For example, if we want to define a Simpson rule in 1D, we can write:
65  \code
66  QuadratureRule simpson1D ("Simpson 1D",LINE,1,3,3, // name,shape,dimension,exactness,number of points
67  0.0, 1.0/6.0, // first point: x=0 with weight 1/6
68  0.5, 2.0/3.0, // second point: x=0.5, weight 2/3
69  1.0, 1.0/6.0); // third point: x=1, weight 1/6
70  \endcode
71 
72 If we want to see this quadrature as a 1D quadrature in a 2D space, the code would have been:
73 
74 \code
75  QuadratureRule simpson2D ("Simpson 2D",LINE,2,3,3, // name,shape,dimension,exactness,number of points
76  0.0,0.0, 1.0/6.0, // first point: (0,0) with weight 1/6
77  0.5,0.0, 2.0/3.0, // second point: (0.5,0) weight 2/3
78  1.0,0.0, 1.0/6.0); // third point: (1,0) weight 1/6
79  \endcode
80 
81 The following code would have produced the same quadrature:
82 
83 \code
84  QuadratureRule simpson2D (simpson1D,2);
85  \endcode
86 
87  <b> Basic Use </b>
88 
89  A quadrature rule consists mainly in a container of quadrature points. The stored quadrature points can be accessed through accessors to the quadrature points or through specific accessors for the coordinates and the weight of the quadrature points.
90 
91  <b> Degree of exactness </b>
92 
93  The quadrature rules store the degree of exactness that they are supposed to achieve. It can be specified when building the quadrature rule. No test is performed automatically to check the order and when the quadrature rule is modified (with the addPoint method for example), the order of exactness is kept unchanged.
94 
95  However, the QuadratureRule class provides a test for the degree of exactness. When called, this test returns the degree of exactness that has been found by trying to perform several integrals, but it does not change the stored degree of exactness.
96 
97  <b> Dimension and Shape </b>
98 
99  For some problems, it makes sens to use quadrature rules outside their "original" space, e.g. one could need a quadrature rule for the triangles in a 3D space (when integrating on a surface). The QuadratureRule class provides the possibility of changing the dimension in which a quadrature rule in defined (i.e. how many coordinates are used for the coordinates of the quadrature points).
100 
101  When using a quadrature rule in a space with higher dimension, 0 coordinates are added to fill the missing coordinates. The shape of the quadrature (i.e. the geometric shape where it is defined) remains the same.
102 
103  It is currently not possible to move a quadrature to a lower space dimension (than the one defined by its shape): the problem resides in the area of the quadrature: a quadrature rule for tetrahedra has a total weight of 1/6 while a quadrature rule for triangles has a total weight of 1/2 (in general for simplexes, the area is 1/n!). If such change would be allowed, one would have to implement all the changes of weight depending on the shape (there is no such phenomena between hexahedra and quadrangles for example). Moreover, it makes very little sense to downgrade a quadrature (use a specific quadrature rule which will have very likely less quadrature nodes).
104 
105  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
106  @date 1 June 2010
107  @version 2.0
108  @note The previous version was due to J.-F. Gerbeau (04/2002). Many ideas were taken from that version.
109 
110 */
112 {
113 public:
114 
115  //! @name Constructor & Destructor
116  //@{
117 
118  //! Empty constructor
119  QuadratureRule();
120 
121  //! Full constructor using pointers
122  /*!
123  With this constructor, the dimension is supposed to be 3 (old style).
124 
125  @param pt The set of quadrature points
126  @param id Backward compatibility arguement
127  @param name The name of the quadrature rule
128  @param shape The shape of the element to be used with
129  @param nbQuadPt The number of quadrature points defined
130  @param degOfExact The degree of exactness of the quadrature rule
131  */
132  QuadratureRule ( const QuadraturePoint* pt, int id, std::string name, ReferenceShapes shape,
133  UInt nbQuadPt, UInt degOfExact );
134 
135  //! Full constructor
136  /*!
137  This constructor enables to use as many arguments as needed for the declaration of the
138  quadrature rules (the number of quadrature points is not known a priori).
139 
140  The last arguements are the coordinates and the weights of the points, in the order:
141  coordinates of the first point, weight of the first point, coordinates of the second
142  point, weight of the second point,...
143 
144  @param name The name of the quadrature
145  @param shape The shape were the quadrature is originally defined
146  @param dimension The dimension of the space in which the quadrature is defined
147  @param degreeOfExactness The degree of exactness of the quadrature
148  @param nbQuadPt The number of quadrature points
149  */
150  QuadratureRule (std::string name, ReferenceShapes shape, UInt dimension, UInt degreeOfExactness, UInt nbQuadPt, ... );
151 
152 
153  //! Copy constructor
154  /*!
155  @param qr The quadrature rule that we want to copy.
156  */
157  QuadratureRule ( const QuadratureRule& qr);
158 
159  //! Copy constructor using a different dimension
160  /*!
161  This can be used to export a quadrature rule from a space dimension
162  to another one.
163 
164  @param qr The quadrature rule to export
165  @param dim The new dimension to be used with the quadrature rule.
166  */
167  QuadratureRule ( const QuadratureRule& qr, const UInt dim);
168 
169 
170  //! Destructor
171  virtual ~QuadratureRule();
172 
173  //@}
174 
175 
176  //! @name Operators
177  //@{
178 
179  //! Output operator
180  friend std::ostream& operator << ( std::ostream& c, const QuadratureRule& qr );
181 
182  //@}
183 
184 
185  //! @name Methods
186  //@{
187 
188  //! Method to add a point to an existing quadrature rule.
189  /*!
190  Beware to have set the dimension and the shape before calling
191  this method.
192 
193  @note: the degree of exactness is not changed, it is up to the user
194  to take care of it.
195 
196  @param qp The quadrature point to add.
197  */
198  void addPoint (const QuadraturePoint& qp)
199  {
200  M_pt.push_back (QuadraturePoint (qp, M_dimension) );
201  M_nbQuadPt += 1;
202  };
203 
204  //! ShowMe method
205  void showMe ( std::ostream& output = std::cout) const;
206 
207  //! Check for the exactness of the quadrature
208  /*!
209  The quadrature rule is used to performed intergrals whose
210  values are known. The degree of exactness is evaluated
211  using these results.
212 
213  @note The degree of exactness stored internally is not
214  changed when calling this method.
215  */
216  UInt checkExactness() const;
217 
218  //! VTK export for the quadrature
219  /*!
220  Creates a file with the positions of the
221  quadrature points in a VTK format. No extension
222  is added to the name of the file, please provide a name
223  ending by ".vtk".
224 
225  @param filename The name of the file to be created.
226  */
227  void vtkExport ( const std::string& filename) const;
228 
229  //! Method for importing the quadrature rule from another class
230  template <typename QRType>
231  void import ( const QRType& qr);
232 
233  //@}
234 
235 
236  //! @name Set methods
237  //@{
238 
239  //! Change the quadrature points for the ones given here.
240  /*!
241  Beware to have set the dimension (default: 0!) before calling
242  this method (use the QuadratureRule::setDimensionShape method for example).
243  */
244  void setPoints (const std::vector<QuadraturePoint>& pts);
245 
246  //! Change the quadrature points for the one given here
247  /*!
248  Use coordinates and weights separetly. The two vectors
249  given in argument must have the same length. The quadrature
250  points are then given by (coorindates[i],weights[i]).
251 
252  Beware to have set the dimension (default: 0!) before calling
253  this method (use the QuadratureRule::setDimensionShape method for example).
254 
255  @param coordinates An array containing the coordinates of the points
256  @param weights An array containing the weights of the points
257  */
258  void setPoints (const std::vector<GeoVector>& coordinates, const std::vector<Real>& weights);
259 
260  //! Change the name of the quadrature
261  void setName (const std::string& newName);
262 
263  //! Change the degree of exactness
264  void setExactness (const UInt& exactness);
265 
266  //! Change the dimension and the shape
267  void setDimensionShape (const UInt& newDim, const ReferenceShapes& newShape);
268 
269 
270  //@}
271 
272 
273  //! @name Get methods
274  //@{
275 
276  //! quadPoint(ig) is the ig-th quadrature point
277  const QuadraturePoint& quadPoint ( const UInt& ig ) const
278  {
279  ASSERT_BD ( ig < M_nbQuadPt );
280  return M_pt[ ig ];
281  }
282 
283  //! weight(ig) is the ig-th quadrature weight
284  const Real& weight (const UInt& ig ) const
285  {
286  ASSERT_BD ( ig < M_nbQuadPt );
287  return M_pt[ ig ].weight();
288  }
289 
290  //! quadPointCoor(ig,icoor) is the coordinate icoor of the quadrature point ig
291  const Real& quadPointCoor ( const UInt& ig, const UInt& icoor ) const
292  {
293  ASSERT_BD ( ig < M_nbQuadPt );
294  return M_pt[ ig ].coor ( icoor );
295  }
296 
297  //! quadPointCoor(ig) is the full coordinates of the quadrature point ig
298  const GeoVector& quadPointCoor ( const UInt& ig ) const
299  {
300  ASSERT_BD ( ig < M_nbQuadPt );
301  return M_pt[ ig ].coor( );
302  }
303 
304  //! Getter for the number of quadrature points
305  const UInt& nbQuadPt() const
306  {
307  return M_nbQuadPt;
308  };
309 
310  //! Getter for the name of the quadrature
311  const std::string& name() const
312  {
313  return M_name;
314  };
315 
316  //! Getter for the degree of exactness
317  const UInt& degreeOfExactness() const
318  {
319  return M_degOfExact;
320  };
321 
322  //@}
323 
324 
325 private:
326 
327  //! @name Private Methods
328  //@{
329 
330  //! Check the exactness for quadrature rules on segments
331  UInt checkExactnessSegment() const;
332 
333  //! Check the exactness for quadrature rules on triangles
335 
336  //! Check the exactness for quadrature rules on tetrahedra
337  UInt checkExactnessTetra() const;
338 
339  //@}
340 
341  //! Tolerance for the test of exactness
343 
344  // Storage for the quadrature nodes
346 
347  //! geometrical shape of the domain on which the quadrature rule can be used
349 
350  //! name of the quadrature rule
351  std::string M_name;
352 
353  //! number of quadrature points
355 
356  //! degree of exactness
358 
359  //! Dimension in which the quadrature is stored
361 };
362 
363 
364 // Definition of the template method
365 template< typename QRType>
366 void
367 QuadratureRule::import (const QRType& qr)
368 {
369  for (UInt i (0); i < qr.nbQuadPt(); ++i)
370  {
371  M_pt.push_back (qr.quadPoint (i) );
372  }
373  M_shape = qr.shape();
374  M_name = "";
375  M_nbQuadPt = qr.nbQuadPt();
376  M_degOfExact = 0;
377  M_dimension = qr.dimension();
378 }
379 
380 
381 
382 //======================================================================
383 extern const QuadratureRule quadRuleDummy;
384 
385 extern const QuadratureRule quadRuleNode1pt;
386 
387 extern const QuadratureRule quadRuleSeg1pt;
388 extern const QuadratureRule quadRuleSeg2pt;
389 extern const QuadratureRule quadRuleSeg3pt;
390 extern const QuadratureRule quadRuleSeg4pt;
391 
392 extern const QuadratureRule quadRuleTria1pt;
393 extern const QuadratureRule quadRuleTria3pt;
394 extern const QuadratureRule quadRuleTria4pt;
395 extern const QuadratureRule quadRuleTria6pt;
396 extern const QuadratureRule quadRuleTria7pt;
397 
398 extern const QuadratureRule quadRuleQuad1pt;
399 extern const QuadratureRule quadRuleQuad4pt;
400 extern const QuadratureRule quadRuleQuad9pt;
401 extern const QuadratureRule quadRuleQuad16pt;
402 
403 extern const QuadratureRule quadRuleTetra1pt;
404 extern const QuadratureRule quadRuleTetra4pt;
406 extern const QuadratureRule quadRuleTetra5pt;
407 extern const QuadratureRule quadRuleTetra15pt;
408 extern const QuadratureRule quadRuleTetra64pt;
409 
410 extern const QuadratureRule quadRuleHexa1pt;
411 extern const QuadratureRule quadRuleHexa8pt;
412 
413 
414 }
415 #endif
UInt M_degOfExact
degree of exactness
const QuadratureRule quadRuleTetra64pt(pt_tetra_64pt, 6, "Quadrature rule 64 points on a tetraedra", TETRA, 64, 7)
const Real & weight(const UInt &ig) const
weight(ig) is the ig-th quadrature weight
void addPoint(const QuadraturePoint &qp)
Method to add a point to an existing quadrature rule.
const QuadratureRule quadRuleQuad16pt(pt_quad_16pt, 4, "Quadrature rule 16 points on a quadrangle", QUAD, 16, 5)
const QuadratureRule quadRuleDummy(pt_node_0pt, QUAD_RULE_DUMMY, "Dummy quadrature rule", NONE, 0, 0)
const QuadratureRule quadRuleQuad4pt(pt_quad_4pt, 2, "Quadrature rule 4 points on a quadrangle", QUAD, 4, 3)
const QuadratureRule quadRuleSeg3pt(pt_seg_3pt, QUAD_RULE_SEG_3PT, "Gauss Legendre 3 points on a segment", LINE, 3, 5)
#define ASSERT_BD(X)
Definition: LifeAssert.hpp:114
const QuadratureRule quadRuleTetra4ptNodal(pt_tetra_4pt_nodal, 3, "Quadrature rule 4 points on a tetraedra vertices", TETRA, 4, 1)
const QuadratureRule quadRuleTetra15pt(pt_tetra_15pt, 5, "Quadrature rule 15 points on a tetraedra", TETRA, 15, 5)
UInt M_nbQuadPt
number of quadrature points
const QuadratureRule quadRuleTria4pt(pt_tria_4pt, 3, "Quadrature rule 4 points on a triangle", TRIANGLE, 4, 3)
void setDimensionShape(const UInt &newDim, const ReferenceShapes &newShape)
Change the dimension and the shape.
const QuadratureRule quadRuleTetra4pt(pt_tetra_4pt, 2, "Quadrature rule 4 points on a tetraedra", TETRA, 4, 2)
UInt M_dimension
Dimension in which the quadrature is stored.
UInt checkExactnessTetra() const
Check the exactness for quadrature rules on tetrahedra.
const QuadratureRule quadRuleNode1pt(pt_node_1pt, QUAD_RULE_NODE_1PT, "Gauss Legendre 1 point on a node", POINT, 1, 1)
virtual ~QuadratureRule()
Destructor.
boost::numeric::ublas::vector< Real > GeoVector
UInt checkExactness() const
Check for the exactness of the quadrature.
QuadratureRule(const QuadratureRule &qr)
Copy constructor.
void updateInverseJacobian(const UInt &iQuadPt)
const QuadratureRule quadRuleSeg4pt(pt_seg_4pt, QUAD_RULE_SEG_4PT, "Gauss Legendre 4 points on a segment", LINE, 4, 7)
ReferenceShapes M_shape
geometrical shape of the domain on which the quadrature rule can be used
const QuadratureRule quadRuleSeg2pt(pt_seg_2pt, QUAD_RULE_SEG_2PT, "Gauss Legendre 2 points on a segment", LINE, 2, 3)
const QuadratureRule quadRuleQuad9pt(pt_quad_9pt, 3, "Quadrature rule 9 points on a quadrangle", QUAD, 9, 5)
UInt checkExactnessSegment() const
Check the exactness for quadrature rules on segments.
const UInt & degreeOfExactness() const
Getter for the degree of exactness.
const QuadratureRule quadRuleQuad1pt(pt_quad_1pt, 1, "Quadrature rule 1 point on a quadrangle", QUAD, 1, 1)
const GeoVector & quadPointCoor(const UInt &ig) const
quadPointCoor(ig) is the full coordinates of the quadrature point ig
QuadratureRule(const QuadratureRule &qr, const UInt dim)
Copy constructor using a different dimension.
void vtkExport(const std::string &filename) const
VTK export for the quadrature.
QuadratureRule()
Empty constructor.
const QuadratureRule quadRuleTetra5pt(pt_tetra_5pt, 4, "Quadrature rule 5 points on a tetraedra", TETRA, 5, 3)
QuadraturePoint - Simple container for a point of a quadrature rule.
static Real S_exactnessTol
Tolerance for the test of exactness.
const QuadratureRule quadRuleSeg1pt(pt_seg_1pt, QUAD_RULE_SEG_1PT, "Gauss Legendre 1 point on a segment", LINE, 1, 1)
UInt checkExactnessTriangle() const
Check the exactness for quadrature rules on triangles.
double Real
Generic real data.
Definition: LifeV.hpp:175
const QuadratureRule quadRuleTria3pt(pt_tria_3pt, 2, "Quadrature rule 3 points on a triangle", TRIANGLE, 3, 2)
std::string M_name
name of the quadrature rule
const QuadratureRule quadRuleTetra1pt(pt_tetra_1pt, 1, "Quadrature rule 1 point on a tetraedra", TETRA, 1, 1)
void setPoints(const std::vector< QuadraturePoint > &pts)
Change the quadrature points for the ones given here.
const QuadratureRule quadRuleTria7pt(pt_tria_7pt, 5, "Quadrature rule 7 points on a triangle", TRIANGLE, 7, 5)
const QuadratureRule quadRuleTria6pt(pt_tria_6pt, 4, "Quadrature rule 6 points on a triangle", TRIANGLE, 6, 4)
void showMe(std::ostream &output=std::cout) const
ShowMe method.
const QuadraturePoint & quadPoint(const UInt &ig) const
quadPoint(ig) is the ig-th quadrature point
void setName(const std::string &newName)
Change the name of the quadrature.
void setPoints(const std::vector< GeoVector > &coordinates, const std::vector< Real > &weights)
Change the quadrature points for the one given here.
const QuadratureRule quadRuleHexa1pt(pt_hexa_1pt, 1, "Quadrature rule 1 point on a hexa", HEXA, 1, 1)
const QuadratureRule quadRuleHexa8pt(pt_hexa_8pt, 2, "Quadrature rule 8 points on a hexa", HEXA, 8, 3)
const std::string & name() const
Getter for the name of the quadrature.
QuadratureRule - The basis class for storing and accessing quadrature rules.
std::vector< QuadraturePoint > M_pt
void setExactness(const UInt &exactness)
Change the degree of exactness.
void import(const QRType &qr)
Method for importing the quadrature rule from another class.
const QuadratureRule quadRuleTria1pt(pt_tria_1pt, 1, "Quadrature rule 1 point on a triangle", TRIANGLE, 1, 1)
const UInt & nbQuadPt() const
Getter for the number of quadrature points.
QuadratureRule(const QuadraturePoint *pt, int id, std::string name, ReferenceShapes shape, UInt nbQuadPt, UInt degOfExact)
Full constructor using pointers.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
const Real & quadPointCoor(const UInt &ig, const UInt &icoor) const
quadPointCoor(ig,icoor) is the coordinate icoor of the quadrature point ig
QuadratureRule(std::string name, ReferenceShapes shape, UInt dimension, UInt degreeOfExactness, UInt nbQuadPt,...)
Full constructor.