Flow123d  release_3.0.0-1193-g9220a69
quadrature.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file quadrature.hh
15  * @brief Basic definitions of numerical quadrature rules.
16  * @author Jan Stebel
17  */
18 
19 #ifndef QUADRATURE_HH_
20 #define QUADRATURE_HH_
21 
22 #include <armadillo>
23 #include <vector>
24 
25 #include "system/armor.hh"
26 #include "mesh/ref_element.hh"
27 
28 
29 
30 /**
31  * @brief Base class for quadrature rules on simplices in arbitrary dimensions.
32  *
33  * This class stores quadrature points and weights on the reference line,
34  * triangle or tetrahedron, respectively.
35  * Quadrature rules are used for evaluation of integrals over elements.
36  * In particular, for a reference element @f$E@f$ we have:
37  * @f[
38  * \int_E f(x)\,dx \approx \sum_{i=1}^{N} w_i f(p_i),
39  * @f]
40  * where @f$\{w_i\}@f$, @f$\{p_i\}@f$ are the quadrature weights and the quadrature points,
41  * respectively.
42  *
43  * TODO:
44  * - remove set_weight, set point; quadrature should be set by its descendants
45  * - introduce Quadrature point which should store point coords together with the weight in raw double[1+dim] array
46  * and just return arma object on the flys
47  */
48 class Quadrature {
49 public:
50 
51  /// Copy constructor.
52  Quadrature(const Quadrature &q);
53 
54  /**
55  * @brief Constructor.
56  * @param n_quadrature_points Number of quadrature points to be allocated.
57  */
58  Quadrature(unsigned int dimension, const unsigned int n_quadrature_points = 0);
59 
60  /** @brief Constructor from quadrature of lower dimension (e.g. for side integration).
61  * @param sub_quadrature lower dimensional (dim-1) quadrature
62  * @param sid local index of side
63  * @param pid index of permutation of nodes on given side
64  */
65 // template<unsigned int quad_dim>
66 // explicit Quadrature(const Quadrature &sub_quadrature, unsigned int sid, unsigned int pid);
67 
68  /// Virtual destructor.
69  virtual ~Quadrature() {};
70 
71  inline unsigned int dim() const
72  { return dim_; }
73 
74  /**
75  * @brief Modify the number of quadrature points.
76  * @param n_q_points New number of quadrature points.
77  */
78  inline void resize(const unsigned int n_q_points)
79  {
80  quadrature_points.resize(n_q_points);
81  weights.resize(n_q_points, 0);
82  }
83 
84  /// Returns number of quadrature points.
85  inline const unsigned int size() const
86  { return weights.size(); }
87 
88  /// Returns the <tt>i</tt>th quadrature point.
89  template<unsigned int point_dim>
90  inline Armor::vec<point_dim> point(const unsigned int i) const
91  {
92  ASSERT_EQ_DBG(point_dim, dim_);
93  return quadrature_points.get<point_dim>(i);
94  }
95 
96  /// Return a reference to the whole array of quadrature points.
97  inline const Armor::array & get_points() const
98  { return quadrature_points; }
99 
100  /// Returns the <tt>i</tt>th weight.
101  inline double weight(const unsigned int i) const
102  { return weights[i]; }
103 
104  /// Returns the <tt>i</tt>th weight (non-const version).
105  inline double &weight(const unsigned int i)
106  { return weights[i]; }
107 
108  /// Return a reference to the whole array of weights.
109  inline const std::vector<double> & get_weights() const
110  { return weights; }
111 
112  Quadrature &operator=(const Quadrature &q);
113 
114  /**
115  * Create bulk quadrature from side quadrature.
116  *
117  * Consider *this as quadrature on a side of an element and create
118  * higher dimensional quadrature considering side and permutation index.
119  */
120  template<unsigned int bulk_dim>
121  Quadrature make_from_side(unsigned int sid, unsigned int pid);
122 
123 
124 protected:
125 
126  /// Dimension of quadrature points.
127  const unsigned int dim_;
128 
129  /**
130  * @brief List of quadrature points.
131  *
132  * To be filled by the constructors of the derived classes.
133  */
135 
136  /**
137  * @brief List of weights to the quadrature points.
138  *
139  * To be filled by the constructors of the derived classes.
140  */
142 
143 };
144 
145 
146 
147 
148 #endif /* QUADRATURE_HH_ */
void resize(uint size)
Definition: armor.hh:141
Mat< Type, nr, nc > get(uint i) const
Definition: armor.hh:162
void resize(const unsigned int n_q_points)
Modify the number of quadrature points.
Definition: quadrature.hh:78
#define ASSERT_EQ_DBG(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
Definition: asserts.hh:331
Quadrature(const Quadrature &q)
Copy constructor.
Definition: quadrature.cc:39
unsigned int dim() const
Definition: quadrature.hh:71
const std::vector< double > & get_weights() const
Return a reference to the whole array of weights.
Definition: quadrature.hh:109
Quadrature make_from_side(unsigned int sid, unsigned int pid)
Definition: quadrature.cc:52
virtual ~Quadrature()
Constructor from quadrature of lower dimension (e.g. for side integration).
Definition: quadrature.hh:69
double weight(const unsigned int i) const
Returns the ith weight.
Definition: quadrature.hh:101
Base class for quadrature rules on simplices in arbitrary dimensions.
Definition: quadrature.hh:48
Armor::vec< point_dim > point(const unsigned int i) const
Returns the ith quadrature point.
Definition: quadrature.hh:90
const Armor::array & get_points() const
Return a reference to the whole array of quadrature points.
Definition: quadrature.hh:97
const unsigned int size() const
Returns number of quadrature points.
Definition: quadrature.hh:85
std::vector< double > weights
List of weights to the quadrature points.
Definition: quadrature.hh:141
double & weight(const unsigned int i)
Returns the ith weight (non-const version).
Definition: quadrature.hh:105
const unsigned int dim_
Dimension of quadrature points.
Definition: quadrature.hh:127
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc...
Quadrature & operator=(const Quadrature &q)
Definition: quadrature.cc:23
Armor::array quadrature_points
List of quadrature points.
Definition: quadrature.hh:134