Flow123d  3.9.0-be1f591da
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  {
93  ASSERT_EQ(point_dim, dim_);
94  return quadrature_points.vec<point_dim>(i);
95  }
96 
98  {
99  return quadrature_points.set(i);
100  }
101 
102  /// Return a reference to the whole array of quadrature points.
103  inline const Armor::Array<double> & get_points() const
104  { return quadrature_points; }
105 
106  /// Returns the <tt>i</tt>th weight.
107  inline double weight(unsigned int i) const
108  { return weights[i]; }
109 
110  /// Returns the <tt>i</tt>th weight (non-const version).
111  inline double &weight(unsigned int i)
112  { return weights[i]; }
113 
114  /// Return a reference to the whole array of weights.
115  inline const std::vector<double> & get_weights() const
116  { return weights; }
117 
118  Quadrature &operator=(const Quadrature &q);
119 
120  /**
121  * Create bulk quadrature from side quadrature.
122  *
123  * Consider *this as quadrature on a side of an element and create
124  * higher dimensional quadrature considering side index.
125  */
126  template<unsigned int bulk_dim>
127  Quadrature make_from_side(unsigned int sid) const;
128 
129 
130 protected:
131 
132  /// Dimension of quadrature points.
133  const unsigned int dim_;
134 
135  /**
136  * @brief List of quadrature points.
137  *
138  * To be filled by the constructors of the derived classes.
139  */
141 
142  /**
143  * @brief List of weights to the quadrature points.
144  *
145  * To be filled by the constructors of the derived classes.
146  */
148 
149 };
150 
151 #endif /* QUADRATURE_HH_ */
Quadrature::point
Armor::ArmaVec< double, point_dim > point(unsigned int i) const
Returns the ith quadrature point.
Definition: quadrature.hh:91
ref_element.hh
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc.
armor.hh
Armor::Array::ArrayMatSet
Definition: armor.hh:599
Quadrature::weights
std::vector< double > weights
List of weights to the quadrature points.
Definition: quadrature.hh:147
Armor::Array::vec
ArmaVec< Type, nr > vec(uint mat_index) const
Definition: armor.hh:821
Quadrature::operator=
Quadrature & operator=(const Quadrature &q)
Definition: quadrature.cc:23
Quadrature::get_weights
const std::vector< double > & get_weights() const
Return a reference to the whole array of weights.
Definition: quadrature.hh:115
Quadrature::size
unsigned int size() const
Returns number of quadrature points.
Definition: quadrature.hh:86
std::vector< double >
Armor::Array::resize
void resize(uint size)
Definition: armor.hh:710
uint
unsigned int uint
Definition: mh_dofhandler.hh:101
Quadrature::~Quadrature
virtual ~Quadrature()
Constructor from quadrature of lower dimension (e.g. for side integration).
Definition: quadrature.hh:68
Quadrature::resize
void resize(unsigned int n_q_points)
Modify the number of quadrature points.
Definition: quadrature.hh:79
Quadrature::weight
double & weight(unsigned int i)
Returns the ith weight (non-const version).
Definition: quadrature.hh:111
Quadrature::set
Armor::Array< double >::ArrayMatSet set(uint i)
Definition: quadrature.hh:97
Quadrature::weight
double weight(unsigned int i) const
Returns the ith weight.
Definition: quadrature.hh:107
ASSERT_EQ
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
Definition: asserts.hh:333
Quadrature::dim
unsigned int dim() const
Definition: quadrature.hh:72
Quadrature::get_points
const Armor::Array< double > & get_points() const
Return a reference to the whole array of quadrature points.
Definition: quadrature.hh:103
Armor::Array::set
ArrayMatSet set(uint index)
Definition: armor.hh:838
Quadrature::Quadrature
Quadrature(const Quadrature &q)
Copy constructor.
Definition: quadrature.cc:39
Quadrature::dim_
const unsigned int dim_
Dimension of quadrature points.
Definition: quadrature.hh:133
Quadrature::quadrature_points
Armor::Array< double > quadrature_points
List of quadrature points.
Definition: quadrature.hh:140
Armor::Array< double >
Quadrature
Base class for quadrature rules on simplices in arbitrary dimensions.
Definition: quadrature.hh:48
Armor::ArmaVec
typename arma::Col< Type >::template fixed< nr > ArmaVec
Definition: armor.hh:505
Quadrature::make_from_side
Quadrature make_from_side(unsigned int sid) const
Definition: quadrature.cc:47