ADMB Documentation  11.1.2535
 All Classes Files Functions Variables Typedefs Friends Defines
df32fun1.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: df32fun1.cpp 2535 2014-10-31 12:28:33Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include <df1b2fun.h>
00012 
00013 #ifndef OPT_LIB
00014   #include <cassert>
00015   #include <climits>
00016 #endif
00017 
00018 void ad_read_pass2_dvdv(void);
00019 
00024  int df1b2_gradlist::write_pass1(const df1b2variable * _px,
00025    const df1b2variable * _py,df1b2variable * pz,double df_x,
00026    double df_y,
00027    double df_xx,
00028    double df_xy,
00029    double df_yy,
00030    double df_xxx,
00031    double df_xxy,
00032    double df_xyy,
00033    double df_yyy)
00034  {
00035    ADUNCONST(df1b2variable*,px)
00036    ADUNCONST(df1b2variable*,py)
00037    ncount++;
00038 #if defined(CHECK_COUNT)
00039   if (ncount >= ncount_check)
00040     ncount_checker(ncount,ncount_check);
00041 #endif
00042   int _nvar=df1b2variable::nvar;
00043 #ifndef OPT_LIB
00044   assert(_nvar >= 0);
00045 #endif
00046   size_t nvar = (size_t)_nvar;
00047 
00048   size_t total_bytes=3*sizeof(df1b2_header)+sizeof(char*)
00049      +(2*nvar+11)*sizeof(double);
00050 
00051 // string identifier debug stuff
00052 #if defined(SAFE_ALL)
00053   char ids[]="UZ";
00054   size_t slen=strlen(ids);
00055   total_bytes+=slen;
00056 #endif
00057 
00058   list.check_buffer_size(total_bytes);
00059 
00060   void * tmpptr=list.bptr;
00061 #if defined(SAFE_ALL)
00062   memcpy(list,ids,slen);
00063 #endif
00064 // end of string identifier debug stuff
00065 
00066    memcpy(list,(df1b2_header*)(px),sizeof(df1b2_header));
00067    memcpy(list,(df1b2_header*)(py),sizeof(df1b2_header));
00068    memcpy(list,(df1b2_header*)(pz),sizeof(df1b2_header));
00069    //memcpy(list,&pf,sizeof(char *));
00070    //*(char**)(list.bptr)=(char*)pf;
00071 
00072   const int sizeofdouble = sizeof(double);
00073 
00074    memcpy(list,&df_x,sizeofdouble);
00075    memcpy(list,&df_y,sizeofdouble);
00076    memcpy(list,&df_xx,sizeofdouble);
00077    memcpy(list,&df_xy,sizeofdouble);
00078    memcpy(list,&df_yy,sizeofdouble);
00079    memcpy(list,&df_xxx,sizeofdouble);
00080    memcpy(list,&df_xxy,sizeofdouble);
00081    memcpy(list,&df_xyy,sizeofdouble);
00082    memcpy(list,&df_yyy,sizeofdouble);
00083 
00084    memcpy(list,px->get_u(),sizeofdouble);
00085    memcpy(list,py->get_u(),sizeofdouble);
00086    memcpy(list,px->get_u_dot(),nvar*sizeofdouble);
00087    memcpy(list,py->get_u_dot(),nvar*sizeofdouble);
00088    // ***** write  record size
00089    nlist.bptr->numbytes=adptr_diff(list.bptr,tmpptr);
00090    nlist.bptr->pf=(ADrfptr)(&ad_read_pass2_dvdv);
00091    ++nlist;
00092    return 0;
00093  }
00094 
00095 
00096 void read_pass2_1_dvdv(void);
00097 void read_pass2_2_dvdv(void);
00098 void read_pass2_3_dvdv(void);
00099 
00104 void ad_read_pass2_dvdv(void)
00105 {
00106   switch(df1b2variable::passnumber)
00107   {
00108   case 1:
00109     read_pass2_1_dvdv();
00110     break;
00111   case 2:
00112     read_pass2_2_dvdv();
00113     break;
00114   case 3:
00115     read_pass2_3_dvdv();
00116     break;
00117   default:
00118     cerr << "illegal value for df1b2variable::pass = "
00119          << df1b2variable::passnumber << endl;
00120     exit(1);
00121   }
00122 }
00123 
00128 void read_pass2_1_dvdv(void)
00129 {
00130   // We are going backword for bptr and nbptr
00131   // and  forward for bptr2 and nbptr2
00132   // the current entry+2 in bptr is the size of the record i.e
00133   // points to the next record
00134   //char * bptr=f1b2gradlist->bptr;
00135   //char * bptr2=f1b2gradlist2->bptr;
00136   int _nvar=df1b2variable::nvar;
00137 #ifndef OPT_LIB
00138   assert(_nvar >= 0);
00139 #endif
00140   size_t nvar = (size_t)_nvar;
00141   test_smartlist& list=f1b2gradlist->list;
00142   //f1b2gradlist->nlist-=sizeof(int);
00143   int num_bytes=f1b2gradlist->nlist.bptr->numbytes;
00144   list-=num_bytes;
00145   list.saveposition(); // save pointer to beginning of record;
00146   double xu,yu;
00147   //ad_dstar xdot,ydot;
00148   //df1b2function2 * pf;
00149 
00150   // get info from tape1
00151 #if defined(SAFE_ALL)
00152   checkidentiferstring("UZ",f1b2gradlist->list);
00153 #endif
00154   char * bptr=f1b2gradlist->list.bptr;
00155   df1b2_header * px=(df1b2_header *) bptr;
00156   bptr+=sizeof(df1b2_header);
00157   df1b2_header * py=(df1b2_header *) bptr;
00158   bptr+=sizeof(df1b2_header);
00159   df1b2_header * pz=(df1b2_header *) bptr;
00160   bptr+=sizeof(df1b2_header);
00161   //pf=*(df1b2function2 **) bptr;
00162   //bptr+=sizeof(char*);
00163 
00164   double df1=*(double*) bptr;
00165   bptr+=sizeof(double);
00166 
00167   double df2=*(double*) bptr;
00168   bptr+=sizeof(double);
00169 
00170   double d2f11=*(double*) bptr;
00171   bptr+=sizeof(double);
00172 
00173   double d2f12=*(double*) bptr;
00174   bptr+=sizeof(double);
00175 
00176   double d2f22=*(double*) bptr;
00177   bptr+=sizeof(double);
00178 
00179 #if defined(PRINT_DERS)
00180   double d3f111=*(double*) bptr;
00181 #endif
00182   bptr+=sizeof(double);
00183 
00184 #if defined(PRINT_DERS)
00185   double d3f112=*(double*) bptr;
00186 #endif
00187   bptr+=sizeof(double);
00188 
00189 #if defined(PRINT_DERS)
00190   double d3f122=*(double*) bptr;
00191 #endif
00192   bptr+=sizeof(double);
00193 
00194 #if defined(PRINT_DERS)
00195   double d3f222=*(double*) bptr;
00196 #endif
00197   bptr+=sizeof(double);
00198 
00199   memcpy(&xu,bptr,sizeof(double));
00200   bptr+=sizeof(double);
00201   memcpy(&yu,bptr,sizeof(double));
00202   bptr+=sizeof(double);
00203   double * xdot=(double*)bptr;
00204   bptr+=nvar*sizeof(double);
00205   double * ydot=(double*)bptr;
00206 
00207   list.restoreposition(); // save pointer to beginning of record;
00208 
00209   // ****************************************************************
00210   // turn this off if no third derivatives are calculated
00211   // if (!no_third_derivatives)
00212   // {
00213   // save for second reverse pass
00214   // save identifier 1
00215      test_smartlist & list2 = f1b2gradlist->list2;
00216 
00217   size_t total_bytes=2*nvar*sizeof(double);
00218 // string identifier debug stuff
00219 #if defined(SAFE_ALL)
00220   char ids[]="FW";
00221   size_t slen=strlen(ids);
00222   total_bytes+=slen;
00223 #endif
00224 
00225   list2.check_buffer_size(total_bytes);
00226   void * tmpptr=list2.bptr;
00227 #if defined(SAFE_ALL)
00228   memcpy(list2,ids,slen);
00229 #endif
00230 
00231      fixed_smartlist2 & nlist2 = f1b2gradlist->nlist2;
00232   const int sizeofdouble = sizeof(double);
00233   memcpy(list2,pz->get_u_bar(),nvar*sizeofdouble);
00234   memcpy(list2,pz->get_u_dot_bar(),nvar*sizeofdouble);
00235   *nlist2.bptr=adptr_diff(list2.bptr,tmpptr);
00236   ++nlist2;
00237   // }
00238   //
00239   // ****************************************************************
00240 #if defined(PRINT_DERS)
00241  print_derivatives(funname,(f),(df1),
00242   (df2),(d2f11),(d2f12),(d2f22),
00243   (d3f111),(d3f112),(d3f122),
00244   (d3f222),1);
00245  print_derivatives(pz,"z");
00246  print_derivatives(px,"x");
00247  print_derivatives(py,"y");
00248 #endif
00249 #if defined(__DERCHECK__)
00250   if (derchecker)
00251   if (derchecker->node_number)
00252   {
00253     if (derchecker->counter == derchecker->node_number)
00254     {
00255       switch (derchecker->pass_number) // increment the variable of interest
00256       {
00257       case 2:
00258         switch(derchecker->vartype)
00259         {
00260         case 1:
00261           if (!derchecker->dotflag)
00262             px->u_bar[derchecker->index-1]+=derchecker->delta;
00263           else
00264             px->u_dot_bar[derchecker->index-1]+=derchecker->delta;
00265           break;
00266         case 2:
00267           if (!derchecker->dotflag)
00268             py->u_bar[derchecker->index-1]+=derchecker->delta;
00269           else
00270             py->u_dot_bar[derchecker->index-1]+=derchecker->delta;
00271           break;
00272         case 3:
00273           if (!derchecker->dotflag)
00274             pz->u_bar[derchecker->index-1]+=derchecker->delta;
00275           else
00276             pz->u_dot_bar[derchecker->index-1]+=derchecker->delta;
00277           break;
00278         default:
00279           cerr << "Invalid index value for dercheck_index was "
00280                << derchecker->index << endl;
00281           break;
00282         }
00283         break;
00284       case 3:
00285         switch(derchecker->vartype)
00286         {
00287         case 1:
00288           if (!derchecker->dotflag)
00289             px->u_bar[derchecker->index-1]-=derchecker->delta;
00290           else
00291             px->u_dot_bar[derchecker->index-1]-=derchecker->delta;
00292           break;
00293         case 2:
00294           if (!derchecker->dotflag)
00295             py->u_bar[derchecker->index-1]-=derchecker->delta;
00296           else
00297             py->u_dot_bar[derchecker->index-1]-=derchecker->delta;
00298           break;
00299         case 3:
00300           if (!derchecker->dotflag)
00301             pz->u_bar[derchecker->index-1]-=derchecker->delta;
00302           else
00303             pz->u_dot_bar[derchecker->index-1]-=derchecker->delta;
00304           break;
00305         default:
00306           cerr << "Invalid index value for dercheck_index was "
00307                << derchecker->index << endl;
00308           break;
00309         }
00310         break;
00311       }
00312     }
00313   }
00314 #endif
00315 
00316   // Do first reverse pass calculations
00317   size_t i;
00318   for (i=0;i<nvar;i++)
00319   {
00320     px->u_bar[i]+=(df1)*pz->u_bar[i];
00321   }
00322   for (i=0;i<nvar;i++)
00323   {
00324     py->u_bar[i]+=(df2)*pz->u_bar[i];
00325   }
00326   for (i=0;i<nvar;i++)
00327   {
00328     px->u_bar[i]+=(d2f11)*xdot[i]*pz->u_dot_bar[i];
00329     px->u_bar[i]+=(d2f12)*ydot[i]*pz->u_dot_bar[i];
00330 #if defined(ADDEBUG_PRINT)
00331     cout << px->u_bar[i] << " " << pz->u_dot_bar[i] << " " << addebug_count
00332          << endl;
00333 #endif
00334   }
00335   for (i=0;i<nvar;i++)
00336   {
00337     //py->u_bar[i]+=(d2f22)(*(px->u),*(py->u))*ydot[i]*pz->u_dot_bar[i];
00338     //py->u_bar[i]+=(d2f12)(*(px->u),*(py->u))*xdot[i]*pz->u_dot_bar[i];
00339     py->u_bar[i]+=(d2f22)*ydot[i]*pz->u_dot_bar[i];
00340     py->u_bar[i]+=(d2f12)*xdot[i]*pz->u_dot_bar[i];
00341 #if defined(ADDEBUG_PRINT)
00342     cout << py->u_bar[i] << " " << pz->u_dot_bar[i] << " " << addebug_count
00343          << endl;
00344 #endif
00345   }
00346   for (i=0;i<nvar;i++)
00347   {
00348     //px->u_dot_bar[i]+=(df1)(*(px->u),*(py->u))*pz->u_dot_bar[i];
00349     px->u_dot_bar[i]+=(df1)*pz->u_dot_bar[i];
00350 #if defined(ADDEBUG_PRINT)
00351     cout << px->u_dot_bar[i] << " " << addebug_count << endl;
00352     cout << pz->u_dot_bar[i] << " " << addebug_count << endl;
00353 #endif
00354   }
00355   for (i=0;i<nvar;i++)
00356   {
00357     py->u_dot_bar[i]+=(df2)*pz->u_dot_bar[i];
00358 #if defined(ADDEBUG_PRINT)
00359     cout << py->u_dot_bar[i] << " " << addebug_count << endl;
00360     cout << pz->u_dot_bar[i] << " " << addebug_count << endl;
00361 #endif
00362   }
00363 
00364   // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00365   for (i=0;i<nvar;i++)
00366   {
00367     pz->u_bar[i]=0;
00368   }
00369   for (i=0;i<nvar;i++)
00370   {
00371     pz->u_dot_bar[i]=0;
00372   }
00373 
00374 #if defined(PRINT_DERS)
00375  print_derivatives(pz,"z");
00376  print_derivatives(px,"x");
00377  print_derivatives(py,"y");
00378 #endif
00379 }
00380 
00385 void read_pass2_2_dvdv(void)
00386 {
00387   //const int nlist_record_size=sizeof(int)+sizeof(char*);
00388   // We are going forward for bptr and backword for bptr2
00389   //
00390   // list 1
00391   //
00392   int _nvar=df1b2variable::nvar;
00393 #ifndef OPT_LIB
00394   assert(_nvar >= 0);
00395 #endif
00396   size_t nvar = (size_t)_nvar;
00397   test_smartlist & list=f1b2gradlist->list;
00398   // !!!!!!!!!!!!!!!!!!!!!! change here
00399   size_t total_bytes=3*sizeof(df1b2_header)+sizeof(char*)
00400      +(2*nvar+11)*sizeof(double);
00401   //int total_bytes=3*sizeof(df1b2_header)+sizeof(char*)
00402    // +2*(nvar+1)*sizeof(double);
00403 // string identifier debug stuff
00404 #if defined(SAFE_ALL)
00405   char ids[]="UZ";
00406   size_t slen=strlen(ids);
00407   total_bytes+=slen;
00408 #endif
00409 
00410   list.check_buffer_size(total_bytes);
00411 
00412 // end of string identifier debug stuff
00413 
00414   list.saveposition(); // save pointer to beginning of record;
00415   fixed_smartlist & nlist=f1b2gradlist->nlist;
00416    // nlist-=sizeof(int);
00417   // get record size
00418   int num_bytes=nlist.bptr->numbytes;
00419     // nlist+=nlist_record_size;
00420   //
00421   // list 2
00422   //
00423   test_smartlist & list2=f1b2gradlist->list2;
00424   fixed_smartlist2 & nlist2=f1b2gradlist->nlist2;
00425   // get record size
00426   int num_bytes2=*nlist2.bptr;
00427   --nlist2;
00428   // backup the size of the record
00429   list2-=num_bytes2;
00430   list2.saveposition(); // save pointer to beginning of record;
00431   // save the pointer to the beginning of the record
00432   // bptr and bptr2 now both point to the beginning of their records
00433 
00434   double xu,yu;
00435   //df1b2_header x,z;
00436   //df1b2function2 * pf;
00437 
00438   // get info from tape1
00439   // get info from tape1
00440 #if defined(SAFE_ALL)
00441   checkidentiferstring("UZ",list);
00442   checkidentiferstring("FW",list2);
00443 #endif
00444   /*
00445   df1b2_header * px=(df1b2_header *) list.bptr;
00446   list.bptr+=sizeof(df1b2_header);
00447   df1b2_header * py=(df1b2_header *) list.bptr;
00448   list.bptr+=sizeof(df1b2_header);
00449   df1b2_header * pz=(df1b2_header *) list.bptr;
00450   list.bptr+=sizeof(df1b2_header);
00451   pf=*(df1b2function2 **) list.bptr;
00452   list.bptr+=sizeof(char*);
00453   memcpy(&xu,list.bptr,sizeof(double));
00454   list.bptr+=sizeof(double);
00455   memcpy(&yu,list.bptr,sizeof(double));
00456   list.bptr+=sizeof(double);
00457   xdot=(double*)list.bptr;
00458   list.bptr+=nvar*sizeof(double);
00459   ydot=(double*)list.bptr;
00460   */
00461   //char * bptr=f1b2gradlist->list.bptr;
00462   df1b2_header * px=(df1b2_header *) list.bptr;
00463   list.bptr+=sizeof(df1b2_header);
00464   df1b2_header * py=(df1b2_header *) list.bptr;
00465   list.bptr+=sizeof(df1b2_header);
00466   df1b2_header * pz=(df1b2_header *) list.bptr;
00467   list.bptr+=sizeof(df1b2_header);
00468   //pf=*(df1b2function2 **) list.bptr;
00469   //list.bptr+=sizeof(char*);
00470 
00471   double df1=*(double*) list.bptr;
00472   list.bptr+=sizeof(double);
00473 
00474   double df2=*(double*) list.bptr;
00475   list.bptr+=sizeof(double);
00476 
00477   double d2f11=*(double*) list.bptr;
00478   list.bptr+=sizeof(double);
00479 
00480   double d2f12=*(double*) list.bptr;
00481   list.bptr+=sizeof(double);
00482 
00483   double d2f22=*(double*) list.bptr;
00484   list.bptr+=sizeof(double);
00485 
00486   double d3f111=*(double*) list.bptr;
00487   list.bptr+=sizeof(double);
00488 
00489   double d3f112=*(double*) list.bptr;
00490   list.bptr+=sizeof(double);
00491 
00492   double d3f122=*(double*) list.bptr;
00493   list.bptr+=sizeof(double);
00494 
00495   double d3f222=*(double*) list.bptr;
00496   list.bptr+=sizeof(double);
00497 
00498   memcpy(&xu,list.bptr,sizeof(double));
00499   list.bptr+=sizeof(double);
00500   memcpy(&yu,list.bptr,sizeof(double));
00501   list.bptr+=sizeof(double);
00502   double * xdot=(double*)list.bptr;
00503   list.bptr+=nvar*sizeof(double);
00504   double * ydot=(double*)list.bptr;
00505 
00506   list.restoreposition(num_bytes); // save pointer to beginning of record;
00507 
00508   double * zbar;
00509   double * zdotbar;
00510 
00511   zbar=(double*)list2.bptr;
00512   zdotbar=(double*)(list2.bptr+nvar*sizeof(double));
00513   list2.restoreposition(); // save pointer to beginning of record;
00514 
00515   double * x_tilde=px->get_u_tilde();
00516   double * x_dot_tilde=px->get_u_dot_tilde();
00517   double * x_bar_tilde=px->get_u_bar_tilde();
00518   double * x_dot_bar_tilde=px->get_u_dot_bar_tilde();
00519   double * y_tilde=py->get_u_tilde();
00520   double * y_dot_tilde=py->get_u_dot_tilde();
00521   double * y_bar_tilde=py->get_u_bar_tilde();
00522   double * y_dot_bar_tilde=py->get_u_dot_bar_tilde();
00523   double * z_bar_tilde=pz->get_u_bar_tilde();
00524   double * z_dot_bar_tilde=pz->get_u_dot_bar_tilde();
00525   // Do second "reverse-reverse" pass calculations
00526 #if defined(PRINT_DERS)
00527  print_derivatives(funname,(f),(df1),
00528   (df2),(d2f11),(d2f12),(d2f22),
00529   (d3f111),(d3f112),(d3f122),
00530   (d3f222),1);
00531  print_derivatives(pz,"z");
00532  print_derivatives(px,"x");
00533  print_derivatives(py,"y");
00534 #endif
00535 
00536   for (size_t i=0;i<nvar;i++)
00537   {
00538     z_bar_tilde[i]=0;
00539     z_dot_bar_tilde[i]=0;
00540   }
00541 
00542   // start with x and add y
00543   for (size_t i=0;i<nvar;i++)
00544   {
00545     *x_tilde+=(d2f11)*zbar[i]*x_bar_tilde[i];
00546     z_bar_tilde[i]+=(df1)*x_bar_tilde[i];
00547     *y_tilde+=(d2f12)*zbar[i]*x_bar_tilde[i];
00548   }
00549 
00550   for (size_t i=0;i<nvar;i++)
00551   {
00552     *x_tilde+=(d2f11)*zdotbar[i]*x_dot_bar_tilde[i];
00553     *y_tilde+=(d2f12)*zdotbar[i]*x_dot_bar_tilde[i];
00554     z_dot_bar_tilde[i]+=(df1)*x_dot_bar_tilde[i];
00555   }
00556 
00557   for (size_t i=0;i<nvar;i++)
00558   {
00559     x_dot_tilde[i]+=(d2f11)*zdotbar[i]*x_bar_tilde[i];
00560     z_dot_bar_tilde[i]+=(d2f11)*xdot[i]*x_bar_tilde[i];
00561     *x_tilde+=(d3f111)*xdot[i]*zdotbar[i]*x_bar_tilde[i];
00562     *y_tilde+=(d3f112)*xdot[i]*zdotbar[i]*x_bar_tilde[i];
00563   }
00564   // start with y and add x
00565   for (size_t i=0;i<nvar;i++)
00566   {
00567     *y_tilde+=(d2f22)*zbar[i]*y_bar_tilde[i];
00568     *x_tilde+=(d2f12)*zbar[i]*y_bar_tilde[i];
00569     z_bar_tilde[i]+=(df2)*y_bar_tilde[i];
00570   }
00571 
00572   for (size_t i=0;i<nvar;i++)
00573   {
00574     *y_tilde+=(d2f22)*zdotbar[i]*y_dot_bar_tilde[i];
00575     *x_tilde+=(d2f12)*zdotbar[i]*y_dot_bar_tilde[i];
00576     z_dot_bar_tilde[i]+=(df2)*y_dot_bar_tilde[i];
00577   }
00578 
00579   for (size_t i=0;i<nvar;i++)
00580   {
00581     y_dot_tilde[i]+=(d2f22)*zdotbar[i]*y_bar_tilde[i];
00582     z_dot_bar_tilde[i]+=(d2f22)*ydot[i]*y_bar_tilde[i];
00583     *y_tilde+=(d3f222)*ydot[i]*zdotbar[i]*y_bar_tilde[i];
00584     *x_tilde+=(d3f122)*ydot[i]*zdotbar[i]*y_bar_tilde[i];
00585   }
00586   for (size_t i=0;i<nvar;i++)
00587   {
00588     *x_tilde+=(d3f112)*ydot[i]*zdotbar[i]*x_bar_tilde[i];
00589     *y_tilde+=(d3f122)*ydot[i]*zdotbar[i]*x_bar_tilde[i];
00590     y_dot_tilde[i]+=(d2f12)*zdotbar[i]*x_bar_tilde[i];
00591     z_dot_bar_tilde[i]+=(d2f12)*ydot[i]*x_bar_tilde[i];
00592   }
00593   for (size_t i=0;i<nvar;i++)
00594   {
00595     *x_tilde+=(d3f112)*xdot[i]*zdotbar[i]*y_bar_tilde[i];
00596     *y_tilde+=(d3f122)*xdot[i]*zdotbar[i]*y_bar_tilde[i];
00597     x_dot_tilde[i]+=(d2f12)*zdotbar[i]*y_bar_tilde[i];
00598     z_dot_bar_tilde[i]+=(d2f12)*xdot[i]*y_bar_tilde[i];
00599   }
00600 #if defined(__DERCHECK__)
00601   if (derchecker->node_number)
00602   {
00603     if (derchecker->counter == derchecker->node_number)
00604     {
00605       if (derchecker->pass_number==1) // increment the variable of interest
00606       {
00607         switch(derchecker->vartype)
00608         {
00609         case 1:
00610           if (!derchecker->dotflag)
00611             derchecker->der_value=
00612               px->u_bar_tilde[derchecker->index-1];
00613           else
00614             derchecker->der_value=
00615               px->u_dot_bar_tilde[derchecker->index-1];
00616           break;
00617         case 2:
00618           if (!derchecker->dotflag)
00619             derchecker->der_value=
00620               py->u_bar_tilde[derchecker->index-1];
00621           else
00622             derchecker->der_value=
00623               py->u_dot_bar_tilde[derchecker->index-1];
00624           break;
00625         case 3:
00626           if (!derchecker->dotflag)
00627             derchecker->der_value=
00628               pz->u_bar_tilde[derchecker->index-1];
00629           else
00630             derchecker->der_value=
00631               pz->u_dot_bar_tilde[derchecker->index-1];
00632           break;
00633         default:
00634           cerr << "Invalid index value for dercheck_index was "
00635                << derchecker->index << endl;
00636         }
00637       }
00638     }
00639   }
00640 #endif
00641 #if defined(PRINT_DERS)
00642  print_derivatives(pz,"z");
00643  print_derivatives(px,"x");
00644  print_derivatives(py,"y");
00645 #endif
00646 }
00647 
00652 void read_pass2_3_dvdv(void)
00653 {
00654   // We are going backword for bptr and forward for bptr2
00655   // the current entry+2 in bptr is the size of the record i.e
00656   // points to the next record
00657   int _nvar=df1b2variable::nvar;
00658 #ifndef OPT_LIB
00659   assert(_nvar >= 0);
00660 #endif
00661   size_t nvar = (size_t)_nvar;
00662   fixed_smartlist & nlist=f1b2gradlist->nlist;
00663   test_smartlist& list=f1b2gradlist->list;
00664    // nlist-=sizeof(int);
00665   // get record size
00666   int num_bytes=nlist.bptr->numbytes;
00667   // backup the size of the record
00668   list-=num_bytes;
00669   list.saveposition(); // save pointer to beginning of record;
00670   // save the pointer to the beginning of the record
00671   double xu;
00672   double yu;
00673   //df1b2_header x,z;
00674   //df1b2function2 * pf;
00675 
00676   // get info from tape1
00677   // get info from tape1
00678 #if defined(SAFE_ALL)
00679   checkidentiferstring("UZ",list);
00680 #endif
00681  /*
00682   df1b2_header * px=(df1b2_header *) list.bptr;
00683   list.bptr+=sizeof(df1b2_header);
00684   df1b2_header * py=(df1b2_header *) list.bptr;
00685   list.bptr+=sizeof(df1b2_header);
00686   df1b2_header * pz=(df1b2_header *) list.bptr;
00687   list.bptr+=sizeof(df1b2_header);
00688   pf=*(df1b2function2 **) list.bptr;
00689   list.bptr+=sizeof(char*);
00690   memcpy(&xu,list.bptr,sizeof(double));
00691   list.bptr+=sizeof(double);
00692   memcpy(&yu,list.bptr,sizeof(double));
00693   list.bptr+=sizeof(double);
00694   xdot=(double*)list.bptr;
00695   list.bptr+=nvar*sizeof(double);
00696   ydot=(double*)list.bptr;
00697  */
00698   df1b2_header * px=(df1b2_header *) list.bptr;
00699   list.bptr+=sizeof(df1b2_header);
00700   df1b2_header * py=(df1b2_header *) list.bptr;
00701   list.bptr+=sizeof(df1b2_header);
00702   df1b2_header * pz=(df1b2_header *) list.bptr;
00703   list.bptr+=sizeof(df1b2_header);
00704   //pf=*(df1b2function2 **) list.bptr;
00705   //list.bptr+=sizeof(char*);
00706 
00707   double df1=*(double*) list.bptr;
00708   list.bptr+=sizeof(double);
00709 
00710   double df2=*(double*) list.bptr;
00711   list.bptr+=sizeof(double);
00712 
00713   double d2f11=*(double*) list.bptr;
00714   list.bptr+=sizeof(double);
00715 
00716   double d2f12=*(double*) list.bptr;
00717   list.bptr+=sizeof(double);
00718 
00719   double d2f22=*(double*) list.bptr;
00720   list.bptr+=sizeof(double);
00721 
00722 #if defined(PRINT_DERS)
00723   double d3f111=*(double*) list.bptr;
00724 #endif
00725   list.bptr+=sizeof(double);
00726 
00727 #if defined(PRINT_DERS)
00728   double d3f112=*(double*) list.bptr;
00729 #endif
00730   list.bptr+=sizeof(double);
00731 
00732 #if defined(PRINT_DERS)
00733   double d3f122=*(double*) list.bptr;
00734 #endif
00735   list.bptr+=sizeof(double);
00736 
00737 #if defined(PRINT_DERS)
00738   double d3f222=*(double*) list.bptr;
00739 #endif
00740   list.bptr+=sizeof(double);
00741 
00742   memcpy(&xu,list.bptr,sizeof(double));
00743   list.bptr+=sizeof(double);
00744   memcpy(&yu,list.bptr,sizeof(double));
00745   list.bptr+=sizeof(double);
00746   double * xdot=(double*)list.bptr;
00747   list.bptr+=nvar*sizeof(double);
00748   double * ydot=(double*)list.bptr;
00749 
00750   list.restoreposition(); // save pointer to beginning of record;
00751 #if defined(PRINT_DERS)
00752  print_derivatives(funname,(f),(df1),
00753   (df2),(d2f11),(d2f12),(d2f22),
00754   (d3f111),(d3f112),(d3f122),
00755   (d3f222),1);
00756  print_derivatives(pz,"z");
00757  print_derivatives(px,"x");
00758  print_derivatives(py,"y");
00759 #endif
00760 
00761   *(px->u_tilde)+=(df1)* *(pz->u_tilde);
00762   *(py->u_tilde)+=(df2)* *(pz->u_tilde);
00763   for (size_t i=0;i<nvar;i++)
00764   {
00765     *(px->u_tilde)+=(d2f11)*xdot[i]*pz->u_dot_tilde[i];
00766     *(py->u_tilde)+=(d2f12)*xdot[i]*pz->u_dot_tilde[i];
00767     *(py->u_tilde)+=(d2f22)*ydot[i]*pz->u_dot_tilde[i];
00768     *(px->u_tilde)+=(d2f12)*ydot[i]*pz->u_dot_tilde[i];
00769   }
00770   for (size_t i=0;i<nvar;i++)
00771   {
00772     px->u_dot_tilde[i]+=(df1)*pz->u_dot_tilde[i];
00773     py->u_dot_tilde[i]+=(df2)*pz->u_dot_tilde[i];
00774   }
00775   *(pz->u_tilde)=0;
00776   for (size_t i=0;i<nvar;i++)
00777   {
00778     pz->u_dot_tilde[i]=0;
00779   }
00780 #if defined(PRINT_DERS)
00781  print_derivatives(pz,"z");
00782  print_derivatives(px,"x");
00783  print_derivatives(py,"y");
00784 #endif
00785 }