/home/coin/SVN-release/CoinAll-1.1.0/cppad/cppad/local/ad_fun.hpp

Go to the documentation of this file.
00001 # ifndef CPPAD_AD_FUN_INCLUDED
00002 # define CPPAD_AD_FUN_INCLUDED
00003 
00004 /* --------------------------------------------------------------------------
00005 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-07 Bradley M. Bell
00006 
00007 CppAD is distributed under multiple licenses. This distribution is under
00008 the terms of the 
00009                     Common Public License Version 1.0.
00010 
00011 A copy of this license is included in the COPYING file of this distribution.
00012 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
00013 -------------------------------------------------------------------------- */
00014 /*
00015 $begin ADFun$$
00016 $spell 
00017         xk
00018         Ind
00019         bool
00020         Taylor
00021         sizeof
00022         const
00023         std
00024         ind_taddr
00025         dep_taddr
00026 $$
00027 
00028 $spell
00029 $$
00030 
00031 $section ADFun Objects$$
00032 
00033 $index ADFun, object$$
00034 $index object, ADFun$$
00035 
00036 $head Purpose$$
00037 An AD of $italic Base$$
00038 $xref/glossary/Operation/Sequence/operation sequence/1/$$
00039 is stored in an $code ADFun$$ object by its $xref/FunConstruct/$$.
00040 The $code ADFun$$ object can then be used to calculate function values,
00041 derivative values, and other values related to the corresponding function.
00042 
00043 $childtable%
00044         cppad/local/independent.hpp%
00045         cppad/local/fun_construct.hpp%
00046         cppad/local/dependent.hpp%
00047         omh/seq_property.omh%
00048         cppad/local/fun_eval.hpp%
00049         cppad/local/drivers.hpp%
00050         cppad/local/fun_check.hpp%
00051         cppad/local/omp_max_thread.hpp%
00052         omh/fun_deprecated.omh
00053 %$$
00054 
00055 $end
00056 */
00057 
00058 
00059 // BEGIN CppAD namespace
00060 namespace CppAD {
00061 
00062 template <class Base>
00063 class ADFun {
00064         // type used for packing sparsity patters
00065         typedef size_t Pack;
00066 
00067 public:
00068         // default constructor
00069         ADFun(void) 
00070         : totalNumVar(0), Taylor(CPPAD_NULL), ForJac(CPPAD_NULL)
00071         { }
00072 
00073         // sequence constructor
00074         template <typename ADvector>
00075         ADFun(const ADvector &x, const ADvector &y);
00076 
00077         // destructor
00078         ~ADFun(void)
00079         {       if( Taylor != CPPAD_NULL )
00080                         CPPAD_TRACK_DEL_VEC(Taylor);
00081                 if( ForJac != CPPAD_NULL )
00082                         CPPAD_TRACK_DEL_VEC(ForJac);
00083         }
00084 
00085         // assign a new operation sequence
00086         template <typename ADvector>
00087         void Dependent(const ADvector &y);  // deprecated 
00088 
00089         template <typename ADvector>
00090         void Dependent(const ADvector &x, const ADvector &y);
00091 
00092         // forward mode sweep
00093         template <typename VectorBase>
00094         VectorBase Forward(size_t p, const VectorBase &u);
00095 
00096         // reverse mode sweep
00097         template <typename VectorBase>
00098         VectorBase Reverse(size_t p, const VectorBase &v) const;
00099 
00100         // forward mode Jacobian sparsity 
00101         template <typename VectorBase>
00102         VectorBase ForSparseJac(size_t q, const VectorBase &Px);
00103 
00104         // reverse mode Jacobian sparsity 
00105         template <typename VectorBase>
00106         VectorBase RevSparseJac(size_t q, const VectorBase &Py) const;
00107 
00108         // reverse mode Hessian sparsity 
00109         template <typename VectorBase>
00110         VectorBase RevSparseHes(size_t q, const VectorBase &Py) const;
00111 
00112         // does this AD operation sequence use VecAD<Base>::reference operands
00113         bool use_VecAD(void) const
00114         {       return Rec.NumVecInd() > 0; }
00115 
00116         // number of variables in opertion sequence
00117         size_t size_var(void) const
00118         {       return totalNumVar; }
00119 
00120         // number of Taylor coefficients currently calculated (per variable)
00121         size_t size_taylor(void) const
00122         {       return taylor_per_var; } 
00123 
00124         // set number of coefficients currently allocated (per variable)
00125         void capacity_taylor(size_t per_var);   
00126 
00127         // number of independent variables
00128         size_t Domain(void) const
00129         {       return ind_taddr.size(); }
00130 
00131         // number of dependent variables
00132         size_t Range(void) const
00133         {       return dep_taddr.size(); }
00134 
00135         // is variable a parameter
00136         bool Parameter(size_t i)
00137         {       CPPAD_ASSERT_KNOWN(
00138                         i < dep_taddr.size(),
00139                         "Argument to Parameter is >= dimension of range space"
00140                 );
00141                 return dep_parameter[i]; 
00142         }
00143 
00144 # ifndef NDEBUG
00145         // in not NDEBUG case, number of comparison operations that change
00146         size_t CompareChange(void) const
00147         {       return compareChange; }
00148 # endif
00149 
00150         // calculate entire Jacobian
00151         template <typename VectorBase>
00152         VectorBase Jacobian(const VectorBase &x); 
00153 
00154         // calculate Hessian for one component of f
00155         template <typename VectorBase>
00156         VectorBase Hessian(const VectorBase &x, size_t i); 
00157 
00158         // forward mode calculation of partial w.r.t one domain component
00159         template <typename VectorBase>
00160         VectorBase ForOne(
00161                 const VectorBase   &x ,
00162                 size_t              j );
00163 
00164         // reverse mode calculation of derivative of one range component
00165         template <typename VectorBase>
00166         VectorBase RevOne(
00167                 const VectorBase   &x ,
00168                 size_t              i );
00169 
00170         // forward mode calculation of a subset of second order partials
00171         template <typename VectorBase, typename VectorSize_t>
00172         VectorBase ForTwo(
00173                 const VectorBase   &x ,
00174                 const VectorSize_t &J ,
00175                 const VectorSize_t &K );
00176 
00177         // reverse mode calculation of a subset of second order partials
00178         template <typename VectorBase, typename VectorSize_t>
00179         VectorBase RevTwo(
00180                 const VectorBase   &x ,
00181                 const VectorSize_t &I ,
00182                 const VectorSize_t &J );
00183 
00184         // ------------------- Deprecated -----------------------------
00185 
00186         // number of variables in opertion sequence
00187         size_t Size(void) const
00188         {       return totalNumVar; }
00189 
00190         // number of Taylor coefficients currently stored (per variable)
00191         size_t Order(void) const
00192         {       return taylor_per_var - 1; }
00193 
00194         // amount of memory for each variable 
00195         size_t Memory(void) const
00196         {       size_t pervar  = TaylorColDim * sizeof(Base)
00197                 + ForJacColDim * sizeof(Pack);
00198                 size_t total   = totalNumVar * pervar + Rec.Memory();
00199                 return total;
00200         }
00201 
00202         // number of Taylor coefficients currently calculated (per variable)
00203         size_t taylor_size(void) const
00204         {       return taylor_per_var; } 
00205         // ------------------------------------------------------------
00206 private:
00207         // maximum amount of memory required for this function object
00208         // mutable size_t memoryMax;
00209 
00210         // debug checking number of comparision operations that changed
00211         size_t compareChange;
00212 
00213         // number of Taylor coefficieint per variable (currently stored)
00214         size_t taylor_per_var;
00215 
00216         // number of bits currently calculated per row of the ForJac array
00217         size_t ForJacBitDim; 
00218 
00219         // number of columns currently allocated for Taylor array
00220         size_t TaylorColDim;
00221 
00222         // number of columns currently allocated for ForJac array
00223         size_t ForJacColDim;
00224 
00225         // number of rows (variables) in the recording (Rec)
00226         size_t totalNumVar;
00227 
00228         // tape address for the independent variables
00229         CppAD::vector<size_t> ind_taddr;
00230 
00231         // tape address and parameter flag for the dependent variables
00232         CppAD::vector<size_t> dep_taddr;
00233         CppAD::vector<bool>   dep_parameter;
00234 
00235         // the operations corresponding to this function
00236         TapeRec<Base> Rec;
00237 
00238         // results of the forward mode calculations
00239         Base *Taylor;
00240 
00241         // results of the forward mode Jacobian sparsity calculations
00242         Pack *ForJac;
00243 
00244 
00245         template <typename ADvector>
00246         void Dependent(ADTape<Base> *tape, const ADvector &y);
00247 };
00248 // ---------------------------------------------------------------------------
00249 
00250 } // END CppAD namespace
00251 
00252 // non-user interfaces
00253 # include <cppad/local/forward_sweep.hpp>
00254 # include <cppad/local/reverse_sweep.hpp>
00255 # include <cppad/local/for_jac_sweep.hpp>
00256 # include <cppad/local/rev_jac_sweep.hpp>
00257 # include <cppad/local/rev_hes_sweep.hpp>
00258 
00259 
00260 // user interfaces
00261 # include <cppad/local/independent.hpp>
00262 # include <cppad/local/dependent.hpp>
00263 # include <cppad/local/fun_construct.hpp>
00264 # include <cppad/local/fun_eval.hpp>
00265 # include <cppad/local/drivers.hpp>
00266 # include <cppad/local/fun_check.hpp>
00267 # include <cppad/local/omp_max_thread.hpp>
00268 
00269 # endif

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