libMesh
quadrature.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 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 // C++ includes
31 #include <vector>
32 #include <string>
33 #include <utility>
34 #include <memory>
35 
36 namespace libMesh
37 {
38 
39 // forward declarations
40 class Elem;
41 enum QuadratureType : int;
42 
53 class QBase : public ReferenceCountedObject<QBase>
54 {
55 protected:
56 
61  QBase (unsigned int dim,
62  Order order=INVALID_ORDER);
63 
64 public:
65 
70  QBase (const QBase &) = default;
71  QBase (QBase &&) = default;
72  QBase & operator= (const QBase &) = default;
73  QBase & operator= (QBase &&) = default;
74  virtual ~QBase() = default;
75 
79  virtual std::unique_ptr<QBase> clone() const;
80 
84  virtual QuadratureType type() const = 0;
85 
95  static std::unique_ptr<QBase> build (std::string_view name,
96  const unsigned int dim,
97  const Order order=INVALID_ORDER);
98 
106  static std::unique_ptr<QBase> build (const QuadratureType qt,
107  const unsigned int dim,
108  const Order order=INVALID_ORDER);
109 
113  ElemType get_elem_type() const { return _type; }
114 
118  unsigned int get_p_level() const { return _p_level; }
119 
123  unsigned int n_points() const
124  {
125  libmesh_assert (!_points.empty());
126  return cast_int<unsigned int>(_points.size());
127  }
128 
134  unsigned int size() const
135  {
136  return n_points();
137  }
138 
142  unsigned int get_dim() const { return _dim; }
143 
148  const std::vector<Point> & get_points() const { return _points; }
149 
154  std::vector<Point> & get_points() { return _points; }
155 
160  const std::vector<Real> & get_weights() const { return _weights; }
161 
166  std::vector<Real> & get_weights() { return _weights; }
167 
171  Point qp(const unsigned int i) const
172  {
173  libmesh_assert_less (i, _points.size());
174  return _points[i];
175  }
176 
180  Real w(const unsigned int i) const
181  {
182  libmesh_assert_less (i, _weights.size());
183  return _weights[i];
184  }
185 
190  virtual void init (const ElemType type=INVALID_ELEM,
191  unsigned int p_level=0);
192 
202  virtual void init (const Elem & elem,
203  const std::vector<Real> & vertex_distance_func,
204  unsigned int p_level=0);
205 
218  Order get_order() const { return static_cast<Order>(_order + 2 * _p_level); }
219 
224  void print_info(std::ostream & os=libMesh::out) const;
225 
231  void scale(std::pair<Real, Real> old_range,
232  std::pair<Real, Real> new_range);
233 
237  friend std::ostream & operator << (std::ostream & os, const QBase & q);
238 
246  virtual bool shapes_need_reinit() { return false; }
247 
262 
275 
276 protected:
277 
278 
288  virtual void init_0D (const ElemType type=INVALID_ELEM,
289  unsigned int p_level=0);
290 
302  virtual void init_1D (const ElemType type=INVALID_ELEM,
303  unsigned int p_level=0) = 0;
304 
317  virtual void init_2D (const ElemType type=INVALID_ELEM,
318  unsigned int p_level=0);
319 
332  virtual void init_3D (const ElemType type=INVALID_ELEM,
333  unsigned int p_level=0);
334 
340  void tensor_product_quad (const QBase & q1D);
341 
347  void tensor_product_hex (const QBase & q1D);
348 
354  void tensor_product_prism (const QBase & q1D, const QBase & q2D);
355 
359  unsigned int _dim;
360 
366 
372 
377  unsigned int _p_level;
378 
383  std::vector<Point> _points;
384 
389  std::vector<Real> _weights;
390 };
391 
392 } // namespace libMesh
393 
394 #endif // LIBMESH_QUADRATURE_H
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
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:64
virtual bool shapes_need_reinit()
Definition: quadrature.h:246
ElemType
Defines an enum for geometric element types.
Order
defines an enum for polynomial orders.
Definition: enum_order.h:40
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:135
QBase & operator=(const QBase &)=default
std::vector< Point > & get_points()
Definition: quadrature.h:154
bool allow_rules_with_negative_weights
Flag (default true) controlling the use of quadrature rules with negative weights.
Definition: quadrature.h:261
Point qp(const unsigned int i) const
Definition: quadrature.h:171
unsigned int dim
ElemType get_elem_type() const
Definition: quadrature.h:113
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
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:128
ElemType _type
The type of element for which the current values have been computed.
Definition: quadrature.h:371
const std::vector< Real > & get_weights() const
Definition: quadrature.h:160
QBase(unsigned int dim, Order order=INVALID_ORDER)
Constructor.
Definition: quadrature.C:27
QuadratureType
Defines an enum for currently available quadrature rules.
unsigned int _dim
The spatial dimension of the quadrature rule.
Definition: quadrature.h:359
friend std::ostream & operator<<(std::ostream &os, const QBase &q)
Same as above, but allows you to use the stream syntax.
Definition: quadrature.C:257
The libMesh namespace provides an interface to certain functionality in the library.
std::vector< Point > _points
The locations of the quadrature points in reference element space.
Definition: quadrature.h:383
std::vector< Real > _weights
The quadrature weights.
Definition: quadrature.h:389
virtual QuadratureType type() const =0
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:230
unsigned int _p_level
The p-level of the element for which the current values have been computed.
Definition: quadrature.h:377
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:203
unsigned int get_p_level() const
Definition: quadrature.h:118
libmesh_assert(ctx)
Order get_order() const
Definition: quadrature.h:218
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:118
unsigned int get_dim() const
Definition: quadrature.h:142
unsigned int n_points() const
Definition: quadrature.h:123
This class implements reference counting.
Order _order
The polynomial order which the quadrature rule is capable of integrating exactly. ...
Definition: quadrature.h:365
void print_info(std::ostream &os=libMesh::out) const
Prints information relevant to the quadrature rule, by default to libMesh::out.
Definition: quadrature.C:42
bool allow_nodal_pyramid_quadrature
The flag&#39;s value defaults to false so that one does not accidentally use a nodal quadrature rule on P...
Definition: quadrature.h:274
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual std::unique_ptr< QBase > clone() const
Definition: quadrature.C:37
const std::vector< Point > & get_points() const
Definition: quadrature.h:148
OStreamProxy out
virtual ~QBase()=default
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:142
unsigned int size() const
Alias for n_points() to enable use in index_range.
Definition: quadrature.h:134
static std::unique_ptr< QBase > build(std::string_view 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:176
Real w(const unsigned int i) const
Definition: quadrature.h:180
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
The QBase class provides the basic functionality from which various quadrature rules can be derived...
Definition: quadrature.h:53
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360
std::vector< Real > & get_weights()
Definition: quadrature.h:166