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