COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
Functions.hpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2011 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 
7 #ifndef cf3_solver_actions_Proto_Functions_hpp
8 #define cf3_solver_actions_Proto_Functions_hpp
9 
10 #include <boost/proto/core.hpp>
11 
12 #include "common/CF.hpp"
14 
15 namespace cf3 {
16 namespace solver {
17 namespace actions {
18 namespace Proto {
19 
22 {
23 };
24 
26 template<Uint Exp>
28 {
29  typedef Real result_type;
30  Real operator()(Real d) const
31  {
32  for(Uint i = 0; i != (Exp-1); ++i)
33  d *= d;
34  return d;
35  }
36 };
37 
38 template<Uint Exp, typename Arg>
39 typename boost::proto::result_of::make_expr<
40  boost::proto::tag::function // Tag type
41  , pow_fun<Exp> // First child (by value)
42  , Arg const & // Second child (by reference)
43 >::type const
44 pow(Arg const &arg)
45 {
46  return boost::proto::make_expr<boost::proto::tag::function>(
47  pow_fun<Exp>() // First child (by value)
48  , boost::ref(arg) // Second child (by reference)
49  );
50 }
51 
52 
55 {
56  mutable std::vector<Real> predefined_values;
57 };
58 
59 
61 {
62 };
63 
65 {
66 };
67 
68 template<typename ResultT, typename CoordsT>
69 void evaluate_function(const ProtoEvaluatedFunction& func, const CoordsT& coords, ResultT& result)
70 {
71  cf3_assert(func.predefined_values.size() >= CoordsT::RowsAtCompileTime);
72  for(int i = 0; i != CoordsT::RowsAtCompileTime; ++i)
73  {
74  func.predefined_values[i] = coords[i];
75  }
76 
77  func.evaluate(func.predefined_values, result);
78 }
79 
82  boost::proto::transform< ParsedVectorFunctionTransform >
83 {
84  template<typename ExprT, typename StateT, typename DataT>
85  struct impl : boost::proto::transform_impl<ExprT, StateT, DataT>
86  {
87  typedef const typename boost::remove_reference<DataT>::type::CoordsT& result_type;
88 
89  result_type operator()(typename impl::expr_param expr, typename impl::state_param state, typename impl::data_param data) const
90  {
91  evaluate_function(boost::proto::value(expr), data.coordinates(), expr.value);
92  return expr.value;
93  }
94  };
95 };
96 
98 boost::proto::transform< ParsedScalarFunctionTransform >
99 {
100  template<typename ExprT, typename StateT, typename DataT>
101  struct impl : boost::proto::transform_impl<ExprT, StateT, DataT>
102  {
103  typedef Real result_type;
104 
105  Real operator()(typename impl::expr_param expr, typename impl::state_param state, typename impl::data_param data) const
106  {
107  std::vector<Real> result(1);
108  evaluate_function(boost::proto::value(expr), data.coordinates(), result);
109  return result.back();
110  }
111  };
112 };
113 
115  boost::proto::or_
116  <
117  boost::proto::when
118  <
119  boost::proto::terminal<VectorFunction>,
120  ParsedVectorFunctionTransform
121  >,
122  boost::proto::when
123  <
124  boost::proto::terminal<ScalarFunction>,
125  ParsedScalarFunctionTransform
126  >
127  >
128 {
129 };
130 
131 } // namespace Proto
132 } // namespace actions
133 } // namespace solver
134 } // namespace cf3
135 
136 #endif // cf3_solver_actions_Proto_Functions_hpp
Base class of all functions that can be evaluated using "default" C++ semantics.
Definition: Functions.hpp:21
void evaluate_function(const ProtoEvaluatedFunction &func, const CoordsT &coords, ResultT &result)
Definition: Functions.hpp:69
const boost::remove_reference< DataT >::type::CoordsT & result_type
Definition: Functions.hpp:87
#define cf3_assert(a)
Definition: Assertions.hpp:93
void evaluate(const var_t &var_values, ret_t &ret_value) const
Pow function based on Proto docs example.
Definition: Functions.hpp:27
Top-level namespace for coolfluid.
Definition: Action.cpp:18
Primitive transform to evaluate a function with the function parser.
Definition: Functions.hpp:81
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
result_type operator()(typename impl::expr_param expr, typename impl::state_param state, typename impl::data_param data) const
Definition: Functions.hpp:89
coolfluid3 header, included almost everywhere
Real operator()(typename impl::expr_param expr, typename impl::state_param state, typename impl::data_param data) const
Definition: Functions.hpp:105
Wrap the vectorial function, adding extra data that may be filled before expression evaluation...
Definition: Functions.hpp:54
boost::proto::result_of::make_expr< boost::proto::tag::function, pow_fun< Exp >, Arg const & >::type const pow(Arg const &arg)
Definition: Functions.hpp:44
Send comments to:
COOLFluiD Web Admin