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.hpp
Go to the documentation of this file.
1 /*
2  adfunctions.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_FUNCS_HPP
26 #define AD_FUNCS_HPP
27 
28 namespace Feel
29 {
30 /****************************************************************************
31  * Cosinus 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 template <class Expr> class ADFuncCos
62 {
63 public:
64  enum { nvar = Expr::nvar };
65  typedef typename Expr::value_type value_type;
66 protected:
67  ADFuncCos () {}
68 
69  Expr expr_;
70 public:
71 
72  ADFuncCos ( const Expr & expr ) : expr_( expr )
73  {
74  ;
75  }
76 
77 
78  template<int isFundamental, typename Expr_>
79  struct Value
80  {
81 
82  typedef typename Expr_::value_type value_type;
83  static value_type signum( value_type a )
84  {
85  if ( abs( a ) < std::numeric_limits<value_type>::epsilon() )
86  return value_type( 0 );
87 
88  return a/abs( a );
89  }
90  static value_type value( Expr_ const& expr_ )
91  {
92  return cos( expr_.value() );
93  }
94  static value_type grad( Expr_ const& expr_, int __i )
95  {
96  return -expr_.grad( __i )*sin( expr_.value() );
97  }
98  static value_type hessian( Expr_ const& expr_, int __i, int __j )
99  {
100  return -expr_.hessian( __i,__j )*sin( expr_.value() ) - expr_.grad( __i )*expr_.grad( __j ) * cos( expr_.value() );
101  }
102  };
103  template<typename Expr_>
104  struct Value<true, Expr_>
105  {
106  typedef typename Expr_::value_type value_type;
107  static value_type signum( value_type a )
108  {
109  if ( std::abs( a ) < std::numeric_limits<value_type>::epsilon() )
110  return value_type( 0 );
111 
112  return a/std::abs( a );
113  }
114  static value_type value( Expr_ const& expr_ )
115  {
116  return std::cos( expr_.value() );
117  }
118  static value_type grad( Expr_ const& expr_, int __i )
119  {
120  return -expr_.grad( __i )*std::sin( expr_.value() );
121  }
122  static value_type hessian( Expr_ const& expr_, int __i, int __j )
123  {
124  return -expr_.hessian( __i,__j )*std::sin( expr_.value() ) - expr_.grad( __i )*expr_.grad( __j ) * std::cos( expr_.value() );
125  }
126  };
127 
128  inline value_type value() const
129  {
130  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::value( expr_ );
131  }
132  inline value_type grad( int __i ) const
133  {
134  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::grad( expr_, __i );
135  }
136  inline value_type hessian( int __i, int __j ) const
137  {
138  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::hessian( expr_, __i, __j );
139  }
140  inline bool deps( int __i ) const
141  {
142  return expr_.deps( __i ) ;
143  }
144 };
145 
146 template <class Expr> inline ADExpr< ADFuncCos< ADExpr<Expr> > >
147 cos ( const ADExpr<Expr>& expr )
148 {
149  typedef ADFuncCos< ADExpr<Expr> > expr_t;
150  return ADExpr< expr_t >( expr_t( expr ) );
151 }
152 
153 template <class T, int Nvar, int Order, int Var> inline ADExpr< ADFuncCos< ADType<T, Nvar, Order, Var> > >
154 cos ( const ADType<T, Nvar, Order, Var>& x )
155 {
156  typedef ADFuncCos< ADType<T, Nvar, Order, Var> > expr_t;
157  return ADExpr< expr_t >( expr_t( x ) );
158 }
159 /****************************************************************************
160  * Sinus function
161  ****************************************************************************/
162 /* -*- 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
163 
164  This file is part of the Feel library
165 
166  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
167  Date: 2008-02-14
168 
169  Copyright (C) 2008 Université Joseph Fourier (Grenoble I)
170 
171  This library is free software; you can redistribute it and/or
172  modify it under the terms of the GNU Lesser General Public
173  License as published by the Free Software Foundation; either
174  version 3.0 of the License, or (at your option) any later version.
175 
176  This library is distributed in the hope that it will be useful,
177  but WITHOUT ANY WARRANTY; without even the implied warranty of
178  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
179  Lesser General Public License for more details.
180 
181  You should have received a copy of the GNU Lesser General Public
182  License along with this library; if not, write to the Free Software
183  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
184 */
190 template <class Expr> class ADFuncSin
191 {
192 public:
193  enum { nvar = Expr::nvar };
194  typedef typename Expr::value_type value_type;
195 protected:
196  ADFuncSin () {}
197 
198  Expr expr_;
199 public:
200 
201  ADFuncSin ( const Expr & expr ) : expr_( expr )
202  {
203  ;
204  }
205 
206 
207  template<int isFundamental, typename Expr_>
208  struct Value
209  {
210 
211  typedef typename Expr_::value_type value_type;
212  static value_type signum( value_type a )
213  {
214  if ( abs( a ) < std::numeric_limits<value_type>::epsilon() )
215  return value_type( 0 );
216 
217  return a/abs( a );
218  }
219  static value_type value( Expr_ const& expr_ )
220  {
221  return sin( expr_.value() );
222  }
223  static value_type grad( Expr_ const& expr_, int __i )
224  {
225  return expr_.grad( __i )*cos( expr_.value() );
226  }
227  static value_type hessian( Expr_ const& expr_, int __i, int __j )
228  {
229  return expr_.hessian( __i,__j )*cos( expr_.value() ) - expr_.grad( __i )*expr_.grad( __j ) * sin( expr_.value() );
230  }
231  };
232  template<typename Expr_>
233  struct Value<true, Expr_>
234  {
235  typedef typename Expr_::value_type value_type;
236  static value_type signum( value_type a )
237  {
238  if ( std::abs( a ) < std::numeric_limits<value_type>::epsilon() )
239  return value_type( 0 );
240 
241  return a/std::abs( a );
242  }
243  static value_type value( Expr_ const& expr_ )
244  {
245  return std::sin( expr_.value() );
246  }
247  static value_type grad( Expr_ const& expr_, int __i )
248  {
249  return expr_.grad( __i )*std::cos( expr_.value() );
250  }
251  static value_type hessian( Expr_ const& expr_, int __i, int __j )
252  {
253  return expr_.hessian( __i,__j )*std::cos( expr_.value() ) - expr_.grad( __i )*expr_.grad( __j ) * std::sin( expr_.value() );
254  }
255  };
256 
257  inline value_type value() const
258  {
259  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::value( expr_ );
260  }
261  inline value_type grad( int __i ) const
262  {
263  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::grad( expr_, __i );
264  }
265  inline value_type hessian( int __i, int __j ) const
266  {
267  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::hessian( expr_, __i, __j );
268  }
269  inline bool deps( int __i ) const
270  {
271  return expr_.deps( __i ) ;
272  }
273 };
274 
275 template <class Expr> inline ADExpr< ADFuncSin< ADExpr<Expr> > >
276 sin ( const ADExpr<Expr>& expr )
277 {
278  typedef ADFuncSin< ADExpr<Expr> > expr_t;
279  return ADExpr< expr_t >( expr_t( expr ) );
280 }
281 
282 template <class T, int Nvar, int Order, int Var> inline ADExpr< ADFuncSin< ADType<T, Nvar, Order, Var> > >
283 sin ( const ADType<T, Nvar, Order, Var>& x )
284 {
285  typedef ADFuncSin< ADType<T, Nvar, Order, Var> > expr_t;
286  return ADExpr< expr_t >( expr_t( x ) );
287 }
288 /****************************************************************************
289  * Tangent function
290  ****************************************************************************/
291 /* -*- 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
292 
293  This file is part of the Feel library
294 
295  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
296  Date: 2008-02-14
297 
298  Copyright (C) 2008 Université Joseph Fourier (Grenoble I)
299 
300  This library is free software; you can redistribute it and/or
301  modify it under the terms of the GNU Lesser General Public
302  License as published by the Free Software Foundation; either
303  version 3.0 of the License, or (at your option) any later version.
304 
305  This library is distributed in the hope that it will be useful,
306  but WITHOUT ANY WARRANTY; without even the implied warranty of
307  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
308  Lesser General Public License for more details.
309 
310  You should have received a copy of the GNU Lesser General Public
311  License along with this library; if not, write to the Free Software
312  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
313 */
319 template <class Expr> class ADFuncTan
320 {
321 public:
322  enum { nvar = Expr::nvar };
323  typedef typename Expr::value_type value_type;
324 protected:
325  ADFuncTan () {}
326 
327  Expr expr_;
328 public:
329 
330  ADFuncTan ( const Expr & expr ) : expr_( expr )
331  {
332  ;
333  }
334 
335 
336  template<int isFundamental, typename Expr_>
337  struct Value
338  {
339 
340  typedef typename Expr_::value_type value_type;
341  static value_type signum( value_type a )
342  {
343  if ( abs( a ) < std::numeric_limits<value_type>::epsilon() )
344  return value_type( 0 );
345 
346  return a/abs( a );
347  }
348  static value_type value( Expr_ const& expr_ )
349  {
350  return tan( expr_.value() );
351  }
352  static value_type grad( Expr_ const& expr_, int __i )
353  {
354  return expr_.grad( __i )*( 1.+tan( expr_.value() )*tan( expr_.value() ) );
355  }
356  static value_type hessian( Expr_ const& expr_, int __i, int __j )
357  {
358  return 2*tan( expr_.value() )*( 1+tan( expr_.value() )*tan( expr_.value() ) )*expr_.grad( __i )*expr_.grad( __j ) + ( 1+tan( expr_.value() )*tan( expr_.value() ) )*expr_.hessian( __i,__j );
359  }
360  };
361  template<typename Expr_>
362  struct Value<true, Expr_>
363  {
364  typedef typename Expr_::value_type value_type;
365  static value_type signum( value_type a )
366  {
367  if ( std::abs( a ) < std::numeric_limits<value_type>::epsilon() )
368  return value_type( 0 );
369 
370  return a/std::abs( a );
371  }
372  static value_type value( Expr_ const& expr_ )
373  {
374  return std::tan( expr_.value() );
375  }
376  static value_type grad( Expr_ const& expr_, int __i )
377  {
378  return expr_.grad( __i )*( 1.+std::tan( expr_.value() )*std::tan( expr_.value() ) );
379  }
380  static value_type hessian( Expr_ const& expr_, int __i, int __j )
381  {
382  return 2*std::tan( expr_.value() )*( 1+std::tan( expr_.value() )*std::tan( expr_.value() ) )*expr_.grad( __i )*expr_.grad( __j ) + ( 1+std::tan( expr_.value() )*std::tan( expr_.value() ) )*expr_.hessian( __i,__j );
383  }
384  };
385 
386  inline value_type value() const
387  {
388  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::value( expr_ );
389  }
390  inline value_type grad( int __i ) const
391  {
392  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::grad( expr_, __i );
393  }
394  inline value_type hessian( int __i, int __j ) const
395  {
396  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::hessian( expr_, __i, __j );
397  }
398  inline bool deps( int __i ) const
399  {
400  return expr_.deps( __i ) ;
401  }
402 };
403 
404 template <class Expr> inline ADExpr< ADFuncTan< ADExpr<Expr> > >
405 tan ( const ADExpr<Expr>& expr )
406 {
407  typedef ADFuncTan< ADExpr<Expr> > expr_t;
408  return ADExpr< expr_t >( expr_t( expr ) );
409 }
410 
411 template <class T, int Nvar, int Order, int Var> inline ADExpr< ADFuncTan< ADType<T, Nvar, Order, Var> > >
412 tan ( const ADType<T, Nvar, Order, Var>& x )
413 {
414  typedef ADFuncTan< ADType<T, Nvar, Order, Var> > expr_t;
415  return ADExpr< expr_t >( expr_t( x ) );
416 }
417 /****************************************************************************
418  * Sqrt function
419  ****************************************************************************/
420 /* -*- 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
421 
422  This file is part of the Feel library
423 
424  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
425  Date: 2008-02-14
426 
427  Copyright (C) 2008 Université Joseph Fourier (Grenoble I)
428 
429  This library is free software; you can redistribute it and/or
430  modify it under the terms of the GNU Lesser General Public
431  License as published by the Free Software Foundation; either
432  version 3.0 of the License, or (at your option) any later version.
433 
434  This library is distributed in the hope that it will be useful,
435  but WITHOUT ANY WARRANTY; without even the implied warranty of
436  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
437  Lesser General Public License for more details.
438 
439  You should have received a copy of the GNU Lesser General Public
440  License along with this library; if not, write to the Free Software
441  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
442 */
448 template <class Expr> class ADFuncSqrt
449 {
450 public:
451  enum { nvar = Expr::nvar };
452  typedef typename Expr::value_type value_type;
453 protected:
454  ADFuncSqrt () {}
455 
456  Expr expr_;
457 public:
458 
459  ADFuncSqrt ( const Expr & expr ) : expr_( expr )
460  {
461  ;
462  }
463 
464 
465  template<int isFundamental, typename Expr_>
466  struct Value
467  {
468 
469  typedef typename Expr_::value_type value_type;
470  static value_type signum( value_type a )
471  {
472  if ( abs( a ) < std::numeric_limits<value_type>::epsilon() )
473  return value_type( 0 );
474 
475  return a/abs( a );
476  }
477  static value_type value( Expr_ const& expr_ )
478  {
479  return sqrt( expr_.value() );
480  }
481  static value_type grad( Expr_ const& expr_, int __i )
482  {
483  return expr_.grad( __i )/( 2.*sqrt( expr_.value() ) );
484  }
485  static value_type hessian( Expr_ const& expr_, int __i, int __j )
486  {
487  return expr_.hessian( __i,__j )/( 2.*sqrt( expr_.value() ) )-expr_.grad( __i )*expr_.grad( __j )/( 4.*pow( expr_.value(),1.5 ) );
488  }
489  };
490  template<typename Expr_>
491  struct Value<true, Expr_>
492  {
493  typedef typename Expr_::value_type value_type;
494  static value_type signum( value_type a )
495  {
496  if ( std::abs( a ) < std::numeric_limits<value_type>::epsilon() )
497  return value_type( 0 );
498 
499  return a/std::abs( a );
500  }
501  static value_type value( Expr_ const& expr_ )
502  {
503  return std::sqrt( expr_.value() );
504  }
505  static value_type grad( Expr_ const& expr_, int __i )
506  {
507  return expr_.grad( __i )/( 2.*std::sqrt( expr_.value() ) );
508  }
509  static value_type hessian( Expr_ const& expr_, int __i, int __j )
510  {
511  return expr_.hessian( __i,__j )/( 2.*std::sqrt( expr_.value() ) )-expr_.grad( __i )*expr_.grad( __j )/( 4.*std::pow( expr_.value(),1.5 ) );
512  }
513  };
514 
515  inline value_type value() const
516  {
517  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::value( expr_ );
518  }
519  inline value_type grad( int __i ) const
520  {
521  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::grad( expr_, __i );
522  }
523  inline value_type hessian( int __i, int __j ) const
524  {
525  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::hessian( expr_, __i, __j );
526  }
527  inline bool deps( int __i ) const
528  {
529  return expr_.deps( __i ) ;
530  }
531 };
532 
533 template <class Expr> inline ADExpr< ADFuncSqrt< ADExpr<Expr> > >
534 sqrt ( const ADExpr<Expr>& expr )
535 {
536  typedef ADFuncSqrt< ADExpr<Expr> > expr_t;
537  return ADExpr< expr_t >( expr_t( expr ) );
538 }
539 
540 template <class T, int Nvar, int Order, int Var> inline ADExpr< ADFuncSqrt< ADType<T, Nvar, Order, Var> > >
541 sqrt ( const ADType<T, Nvar, Order, Var>& x )
542 {
543  typedef ADFuncSqrt< ADType<T, Nvar, Order, Var> > expr_t;
544  return ADExpr< expr_t >( expr_t( x ) );
545 }
546 /****************************************************************************
547  * Exponential function
548  ****************************************************************************/
549 /* -*- 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
550 
551  This file is part of the Feel library
552 
553  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
554  Date: 2008-02-14
555 
556  Copyright (C) 2008 Université Joseph Fourier (Grenoble I)
557 
558  This library is free software; you can redistribute it and/or
559  modify it under the terms of the GNU Lesser General Public
560  License as published by the Free Software Foundation; either
561  version 3.0 of the License, or (at your option) any later version.
562 
563  This library is distributed in the hope that it will be useful,
564  but WITHOUT ANY WARRANTY; without even the implied warranty of
565  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
566  Lesser General Public License for more details.
567 
568  You should have received a copy of the GNU Lesser General Public
569  License along with this library; if not, write to the Free Software
570  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
571 */
577 template <class Expr> class AdFuncExp
578 {
579 public:
580  enum { nvar = Expr::nvar };
581  typedef typename Expr::value_type value_type;
582 protected:
583  AdFuncExp () {}
584 
585  Expr expr_;
586 public:
587 
588  AdFuncExp ( const Expr & expr ) : expr_( expr )
589  {
590  ;
591  }
592 
593 
594  template<int isFundamental, typename Expr_>
595  struct Value
596  {
597 
598  typedef typename Expr_::value_type value_type;
599  static value_type signum( value_type a )
600  {
601  if ( abs( a ) < std::numeric_limits<value_type>::epsilon() )
602  return value_type( 0 );
603 
604  return a/abs( a );
605  }
606  static value_type value( Expr_ const& expr_ )
607  {
608  return exp( expr_.value() );
609  }
610  static value_type grad( Expr_ const& expr_, int __i )
611  {
612  return expr_.grad( __i )*exp( expr_.value() );
613  }
614  static value_type hessian( Expr_ const& expr_, int __i, int __j )
615  {
616  return expr_.hessian( __i,__j )*exp( expr_.value() ) + expr_.grad( __i )*expr_.grad( __j )*exp( expr_.value() );
617  }
618  };
619  template<typename Expr_>
620  struct Value<true, Expr_>
621  {
622  typedef typename Expr_::value_type value_type;
623  static value_type signum( value_type a )
624  {
625  if ( std::abs( a ) < std::numeric_limits<value_type>::epsilon() )
626  return value_type( 0 );
627 
628  return a/std::abs( a );
629  }
630  static value_type value( Expr_ const& expr_ )
631  {
632  return std::exp( expr_.value() );
633  }
634  static value_type grad( Expr_ const& expr_, int __i )
635  {
636  return expr_.grad( __i )*std::exp( expr_.value() );
637  }
638  static value_type hessian( Expr_ const& expr_, int __i, int __j )
639  {
640  return expr_.hessian( __i,__j )*std::exp( expr_.value() ) + expr_.grad( __i )*expr_.grad( __j )*std::exp( expr_.value() );
641  }
642  };
643 
644  inline value_type value() const
645  {
646  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::value( expr_ );
647  }
648  inline value_type grad( int __i ) const
649  {
650  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::grad( expr_, __i );
651  }
652  inline value_type hessian( int __i, int __j ) const
653  {
654  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::hessian( expr_, __i, __j );
655  }
656  inline bool deps( int __i ) const
657  {
658  return expr_.deps( __i ) ;
659  }
660 };
661 
662 template <class Expr> inline ADExpr< AdFuncExp< ADExpr<Expr> > >
663 exp ( const ADExpr<Expr>& expr )
664 {
665  typedef AdFuncExp< ADExpr<Expr> > expr_t;
666  return ADExpr< expr_t >( expr_t( expr ) );
667 }
668 
669 template <class T, int Nvar, int Order, int Var> inline ADExpr< AdFuncExp< ADType<T, Nvar, Order, Var> > >
670 exp ( const ADType<T, Nvar, Order, Var>& x )
671 {
672  typedef AdFuncExp< ADType<T, Nvar, Order, Var> > expr_t;
673  return ADExpr< expr_t >( expr_t( x ) );
674 }
675 /****************************************************************************
676  * Logarithm function
677  ****************************************************************************/
678 /* -*- 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
679 
680  This file is part of the Feel library
681 
682  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
683  Date: 2008-02-14
684 
685  Copyright (C) 2008 Université Joseph Fourier (Grenoble I)
686 
687  This library is free software; you can redistribute it and/or
688  modify it under the terms of the GNU Lesser General Public
689  License as published by the Free Software Foundation; either
690  version 3.0 of the License, or (at your option) any later version.
691 
692  This library is distributed in the hope that it will be useful,
693  but WITHOUT ANY WARRANTY; without even the implied warranty of
694  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
695  Lesser General Public License for more details.
696 
697  You should have received a copy of the GNU Lesser General Public
698  License along with this library; if not, write to the Free Software
699  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
700 */
706 template <class Expr> class AdFuncLog
707 {
708 public:
709  enum { nvar = Expr::nvar };
710  typedef typename Expr::value_type value_type;
711 protected:
712  AdFuncLog () {}
713 
714  Expr expr_;
715 public:
716 
717  AdFuncLog ( const Expr & expr ) : expr_( expr )
718  {
719  ;
720  }
721 
722 
723  template<int isFundamental, typename Expr_>
724  struct Value
725  {
726 
727  typedef typename Expr_::value_type value_type;
728  static value_type signum( value_type a )
729  {
730  if ( abs( a ) < std::numeric_limits<value_type>::epsilon() )
731  return value_type( 0 );
732 
733  return a/abs( a );
734  }
735  static value_type value( Expr_ const& expr_ )
736  {
737  return log( expr_.value() );
738  }
739  static value_type grad( Expr_ const& expr_, int __i )
740  {
741  return expr_.grad( __i )/expr_.value();
742  }
743  static value_type hessian( Expr_ const& expr_, int __i, int __j )
744  {
745  return expr_.hessian( __i,__j )/expr_.value() - expr_.grad( __i )*expr_.grad( __j )/( pow( expr_.value(),2. ) );
746  }
747  };
748  template<typename Expr_>
749  struct Value<true, Expr_>
750  {
751  typedef typename Expr_::value_type value_type;
752  static value_type signum( value_type a )
753  {
754  if ( std::abs( a ) < std::numeric_limits<value_type>::epsilon() )
755  return value_type( 0 );
756 
757  return a/std::abs( a );
758  }
759  static value_type value( Expr_ const& expr_ )
760  {
761  return std::log( expr_.value() );
762  }
763  static value_type grad( Expr_ const& expr_, int __i )
764  {
765  return expr_.grad( __i )/expr_.value();
766  }
767  static value_type hessian( Expr_ const& expr_, int __i, int __j )
768  {
769  return expr_.hessian( __i,__j )/expr_.value() - expr_.grad( __i )*expr_.grad( __j )/( std::pow( expr_.value(),2. ) );
770  }
771  };
772 
773  inline value_type value() const
774  {
775  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::value( expr_ );
776  }
777  inline value_type grad( int __i ) const
778  {
779  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::grad( expr_, __i );
780  }
781  inline value_type hessian( int __i, int __j ) const
782  {
783  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::hessian( expr_, __i, __j );
784  }
785  inline bool deps( int __i ) const
786  {
787  return expr_.deps( __i ) ;
788  }
789 };
790 
791 template <class Expr> inline ADExpr< AdFuncLog< ADExpr<Expr> > >
792 log ( const ADExpr<Expr>& expr )
793 {
794  typedef AdFuncLog< ADExpr<Expr> > expr_t;
795  return ADExpr< expr_t >( expr_t( expr ) );
796 }
797 
798 template <class T, int Nvar, int Order, int Var> inline ADExpr< AdFuncLog< ADType<T, Nvar, Order, Var> > >
799 log ( const ADType<T, Nvar, Order, Var>& x )
800 {
801  typedef AdFuncLog< ADType<T, Nvar, Order, Var> > expr_t;
802  return ADExpr< expr_t >( expr_t( x ) );
803 }
804 /****************************************************************************
805  * Log10 function
806  ****************************************************************************/
807 /* -*- 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
808 
809  This file is part of the Feel library
810 
811  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
812  Date: 2008-02-14
813 
814  Copyright (C) 2008 Université Joseph Fourier (Grenoble I)
815 
816  This library is free software; you can redistribute it and/or
817  modify it under the terms of the GNU Lesser General Public
818  License as published by the Free Software Foundation; either
819  version 3.0 of the License, or (at your option) any later version.
820 
821  This library is distributed in the hope that it will be useful,
822  but WITHOUT ANY WARRANTY; without even the implied warranty of
823  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
824  Lesser General Public License for more details.
825 
826  You should have received a copy of the GNU Lesser General Public
827  License along with this library; if not, write to the Free Software
828  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
829 */
835 template <class Expr> class AdFuncLog10
836 {
837 public:
838  enum { nvar = Expr::nvar };
839  typedef typename Expr::value_type value_type;
840 protected:
841  AdFuncLog10 () {}
842 
843  Expr expr_;
844 public:
845 
846  AdFuncLog10 ( const Expr & expr ) : expr_( expr )
847  {
848  ;
849  }
850 
851 
852  template<int isFundamental, typename Expr_>
853  struct Value
854  {
855 
856  typedef typename Expr_::value_type value_type;
857  static value_type signum( value_type a )
858  {
859  if ( abs( a ) < std::numeric_limits<value_type>::epsilon() )
860  return value_type( 0 );
861 
862  return a/abs( a );
863  }
864  static value_type value( Expr_ const& expr_ )
865  {
866  return log10( expr_.value() );
867  }
868  static value_type grad( Expr_ const& expr_, int __i )
869  {
870  return expr_.grad( __i )/( log( value_type( 10 ) )*expr_.value() );
871  }
872  static value_type hessian( Expr_ const& expr_, int __i, int __j )
873  {
874  return expr_.hessian( __i,__j )/( log( value_type( 10 ) )*expr_.value() ) - expr_.grad( __i )*expr_.grad( __j )/( log( value_type( 10 ) )*pow( expr_.value(),2. ) );
875  }
876  };
877  template<typename Expr_>
878  struct Value<true, Expr_>
879  {
880  typedef typename Expr_::value_type value_type;
881  static value_type signum( value_type a )
882  {
883  if ( std::abs( a ) < std::numeric_limits<value_type>::epsilon() )
884  return value_type( 0 );
885 
886  return a/std::abs( a );
887  }
888  static value_type value( Expr_ const& expr_ )
889  {
890  return std::log10( expr_.value() );
891  }
892  static value_type grad( Expr_ const& expr_, int __i )
893  {
894  return expr_.grad( __i )/( std::log( value_type( 10 ) )*expr_.value() );
895  }
896  static value_type hessian( Expr_ const& expr_, int __i, int __j )
897  {
898  return expr_.hessian( __i,__j )/( std::log( value_type( 10 ) )*expr_.value() ) - expr_.grad( __i )*expr_.grad( __j )/( std::log( value_type( 10 ) )*std::pow( expr_.value(),2. ) );
899  }
900  };
901 
902  inline value_type value() const
903  {
904  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::value( expr_ );
905  }
906  inline value_type grad( int __i ) const
907  {
908  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::grad( expr_, __i );
909  }
910  inline value_type hessian( int __i, int __j ) const
911  {
912  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::hessian( expr_, __i, __j );
913  }
914  inline bool deps( int __i ) const
915  {
916  return expr_.deps( __i ) ;
917  }
918 };
919 
920 template <class Expr> inline ADExpr< AdFuncLog10< ADExpr<Expr> > >
921 log10 ( const ADExpr<Expr>& expr )
922 {
923  typedef AdFuncLog10< ADExpr<Expr> > expr_t;
924  return ADExpr< expr_t >( expr_t( expr ) );
925 }
926 
927 template <class T, int Nvar, int Order, int Var> inline ADExpr< AdFuncLog10< ADType<T, Nvar, Order, Var> > >
928 log10 ( const ADType<T, Nvar, Order, Var>& x )
929 {
930  typedef AdFuncLog10< ADType<T, Nvar, Order, Var> > expr_t;
931  return ADExpr< expr_t >( expr_t( x ) );
932 }
933 /****************************************************************************
934  * Absolute function
935  ****************************************************************************/
936 /* -*- 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
937 
938  This file is part of the Feel library
939 
940  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
941  Date: 2008-02-14
942 
943  Copyright (C) 2008 Université Joseph Fourier (Grenoble I)
944 
945  This library is free software; you can redistribute it and/or
946  modify it under the terms of the GNU Lesser General Public
947  License as published by the Free Software Foundation; either
948  version 3.0 of the License, or (at your option) any later version.
949 
950  This library is distributed in the hope that it will be useful,
951  but WITHOUT ANY WARRANTY; without even the implied warranty of
952  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
953  Lesser General Public License for more details.
954 
955  You should have received a copy of the GNU Lesser General Public
956  License along with this library; if not, write to the Free Software
957  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
958 */
964 template <class Expr> class AdFuncAbs
965 {
966 public:
967  enum { nvar = Expr::nvar };
968  typedef typename Expr::value_type value_type;
969 protected:
970  AdFuncAbs () {}
971 
972  Expr expr_;
973 public:
974 
975  AdFuncAbs ( const Expr & expr ) : expr_( expr )
976  {
977  ;
978  }
979 
980 
981  template<int isFundamental, typename Expr_>
982  struct Value
983  {
984 
985  typedef typename Expr_::value_type value_type;
986  static value_type signum( value_type a )
987  {
988  if ( abs( a ) < std::numeric_limits<value_type>::epsilon() )
989  return value_type( 0 );
990 
991  return a/abs( a );
992  }
993  static value_type value( Expr_ const& expr_ )
994  {
995  return abs( expr_.value() );
996  }
997  static value_type grad( Expr_ const& expr_, int __i )
998  {
999  return signum( expr_.value() ) * expr_.grad( __i );
1000  }
1001  static value_type hessian( Expr_ const& expr_, int __i, int __j )
1002  {
1003  return signum( expr_.value() ) * expr_.hessian( __i,__j );
1004  }
1005  };
1006  template<typename Expr_>
1007  struct Value<true, Expr_>
1008  {
1009  typedef typename Expr_::value_type value_type;
1010  static value_type signum( value_type a )
1011  {
1012  if ( std::abs( a ) < std::numeric_limits<value_type>::epsilon() )
1013  return value_type( 0 );
1014 
1015  return a/std::abs( a );
1016  }
1017  static value_type value( Expr_ const& expr_ )
1018  {
1019  return std::abs( expr_.value() );
1020  }
1021  static value_type grad( Expr_ const& expr_, int __i )
1022  {
1023  return signum( expr_.value() ) * expr_.grad( __i );
1024  }
1025  static value_type hessian( Expr_ const& expr_, int __i, int __j )
1026  {
1027  return signum( expr_.value() ) * expr_.hessian( __i,__j );
1028  }
1029  };
1030 
1031  inline value_type value() const
1032  {
1033  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::value( expr_ );
1034  }
1035  inline value_type grad( int __i ) const
1036  {
1037  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::grad( expr_, __i );
1038  }
1039  inline value_type hessian( int __i, int __j ) const
1040  {
1041  return Value<true/*boost::type_traits::is_fundamental<value_type>::value*/,Expr>::hessian( expr_, __i, __j );
1042  }
1043  inline bool deps( int __i ) const
1044  {
1045  return expr_.deps( __i ) ;
1046  }
1047 };
1048 
1049 template <class Expr> inline ADExpr< AdFuncAbs< ADExpr<Expr> > >
1050 abs ( const ADExpr<Expr>& expr )
1051 {
1052  typedef AdFuncAbs< ADExpr<Expr> > expr_t;
1053  return ADExpr< expr_t >( expr_t( expr ) );
1054 }
1055 
1056 template <class T, int Nvar, int Order, int Var> inline ADExpr< AdFuncAbs< ADType<T, Nvar, Order, Var> > >
1057 abs ( const ADType<T, Nvar, Order, Var>& x )
1058 {
1059  typedef AdFuncAbs< ADType<T, Nvar, Order, Var> > expr_t;
1060  return ADExpr< expr_t >( expr_t( x ) );
1061 }
1062 }
1063 
1064 #endif
PolynomialSet< Poly, Tensor2 > hessian(PolynomialSet< Poly, Scalar > const &p)
compute the gradient of a vectorial polynomial set
Definition: operations.hpp:231

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