1
#ifndef _RHEO_BASIS_ON_POINTSET_H
2
#define _RHEO_BASIS_ON_POINTSET_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
/// =========================================================================
24
//! Pre-compute a piola transformation polynomial basis
25
//! on a lattice definied on the reference element.
26
//! The computation is performed one time for all
27
//! the first time the reference element appears.
28
//! Thus, when looping on the mesh for the Lagrange interpolation
29
//! on a Lagrange nodal basis : the lattice is the set of nodes
30
//! the evaluation of the fem polynomial basis.
31
//! The evaluation is performed only one time.
33
#include "rheolef/basis.h"
34
#include "rheolef/quadrature.h"
37
// -----------------------------------------------------------------------
38
// basis evaluated on lattice of quadrature formulae
39
// -----------------------------------------------------------------------
41
class basis_on_pointset {
44
typedef typename std::vector<T>::size_type size_type;
45
typedef typename std::vector<T>::const_iterator const_iterator;
46
typedef typename std::vector<point_basic<T> >::const_iterator const_iterator_grad;
51
basis_on_pointset (const quadrature<T>& quad, const basis_basic<T>& b);
52
basis_on_pointset (const basis_basic<T>& nb, const basis_basic<T>& b);
56
void set (const quadrature<T>& quad, const basis_basic<T>& b);
57
void set (const basis_basic<T>& nb, const basis_basic<T>& b);
61
const basis_basic<T>& get_basis() const { return _b; }
62
size_type size (reference_element hat_K) const;
65
const_iterator begin (reference_element hat_K, size_type q) const;
66
const_iterator end (reference_element hat_K, size_type q) const;
68
const_iterator_grad begin_grad (reference_element hat_K, size_type q) const;
69
const_iterator_grad end_grad (reference_element hat_K, size_type q) const;
72
void evaluate (reference_element hat_K, size_type q) const;
73
void evaluate_grad (reference_element hat_K, size_type q) const;
74
void evaluate (reference_element hat_K, const point_basic<T>& hat_xq) const;
75
void evaluate_grad (reference_element hat_K, const point_basic<T>& hat_xq) const;
76
const_iterator begin() const;
77
const_iterator end() const;
78
const_iterator_grad begin_grad() const;
79
const_iterator_grad end_grad() const;
90
mutable mode_type _mode;
91
const quadrature<T>* _p_quad; // when mode: on quadrature pointset
92
basis_basic<T> _nb; // when mode: on nodal basis pointset
93
mutable std::vector<std::vector<T> > _val [reference_element::max_variant];
94
mutable std::vector<std::vector<point_basic<T> > > _grad_val [reference_element::max_variant];
95
mutable std::vector<bool> _initialized;
96
mutable std::vector<bool> _grad_initialized;
97
mutable std::vector<T> _val_specific;
98
mutable std::vector<point_basic<T> > _grad_val_specific;
99
mutable size_type _curr_K_variant;
100
mutable size_type _curr_q;
101
void _initialize (reference_element hat_K) const;
102
void _grad_initialize (reference_element hat_K) const;
104
// ----------------------------------------------------------
106
// ----------------------------------------------------------
109
basis_on_pointset<T>::basis_on_pointset ()
116
_initialized(reference_element::max_variant, false),
117
_grad_initialized(reference_element::max_variant, false),
119
_curr_K_variant (std::numeric_limits<size_type>::max()),
120
_curr_q (std::numeric_limits<size_type>::max())
125
basis_on_pointset<T>::basis_on_pointset (const quadrature<T>& quad, const basis_basic<T>& b)
132
_initialized(reference_element::max_variant, false),
133
_grad_initialized(reference_element::max_variant, false),
135
_curr_K_variant (std::numeric_limits<size_type>::max()),
136
_curr_q (std::numeric_limits<size_type>::max())
141
basis_on_pointset<T>::basis_on_pointset (const basis_basic<T>& nb, const basis_basic<T>& b)
148
_initialized(reference_element::max_variant, false),
149
_grad_initialized(reference_element::max_variant, false),
151
_curr_K_variant (std::numeric_limits<size_type>::max()),
152
_curr_q (std::numeric_limits<size_type>::max())
158
basis_on_pointset<T>::set (const quadrature<T>& quad, const basis_basic<T>& b)
160
// data was not defined on this quadrature formulae : reset
164
std::fill (_initialized.begin(), _initialized.end(), false);
165
std::fill (_grad_initialized.begin(), _grad_initialized.end(), false);
170
basis_on_pointset<T>::set (const basis_basic<T>& nb, const basis_basic<T>& b)
172
// data was not defined on this quadrature formulae : reset
176
std::fill (_initialized.begin(), _initialized.end(), false);
177
std::fill (_grad_initialized.begin(), _grad_initialized.end(), false);
179
// ==================================================================================
181
// ==================================================================================
184
typename basis_on_pointset<T>::const_iterator
185
basis_on_pointset<T>::begin (reference_element hat_K, size_type q) const
187
reference_element::variant_type K_variant = hat_K.variant();
188
if (!_initialized [K_variant]) _initialize (hat_K);
189
return _val[K_variant][q].begin();
193
typename basis_on_pointset<T>::const_iterator
194
basis_on_pointset<T>::end (reference_element hat_K, size_type q) const
196
reference_element::variant_type K_variant = hat_K.variant();
197
if (!_initialized [K_variant]) _initialize (hat_K);
198
return _val[K_variant][q].end();
202
typename basis_on_pointset<T>::const_iterator_grad
203
basis_on_pointset<T>::begin_grad (reference_element hat_K, size_type q) const
205
reference_element::variant_type K_variant = hat_K.variant();
206
if (!_grad_initialized [K_variant]) _grad_initialize (hat_K);
207
return _grad_val[K_variant][q].begin();
211
typename basis_on_pointset<T>::const_iterator_grad
212
basis_on_pointset<T>::end_grad (reference_element hat_K, size_type q) const
214
reference_element::variant_type K_variant = hat_K.variant();
215
if (!_grad_initialized [K_variant]) _grad_initialize (hat_K);
216
return _grad_val[K_variant][q].end();
218
// ==================================================================================
220
// ==================================================================================
221
// -------------------
223
// -------------------
227
basis_on_pointset<T>::evaluate (reference_element hat_K, size_type q) const
229
reference_element::variant_type K_variant = hat_K.variant();
230
if (!_initialized [K_variant]) _initialize (hat_K);
231
_curr_K_variant = K_variant;
237
basis_on_pointset<T>::evaluate (reference_element hat_K, const point_basic<T>& hat_xq) const
239
size_type nb = _b.size(hat_K);
240
if (nb != _val_specific.size ()) { _val_specific.resize (nb); }
241
_b.eval (hat_K, hat_xq, _val_specific);
242
_mode = specific_mode;
246
typename basis_on_pointset<T>::const_iterator
247
basis_on_pointset<T>::begin() const
249
if (_mode != specific_mode) return _val[_curr_K_variant][_curr_q].begin();
250
else return _val_specific.begin();
254
typename basis_on_pointset<T>::const_iterator
255
basis_on_pointset<T>::end() const
257
if (_mode != specific_mode) return _val[_curr_K_variant][_curr_q].end();
258
else return _val_specific.end();
260
// -------------------
262
// -------------------
266
basis_on_pointset<T>::evaluate_grad (reference_element hat_K, size_type q) const
268
reference_element::variant_type K_variant = hat_K.variant();
269
if (!_grad_initialized [K_variant]) _grad_initialize (hat_K);
270
_curr_K_variant = K_variant;
276
basis_on_pointset<T>::evaluate_grad (reference_element hat_K, const point_basic<T>& hat_xq) const
278
size_type nb = _b.size(hat_K);
279
if (nb != _grad_val_specific.size ()) { _grad_val_specific.resize (nb); }
280
_b.grad_eval (hat_K, hat_xq, _grad_val_specific);
281
_mode = specific_mode;
285
typename basis_on_pointset<T>::const_iterator_grad
286
basis_on_pointset<T>::begin_grad() const
288
if (_mode != specific_mode) return _grad_val[_curr_K_variant][_curr_q].begin();
289
else return _grad_val_specific.begin();
293
typename basis_on_pointset<T>::const_iterator_grad
294
basis_on_pointset<T>::end_grad() const
296
if (_mode != specific_mode) return _grad_val[_curr_K_variant][_curr_q].end();
297
else return _grad_val_specific.end();
300
}// namespace rheolef
301
#endif // _RHEO_BASIS_ON_POINTSET_H