Flow123d  jenkins-Flow123d-windows32-release-multijob-51
quadrature.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2007 Technical University of Liberec. All rights reserved.
4  *
5  * Please make a following refer to Flow123d on your project site if you use the program for any purpose,
6  * especially for academic research:
7  * Flow123d, Research Centre: Advanced Remedial Technologies, Technical University of Liberec, Czech Republic
8  *
9  * This program is free software; you can redistribute it and/or modify it under the terms
10  * of the GNU General Public License version 3 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with this program; if not,
17  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.
18  *
19  *
20  * $Id$
21  * $Revision$
22  * $LastChangedBy$
23  * $LastChangedDate$
24  *
25  * @file
26  * @brief Basic definitions of numerical quadrature rules.
27  * @author Jan Stebel
28  */
29 
30 #ifndef QUADRATURE_HH_
31 #define QUADRATURE_HH_
32 
33 #include <armadillo>
34 #include <vector>
35 
36 /**
37  * @brief Base class for quadrature rules on simplices in arbitrary dimensions.
38  *
39  * This class stores quadrature points and weights on the reference line,
40  * triangle or tetrahedron, respectively.
41  * Quadrature rules are used for evaluation of integrals over elements.
42  * In particular, for a reference element @f$E@f$ we have:
43  * @f[
44  * \int_E f(x)\,dx \approx \sum_{i=1}^{N} w_i f(p_i),
45  * @f]
46  * where @f$\{w_i\}@f$, @f$\{p_i\}@f$ are the quadrature weights and the quadrature points,
47  * respectively.
48  */
49 template<unsigned int dim>
50 class Quadrature {
51 public:
52  /**
53  * @brief Constructor.
54  * @param n_quadrature_points Number of quadrature points to be allocated.
55  */
56  Quadrature(const unsigned int n_quadrature_points = 0);
57 
58  /// Copy constructor.
59  Quadrature(const Quadrature<dim> &q);
60 
61  /// Virtual destructor.
62  virtual ~Quadrature();
63 
64  /**
65  * @brief Modify the number of quadrature points.
66  * @param n_q_points New number of quadrature points.
67  */
68  void resize(const unsigned int n_q_points);
69 
70  /// Returns number of quadrature points.
71  const unsigned int size() const;
72 
73  /// Returns the <tt>i</tt>th quadrature point.
74  const arma::vec::fixed<dim> & point(const unsigned int i) const;
75 
76  /// Return a reference to the whole array of quadrature points.
78 
79  /**
80  * @brief Sets individual quadrature point coordinates.
81  * @param i Number of the quadrature point.
82  * @param p New coordinates.
83  */
84  void set_point(const unsigned int i, const arma::vec::fixed<dim> &p);
85 
86  /// Returns the <tt>i</tt>th weight.
87  double weight(const unsigned int i) const;
88 
89  /// Return a reference to the whole array of weights.
90  const std::vector<double> & get_weights() const;
91 
92  /// Sets individual quadrature weight.
93  void set_weight(const unsigned int i, const double w);
94 
95 protected:
96  /**
97  * @brief List of quadrature points.
98  *
99  * To be filled by the constructors of the derived classes.
100  */
102 
103  /**
104  * @brief List of weights to the quadrature points.
105  *
106  * To be filled by the constructors of the derived classes.
107  */
109 
110 };
111 
112 
113 
114 template<unsigned int dim>
115 Quadrature<dim>::Quadrature(const unsigned int n_q)
116 {
117  resize(n_q);
118 }
119 
120 template<unsigned int dim>
122  quadrature_points(q.quadrature_points),
123  weights(q.weights)
124 {}
125 
126 template<unsigned int dim>
127 void Quadrature<dim>::resize(const unsigned int n_q)
128 {
129  arma::vec::fixed<dim> v;
130  v.fill(0);
131  quadrature_points.resize(n_q, v);
132  weights.resize(n_q, 0);
133 }
134 
135 template<unsigned int dim>
136 inline const unsigned int Quadrature<dim>::size() const {
137  return weights.size();
138 }
139 
140 template<unsigned int dim>
141 inline const arma::vec::fixed<dim> & Quadrature<dim>::point(
142  const unsigned int i) const {
143  return quadrature_points[i];
144 }
145 
146 template<unsigned int dim>
148  return quadrature_points;
149 }
150 
151 template<unsigned int dim>
152 inline void Quadrature<dim>::set_point(const unsigned int i, const arma::vec::fixed<dim> &p)
153 {
154  quadrature_points[i] = p;
155 }
156 
157 template<unsigned int dim>
158 inline double Quadrature<dim>::weight(const unsigned int i) const {
159  return weights[i];
160 }
161 
162 template<unsigned int dim>
164  return weights;
165 }
166 
167 template<unsigned int dim>
168 inline void Quadrature<dim>::set_weight(const unsigned int i, const double w)
169 {
170  weights[i] = w;
171 }
172 
173 template<unsigned int dim>
175 {}
176 
177 
178 
179 
180 
181 
182 #endif /* QUADRATURE_HH_ */
void set_weight(const unsigned int i, const double w)
Sets individual quadrature weight.
Definition: quadrature.hh:168
std::vector< double > weights
List of weights to the quadrature points.
Definition: quadrature.hh:108
Quadrature(const unsigned int n_quadrature_points=0)
Constructor.
Definition: quadrature.hh:115
std::vector< arma::vec::fixed< dim > > quadrature_points
List of quadrature points.
Definition: quadrature.hh:101
const std::vector< arma::vec::fixed< dim > > & get_points() const
Return a reference to the whole array of quadrature points.
Definition: quadrature.hh:147
Base class for quadrature rules on simplices in arbitrary dimensions.
Definition: fe_values.hh:42
virtual ~Quadrature()
Virtual destructor.
Definition: quadrature.hh:174
double weight(const unsigned int i) const
Returns the ith weight.
Definition: quadrature.hh:158
void resize(const unsigned int n_q_points)
Modify the number of quadrature points.
Definition: quadrature.hh:127
void set_point(const unsigned int i, const arma::vec::fixed< dim > &p)
Sets individual quadrature point coordinates.
Definition: quadrature.hh:152
const unsigned int size() const
Returns number of quadrature points.
Definition: quadrature.hh:136
const std::vector< double > & get_weights() const
Return a reference to the whole array of weights.
Definition: quadrature.hh:163
const arma::vec::fixed< dim > & point(const unsigned int i) const
Returns the ith quadrature point.
Definition: quadrature.hh:141