Flow123d  DF_patch_fe_data_tables-5938e3d
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, 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  */
64 // template<unsigned int quad_dim>
65 // explicit Quadrature(const Quadrature &sub_quadrature, unsigned int sid, unsigned int pid);
66 
67  /// Virtual destructor.
68  virtual ~Quadrature()
69  {
70  };
71 
72  inline unsigned int dim() const
73  { return dim_; }
74 
75  /**
76  * @brief Modify the number of quadrature points.
77  * @param n_q_points New number of quadrature points.
78  */
79  inline void resize(unsigned int n_q_points)
80  {
81  quadrature_points.resize(n_q_points);
82  weights.resize(n_q_points, 0);
83  }
84 
85  /// Returns number of quadrature points.
86  inline unsigned int size() const
87  { return weights.size(); }
88 
89  /// Returns the <tt>i</tt>th quadrature point.
90  template<unsigned int point_dim>
91  inline Armor::ArmaVec<double, point_dim> point(unsigned int i) const;
92 
94  {
95  return quadrature_points.set(i);
96  }
97 
98  /// Return a reference to the whole array of quadrature points.
99  inline const Armor::Array<double> & get_points() const
100  { return quadrature_points; }
101 
102  /// Returns the <tt>i</tt>th weight.
103  inline double weight(unsigned int i) const
104  { return weights[i]; }
105 
106  /// Returns the <tt>i</tt>th weight (non-const version).
107  inline double &weight(unsigned int i)
108  { return weights[i]; }
109 
110  /// Return a reference to the whole array of weights.
111  inline const std::vector<double> & get_weights() const
112  { return weights; }
113 
114  Quadrature &operator=(const Quadrature &q);
115 
116  /**
117  * Create bulk quadrature from side quadrature.
118  *
119  * Consider *this as quadrature on a side of an element and create
120  * higher dimensional quadrature considering side index.
121  */
122  template<unsigned int bulk_dim>
123  Quadrature make_from_side(unsigned int sid) const;
124 
125 
126 protected:
127 
128  /// Dimension of quadrature points.
129  const unsigned int dim_;
130 
131  /**
132  * @brief List of quadrature points.
133  *
134  * To be filled by the constructors of the derived classes.
135  */
137 
138  /**
139  * @brief List of weights to the quadrature points.
140  *
141  * To be filled by the constructors of the derived classes.
142  */
144 
145 };
146 
147 
148 
149 
150 template<unsigned int point_dim>
152 {
153  ASSERT_EQ(point_dim, dim_);
154  return quadrature_points.vec<point_dim>(i);
155 }
156 
157 template<>
158 inline Armor::ArmaVec<double, 0> Quadrature::point<0>(unsigned int i) const
159 {
160  ASSERT_EQ(0, dim_);
161  ASSERT_EQ(i, 0);
162  return Armor::ArmaVec<double, 0>();
163 }
164 
165 #endif /* QUADRATURE_HH_ */
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
Definition: asserts.hh:333
void resize(uint size)
Definition: armor.hh:758
ArrayMatSet set(uint index)
Definition: armor.hh:886
ArmaVec< Type, nr > vec(uint mat_index) const
Definition: armor.hh:869
Base class for quadrature rules on simplices in arbitrary dimensions.
Definition: quadrature.hh:48
Quadrature make_from_side(unsigned int sid) const
Definition: quadrature.cc:47
const Armor::Array< double > & get_points() const
Return a reference to the whole array of quadrature points.
Definition: quadrature.hh:99
unsigned int size() const
Returns number of quadrature points.
Definition: quadrature.hh:86
unsigned int dim() const
Definition: quadrature.hh:72
double & weight(unsigned int i)
Returns the ith weight (non-const version).
Definition: quadrature.hh:107
Armor::ArmaVec< double, point_dim > point(unsigned int i) const
Returns the ith quadrature point.
Definition: quadrature.hh:151
Armor::Array< double >::ArrayMatSet set(uint i)
Definition: quadrature.hh:93
Quadrature(const Quadrature &q)
Copy constructor.
Definition: quadrature.cc:39
virtual ~Quadrature()
Constructor from quadrature of lower dimension (e.g. for side integration).
Definition: quadrature.hh:68
std::vector< double > weights
List of weights to the quadrature points.
Definition: quadrature.hh:143
Quadrature & operator=(const Quadrature &q)
Definition: quadrature.cc:23
double weight(unsigned int i) const
Returns the ith weight.
Definition: quadrature.hh:103
void resize(unsigned int n_q_points)
Modify the number of quadrature points.
Definition: quadrature.hh:79
Armor::Array< double > quadrature_points
List of quadrature points.
Definition: quadrature.hh:136
const unsigned int dim_
Dimension of quadrature points.
Definition: quadrature.hh:129
const std::vector< double > & get_weights() const
Return a reference to the whole array of weights.
Definition: quadrature.hh:111
unsigned int uint
typename arma::Col< Type >::template fixed< nr > ArmaVec
Definition: armor.hh:505
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc.