table of contents
functor(2rheolef) | rheolef-7.0 | functor(2rheolef) |
NAME¶
functor - a function wrapper suitable for field expressions
DESCRIPTION¶
A functor is a class-function, i.e. a class that defines the operator(): it can be used in place of an usual function. Moreover, functors can be used in Rheolef field expressions, mixed with fields (see field(2)). For instance, assuming that uh is a field and u_ex is a functor:
where omega denotes a mesh (see geo(2)) and qopt a quadrature formula (see quadrature_option(2)). See also the integrate(4) function. An usual function u_ex_f cannot always be mixed so nicely in expressions, due to c++ language rules. For instance, the following exprtession is valid:
Float err_l1 = integrate (omega, abs(uh - uh_ex), qopt);
In some case, the compiler cannot build a field expression using usual functionsn e.g.
Float err_l1 = integrate (omega, abs(uh - u_ex_f), qopt);
because 0.5*u_ex_f is a direct algebraic operation between usual functions and flmoating points, that is not defined in the c++ language. A way to circumvent this difficulty is to convert the usual function into a functor, as in:
Float I = integrate (omega, 0.5*u_ex_f), qopt);
Float I = integrate (omega, 0.5*functor(u_ex_f)), qopt);
IMPLEMENTATION¶
template<class R, class... Args> std::function<R(Args...)> functor (R(*f)(Args...)) {
return std::function<R(Args...)>(f); }
SEE ALSO¶
COPYRIGHT¶
Copyright (C) 2000-2018 Pierre Saramito <Pierre.Saramito@imag.fr> GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
rheolef-7.0 | rheolef-7.0 |