~ubuntu-branches/ubuntu/trusty/rheolef/trusty

« back to all changes in this revision

Viewing changes to nfem/plib/interpolate.h

  • Committer: Package Import Robot
  • Author(s): Pierre Saramito
  • Date: 2012-04-06 09:12:21 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120406091221-m58me99p1nxqui49
Tags: 6.0-1
* New upstream release 6.0 (major changes):
  - massively distributed and parallel support
  - full FEM characteristic method (Lagrange-Gakerkin method) support
  - enhanced users documentation 
  - source code supports g++-4.7 (closes: #667356)
* debian/control: dependencies for MPI distributed solvers added
* debian/rules: build commands simplified
* debian/librheolef-dev.install: man1/* to man9/* added
* debian/changelog: package description rewritted (closes: #661689)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
// 
24
24
// interpolation with a class-function or a function
25
25
//
26
 
#include "rheolef/tensor.h"
 
26
#include "rheolef/field.h"
27
27
namespace rheolef { 
28
28
 
 
29
// --------------------------------------------------------------------------
 
30
// implementation details of the interpolate() function
 
31
// --------------------------------------------------------------------------
 
32
namespace details {
 
33
 
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&)
 
35
field_basic<T,M>
 
36
interpolate_tag (const space_basic<T,M>& V, Function f, const T&)
31
37
{
32
 
  typedef typename field_basic<T,M>::size_type size_type;
33
 
 
 
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);
37
44
  }
38
45
  return u;
39
46
}
40
 
template <class T, class Func>
41
 
inline
42
 
field_basic<T>
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());
46
 
}
47
 
// specialization for functions:
48
 
template <class T>
49
 
inline
50
 
field_basic<T>
51
 
interpolate (const space_basic<T>& V, T (*f)(const basic_point<T>&)) {
52
 
    return __interpolate_tag (V, f, T());
53
 
}
 
47
template <class T, class M, class Function>
 
48
field_basic<T,M>
 
49
interpolate_tag (const space_basic<T,M>& V, Function f, const point_basic<T>&)
 
50
{
 
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();
 
56
  point_basic<T> value;
 
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];
 
62
    }
 
63
  }
 
64
  return u;
 
65
}
 
66
 
 
67
} // namespace details
 
68
 
 
69
// --------------------------------------------------------------------------
 
70
// interface of the interpolate() function
 
71
// --------------------------------------------------------------------------
 
72
 
 
73
/*Class:interpolate
 
74
NAME: @code{interpolate} - Lagrange interpolation of a function
 
75
@findex  interpolate
 
76
@clindex space
 
77
@clindex field
 
78
 
 
79
DESCRIPTION:
 
80
 The function @code{interpolation} implements the
 
81
 Lagrange interpolation of a function or a class-function.
 
82
SYNOPSYS:
 
83
 template <class Function>
 
84
 field interpolate (const space& Vh, const Function& f);
 
85
EXAMPLE:
 
86
@noindent
 
87
 The following code compute the Lagrange interpolation
 
88
 @code{pi_h_u} of u(x).
 
89
@example
 
90
  Float u(const point& x);
 
91
  ...
 
92
  geo omega("square");
 
93
  space Xh (omega, "P1");
 
94
  field pi_h_u = interpolate (Xh, u);
 
95
@end example
 
96
ADVANCED EXAMPLE:
 
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.
 
102
@example
 
103
  geo omega2 ("square2");
 
104
  space X2h (omega2, "P1");
 
105
  field uh2 = interpolate (X2h, pi_h_u);
 
106
@end example
 
107
End: */
 
108
//<interpolate:
 
109
template <class T, class M, class Function>
 
110
inline
 
111
field_basic<T,M>
 
112
interpolate (const space_basic<T,M>& V, Function f)
 
113
//>interpolate:
 
114
{
 
115
  typedef typename Function::result_type  result_type ;
 
116
  return details::interpolate_tag (V, f, result_type());
 
117
}
 
118
// specialization for scalar-valued functions:
 
119
template <class T, class M>
 
120
inline
 
121
field_basic<T,M>
 
122
interpolate (const space_basic<T,M>& V, T (*f)(const point_basic<T>&))
 
123
{
 
124
  return details::interpolate_tag (V, f, T());
 
125
}
 
126
// specialization for vector-valued functions:
 
127
template <class T, class M>
 
128
inline
 
129
field_basic<T,M>
 
130
interpolate (const space_basic<T,M>& V, point_basic<T> (*f)(const point_basic<T>&))
 
131
{
 
132
  return details::interpolate_tag (V, f, point_basic<T>());
 
133
}
 
134
// specialization for re-interpoltion of fields (change of mesh, of approx, ect):
 
135
template<class T, class M>
 
136
field_basic<T,M>
 
137
interpolate (const space_basic<T,M>& V2h, const field_basic<T,M>& u1h);
54
138
 
55
139
}// namespace rheolef
56
140
#endif // _RHEOLEF_INTERPOLATE_H