Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
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
33namespace rheolef {
34
35/*Class:field_functor
36NAME: @code{field_functor} - a functor wrapper suitable for field expressions (obsolete)
37DESCRIPTION:
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}.
57EXAMPLE:
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
69IMPLEMENTATION 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}.
77AUTHOR: Pierre.Saramito@imag.fr
78DATE: 12 march 2013
79End:
80*/
81//<doc:
82template <class Function, class Result>
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
93template <class F, class R>
94struct field_function_s : field_functor<field_function_s<F,R>, R> {
96 R operator() (const point_basic<float_type>& x) const { return _f.operator()(x); }
98 F _f;
99};
100template <class F>
101field_function_s<std::function<F>, typename F::result_type>
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
see the point page for the full documentation
This file is part of Rheolef.
field_function_s< std::function< F >, typename F::result_type > field_function(F f)
Definition cavity_dg.h:29
float_traits< R >::type float_type
R operator()(const point_basic< float_type > &x) const
Result operator()(const point &x) const
const Function & get_ref() const