Rheolef
7.1
an efficient C++ finite element environment
functor.h
Go to the documentation of this file.
1
#ifndef _RHEOLEF_FUNCTOR_H
2
#define _RHEOLEF_FUNCTOR_H
3
//
4
// This file is part of Rheolef.
5
//
6
// Copyright (C) 2000-2009 Pierre Saramito
7
//
8
// Rheolef is free software; you can redistribute it and/or modify
9
// it under the terms of the GNU General Public License as published by
10
// the Free Software Foundation; either version 2 of the License, or
11
// (at your option) any later version.
12
//
13
// Rheolef is distributed in the hope that it will be useful,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
// GNU General Public License for more details.
17
//
18
// You should have received a copy of the GNU General Public License
19
// along with Rheolef; if not, write to the Free Software
20
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
//
22
// ==========================================================================
23
//
24
// utiities for field expressions
25
//
26
// author: Pierre.Saramito@imag.fr
27
//
28
// date: 4 september 2015
29
//
30
31
/*Class:functor
32
NAME: @code{functor} - a function wrapper suitable for field expressions
33
DESCRIPTION:
34
@noindent
35
A @emph{functor} is a class-function, i.e. a class that defines
36
the @code{operator()}:
37
it can be used in place of an usual function.
38
Moreover, functors can be used in Rheolef field expressions, mixed
39
with fields (see @ref{field class}).
40
For instance, assuming that @code{uh} is a field and @code{u_ex} is a functor:
41
@example
42
Float err_l1 = integrate (omega, abs(uh - uh_ex), qopt);
43
@end example
44
where @code{omega} denotes a mesh
45
(see @ref{geo class})
46
and @code{qopt} a quadrature formula
47
(see @ref{quadrature_option class}).
48
See also the @ref{integrate algorithm} function.
49
An usual function @code{u_ex_f} cannot always be mixed so nicely
50
in expressions, due to c++ language rules.
51
For instance, the following exprtession is valid:
52
@example
53
Float err_l1 = integrate (omega, abs(uh - u_ex_f), qopt);
54
@end example
55
In some case, the compiler cannot build a field expression using
56
usual functionsn e.g.
57
@example
58
Float I = integrate (omega, 0.5*u_ex_f), qopt);
59
@end example
60
because @code{0.5*u_ex_f} is a direct algebraic operation between
61
usual functions and flmoating points, that is not defined in the
62
c++ language.
63
A way to circumvent this difficulty is to convert the usual function
64
into a functor, as in:
65
@example
66
Float I = integrate (omega, 0.5*functor(u_ex_f)), qopt);
67
@end example
68
AUTHOR: Pierre.Saramito@imag.fr
69
DATE: 12 march 2013
70
End:
71
*/
72
#include "rheolef/compiler.h"
73
74
namespace
rheolef
{
75
76
//<doc:
77
template
<
class
R,
class
... Args>
78
std::function<R(Args...)>
79
functor
(R(*
f
)(Args...)) {
80
return
std::function<R(Args...)>(
f
);
81
}
82
//>doc:
83
}
// namespace rheolef
84
#endif // _RHEOLEF_FUNCTOR_H
mkgeo_ball.f
f
Definition:
mkgeo_ball.sh:221
rheolef::functor
std::function< R(Args...)> functor(R(*f)(Args...))
Definition:
functor.h:79
rheolef
This file is part of Rheolef.
Definition:
compiler_eigen.h:37
f
Definition:
cavity_dg.h:29