Flow123d  release_2.2.0-37-g336ee74
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 /**
26  * @brief Base class for quadrature rules on simplices in arbitrary dimensions.
27  *
28  * This class stores quadrature points and weights on the reference line,
29  * triangle or tetrahedron, respectively.
30  * Quadrature rules are used for evaluation of integrals over elements.
31  * In particular, for a reference element @f$E@f$ we have:
32  * @f[
33  * \int_E f(x)\,dx \approx \sum_{i=1}^{N} w_i f(p_i),
34  * @f]
35  * where @f$\{w_i\}@f$, @f$\{p_i\}@f$ are the quadrature weights and the quadrature points,
36  * respectively.
37  */
38 template<unsigned int dim>
39 class Quadrature {
40 public:
41  /**
42  * @brief Constructor.
43  * @param n_quadrature_points Number of quadrature points to be allocated.
44  */
45  Quadrature(const unsigned int n_quadrature_points = 0);
46 
47  /// Copy constructor.
48  Quadrature(const Quadrature<dim> &q);
49 
50  /// Virtual destructor.
51  virtual ~Quadrature();
52 
53  /**
54  * @brief Modify the number of quadrature points.
55  * @param n_q_points New number of quadrature points.
56  */
57  void resize(const unsigned int n_q_points);
58 
59  /// Returns number of quadrature points.
60  const unsigned int size() const;
61 
62  /// Returns the <tt>i</tt>th quadrature point.
63  const arma::vec::fixed<dim> & point(const unsigned int i) const;
64 
65  /// Return a reference to the whole array of quadrature points.
67 
68  /**
69  * @brief Sets individual quadrature point coordinates.
70  * @param i Number of the quadrature point.
71  * @param p New coordinates.
72  */
73  void set_point(const unsigned int i, const arma::vec::fixed<dim> &p);
74 
75  /// Returns the <tt>i</tt>th weight.
76  double weight(const unsigned int i) const;
77 
78  /// Return a reference to the whole array of weights.
79  const std::vector<double> & get_weights() const;
80 
81  /// Sets individual quadrature weight.
82  void set_weight(const unsigned int i, const double w);
83 
84 protected:
85  /**
86  * @brief List of quadrature points.
87  *
88  * To be filled by the constructors of the derived classes.
89  */
91 
92  /**
93  * @brief List of weights to the quadrature points.
94  *
95  * To be filled by the constructors of the derived classes.
96  */
98 
99 };
100 
101 
102 
103 template<unsigned int dim>
104 Quadrature<dim>::Quadrature(const unsigned int n_q)
105 {
106  resize(n_q);
107 }
108 
109 template<unsigned int dim>
112  weights(q.weights)
113 {}
114 
115 template<unsigned int dim>
116 void Quadrature<dim>::resize(const unsigned int n_q)
117 {
118  arma::vec::fixed<dim> v;
119  v.fill(0);
120  quadrature_points.resize(n_q, v);
121  weights.resize(n_q, 0);
122 }
123 
124 template<unsigned int dim>
125 inline const unsigned int Quadrature<dim>::size() const {
126  return weights.size();
127 }
128 
129 template<unsigned int dim>
130 inline const arma::vec::fixed<dim> & Quadrature<dim>::point(
131  const unsigned int i) const {
132  return quadrature_points[i];
133 }
134 
135 template<unsigned int dim>
137  return quadrature_points;
138 }
139 
140 template<unsigned int dim>
141 inline void Quadrature<dim>::set_point(const unsigned int i, const arma::vec::fixed<dim> &p)
142 {
143  quadrature_points[i] = p;
144 }
145 
146 template<unsigned int dim>
147 inline double Quadrature<dim>::weight(const unsigned int i) const {
148  return weights[i];
149 }
150 
151 template<unsigned int dim>
153  return weights;
154 }
155 
156 template<unsigned int dim>
157 inline void Quadrature<dim>::set_weight(const unsigned int i, const double w)
158 {
159  weights[i] = w;
160 }
161 
162 template<unsigned int dim>
164 {}
165 
166 
167 
168 
169 
170 
171 #endif /* QUADRATURE_HH_ */
void set_weight(const unsigned int i, const double w)
Sets individual quadrature weight.
Definition: quadrature.hh:157
std::vector< double > weights
List of weights to the quadrature points.
Definition: quadrature.hh:97
Quadrature(const unsigned int n_quadrature_points=0)
Constructor.
Definition: quadrature.hh:104
std::vector< arma::vec::fixed< dim > > quadrature_points
List of quadrature points.
Definition: quadrature.hh:90
const std::vector< arma::vec::fixed< dim > > & get_points() const
Return a reference to the whole array of quadrature points.
Definition: quadrature.hh:136
Base class for quadrature rules on simplices in arbitrary dimensions.
Definition: fe_values.hh:31
virtual ~Quadrature()
Virtual destructor.
Definition: quadrature.hh:163
double weight(const unsigned int i) const
Returns the ith weight.
Definition: quadrature.hh:147
void resize(const unsigned int n_q_points)
Modify the number of quadrature points.
Definition: quadrature.hh:116
void set_point(const unsigned int i, const arma::vec::fixed< dim > &p)
Sets individual quadrature point coordinates.
Definition: quadrature.hh:141
const unsigned int size() const
Returns number of quadrature points.
Definition: quadrature.hh:125
const std::vector< double > & get_weights() const
Return a reference to the whole array of weights.
Definition: quadrature.hh:152
const arma::vec::fixed< dim > & point(const unsigned int i) const
Returns the ith quadrature point.
Definition: quadrature.hh:130