libMesh
quadrature.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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 // We used to have additional arguments to the init_0D, init_1D, etc.
37 // classes, but they became unused after QBase members made them
38 // redundant, so they were deprecated and eventually removed. Users'
39 // derived classes that need to compile against both old and new
40 // libMesh version can test this macro to determine what signature
41 // their overrides should have.
42 #define LIBMESH_QBASE_INIT_ARGUMENTS_REMOVED
43 
44 namespace libMesh
45 {
46 
47 // forward declarations
48 class Elem;
49 enum QuadratureType : int;
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 std::unique_ptr<QBase> clone() const;
88 
92  virtual QuadratureType type() const = 0;
93 
103  static std::unique_ptr<QBase> build (std::string_view name,
104  const unsigned int dim,
105  const Order order=INVALID_ORDER);
106 
114  static std::unique_ptr<QBase> build (const QuadratureType qt,
115  const unsigned int dim,
116  const Order order=INVALID_ORDER);
117 
121  ElemType get_elem_type() const { return _type; }
122 
126  unsigned int get_p_level() const { return _p_level; }
127 
131  unsigned int n_points() const
132  {
133  libmesh_assert (!_points.empty());
134  return cast_int<unsigned int>(_points.size());
135  }
136 
142  unsigned int size() const
143  {
144  return n_points();
145  }
146 
150  unsigned int get_dim() const { return _dim; }
151 
156  const std::vector<Point> & get_points() const { return _points; }
157 
162  std::vector<Point> & get_points() { return _points; }
163 
168  const std::vector<Real> & get_weights() const { return _weights; }
169 
174  std::vector<Real> & get_weights() { return _weights; }
175 
179  Point qp(const unsigned int i) const
180  {
181  libmesh_assert_less (i, _points.size());
182  return _points[i];
183  }
184 
188  Real w(const unsigned int i) const
189  {
190  libmesh_assert_less (i, _weights.size());
191  return _weights[i];
192  }
193 
199  virtual void init (const Elem & e,
200  unsigned int p_level=invalid_uint);
201 
214  virtual void init (const ElemType type=INVALID_ELEM,
215  unsigned int p_level=0,
216  bool simple_type_only=false);
217 
222  virtual void init (const QBase & other_rule);
223 
233  virtual void init (const Elem & elem,
234  const std::vector<Real> & vertex_distance_func,
235  unsigned int p_level=0);
236 
249  Order get_order() const { return static_cast<Order>(_order + 2 * _p_level); }
250 
258  Order get_base_order() const { return static_cast<Order>(_order); }
259 
264  void print_info(std::ostream & os=libMesh::out) const;
265 
271  void scale(std::pair<Real, Real> old_range,
272  std::pair<Real, Real> new_range);
273 
277  friend std::ostream & operator << (std::ostream & os, const QBase & q);
278 
286  virtual bool shapes_need_reinit() { return false; }
287 
302 
315 
316 protected:
317 
318 
324  virtual void init_0D ();
325 
333  virtual void init_1D () = 0;
334 
343  virtual void init_2D ();
344 
353  virtual void init_3D ();
354 
360  void tensor_product_quad (const QBase & q1D);
361 
367  void tensor_product_hex (const QBase & q1D);
368 
374  void tensor_product_prism (const QBase & q1D, const QBase & q2D);
375 
379  unsigned int _dim;
380 
386 
392 
397  const Elem * _elem;
398 
403  unsigned int _p_level;
404 
409  std::vector<Point> _points;
410 
415  std::vector<Real> _weights;
416 };
417 
418 } // namespace libMesh
419 
420 #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 bool shapes_need_reinit()
Definition: quadrature.h:286
ElemType
Defines an enum for geometric element types.
Order
defines an enum for polynomial orders.
Definition: enum_order.h:40
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
Definition: libmesh.h:310
QBase & operator=(const QBase &)=default
std::vector< Point > & get_points()
Definition: quadrature.h:162
bool allow_rules_with_negative_weights
Flag (default true) controlling the use of quadrature rules with negative weights.
Definition: quadrature.h:301
Point qp(const unsigned int i) const
Definition: quadrature.h:179
unsigned int dim
virtual void init_2D()
Initializes the 2D quadrature rule by filling the points and weights vectors with the appropriate val...
Definition: quadrature.C:208
ElemType get_elem_type() const
Definition: quadrature.h:121
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
ElemType _type
The type of element for which the current values have been computed.
Definition: quadrature.h:391
const std::vector< Real > & get_weights() const
Definition: quadrature.h:168
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:379
const Elem * _elem
The element for which the current values were computed, or nullptr if values were computed without a ...
Definition: quadrature.h:397
friend std::ostream & operator<<(std::ostream &os, const QBase &q)
Same as above, but allows you to use the stream syntax.
Definition: quadrature.C:337
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:409
std::vector< Real > _weights
The quadrature weights.
Definition: quadrature.h:415
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:310
unsigned int _p_level
The p-level of the element for which the current values have been computed.
Definition: quadrature.h:403
Order get_base_order() const
Definition: quadrature.h:258
virtual void init_0D()
Initializes the 0D quadrature rule by filling the points and weights vectors with the appropriate val...
Definition: quadrature.C:198
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:283
unsigned int get_p_level() const
Definition: quadrature.h:126
libmesh_assert(ctx)
Order get_order() const
Definition: quadrature.h:249
unsigned int get_dim() const
Definition: quadrature.h:150
unsigned int n_points() const
Definition: quadrature.h:131
This class implements reference counting.
virtual void init_1D()=0
Initializes the 1D quadrature rule by filling the points and weights vectors with the appropriate val...
Order _order
The polynomial order which the quadrature rule is capable of integrating exactly. ...
Definition: quadrature.h:385
void print_info(std::ostream &os=libMesh::out) const
Prints information relevant to the quadrature rule, by default to libMesh::out.
Definition: quadrature.C:43
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:314
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual std::unique_ptr< QBase > clone() const
Definition: quadrature.C:38
const std::vector< Point > & get_points() const
Definition: quadrature.h:156
OStreamProxy out
virtual ~QBase()=default
virtual void init_3D()
Initializes the 3D quadrature rule by filling the points and weights vectors with the appropriate val...
Definition: quadrature.C:215
virtual void init(const Elem &e, unsigned int p_level=invalid_uint)
Initializes the data structures for a quadrature rule for the element e.
Definition: quadrature.C:65
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:222
unsigned int size() const
Alias for n_points() to enable use in index_range.
Definition: quadrature.h:142
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:256
Real w(const unsigned int i) const
Definition: quadrature.h:188
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:61
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360
std::vector< Real > & get_weights()
Definition: quadrature.h:174