Flow123d  intersections_paper-476-gbe68821
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  * TODO:
39  * - remove set_weight, set point; quadrature should be set by its descendants
40  * - introduce Quadrature point which should store point coords together with the weight in raw double[1+dim] array
41  * and just return arma object on the flys
42  */
43 template<unsigned int dim>
44 class Quadrature {
45 public:
46  /**
47  * @brief Constructor.
48  * @param n_quadrature_points Number of quadrature points to be allocated.
49  */
50  Quadrature(const unsigned int n_quadrature_points = 0);
51 
52  /// Copy constructor.
53  Quadrature(const Quadrature<dim> &q);
54 
55  /// Virtual destructor.
56  virtual ~Quadrature();
57 
58  /**
59  * @brief Modify the number of quadrature points.
60  * @param n_q_points New number of quadrature points.
61  */
62  void resize(const unsigned int n_q_points);
63 
64  /// Returns number of quadrature points.
65  const unsigned int size() const;
66 
67  /// Returns the <tt>i</tt>th quadrature point.
68  const arma::vec::fixed<dim> & point(const unsigned int i) const;
69 
70  /// Return a reference to the whole array of quadrature points.
72 
73  /**
74  * @brief Sets individual quadrature point coordinates.
75  * @param i Number of the quadrature point.
76  * @param p New coordinates.
77  */
78  void set_point(const unsigned int i, const arma::vec::fixed<dim> &p);
79 
80  /// Returns the <tt>i</tt>th weight.
81  double weight(const unsigned int i) const;
82 
83  /// Return a reference to the whole array of weights.
84  const std::vector<double> & get_weights() const;
85 
86  /// Sets individual quadrature weight.
87  void set_weight(const unsigned int i, const double w);
88 
89 protected:
90  /**
91  * @brief List of quadrature points.
92  *
93  * To be filled by the constructors of the derived classes.
94  */
96 
97  /**
98  * @brief List of weights to the quadrature points.
99  *
100  * To be filled by the constructors of the derived classes.
101  */
103 
104 };
105 
106 
107 
108 template<unsigned int dim>
109 Quadrature<dim>::Quadrature(const unsigned int n_q)
110 {
111  resize(n_q);
112 }
113 
114 template<unsigned int dim>
117  weights(q.weights)
118 {}
119 
120 template<unsigned int dim>
121 void Quadrature<dim>::resize(const unsigned int n_q)
122 {
123  arma::vec::fixed<dim> v;
124  v.fill(0);
125  quadrature_points.resize(n_q, v);
126  weights.resize(n_q, 0);
127 }
128 
129 template<unsigned int dim>
130 inline const unsigned int Quadrature<dim>::size() const {
131  return weights.size();
132 }
133 
134 template<unsigned int dim>
135 inline const arma::vec::fixed<dim> & Quadrature<dim>::point(
136  const unsigned int i) const {
137  return quadrature_points[i];
138 }
139 
140 template<unsigned int dim>
142  return quadrature_points;
143 }
144 
145 template<unsigned int dim>
146 inline void Quadrature<dim>::set_point(const unsigned int i, const arma::vec::fixed<dim> &p)
147 {
148  quadrature_points[i] = p;
149 }
150 
151 template<unsigned int dim>
152 inline double Quadrature<dim>::weight(const unsigned int i) const {
153  return weights[i];
154 }
155 
156 template<unsigned int dim>
158  return weights;
159 }
160 
161 template<unsigned int dim>
162 inline void Quadrature<dim>::set_weight(const unsigned int i, const double w)
163 {
164  weights[i] = w;
165 }
166 
167 template<unsigned int dim>
169 {}
170 
171 
172 
173 
174 
175 
176 #endif /* QUADRATURE_HH_ */
void set_weight(const unsigned int i, const double w)
Sets individual quadrature weight.
Definition: quadrature.hh:162
std::vector< double > weights
List of weights to the quadrature points.
Definition: quadrature.hh:102
Quadrature(const unsigned int n_quadrature_points=0)
Constructor.
Definition: quadrature.hh:109
std::vector< arma::vec::fixed< dim > > quadrature_points
List of quadrature points.
Definition: quadrature.hh:95
const std::vector< arma::vec::fixed< dim > > & get_points() const
Return a reference to the whole array of quadrature points.
Definition: quadrature.hh:141
Base class for quadrature rules on simplices in arbitrary dimensions.
Definition: fe_values.hh:31
virtual ~Quadrature()
Virtual destructor.
Definition: quadrature.hh:168
double weight(const unsigned int i) const
Returns the ith weight.
Definition: quadrature.hh:152
void resize(const unsigned int n_q_points)
Modify the number of quadrature points.
Definition: quadrature.hh:121
void set_point(const unsigned int i, const arma::vec::fixed< dim > &p)
Sets individual quadrature point coordinates.
Definition: quadrature.hh:146
const unsigned int size() const
Returns number of quadrature points.
Definition: quadrature.hh:130
const std::vector< double > & get_weights() const
Return a reference to the whole array of weights.
Definition: quadrature.hh:157
const arma::vec::fixed< dim > & point(const unsigned int i) const
Returns the ith quadrature point.
Definition: quadrature.hh:135