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
adfunctions.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 template <class Expr> class @NAME@
30 {
31 public:
32  enum { nvar = Expr::nvar };
33  typedef typename Expr::value_type value_type;
34 protected:
35  @NAME@ () {}
36 
37  Expr expr_;
38 public:
39 
40  @NAME@ ( const Expr & expr ) : expr_( expr )
41  {
42  ;
43  }
44 
45 
46  template<int isFundamental, typename Expr_>
47  struct Value
48  {
49 
50  typedef typename Expr_::value_type value_type;
51  static value_type signum( value_type a )
52  {
53  if ( abs( a ) < std::numeric_limits<value_type>::epsilon() )
54  return value_type( 0 );
55 
56  return a/abs( a );
57  }
58  static value_type value( Expr_ const& expr_ )
59  {
60  return @FCT@( expr_.value() );
61  }
62  static value_type grad( Expr_ const& expr_, int __i )
63  {
64  return @GRDI@;
65  }
66  static value_type hessian( Expr_ const& expr_, int __i, int __j )
67  {
68  return @HESSIJ@;
69  }
70  };
71  template<typename Expr_>
72  struct Value<true, Expr_>
73  {
74  typedef typename Expr_::value_type value_type;
75  static value_type signum( value_type a )
76  {
77  if ( std::abs( a ) < std::numeric_limits<value_type>::epsilon() )
78  return value_type( 0 );
79 
80  return a/std::abs( a );
81  }
82  static value_type value( Expr_ const& expr_ )
83  {
84  return std::@FCT@( expr_.value() );
85  }
86  static value_type grad( Expr_ const& expr_, int __i )
87  {
88  return @GRDI_STD@;
89  }
90  static value_type hessian( Expr_ const& expr_, int __i, int __j )
91  {
92  return @HESSIJ_STD@;
93  }
94  };
95 
96  inline value_type value() const
97  {
98  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::value( expr_ );
99  }
100  inline value_type grad( int __i ) const
101  {
102  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::grad( expr_, __i );
103  }
104  inline value_type hessian( int __i, int __j ) const
105  {
106  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::hessian( expr_, __i, __j );
107  }
108  inline bool deps( int __i ) const
109  {
110  return expr_.deps( __i ) ;
111  }
112 };
113 
114 template <class Expr> inline ADExpr< @NAME@< ADExpr<Expr> > >
115 @FCT@ ( const ADExpr<Expr>& expr )
116 {
117  typedef @NAME@< ADExpr<Expr> > expr_t;
118  return ADExpr< expr_t >( expr_t( expr ) );
119 }
120 
121 template <class T, int Nvar, int Order, int Var> inline ADExpr< @NAME@< ADType<T, Nvar, Order, Var> > >
122 @FCT@ ( const ADType<T, Nvar, Order, Var>& x )
123 {
124  typedef @NAME@< ADType<T, Nvar, Order, Var> > expr_t;
125  return ADExpr< expr_t >( expr_t( x ) );
126 }

Generated on Sun Oct 20 2013 08:24:54 for Feel++ by doxygen 1.8.4