22
22
/// =========================================================================
24
#include "rheolef/reference_element.h"
25
#include "rheolef/point.h"
25
30
NAME: @code{quadrature} - quadrature formulae on the reference lement
26
31
@cindex quadrature formulae
61
#include "rheolef/reference_element.h"
62
#include "rheolef/point.h"
65
struct weighted_point {
67
weighted_point (const point& x, Float w);
72
66
class quadrature_option_type {
70
typedef size_t size_type;
79
77
superconvergent = 4,
81
} family_type; // update also family_name[] in quatrature.cc
83
typedef size_t size_type;
84
quadrature_option_type(
79
} family_type; // update also family_name[] in quatrature.cc
83
quadrature_option_type(
85
84
family_type ft = quadrature_option_type::gauss,
86
85
size_type k = std::numeric_limits<size_type>::max());
87
size_t get_order() const;
88
family_type get_family() const;
89
std::string get_family_name() const;
90
void set_order (size_t r);
91
void set_family (family_type ft);
87
quadrature_option_type (const quadrature_option_type& qopt);
88
quadrature_option_type& operator= (const quadrature_option_type& qopt);
90
// accessors & modifiers:
92
size_t get_order() const;
93
family_type get_family() const;
94
std::string get_family_name() const;
95
void set_order (size_t r);
96
void set_family (family_type ft);
96
class quadrature_on_geo : public std::vector<weighted_point> {
103
struct weighted_point {
104
weighted_point () : x(), w(0) {}
105
weighted_point (const point_basic<T>& x1, const T& w1) : x(x1), w(w1) {}
110
class quadrature_on_geo : public std::vector<weighted_point<T> > {
101
typedef std::vector<weighted_point>:: size_type size_type;
115
typedef std::vector<weighted_point<T> > base;
116
typedef typename base::size_type size_type;
117
typedef point_basic<T> x;
104
119
// alocators/deallocators:
110
void initialize (reference_element hat_K, quadrature_option_type opt);
111
void init_point (quadrature_option_type opt);
112
void init_edge (quadrature_option_type opt);
113
void init_triangle (quadrature_option_type opt);
114
void init_square (quadrature_option_type opt);
125
void initialize (reference_element hat_K, quadrature_option_type opt);
126
void init_point (quadrature_option_type opt);
127
void init_edge (quadrature_option_type opt);
128
void init_triangle (quadrature_option_type opt);
129
void init_square (quadrature_option_type opt);
115
130
void init_tetrahedron (quadrature_option_type opt);
116
void init_prism (quadrature_option_type opt);
117
void init_hexahedron (quadrature_option_type opt);
119
void wx (const point& x, const Float& w) {
120
push_back (weighted_point(x,w)); }
122
static size_type n_node_gauss (size_t r);
124
friend std::ostream& operator<< (std::ostream&, const quadrature_on_geo&);
131
void init_prism (quadrature_option_type opt);
132
void init_hexahedron (quadrature_option_type opt);
134
void wx (const point_basic<T>& x, const T& w) {
135
base::push_back (weighted_point<T>(x,w)); }
137
static size_type n_node_gauss (size_type r);
140
friend std::ostream& operator<< (std::ostream&, const quadrature_on_geo<U>&);
126
142
quadrature_on_geo (const quadrature_on_geo&);
127
143
quadrature_on_geo operator= (const quadrature_on_geo&);
130
147
class quadrature {
135
typedef quadrature_on_geo::size_type size_type;
136
typedef quadrature_option_type::family_type family_type;
137
typedef std::vector<weighted_point>::const_iterator const_iterator;
152
typedef typename quadrature_on_geo<T>::size_type size_type;
153
typedef quadrature_option_type::family_type family_type;
154
typedef typename std::vector<weighted_point<T> >::const_iterator const_iterator;
153
170
size_type size (reference_element hat_K) const;
154
171
const_iterator begin (reference_element hat_K) const;
155
172
const_iterator end (reference_element hat_K) const;
156
friend std::ostream& operator<< (std::ostream&, const quadrature&);
174
friend std::ostream& operator<< (std::ostream&, const quadrature<U>&);
158
quadrature_option_type _options;
159
mutable quadrature_on_geo _quad [reference_element::max_variant];
160
mutable std::vector<bool> _initialized;
176
quadrature_option_type _options;
177
mutable quadrature_on_geo<T> _quad [reference_element::max_variant];
178
mutable std::vector<bool> _initialized;
161
179
void _initialize (reference_element hat_K) const;
163
quadrature (const quadrature&);
164
quadrature operator= (const quadrature&);
181
quadrature (const quadrature<T>&);
182
quadrature operator= (const quadrature<T>&);
167
185
// ------------------------------------------------------------
195
quadrature_option_type::quadrature_option_type (const quadrature_option_type& qopt)
196
: _family(qopt._family),
201
quadrature_option_type&
202
quadrature_option_type::operator= (const quadrature_option_type& qopt)
204
_family = qopt._family;
205
_order = qopt._order;
177
209
quadrature_option_type::size_type
178
210
quadrature_option_type::get_order () const
201
weighted_point::weighted_point ()
205
weighted_point::weighted_point (const point& x1, Float w1)
209
quadrature_on_geo::quadrature_on_geo ()
210
: std::vector<weighted_point>()
214
quadrature::size_type
215
quadrature::get_order () const
234
quadrature_on_geo<T>::quadrature_on_geo ()
235
: std::vector<weighted_point<T> >()
240
typename quadrature_on_geo<T>::size_type
241
quadrature_on_geo<T>::n_node_gauss (size_type r)
243
// when using n nodes : gauss quadrature formulae order is r=2*n-1
244
if (r == 0) return 1;
245
size_type n = (r % 2 == 0) ? r/2+1 : (r+1)/2;
246
return std::max(size_t(1), n);
250
typename quadrature<T>::size_type
251
quadrature<T>::get_order () const
217
253
return _options.get_order();
220
quadrature::family_type
221
quadrature::get_family () const
257
typename quadrature<T>::family_type
258
quadrature<T>::get_family () const
223
260
return _options.get_family();
227
quadrature::get_family_name () const
265
quadrature<T>::get_family_name () const
229
267
return _options.get_family_name();
232
quadrature::quadrature (quadrature_option_type opt)
271
quadrature<T>::quadrature (quadrature_option_type opt)
235
274
_initialized(reference_element::max_variant, false)
241
quadrature::set_order (size_type r)
281
quadrature<T>::set_order (size_type r)
243
283
if (get_order() != r) {
244
284
// do not re-initialize nodes-weights if unchanged
246
286
std::fill (_initialized.begin(), _initialized.end(), false);
251
quadrature::set_family (family_type ft)
292
quadrature<T>::set_family (family_type ft)
253
294
if (get_family() != ft) {
254
295
// do not re-initialize nodes-weights if unchanged
256
297
std::fill (_initialized.begin(), _initialized.end(), false);
260
quadrature_on_geo::size_type
261
quadrature_on_geo::n_node_gauss (size_type r)
263
// when using n nodes : gauss quadrature formulae order is r=2*n-1
264
if (r == 0) return 1;
265
size_type n = (r % 2 == 0) ? r/2+1 : (r+1)/2;
266
return std::max(size_t(1), n);
268
301
}// namespace rheolef
269
302
#endif // _RHEO_QUADRATURE_H