Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
adbinaryfunctions.tmpl.hpp
1 /* -*- mode: c++; coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; show-trailing-whitespace: t -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2 
3  This file is part of the Feel library
4 
5  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
6  Date: 2008-02-14
7 
8  Copyright (C) 2008 Université Joseph Fourier (Grenoble I)
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 3.0 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
29 #ifndef __AdBinaryFunctions_H
30 #define __AdBinaryFunctions_H 1
31 
32 
33 # include <boost/preprocessor/comparison/less.hpp>
34 # include <boost/preprocessor/logical/and.hpp>
35 # include <boost/preprocessor/control/if.hpp>
36 # include <boost/preprocessor/list/at.hpp>
37 # include <boost/preprocessor/list/cat.hpp>
38 # include <boost/preprocessor/list/for_each_product.hpp>
39 # include <boost/preprocessor/logical/or.hpp>
40 # include <boost/preprocessor/tuple/to_list.hpp>
41 # include <boost/preprocessor/tuple/eat.hpp>
42 # include <boost/preprocessor/facilities/empty.hpp>
43 # include <boost/preprocessor/punctuation/comma.hpp>
44 # include <boost/preprocessor/facilities/identity.hpp>
45 # include <boost/preprocessor/stringize.hpp>
46 namespace Feel
47 {
48 namespace detail
49 {
50 # /* Accessors for the operator datatype. */
51 # define AD_BINARY_FUNCTION_NAME(O) BOOST_PP_TUPLE_ELEM(5, 0, O)
52 # define AD_BINARY_FUNCTION_SYMBOL(O) BOOST_PP_TUPLE_ELEM(5, 1, O)
53 # define AD_BINARY_FUNCTION_COMMENT(O) BOOST_PP_TUPLE_ELEM(5, 2, O)
54 # define AD_BINARY_FUNCTION_GRAD(O) BOOST_PP_TUPLE_ELEM(5, 3, O)
55 # define AD_BINARY_FUNCTION_HESS(O) BOOST_PP_TUPLE_ELEM(5, 4, O)
56 
57 # /* List of applicative operators. */
58 # define AD_BINARY_FUNCTIONS \
59  BOOST_PP_TUPLE_TO_LIST( \
60  1, \
61  ( \
62  ( ADBinFunPow , pow, "Power function", (expr2_.value() * expr1_.grad(__i) * math::pow(expr1_.value(),expr2_.value()-1)), (expr2_.value() * ( (expr2_.value()-1) * expr1_.grad(__i) * expr1_.grad(__j) * math::pow(expr1_.value(),expr2_.value()-2) + expr1_.hessian(__i,__j) * math::pow(expr1_.value(),expr2_.value()-1))) ) \
63  ) \
64  ) \
65 
66 #
67 
75 template <class Expr1, class Expr2> class @NAME@
76 {
77 public:
78 
79  enum { nvar = Expr1::nvar };
80  //enum { nvar2 = Expr2::nvar };
81 
82  typedef typename Expr1::value_type value_type;
83 
84 protected:
85  @NAME@ () {}
86 
87  Expr1 expr1_;
88  Expr2 expr2_;
89 
90 public:
91 
92  @NAME@ ( const Expr1 & expr1, const Expr2& expr2 ) : expr1_( expr1 ), expr2_( expr2 )
93  {
94  ;
95  }
96 
97 
98  template<int isFundamental, typename Expr1_, typename Expr2_>
99  struct Value
100  {
101 
102  typedef typename Expr1_::value_type value_type;
103 
104  static value_type value( Expr1_ const& expr1_, Expr2_ const& expr2_ )
105  {
106  return @FCT@( expr1_.value(), expr2_.value() );
107  }
108  static value_type grad( Expr1_ const& expr1_, Expr2_ const& expr2_, int __i )
109  {
110  return @GRDI@;
111  }
112  static value_type hessian( Expr1_ const& expr1_, Expr2_ const& expr2_, int __i, int __j )
113  {
114  return @HESSIJ@;
115  }
116  };
117  template<typename Expr1_, typename Expr2_>
118  struct Value<true, Expr1_, Expr2_>
119  {
120  typedef typename Expr1_::value_type value_type;
121 
122  static value_type value( Expr1_ const& expr1_, Expr2_ const& expr2_ )
123  {
124  return std::@FCT@( expr1_.value(), expr2_.value() );
125  }
126  static value_type grad( Expr1_ const& expr1_, Expr2_ const& expr2_, int __i )
127  {
128  return @GRDI_STD@;
129  }
130  static value_type hessian( Expr1_ const& expr1_, Expr2_ const& expr2_, int __i, int __j )
131  {
132  return @HESSIJ_STD@;
133  }
134  };
135 
136  inline value_type value() const
137  {
138  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr1,Expr2>::value( expr1_, expr2_ );
139  }
140  inline value_type grad( int __i ) const
141  {
142  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr1,Expr2>::grad( expr1_, expr2_, __i );
143  }
144  inline value_type hessian( int __i, int __j ) const
145  {
146  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr1, Expr2>::hessian( expr1_, expr2_, __i, __j );
147  }
148  inline bool deps( int __i ) const
149  {
150  return expr1_.deps( __i ) || expr2_.deps( __i );
151  }
152 };
153 
154 template <class Expr1, class Expr2>
155 inline
157 @FCT@ ( const ADExpr<Expr1>& expr1, const ADExpr<Expr2>& expr2 )
158 {
159  typedef @NAME@< ADExpr<Expr1>, ADExpr<Expr2> > expr_t;
160  return ADExpr< expr_t >( expr_t( expr1, expr2 ) );
161 }
162 
163 template <class T, int Nvar, int Order, int Var>
164 inline
166 @FCT@ ( const ADType<T, Nvar, Order, Var>& x, const ADType<T, Nvar, Order, Var>& y )
167 {
168  typedef @NAME@< ADType<T, Nvar, Order, Var>, ADType<T, Nvar, Order, Var> > expr_t;
169  return ADExpr< expr_t >( expr_t( x, y ) );
170 }
171 
172 template <class W, class T, int Nvar, int Order, int Var>
173 inline
174 ADExpr< AdFuncPow< ADType<T, Nvar, Order, Var>, ADCst<W> > >
175 pow ( const ADType<T, Nvar, Order, Var>& x, W y )
176 {
177  typedef AdFuncPow< ADType<T, Nvar, Order, Var>, ADCst<W> > expr_t;
178  ADCst<W> y1 ( y );
179  return ADExpr< expr_t >( expr_t( x, y1 ) );
180 }
181 }
182 }
183 #endif /* __AdBinaryFunctions_H */
PolynomialSet< Poly, Tensor2 > hessian(PolynomialSet< Poly, Scalar > const &p)
compute the gradient of a vectorial polynomial set
Definition: operations.hpp:231
Automatically Diffentiated Numerical Type.
Definition: adtype.hpp:92
brief description
Definition: adexpr.hpp:44
brief description
Definition: adbinaryfunctions.tmpl.hpp:75

Generated on Sun Dec 22 2013 13:10:54 for Feel++ by doxygen 1.8.5