1
#ifndef _RHEO_QUADRATURE_H
2
#define _RHEO_QUADRATURE_H
4
/// This file is part of Rheolef.
6
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
8
/// Rheolef is free software; you can redistribute it and/or modify
9
/// it under the terms of the GNU General Public License as published by
10
/// the Free Software Foundation; either version 2 of the License, or
11
/// (at your option) any later version.
13
/// Rheolef is distributed in the hope that it will be useful,
14
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
/// GNU General Public License for more details.
18
/// You should have received a copy of the GNU General Public License
19
/// along with Rheolef; if not, write to the Free Software
20
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
/// =========================================================================
25
NAME: @code{quadrature} - quadrature formulae on the reference lement
26
@cindex quadrature formulae
28
@clindex reference_element
31
The @code{quadrature} class defines a container for a quadrature
32
formulae on the reference element (@pxref{reference_element internal}).
33
This container stores the nodes coordinates and the weights.
34
The constructor takes two arguments: the reference element
36
and the order @math{r} of the quadrature formulae.
37
The formulae is exact when computing the integral
38
of a polynom @math{p} that degree is less or equal to order @math{r}.
42
| p(x) dx = \ p(x_q) w_q
48
The formulae is optimal when it uses a minimal number
50
Optimal quadrature formula are hard-coded in this class.
51
Not all reference elements and orders are yet
52
implemented. This class will be completed in the future.
55
LMC-IMAG, 38041 Grenoble cedex 9, France
56
| Pierre.Saramito@imag.fr
57
DATE: 30 november 2003
61
#include "rheolef/reference_element.h"
62
#include "rheolef/point.h"
64
struct weighted_point {
66
weighted_point (const point& x, Float w);
71
class quadrature_option_type {
80
} family_type; // update also family_name[] in quatrature.cc
82
typedef size_t size_type;
83
quadrature_option_type(
84
family_type ft = quadrature_option_type::gauss,
85
size_type k = std::numeric_limits<size_type>::max());
86
size_t get_order() const;
87
family_type get_family() const;
88
std::string get_family_name() const;
89
void set_order (size_t r);
90
void set_family (family_type ft);
95
class quadrature_on_geo : public std::vector<weighted_point> {
100
typedef std::vector<weighted_point>:: size_type size_type;
103
// alocators/deallocators:
105
quadrature_on_geo ();
109
void initialize (reference_element hat_K, quadrature_option_type opt);
110
void init_point (quadrature_option_type opt);
111
void init_edge (quadrature_option_type opt);
112
void init_triangle (quadrature_option_type opt);
113
void init_square (quadrature_option_type opt);
114
void init_tetrahedron (quadrature_option_type opt);
115
void init_prism (quadrature_option_type opt);
116
void init_hexahedron (quadrature_option_type opt);
118
void wx (const point& x, const Float& w) {
119
push_back (weighted_point(x,w)); }
121
static size_type n_node_gauss (size_t r);
123
friend std::ostream& operator<< (std::ostream&, const quadrature_on_geo&);
125
quadrature_on_geo (const quadrature_on_geo&);
126
quadrature_on_geo operator= (const quadrature_on_geo&);
134
typedef quadrature_on_geo::size_type size_type;
135
typedef quadrature_option_type::family_type family_type;
136
typedef std::vector<weighted_point>::const_iterator const_iterator;
140
quadrature (quadrature_option_type opt = quadrature_option_type());
144
void set_order (size_type order);
145
void set_family (family_type ft);
149
size_type get_order() const;
150
family_type get_family() const;
151
std::string get_family_name() const;
152
size_type size (reference_element hat_K) const;
153
const_iterator begin (reference_element hat_K) const;
154
const_iterator end (reference_element hat_K) const;
155
friend std::ostream& operator<< (std::ostream&, const quadrature&);
157
quadrature_option_type _options;
158
mutable quadrature_on_geo _quad [reference_element::max_size];
159
mutable std::vector<bool> _initialized;
160
void _initialize (reference_element hat_K) const;
162
quadrature (const quadrature&);
163
quadrature operator= (const quadrature&);
166
// ------------------------------------------------------------
168
// ------------------------------------------------------------
170
quadrature_option_type::quadrature_option_type (family_type ft, size_type k)
176
quadrature_option_type::size_type
177
quadrature_option_type::get_order () const
182
quadrature_option_type::family_type
183
quadrature_option_type::get_family () const
189
quadrature_option_type::set_order (size_t r)
195
quadrature_option_type::set_family (family_type ft)
200
weighted_point::weighted_point ()
204
weighted_point::weighted_point (const point& x1, Float w1)
208
quadrature_on_geo::quadrature_on_geo ()
209
: std::vector<weighted_point>()
213
quadrature::size_type
214
quadrature::get_order () const
216
return _options.get_order();
219
quadrature::family_type
220
quadrature::get_family () const
222
return _options.get_family();
226
quadrature::get_family_name () const
228
return _options.get_family_name();
231
quadrature::quadrature (quadrature_option_type opt)
234
_initialized(reference_element::max_size, false)
240
quadrature::set_order (size_type r)
242
if (get_order() != r) {
243
// do not re-initialize nodes-weights if unchanged
244
_options.set_order(r);
245
std::fill (_initialized.begin(), _initialized.end(), false);
250
quadrature::set_family (family_type ft)
252
if (get_family() != ft) {
253
// do not re-initialize nodes-weights if unchanged
254
_options.set_family(ft);
255
std::fill (_initialized.begin(), _initialized.end(), false);
259
quadrature_on_geo::size_type
260
quadrature_on_geo::n_node_gauss (size_type r)
262
// when using n nodes : gauss quadrature formulae order is r=2*n-1
263
if (r == 0) return 1;
264
size_type n = (r % 2 == 0) ? r/2+1 : (r+1)/2;
265
return std::max(size_t(1), n);
267
#endif // _RHEO_QUADRATURE_H