libMesh
quadrature.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_QUADRATURE_H
21 #define LIBMESH_QUADRATURE_H
22 
23 // Local includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/reference_counted_object.h"
26 #include "libmesh/point.h"
27 #include "libmesh/enum_elem_type.h"
28 #include "libmesh/enum_order.h"
29 #include "libmesh/enum_quadrature_type.h"
30 #include "libmesh/auto_ptr.h"
31 
32 // C++ includes
33 #include <vector>
34 #include <string>
35 #include <utility>
36 
37 namespace libMesh
38 {
39 
40 // forward declarations
41 class Elem;
42 
53 class QBase : public ReferenceCountedObject<QBase>
54 {
55 protected:
56 
61  QBase (const unsigned int _dim,
62  const Order _order=INVALID_ORDER);
63 
64 public:
65 
69  virtual ~QBase() {}
70 
74  virtual QuadratureType type() const = 0;
75 
85  static UniquePtr<QBase> build (const std::string & name,
86  const unsigned int dim,
87  const Order order=INVALID_ORDER);
88 
96  static UniquePtr<QBase> build (const QuadratureType qt,
97  const unsigned int dim,
98  const Order order=INVALID_ORDER);
99 
103  ElemType get_elem_type() const { return _type; }
104 
108  unsigned int get_p_level() const { return _p_level; }
109 
113  unsigned int n_points() const
114  {
115  libmesh_assert (!_points.empty());
116  return cast_int<unsigned int>(_points.size());
117  }
118 
122  unsigned int get_dim() const { return _dim; }
123 
128  const std::vector<Point> & get_points() const { return _points; }
129 
134  std::vector<Point> & get_points() { return _points; }
135 
140  const std::vector<Real> & get_weights() const { return _weights; }
141 
146  std::vector<Real> & get_weights() { return _weights; }
147 
151  Point qp(const unsigned int i) const
152  {
153  libmesh_assert_less (i, _points.size());
154  return _points[i];
155  }
156 
160  Real w(const unsigned int i) const
161  {
162  libmesh_assert_less (i, _weights.size());
163  return _weights[i];
164  }
165 
170  virtual void init (const ElemType type=INVALID_ELEM,
171  unsigned int p_level=0);
172 
182  virtual void init (const Elem & elem,
183  const std::vector<Real> & vertex_distance_func,
184  unsigned int p_level=0);
185 
189  Order get_order() const { return static_cast<Order>(_order + _p_level); }
190 
195  void print_info(std::ostream & os=libMesh::out) const;
196 
202  void scale(std::pair<Real, Real> old_range,
203  std::pair<Real, Real> new_range);
204 
208  friend std::ostream & operator << (std::ostream & os, const QBase & q);
209 
217  virtual bool shapes_need_reinit() { return false; }
218 
233 
234 protected:
235 
236 
242  virtual void init_0D (const ElemType type=INVALID_ELEM,
243  unsigned int p_level=0);
244 
252  virtual void init_1D (const ElemType type=INVALID_ELEM,
253  unsigned int p_level=0) = 0;
254 
263  virtual void init_2D (const ElemType,
264  unsigned int = 0)
265  {
266 #ifdef DEBUG
267  libmesh_error_msg("ERROR: Seems as if this quadrature rule \nis not implemented for 2D.");
268 #endif
269  }
270 
279  virtual void init_3D (const ElemType,
280  unsigned int = 0)
281  {
282 #ifdef DEBUG
283  libmesh_error_msg("ERROR: Seems as if this quadrature rule \nis not implemented for 3D.");
284 #endif
285  }
286 
292  void tensor_product_quad (const QBase & q1D);
293 
299  void tensor_product_hex (const QBase & q1D);
300 
306  void tensor_product_prism (const QBase & q1D, const QBase & q2D);
307 
311  const unsigned int _dim;
312 
317  const Order _order;
318 
324 
329  unsigned int _p_level;
330 
335  std::vector<Point> _points;
336 
341  std::vector<Real> _weights;
342 };
343 
344 
345 
346 // ------------------------------------------------------------
347 // QBase class members
348 
349 inline
350 QBase::QBase(const unsigned int d,
351  const Order o) :
353  _dim(d),
354  _order(o),
356  _p_level(0)
357 {
358 }
359 
360 
361 
362 
363 inline
364 void QBase::print_info(std::ostream & os) const
365 {
366  libmesh_assert(!_points.empty());
367  libmesh_assert(!_weights.empty());
368 
369  Real summed_weights=0;
370  os << "N_Q_Points=" << this->n_points() << std::endl << std::endl;
371  for (unsigned int qpoint=0; qpoint<this->n_points(); qpoint++)
372  {
373  os << " Point " << qpoint << ":\n"
374  << " "
375  << _points[qpoint]
376  << "\n Weight:\n "
377  << " w=" << _weights[qpoint] << "\n" << std::endl;
378 
379  summed_weights += _weights[qpoint];
380  }
381  os << "Summed Weights: " << summed_weights << std::endl;
382 }
383 
384 } // namespace libMesh
385 
386 #endif // LIBMESH_QUADRATURE_H
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
virtual void init(const ElemType type=INVALID_ELEM, unsigned int p_level=0)
Initializes the data structures for a quadrature rule for an element of type type.
Definition: quadrature.C:28
ElemType get_elem_type() const
Definition: quadrature.h:103
virtual bool shapes_need_reinit()
Definition: quadrature.h:217
Order get_order() const
Definition: quadrature.h:189
QuadratureType
Defines an enum for currently available quadrature rules.
const unsigned int _dim
The spatial dimension of the quadrature rule.
Definition: quadrature.h:311
std::vector< Point > & get_points()
Definition: quadrature.h:134
bool allow_rules_with_negative_weights
Flag (default true) controlling the use of quadrature rules with negative weights.
Definition: quadrature.h:232
unsigned int dim
ElemType
Defines an enum for geometric element types.
Real w(const unsigned int i) const
Definition: quadrature.h:160
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
ElemType _type
The type of element for which the current values have been computed.
Definition: quadrature.h:323
friend std::ostream & operator<<(std::ostream &os, const QBase &q)
Same as above, but allows you to use the stream syntax.
Definition: quadrature.C:208
The libMesh namespace provides an interface to certain functionality in the library.
Point qp(const unsigned int i) const
Definition: quadrature.h:151
std::vector< Point > _points
The locations of the quadrature points in reference element space.
Definition: quadrature.h:335
std::vector< Real > _weights
The quadrature weights.
Definition: quadrature.h:341
void tensor_product_prism(const QBase &q1D, const QBase &q2D)
Computes the tensor product of a 1D quadrature rule and a 2D quadrature rule.
Definition: quadrature.C:181
libmesh_assert(j)
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
unsigned int _p_level
The p-level of the element for which the current values have been computed.
Definition: quadrature.h:329
QBase(const unsigned int _dim, const Order _order=INVALID_ORDER)
Constructor.
Definition: quadrature.h:350
virtual void init_2D(const ElemType, unsigned int=0)
Initializes the 2D quadrature rule by filling the points and weights vectors with the appropriate val...
Definition: quadrature.h:263
virtual void init_1D(const ElemType type=INVALID_ELEM, unsigned int p_level=0)=0
Initializes the 1D quadrature rule by filling the points and weights vectors with the appropriate val...
void tensor_product_hex(const QBase &q1D)
Computes the tensor product quadrature rule [q1D x q1D x q1D] from the 1D rule q1D.
Definition: quadrature.C:154
virtual void init_0D(const ElemType type=INVALID_ELEM, unsigned int p_level=0)
Initializes the 0D quadrature rule by filling the points and weights vectors with the appropriate val...
Definition: quadrature.C:82
virtual QuadratureType type() const =0
This class implements reference counting.
void print_info(std::ostream &os=libMesh::out) const
Prints information relevant to the quadrature rule, by default to libMesh::out.
Definition: quadrature.h:364
virtual ~QBase()
Destructor.
Definition: quadrature.h:69
const std::vector< Real > & get_weights() const
Definition: quadrature.h:140
unsigned int get_p_level() const
Definition: quadrature.h:108
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int get_dim() const
Definition: quadrature.h:122
OStreamProxy out
const std::vector< Point > & get_points() const
Definition: quadrature.h:128
Order
defines an enum for polynomial orders.
Definition: enum_order.h:32
void scale(std::pair< Real, Real > old_range, std::pair< Real, Real > new_range)
Maps the points of a 1D quadrature rule defined by "old_range" to another 1D interval defined by "new...
Definition: quadrature.C:93
static UniquePtr< QBase > build(const std::string &name, const unsigned int dim, const Order order=INVALID_ORDER)
Builds a specific quadrature rule based on the name string.
void tensor_product_quad(const QBase &q1D)
Constructs a 2D rule from the tensor product of q1D with itself.
Definition: quadrature.C:127
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
virtual void init_3D(const ElemType, unsigned int=0)
Initializes the 3D quadrature rule by filling the points and weights vectors with the appropriate val...
Definition: quadrature.h:279
unsigned int n_points() const
Definition: quadrature.h:113
The QBase class provides the basic functionality from which various quadrature rules can be derived...
Definition: quadrature.h:53
std::vector< Real > & get_weights()
Definition: quadrature.h:146
const Order _order
The polynomial order which the quadrature rule is capable of integrating exactly. ...
Definition: quadrature.h:317