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.hpp
Go to the documentation of this file.
1 /*
2  adbinaryfunctions.hpp ADType expression templates
3  This file is part of gstlibs.
4 
5  Copyright (C) 2011 Christophe Prud'homme
6 
7  gstlibs is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  gstlibs is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with gstlibs; if not, write to the Free Software
19  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21 
22 // Generated source file. Do not edit.
23 // /home/prudhomm/Devel/FEEL/feel/feel/feelopt/adgenerate.cpp Jun 22 2011 01:46:56
24 
25 #ifndef AD_BINARY_FUNCS_HPP
26 #define AD_BINARY_FUNCS_HPP
27 
28 namespace Feel
29 {
30 /****************************************************************************
31  * Power function
32  ****************************************************************************/
33 /* -*- 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
34 
35  This file is part of the Feel library
36 
37  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
38  Date: 2008-02-14
39 
40  Copyright (C) 2008 Université Joseph Fourier (Grenoble I)
41 
42  This library is free software; you can redistribute it and/or
43  modify it under the terms of the GNU Lesser General Public
44  License as published by the Free Software Foundation; either
45  version 3.0 of the License, or (at your option) any later version.
46 
47  This library is distributed in the hope that it will be useful,
48  but WITHOUT ANY WARRANTY; without even the implied warranty of
49  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
50  Lesser General Public License for more details.
51 
52  You should have received a copy of the GNU Lesser General Public
53  License along with this library; if not, write to the Free Software
54  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
55 */
61 #ifndef __AdBinaryFunctions_H
62 #define __AdBinaryFunctions_H 1
63 
64 
65 # include <boost/preprocessor/comparison/less.hpp>
66 # include <boost/preprocessor/logical/and.hpp>
67 # include <boost/preprocessor/control/if.hpp>
68 # include <boost/preprocessor/list/at.hpp>
69 # include <boost/preprocessor/list/cat.hpp>
70 # include <boost/preprocessor/list/for_each_product.hpp>
71 # include <boost/preprocessor/logical/or.hpp>
72 # include <boost/preprocessor/tuple/to_list.hpp>
73 # include <boost/preprocessor/tuple/eat.hpp>
74 # include <boost/preprocessor/facilities/empty.hpp>
75 # include <boost/preprocessor/punctuation/comma.hpp>
76 # include <boost/preprocessor/facilities/identity.hpp>
77 # include <boost/preprocessor/stringize.hpp>
78 namespace Feel
79 {
80 namespace detail
81 {
82 # /* Accessors for the operator datatype. */
83 # define AD_BINARY_FUNCTION_NAME(O) BOOST_PP_TUPLE_ELEM(5, 0, O)
84 # define AD_BINARY_FUNCTION_SYMBOL(O) BOOST_PP_TUPLE_ELEM(5, 1, O)
85 # define AD_BINARY_FUNCTION_COMMENT(O) BOOST_PP_TUPLE_ELEM(5, 2, O)
86 # define AD_BINARY_FUNCTION_GRAD(O) BOOST_PP_TUPLE_ELEM(5, 3, O)
87 # define AD_BINARY_FUNCTION_HESS(O) BOOST_PP_TUPLE_ELEM(5, 4, O)
88 
89 # /* List of applicative operators. */
90 # define AD_BINARY_FUNCTIONS \
91  BOOST_PP_TUPLE_TO_LIST( \
92  1, \
93  ( \
94  ( 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))) ) \
95  ) \
96  ) \
97 
98 #
99 
107 template <class Expr1, class Expr2> class AdFuncPow
108 {
109 public:
110 
111  enum { nvar = Expr1::nvar };
112  //enum { nvar2 = Expr2::nvar };
113 
114  typedef typename Expr1::value_type value_type;
115 
116 protected:
117  AdFuncPow () {}
118 
119  Expr1 expr1_;
120  Expr2 expr2_;
121 
122 public:
123 
124  AdFuncPow ( const Expr1 & expr1, const Expr2& expr2 ) : expr1_( expr1 ), expr2_( expr2 )
125  {
126  ;
127  }
128 
129 
130  template<int isFundamental, typename Expr1_, typename Expr2_>
131  struct Value
132  {
133 
134  typedef typename Expr1_::value_type value_type;
135 
136  static value_type value( Expr1_ const& expr1_, Expr2_ const& expr2_ )
137  {
138  return pow( expr1_.value(), expr2_.value() );
139  }
140  static value_type grad( Expr1_ const& expr1_, Expr2_ const& expr2_, int __i )
141  {
142  return expr2_.value() * expr1_.grad( __i ) * pow( expr1_.value(),expr2_.value()-1 );
143  }
144  static value_type hessian( Expr1_ const& expr1_, Expr2_ const& expr2_, int __i, int __j )
145  {
146  return expr2_.value() * ( ( expr2_.value()-1 ) * expr1_.grad( __i ) * expr1_.grad( __j ) * pow( expr1_.value(),expr2_.value()-2 ) + expr1_.hessian( __i,__j ) * pow( expr1_.value(),expr2_.value()-1 ) );
147  }
148  };
149  template<typename Expr1_, typename Expr2_>
150  struct Value<true, Expr1_, Expr2_>
151  {
152  typedef typename Expr1_::value_type value_type;
153 
154  static value_type value( Expr1_ const& expr1_, Expr2_ const& expr2_ )
155  {
156  return std::pow( expr1_.value(), expr2_.value() );
157  }
158  static value_type grad( Expr1_ const& expr1_, Expr2_ const& expr2_, int __i )
159  {
160  return expr2_.value() * expr1_.grad( __i ) * std::pow( expr1_.value(),expr2_.value()-1 );
161  }
162  static value_type hessian( Expr1_ const& expr1_, Expr2_ const& expr2_, int __i, int __j )
163  {
164  return expr2_.value() * ( ( expr2_.value()-1 ) * expr1_.grad( __i ) * expr1_.grad( __j ) * std::pow( expr1_.value(),expr2_.value()-2 ) + expr1_.hessian( __i,__j ) * std::pow( expr1_.value(),expr2_.value()-1 ) );
165  }
166  };
167 
168  inline value_type value() const
169  {
170  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr1,Expr2>::value( expr1_, expr2_ );
171  }
172  inline value_type grad( int __i ) const
173  {
174  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr1,Expr2>::grad( expr1_, expr2_, __i );
175  }
176  inline value_type hessian( int __i, int __j ) const
177  {
178  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr1, Expr2>::hessian( expr1_, expr2_, __i, __j );
179  }
180  inline bool deps( int __i ) const
181  {
182  return expr1_.deps( __i ) || expr2_.deps( __i );
183  }
184 };
185 
186 template <class Expr1, class Expr2>
187 inline
189 pow ( const ADExpr<Expr1>& expr1, const ADExpr<Expr2>& expr2 )
190 {
191  typedef AdFuncPow< ADExpr<Expr1>, ADExpr<Expr2> > expr_t;
192  return ADExpr< expr_t >( expr_t( expr1, expr2 ) );
193 }
194 
195 template <class T, int Nvar, int Order, int Var>
196 inline
199 {
200  typedef AdFuncPow< ADType<T, Nvar, Order, Var>, ADType<T, Nvar, Order, Var> > expr_t;
201  return ADExpr< expr_t >( expr_t( x, y ) );
202 }
203 
204 template <class W, class T, int Nvar, int Order, int Var>
205 inline
207 pow ( const ADType<T, Nvar, Order, Var>& x, W y )
208 {
209  typedef AdFuncPow< ADType<T, Nvar, Order, Var>, ADCst<W> > expr_t;
210  ADCst<W> y1 ( y );
211  return ADExpr< expr_t >( expr_t( x, y1 ) );
212 }
213 }
214 }
215 #endif /* __AdBinaryFunctions_H */
216 }
217 
218 #endif

Generated on Fri Oct 25 2013 14:24:03 for Feel++ by doxygen 1.8.4