ADMB Documentation  11.1.2490
 All Classes Files Functions Variables Typedefs Friends Defines
def_eval.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: def_eval.cpp 2337 2014-09-13 09:46:27Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include "fvar.hpp"
00012 
00013 #include <sys/stat.h>
00014 #include <fcntl.h>
00015 #include <string.h>
00016 
00017 #ifdef __TURBOC__
00018   #pragma hdrstop
00019   #include <iostream.h>
00020 #endif
00021 
00022 #ifdef __ZTC__
00023   #include <iostream.hpp>
00024 #endif
00025 
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 
00029 #ifdef __SUN__
00030   #include <iostream.h>
00031   #include <sys/stat.h>
00032   #include <sys/types.h>
00033   #include <unistd.h>
00034 #endif
00035 
00036 #ifdef _MSC_VER
00037   #define lseek _lseek
00038   #define  read _read
00039   #define write _write
00040 #else
00041   #include <iostream>
00042   using namespace std;
00043   #include <sys/stat.h>
00044   #include <sys/types.h>
00045   #include <unistd.h>
00046 #endif
00047 
00048 #if defined (__WAT32__)
00049   #include <io.h>
00050 #endif
00051 
00052 #include <math.h>
00053 //#define XXX 3.70255042e-17
00054 
00055   //ofstream gradlog("grad.log");
00056 
00061   void default_evaluation(void)
00062   {
00063     // checks to see how many independent variables there are
00064     grad_stack_entry * grad_ptr = gradient_structure::GRAD_STACK1->ptr;
00065     double * zptr = grad_ptr->dep_addr;
00066     double z = *zptr;
00067     *zptr = 0;
00068     // Check to see if first independent variable is a NULL adress
00069     if  ( grad_ptr->ind_addr1 )
00070     {
00071       * grad_ptr->ind_addr1 += z * grad_ptr->mult1 ;
00072         //gradlog <<  setprecision(13) << * grad_ptr->ind_addr1  << endl;
00073         //if (fabs(* grad_ptr->ind_addr1+XXX)<1.e-16)
00074          // cout <<  setprecision(13) << * grad_ptr->ind_addr1  << endl;
00075 #if defined(USE_DDOUBLE)
00076       if  ( grad_ptr->mult2 !=0)
00077 #else
00078       if  ( grad_ptr->mult2)
00079 #endif
00080       {
00081         * grad_ptr->ind_addr2 += z * grad_ptr->mult2 ;
00082         //gradlog <<  setprecision(13) << * grad_ptr->ind_addr2  << endl;
00083         //if (fabs(* grad_ptr->ind_addr2+XXX)<1.e-16)
00084          // cout <<  setprecision(13) << * grad_ptr->ind_addr2  << endl;
00085       }
00086     }
00087   }
00088 
00093   void default_evaluation1(void)
00094   {
00095     // there is one independent variable
00096     grad_stack_entry * grad_ptr = gradient_structure::GRAD_STACK1->ptr;
00097     double z = * grad_ptr->dep_addr;
00098     * grad_ptr->dep_addr=0.;
00099     * grad_ptr->ind_addr1 += z;
00100     //gradlog <<  setprecision(13) << * grad_ptr->ind_addr1  << endl;
00101     //if (fabs(* grad_ptr->ind_addr1+XXX)<1.e-16)
00102     //cout << setscientific() <<  setprecision(13) << * grad_ptr->ind_addr1
00103     //<< endl;
00104   }
00105 
00110   void default_evaluation1m(void)
00111   {
00112     // there is one independent variable
00113     grad_stack_entry * grad_ptr = gradient_structure::GRAD_STACK1->ptr;
00114     double z = * grad_ptr->dep_addr;
00115     * grad_ptr->dep_addr=0.;
00116     * grad_ptr->ind_addr1 -= z;
00117     //gradlog <<  setprecision(13) << * grad_ptr->ind_addr1  << endl;
00118      //   if (fabs(* grad_ptr->ind_addr1+XXX)<1.e-16)
00119       //    cout <<  setprecision(13) << * grad_ptr->ind_addr1  << endl;
00120   }
00121 
00126   void default_evaluation0(void)
00127   {
00128     // there is one independent variable
00129     * gradient_structure::GRAD_STACK1->ptr->dep_addr=0.;
00130   }
00131 
00136   void default_evaluation2(void)
00137   {
00138     //char ch;
00139     // there is one independent variable
00140     grad_stack_entry * grad_ptr = gradient_structure::GRAD_STACK1->ptr;
00141     //cout << setprecision(16) << *grad_ptr->dep_addr << endl;
00142     //cout << setprecision(16) << *grad_ptr->ind_addr1 << endl;
00143     //cout << setprecision(16) << grad_ptr->mult1 << endl;
00144     //cin >> ch;
00145     double z = * grad_ptr->dep_addr;
00146     * grad_ptr->dep_addr=0.;
00147     * grad_ptr->ind_addr1 += z * grad_ptr->mult1 ;
00148     //gradlog <<  setprecision(13) << * grad_ptr->ind_addr1  << endl;
00149      //   if (fabs(* grad_ptr->ind_addr1+XXX)<1.e-16)
00150       //    cout <<  setprecision(13) << * grad_ptr->ind_addr1  << endl;
00151   }
00152 
00157   void default_evaluation3(void)
00158   {
00159     // there are two independent variables
00160     grad_stack_entry * grad_ptr = gradient_structure::GRAD_STACK1->ptr;
00161     double z = * grad_ptr->dep_addr;
00162     * grad_ptr->dep_addr=0.;
00163     * grad_ptr->ind_addr1 += z * grad_ptr->mult1 ;
00164     * grad_ptr->ind_addr2 += z * grad_ptr->mult2 ;
00165     //gradlog <<  setprecision(13) << * grad_ptr->ind_addr1  << endl;
00166      //   if (fabs(* grad_ptr->ind_addr1+XXX)<1.e-16)
00167       //    cout <<  setprecision(13) << * grad_ptr->ind_addr1  << endl;
00168   }
00169 
00174   void default_evaluation3ind(void)
00175   {
00176     // there are three independent variables
00177     grad_stack_entry *  grad_ptr = gradient_structure::GRAD_STACK1->ptr;
00178 
00179     double mult3=grad_ptr->mult1 ;
00180     double * ind_addr3=grad_ptr->ind_addr1;
00181     if (gradient_structure::GRAD_STACK1->ptr-- ==
00182       gradient_structure::GRAD_STACK1->ptr_first)
00183     {
00184       // back up the file one buffer size and read forward
00185 
00186       off_t lpos=lseek(gradient_structure::GRAD_STACK1->_GRADFILE_PTR,
00187         -((long int)(sizeof(grad_stack_entry)*gradient_structure::
00188         GRAD_STACK1->length)),SEEK_CUR);
00189 
00190       gradient_structure::GRAD_STACK1->read_grad_stack_buffer(lpos);
00191       //gradient_structure::GRAD_STACK1->ptr++;
00192     }
00193 
00194     grad_ptr = gradient_structure::GRAD_STACK1->ptr;
00195     double z = * grad_ptr->dep_addr;
00196     * grad_ptr->dep_addr=0.;
00197     * grad_ptr->ind_addr1 += z * grad_ptr->mult1 ;
00198     * grad_ptr->ind_addr2 += z * grad_ptr->mult2 ;
00199     * ind_addr3 += z * mult3 ;
00200   }
00201 
00206   void default_evaluation4ind(void)
00207   {
00208     // there are three independent variables
00209     grad_stack_entry *  grad_ptr = gradient_structure::GRAD_STACK1->ptr;
00210 
00211     double * ind_addr3=grad_ptr->ind_addr1;
00212     double mult3=grad_ptr->mult1 ;
00213     double * ind_addr4=grad_ptr->ind_addr2;
00214     double mult4=grad_ptr->mult2 ;
00215     if (gradient_structure::GRAD_STACK1->ptr-- ==
00216       gradient_structure::GRAD_STACK1->ptr_first)
00217     {
00218       // back up the file one buffer size and read forward
00219       off_t lpos=lseek(gradient_structure::GRAD_STACK1->_GRADFILE_PTR,
00220         -((long int)(sizeof(grad_stack_entry)*gradient_structure::
00221         GRAD_STACK1->length)),SEEK_CUR);
00222 
00223       gradient_structure::GRAD_STACK1->read_grad_stack_buffer(lpos);
00224       //gradient_structure::GRAD_STACK1->ptr++;
00225     }
00226 
00227     grad_ptr = gradient_structure::GRAD_STACK1->ptr;
00228     double z = * grad_ptr->dep_addr;
00229     * grad_ptr->dep_addr=0.;
00230     * grad_ptr->ind_addr1 += z * grad_ptr->mult1 ;
00231     * grad_ptr->ind_addr2 += z * grad_ptr->mult2 ;
00232     * ind_addr3 += z * mult3 ;
00233     * ind_addr4 += z * mult4 ;
00234     //gradlog <<  setprecision(13) << * grad_ptr->ind_addr1  << endl;
00235      //   if (fabs(* grad_ptr->ind_addr1+XXX)<1.e-16)
00236       //    cout <<  setprecision(13) << * grad_ptr->ind_addr1  << endl;
00237     //gradlog <<  setprecision(13) << * grad_ptr->ind_addr2  << endl;
00238      //   if (fabs(* grad_ptr->ind_addr2+XXX)<1.e-16)
00239       //    cout <<  setprecision(13) << * grad_ptr->ind_addr2  << endl;
00240     //gradlog <<  setprecision(13) << * ind_addr3  << endl;
00241      //   if (fabs(* ind_addr3+XXX)<1.e-16)
00242       //    cout <<  setprecision(13) << * ind_addr3  << endl;
00243     //gradlog <<  setprecision(13) << * ind_addr4  << endl;
00244      //   if (fabs(* ind_addr4+XXX)<1.e-16)
00245       //    cout <<  setprecision(13) << * ind_addr4  << endl;
00246   }
00247 
00252   void default_evaluation4(void)
00253   {
00254     // there are two independent variables
00255     grad_stack_entry * grad_ptr = gradient_structure::GRAD_STACK1->ptr;
00256     double z = * grad_ptr->dep_addr;
00257     * grad_ptr->dep_addr=0.;
00258     * grad_ptr->ind_addr1 += z;
00259     * grad_ptr->ind_addr2 += z;
00260   }
00261 
00266   void default_evaluation4m(void)
00267   {
00268     // there are two independent variables
00269     grad_stack_entry * grad_ptr = gradient_structure::GRAD_STACK1->ptr;
00270     double z = * grad_ptr->dep_addr;
00271     * grad_ptr->dep_addr=0.;
00272     * grad_ptr->ind_addr1 += z;
00273     * grad_ptr->ind_addr2 -= z;
00274   }