libMesh
quadrature.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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" // INVALID_ELEM
28 #include "libmesh/enum_order.h" // INVALID_ORDER
29 
30 #ifdef LIBMESH_FORWARD_DECLARE_ENUMS
31 namespace libMesh
32 {
33 enum QuadratureType : int;
34 }
35 #else
36 #include "libmesh/enum_quadrature_type.h"
37 #endif
38 
39 // C++ includes
40 #include <vector>
41 #include <string>
42 #include <utility>
43 #include <memory>
44 
45 namespace libMesh
46 {
47 
48 // forward declarations
49 class Elem;
50 
61 class QBase : public ReferenceCountedObject<QBase>
62 {
63 protected:
64 
69  QBase (unsigned int dim,
70  Order order=INVALID_ORDER);
71 
72 public:
73 
78  QBase (const QBase &) = default;
79  QBase (QBase &&) = default;
80  QBase & operator= (const QBase &) = default;
81  QBase & operator= (QBase &&) = default;
82  virtual ~QBase() = default;
83 
87  virtual QuadratureType type() const = 0;
88 
98  static std::unique_ptr<QBase> build (const std::string & name,
99  const unsigned int dim,
100  const Order order=INVALID_ORDER);
101 
109  static std::unique_ptr<QBase> build (const QuadratureType qt,
110  const unsigned int dim,
111  const Order order=INVALID_ORDER);
112 
116  ElemType get_elem_type() const { return _type; }
117 
121  unsigned int get_p_level() const { return _p_level; }
122 
126  unsigned int n_points() const
127  {
128  libmesh_assert (!_points.empty());
129  return cast_int<unsigned int>(_points.size());
130  }
131 
135  unsigned int get_dim() const { return _dim; }
136 
141  const std::vector<Point> & get_points() const { return _points; }
142 
147  std::vector<Point> & get_points() { return _points; }
148 
153  const std::vector<Real> & get_weights() const { return _weights; }
154 
159  std::vector<Real> & get_weights() { return _weights; }
160 
164  Point qp(const unsigned int i) const
165  {
166  libmesh_assert_less (i, _points.size());
167  return _points[i];
168  }
169 
173  Real w(const unsigned int i) const
174  {
175  libmesh_assert_less (i, _weights.size());
176  return _weights[i];
177  }
178 
183  virtual void init (const ElemType type=INVALID_ELEM,
184  unsigned int p_level=0);
185 
195  virtual void init (const Elem & elem,
196  const std::vector<Real> & vertex_distance_func,
197  unsigned int p_level=0);
198 
211  Order get_order() const { return static_cast<Order>(_order + 2 * _p_level); }
212 
217  void print_info(std::ostream & os=libMesh::out) const;
218 
224  void scale(std::pair<Real, Real> old_range,
225  std::pair<Real, Real> new_range);
226 
230  friend std::ostream & operator << (std::ostream & os, const QBase & q);
231 
239  virtual bool shapes_need_reinit() { return false; }
240 
255 
256 protected:
257 
258 
268  virtual void init_0D (const ElemType type=INVALID_ELEM,
269  unsigned int p_level=0);
270 
282  virtual void init_1D (const ElemType type=INVALID_ELEM,
283  unsigned int p_level=0) = 0;
284 
297  virtual void init_2D (const ElemType type=INVALID_ELEM,
298  unsigned int p_level=0);
299 
312  virtual void init_3D (const ElemType type=INVALID_ELEM,
313  unsigned int p_level=0);
314 
320  void tensor_product_quad (const QBase & q1D);
321 
327  void tensor_product_hex (const QBase & q1D);
328 
334  void tensor_product_prism (const QBase & q1D, const QBase & q2D);
335 
339  unsigned int _dim;
340 
346 
352 
357  unsigned int _p_level;
358 
363  std::vector<Point> _points;
364 
369  std::vector<Real> _weights;
370 };
371 
372 } // namespace libMesh
373 
374 #endif // LIBMESH_QUADRATURE_H
libMesh::QBase
The QBase class provides the basic functionality from which various quadrature rules can be derived.
Definition: quadrature.h:61
libMesh::QBase::_p_level
unsigned int _p_level
The p-level of the element for which the current values have been computed.
Definition: quadrature.h:357
libMesh::QBase::tensor_product_hex
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:198
libMesh::QBase::get_weights
std::vector< Real > & get_weights()
Definition: quadrature.h:159
libMesh::QBase::n_points
unsigned int n_points() const
Definition: quadrature.h:126
libMesh::QBase::get_dim
unsigned int get_dim() const
Definition: quadrature.h:135
libMesh::ReferenceCountedObject
This class implements reference counting.
Definition: reference_counted_object.h:65
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::QuadratureType
QuadratureType
Defines an enum for currently available quadrature rules.
Definition: enum_quadrature_type.h:33
libMesh::Order
Order
Definition: enum_order.h:40
libMesh::QBase::init_1D
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...
libMesh::QBase::get_p_level
unsigned int get_p_level() const
Definition: quadrature.h:121
libMesh::QBase::w
Real w(const unsigned int i) const
Definition: quadrature.h:173
libMesh::QBase::init_3D
virtual void init_3D(const ElemType type=INVALID_ELEM, unsigned int p_level=0)
Initializes the 3D quadrature rule by filling the points and weights vectors with the appropriate val...
Definition: quadrature.C:130
libMesh::QBase::init
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:59
dim
unsigned int dim
Definition: adaptivity_ex3.C:113
libMesh::QBase::build
static std::unique_ptr< 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.
Definition: quadrature_build.C:41
libMesh::QBase::_order
Order _order
The polynomial order which the quadrature rule is capable of integrating exactly.
Definition: quadrature.h:345
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::QBase::operator=
QBase & operator=(const QBase &)=default
libMesh::QBase::get_points
const std::vector< Point > & get_points() const
Definition: quadrature.h:141
libMesh::QBase::QBase
QBase(unsigned int dim, Order order=INVALID_ORDER)
Constructor.
Definition: quadrature.C:27
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::QBase::_type
ElemType _type
The type of element for which the current values have been computed.
Definition: quadrature.h:351
libMesh::QBase::~QBase
virtual ~QBase()=default
libMesh::QBase::get_elem_type
ElemType get_elem_type() const
Definition: quadrature.h:116
libMesh::QBase::scale
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:137
libMesh::INVALID_ORDER
Definition: enum_order.h:86
libMesh::QBase::tensor_product_prism
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:225
libMesh::QBase::get_weights
const std::vector< Real > & get_weights() const
Definition: quadrature.h:153
libMesh::QBase::_weights
std::vector< Real > _weights
The quadrature weights.
Definition: quadrature.h:369
libMesh::QBase::tensor_product_quad
void tensor_product_quad(const QBase &q1D)
Constructs a 2D rule from the tensor product of q1D with itself.
Definition: quadrature.C:171
libMesh::INVALID_ELEM
Definition: enum_elem_type.h:75
libMesh::QBase::type
virtual QuadratureType type() const =0
libMesh::QBase::get_points
std::vector< Point > & get_points()
Definition: quadrature.h:147
libMesh::QBase::shapes_need_reinit
virtual bool shapes_need_reinit()
Definition: quadrature.h:239
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition: elem.h:100
libMesh::QBase::allow_rules_with_negative_weights
bool allow_rules_with_negative_weights
Flag (default true) controlling the use of quadrature rules with negative weights.
Definition: quadrature.h:254
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::QBase::get_order
Order get_order() const
Definition: quadrature.h:211
libMesh::QBase::init_0D
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:113
libMesh::QBase::_dim
unsigned int _dim
The spatial dimension of the quadrature rule.
Definition: quadrature.h:339
libMesh::QBase::qp
Point qp(const unsigned int i) const
Definition: quadrature.h:164
libMesh::out
OStreamProxy out
libMesh::QBase::_points
std::vector< Point > _points
The locations of the quadrature points in reference element space.
Definition: quadrature.h:363
libMesh::QBase::operator<<
friend std::ostream & operator<<(std::ostream &os, const QBase &q)
Same as above, but allows you to use the stream syntax.
Definition: quadrature.C:252
libMesh::QBase::print_info
void print_info(std::ostream &os=libMesh::out) const
Prints information relevant to the quadrature rule, by default to libMesh::out.
Definition: quadrature.C:37
int
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360
libMesh::Quality::name
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
libMesh::ElemType
ElemType
Defines an enum for geometric element types.
Definition: enum_elem_type.h:33
libMesh::QBase::init_2D
virtual void init_2D(const ElemType type=INVALID_ELEM, unsigned int p_level=0)
Initializes the 2D quadrature rule by filling the points and weights vectors with the appropriate val...
Definition: quadrature.C:123