24
24
// interpolation with a class-function or a function
26
#include "rheolef/tensor.h"
26
#include "rheolef/field.h"
27
27
namespace rheolef {
29
// --------------------------------------------------------------------------
30
// implementation details of the interpolate() function
31
// --------------------------------------------------------------------------
29
34
template <class T, class M, class Function>
30
field_basic<T,M> __interpolate_tag (const space_basic<T,M>& V, Function f, const T&)
36
interpolate_tag (const space_basic<T,M>& V, Function f, const T&)
32
typedef typename field_basic<T,M>::size_type size_type;
38
check_macro (V.valued_tag() == space_constant::scalar,
39
"interpolate: invalid "<<V.valued()<<"-valued space and scalar function");
40
typedef typename space_basic<T,M>::size_type size_type;
34
41
field_basic<T,M> u (V, std::numeric_limits<T>::max());
35
for (size_type idof = 0, ndof = V.size(); idof < ndof; idof++) {
42
for (size_type idof = 0, ndof = V.ndof(); idof < ndof; idof++) {
36
43
u.dof (idof) = V.momentum (f, idof);
40
template <class T, class Func>
43
interpolate (const space_basic<T>& V, Func f) {
44
typedef typename Func::result_type result_type ;
45
return __interpolate_tag (V, f, result_type());
47
// specialization for functions:
51
interpolate (const space_basic<T>& V, T (*f)(const basic_point<T>&)) {
52
return __interpolate_tag (V, f, T());
47
template <class T, class M, class Function>
49
interpolate_tag (const space_basic<T,M>& V, Function f, const point_basic<T>&)
51
check_macro (V.valued_tag() == space_constant::vector,
52
"interpolate: invalid "<<V.valued()<<"-valued space and vector function");
53
typedef typename space_basic<T,M>::size_type size_type;
54
field_basic<T,M> u (V, std::numeric_limits<T>::max());
55
size_type dim = V.get_geo().dimension();
57
for (size_type vec_idof = 0, vec_ndof = V.ndof()/dim; vec_idof < vec_ndof; vec_idof++) {
58
value = V.vector_momentum (f, vec_idof);
59
for (size_type i_comp = 0; i_comp < dim; i_comp++) {
60
size_type idof = vec_idof + i_comp*vec_ndof;
61
u.dof (idof) = value [i_comp];
67
} // namespace details
69
// --------------------------------------------------------------------------
70
// interface of the interpolate() function
71
// --------------------------------------------------------------------------
74
NAME: @code{interpolate} - Lagrange interpolation of a function
80
The function @code{interpolation} implements the
81
Lagrange interpolation of a function or a class-function.
83
template <class Function>
84
field interpolate (const space& Vh, const Function& f);
87
The following code compute the Lagrange interpolation
88
@code{pi_h_u} of u(x).
90
Float u(const point& x);
93
space Xh (omega, "P1");
94
field pi_h_u = interpolate (Xh, u);
97
It is possible the replace the function @code{u}
98
by a variable of the @code{field} type that represents
99
a picewise polynomial function: this invocation allows
100
the reinterpolation of a field on another mesh or with
101
another approximation.
103
geo omega2 ("square2");
104
space X2h (omega2, "P1");
105
field uh2 = interpolate (X2h, pi_h_u);
109
template <class T, class M, class Function>
112
interpolate (const space_basic<T,M>& V, Function f)
115
typedef typename Function::result_type result_type ;
116
return details::interpolate_tag (V, f, result_type());
118
// specialization for scalar-valued functions:
119
template <class T, class M>
122
interpolate (const space_basic<T,M>& V, T (*f)(const point_basic<T>&))
124
return details::interpolate_tag (V, f, T());
126
// specialization for vector-valued functions:
127
template <class T, class M>
130
interpolate (const space_basic<T,M>& V, point_basic<T> (*f)(const point_basic<T>&))
132
return details::interpolate_tag (V, f, point_basic<T>());
134
// specialization for re-interpoltion of fields (change of mesh, of approx, ect):
135
template<class T, class M>
137
interpolate (const space_basic<T,M>& V2h, const field_basic<T,M>& u1h);
55
139
}// namespace rheolef
56
140
#endif // _RHEOLEF_INTERPOLATE_H