DESCRIPTION

A functor is a class-function, i.e. a class that defines the operator(). A variable f of a class-function can be used as f(arg) and when its argument is of type point see point(2), the function f interprets as a continuous field field. Thus, it can be interpolated see interpolate(4) and it can be combined within field expressions see field(2) that appears in arguments of see integrate(4).

EXAMPLE

    struct f : field_functor<f,Float> {
      Float operator() (const point& x) const { return 1-norm(x); }
    };
    // ...
    geo omega ("square");
    space Xh (omega, "P1");
    field fh = interpolate (Xh, f);
    test  (Xh);
    field lh = integrate (f*v);

IMPLEMENTATION NOTE

The current implementation of a field_functor class bases on the curiously recurring template pattern (CRTP) C++ idiom: the definition of the class f derives from field_functor<f,Float> that depend itself upon f. So, be carrefull when using copy-paste, as there is no checks if you write e.g. field_functor<g,Float> with another function g instead of f.

IMPLEMENTATION

template <class Function, class Result>
struct field_functor
  : std::unary_function<point_basic<float_traits<Result> >,Result> {
 const Function& get_ref() const { return static_cast<const Function&>(*this); }
 operator Function() const { return get_ref(); }
 Result operator() (const point& x) const { return get_ref().operator()(x); }
};
#ifdef TODO
// transforme a function or a functor into a field_functor, suitable for expressions mixing field and functions
template <class F, class R>
struct field_function_s : field_functor<field_function_s<F,R>, R> {
  typedef typename float_traits<R>::type float_type;
  R operator() (const point_basic<float_type>& x) const { return _f.operator()(x); }
  field_function_s(F f) : _f(f) {}
  F _f;
};
template <class F>
field_function_s<function<F>, typename F::result_type>
field_function (F f) {
  typedef typename F::result_type R;
  return field_function_s<function<F>,R>(function<F>(f));
}
#endif // TODO

RELATED TO field_functor…

point(2), interpolate(4), field(2), integrate(4)