Rheolef
7.1
an efficient C++ finite element environment
field_functor.h
Go to the documentation of this file.
1
#ifndef _RHEOLEF_FIELD_FUNCTOR_H
2
#define _RHEOLEF_FIELD_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
// field_vf: template expressions
25
//
26
// author: Pierre.Saramito@imag.fr
27
//
28
// date: 20 march 2011
29
//
30
#include "rheolef/point.h"
31
#include <functional>
// for std::function
32
33
namespace
rheolef
{
34
35
/*Class:field_functor
36
NAME: @code{field_functor} - a functor wrapper suitable for field expressions (obsolete)
37
DESCRIPTION:
38
@noindent
39
This class is now obsolete, from Rheolef version 6.7
40
and is maintained for backward compatibility purpose only.
41
Until Rheolef version 6.6, this class was used
42
to mark functors with profil compatible with fields, i.e. that accepts
43
@code{point} as parameter and returns a field value (scalar, vector, tensor).
44
This mark was used to filter field expression arguments in @code{interpolate}
45
and @code{integrate}.
46
From version 6.7, this mark is no more required, and any function or functor
47
that is callable with a @code{point} as argument is valid in a field expression.
48
49
@noindent
50
A functor is a class-function, i.e. a class that defines
51
the @code{operator()}. A variable @code{f} of a class-function can be
52
used as @code{f(arg)} and when its argument is of type @code{point}
53
@pxref{point class}, the function @code{f} interprets as a continuous field field.
54
Thus, it can be interpolated @pxref{interpolate algorithm} and
55
it can be combined within field expressions @pxref{field class}
56
that appears in arguments of @pxref{integrate algorithm}.
57
EXAMPLE:
58
@example
59
struct f : field_functor<f,Float> @{
60
Float operator() (const point& x) const @{ return 1-norm(x); @}
61
@};
62
// ...
63
geo omega ("square");
64
space Xh (omega, "P1");
65
field fh = interpolate (Xh, f);
66
test (Xh);
67
field lh = integrate (f*v);
68
@end example
69
IMPLEMENTATION NOTE:
70
The current implementation of a @code{field_functor} class
71
bases on the curiously recurring template pattern (CRTP) C++ idiom:
72
the definition of the class @code{f} derives from
73
@code{field_functor}<@code{f},Float> that depend itself upon @code{f}.
74
So, be carrefull when using copy-paste, as there is no checks if
75
you write e.g. @code{field_functor}<@code{g},Float> with another function @code{g}
76
instead of @code{f}.
77
AUTHOR: Pierre.Saramito@imag.fr
78
DATE: 12 march 2013
79
End:
80
*/
81
//<doc:
82
template
<
class
Function,
class
Result>
83
struct
field_functor
84
: std::unary_function<point_basic<float_traits<Result> >,Result> {
85
const
Function
&
get_ref
()
const
{
return
static_cast<const Function&>(*
this
); }
86
operator
Function
()
const
{
return
get_ref
(); }
87
Result
operator()
(
const
point
& x)
const
{
return
get_ref
().operator()(x); }
88
};
89
//>doc:
90
91
#ifdef TODO
92
// transforme a function or a functor into a field_functor, suitable for expressions mixing field and functions
93
template
<
class
F,
class
R>
94
struct
field_function_s
:
field_functor
<field_function_s<F,R>, R> {
95
typedef
typename
float_traits<R>::type
float_type
;
96
R
operator()
(
const
point_basic<float_type>
& x)
const
{
return
_f
.operator()(x); }
97
field_function_s
(F
f
) :
_f
(
f
) {}
98
F
_f
;
99
};
100
template
<
class
F>
101
field_function_s<std::function<F>
,
typename
F::result_type>
102
field_function
(F
f
) {
103
typedef
typename
F::result_type R;
104
return
field_function_s<function<F>
,R>(function<F>(
f
));
105
}
106
#endif // TODO
107
108
109
110
}
// namespace rheolef
111
#endif // _RHEOLEF_FIELD_FUNCTOR_H
rheolef::point_basic
Definition:
point.h:87
rheolef::field_function_s::operator()
R operator()(const point_basic< float_type > &x) const
Definition:
field_functor.h:96
rheolef::field_function_s::float_type
float_traits< R >::type float_type
Definition:
field_functor.h:95
rheolef::field_functor::get_ref
const Function & get_ref() const
Definition:
field_functor.h:85
rheolef::field_function_s
Definition:
field_functor.h:94
rheolef::field_function_s::field_function_s
field_function_s(F f)
Definition:
field_functor.h:97
rheolef::field_function_s::_f
F _f
Definition:
field_functor.h:98
rheolef
This file is part of Rheolef.
Definition:
compiler_eigen.h:37
rheolef::float_traits::type
T type
Definition:
Float.h:94
rheolef::Function
rheolef::std Function
point
see the point page for the full documentation
rheolef::field_functor
Definition:
field_functor.h:83
f
Definition:
cavity_dg.h:29
rheolef::field_functor::operator()
Result operator()(const point &x) const
Definition:
field_functor.h:87
rheolef::field_function
field_function_s< std::function< F >, typename F::result_type > field_function(F f)
Definition:
field_functor.h:102