/home/coin/SVN-release/CoinAll-1.1.0/cppad/example/base_adolc.hpp

Go to the documentation of this file.
00001 # ifndef CPPAD_BASE_ADOLC_INCLUDED
00002 # define CPPAD_BASE_ADOLC_INCLUDED
00003 /* --------------------------------------------------------------------------
00004 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-07 Bradley M. Bell
00005 
00006 CppAD is distributed under multiple licenses. This distribution is under
00007 the terms of the 
00008                     Common Public License Version 1.0.
00009 
00010 A copy of this license is included in the COPYING file of this distribution.
00011 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
00012 -------------------------------------------------------------------------- */
00013 /*
00014 $begin base_adolc.hpp$$
00015 $spell
00016         Lt
00017         Le
00018         Eq
00019         Ge
00020         Gt
00021         namespace
00022         erf
00023         cassert
00024         condassign
00025         hpp
00026         bool
00027         const
00028         Adolc
00029         adouble
00030         CondExpOp
00031         inline
00032         enum
00033         CppAD
00034         pow
00035         acos
00036         asin
00037         atan
00038         cos
00039         cosh
00040         exp
00041         sqrt
00042 $$
00043 
00044 $index Adolc, adouble as Base$$
00045 $index Base, Adolc's adouble$$
00046 $index adouble, as Base$$ 
00047 
00048 $section Enable use of AD<Base> where Base is Adolc's adouble Type$$
00049 
00050 $head Syntax$$
00051 This file in located in the $code example$$ directory. 
00052 It can be copied into the current working directory and
00053 included with the command:
00054 $syntax%
00055         # include "base_adolc.hpp"
00056 %$$
00057 
00058 $children%
00059         example/mul_level_adolc.cpp
00060 %$$
00061 
00062 $head Example$$
00063 The file $cref/mul_level_adolc.cpp/$$ contains an example use of
00064 Adolc's $code adouble$$ type for a CppAD $italic Base$$ type.
00065 It returns true if it succeeds and false otherwise.
00066 The file $cref/ode_taylor_adolc.cpp/$$ contains a more realistic
00067 (and complex) example.
00068 
00069 $head Functions Defined by Adolc Package$$
00070 The following $cref/required/base_require/$$ 
00071 functions are defined by the Adolc package:
00072 $pre
00073 $$
00074 $code abs$$,
00075 $code acos$$,
00076 $code asin$$,
00077 $code atan$$,
00078 $code cos$$,
00079 $code cosh$$,
00080 $code erf$$,
00081 $code exp$$,
00082 $code log$$,
00083 $code pow$$,
00084 $code sin$$,
00085 $code sinh$$,
00086 $code sqrt$$,
00087 $code tan$$.
00088 
00089 $head CondExpOp$$
00090 The type $code adouble$$ supports a conditional assignment function
00091 with the syntax
00092 $syntax%
00093         condassign(%a%, %b%, %c%, %d%)
00094 %$$
00095 which evaluates to
00096 $syntax%
00097         %a% = (%b% > 0) ? %c% : %d%;
00098 %$$
00099 This enables one to include conditionals in the recording of
00100 $code adouble$$ operations and later evaluation for different
00101 values of the independent variables 
00102 (in the same spirit as the CppAD $cref/CondExp/$$ function).
00103 $codep */
00104 namespace CppAD {
00105         inline adouble CondExpOp(
00106                 enum  CppAD::CompareOp     cop ,
00107                 const adouble            &left ,
00108                 const adouble           &right ,
00109                 const adouble        &trueCase ,
00110                 const adouble       &falseCase )
00111         {       adouble result;
00112                 switch( cop )
00113                 {
00114                         case CompareLt: // left < right
00115                         condassign(result, right - left, trueCase, falseCase);
00116                         break;
00117 
00118                         case CompareLe: // left <= right
00119                         condassign(result, left - right, falseCase, trueCase);
00120                         break;
00121 
00122                         case CompareEq: // left == right
00123                         condassign(result, left - right, falseCase, trueCase);
00124                         condassign(result, right - left, falseCase, result);
00125                         break;
00126 
00127                         case CompareGe: // left >= right
00128                         condassign(result, right - left, falseCase, trueCase);
00129                         break;
00130 
00131                         case CompareGt: // left > right
00132                         condassign(result, left - right, trueCase, falseCase);
00133                         break;
00134 
00135                         default:
00136                         CppAD::ErrorHandler::Call(
00137                                 true     , __LINE__ , __FILE__ ,
00138                                 "CppAD::CondExp",
00139                                 "Error: for unknown reason."
00140                         );
00141                         result = trueCase;
00142                 }
00143                 return result;
00144         }
00145 }
00146 /* $$
00147 
00148 $head EqualOpSeq$$
00149 The Adolc user interface does not specify a way to determine if 
00150 two $code adouble$$ variables correspond to the same operations sequence. 
00151 Make $code EqualOpSeq$$ an error if it gets used:
00152 $codep */
00153 namespace CppAD {
00154         inline bool EqualOpSeq(const adouble &x, const adouble &y)
00155         {       CppAD::ErrorHandler::Call(
00156                         true     , __LINE__ , __FILE__ ,
00157                         "CppAD::EqualOpSeq(x, y)",
00158                         "Error: adouble does not support EqualOpSeq."
00159                 );
00160                 return false;
00161         }
00162 }
00163 /* $$
00164 
00165 $head Identical$$
00166 The Adolc user interface does not specify a way to determine if an 
00167 $code adouble$$ depends on the independent variables. 
00168 To be safe (but slow) return $code false$$ in all the cases below.
00169 $codep */
00170 namespace CppAD {
00171         inline bool IdenticalPar(const adouble &x)
00172         {       return false; }
00173         inline bool IdenticalZero(const adouble &x)
00174         {       return false; }
00175         inline bool IdenticalOne(const adouble &x)
00176         {       return false; }
00177         inline bool IdenticalEqualPar(const adouble &x, const adouble &y)
00178         {       return false; }
00179 }
00180 /* $$
00181 
00182 $head Ordered$$
00183 $codep */
00184         inline bool GreaterThanZero(const adouble &x)
00185         {    return (x > 0); }
00186         inline bool GreaterThanOrZero(const adouble &x)
00187         {    return (x >= 0); }
00188         inline bool LessThanZero(const adouble &x)
00189         {    return (x < 0); }
00190         inline bool LessThanOrZero(const adouble &x)
00191         {    return (x <= 0); }
00192 /* $$
00193 
00194 $head Integer$$
00195 $codep */
00196         inline int Integer(const adouble &x)
00197         {    return static_cast<int>( x.value() ); }
00198 /* $$
00199 $end
00200 */
00201 # endif

Generated on Sun Nov 14 14:06:33 2010 for Coin-All by  doxygen 1.4.7