Functor

Let

  class MyFunctor {
     publuc:
        MyFunctor() {};
        float evaluate(double x, douzble y, double z) { ... };
  };  

a class which contains a member function evaluate . Then, one can define a functor expression template construction as follows:

  MyFunctor myFunctor;
  Functor3<double,double> F(&myFunctor);

F is now a function which can be applied in an expression and which evaluates the member function evaluate .

Functors can be defined for 1,2, and 3 arguments.

Expressions with functors are not allowed to contain stencil operators!



Example:

class MyCos {

    public:
      float evaluate(double x) { return cos(x); }
}
  ...

    ...     {

  Variable<double> u_exact(grid);
  X_coordinate X(grid);
  Y_coordinate Y(grid);

  MyCos myCos;

  Function1<double,double> Cos(&myCos);        // definition of a functor
  u_exact = Cos(X)*Cos(Y);                    // exact solution
                                              // of an equation
}
Handbook

Last modified: Tue Feb 22 11:08:52 MET 2000