ADMB Documentation  11.1.2397
 All Classes Files Functions Variables Typedefs Friends Defines
df32fun1.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: df32fun1.cpp 2347 2014-09-15 22:54: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 
00044   size_t total_bytes=3*sizeof(df1b2_header)+sizeof(char*)
00045      +(2*nvar+11)*sizeof(double);
00046 
00047 // string identifier debug stuff
00048 #if defined(SAFE_ALL)
00049   char ids[]="UZ";
00050   size_t slen=strlen(ids);
00051   total_bytes+=slen;
00052 #endif
00053 
00054 #ifndef OPT_LIB
00055   assert(total_bytes <= INT_MAX);
00056 #endif
00057 
00058   list.check_buffer_size((int)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   test_smartlist& list=f1b2gradlist->list;
00138   //f1b2gradlist->nlist-=sizeof(int);
00139   int num_bytes=f1b2gradlist->nlist.bptr->numbytes;
00140   list-=num_bytes;
00141   list.saveposition(); // save pointer to beginning of record;
00142   double xu,yu;
00143   //ad_dstar xdot,ydot;
00144   //df1b2function2 * pf;
00145 
00146   // get info from tape1
00147 #if defined(SAFE_ALL)
00148   checkidentiferstring("UZ",f1b2gradlist->list);
00149 #endif
00150   char * bptr=f1b2gradlist->list.bptr;
00151   df1b2_header * px=(df1b2_header *) bptr;
00152   bptr+=sizeof(df1b2_header);
00153   df1b2_header * py=(df1b2_header *) bptr;
00154   bptr+=sizeof(df1b2_header);
00155   df1b2_header * pz=(df1b2_header *) bptr;
00156   bptr+=sizeof(df1b2_header);
00157   //pf=*(df1b2function2 **) bptr;
00158   //bptr+=sizeof(char*);
00159 
00160   double df1=*(double*) bptr;
00161   bptr+=sizeof(double);
00162 
00163   double df2=*(double*) bptr;
00164   bptr+=sizeof(double);
00165 
00166   double d2f11=*(double*) bptr;
00167   bptr+=sizeof(double);
00168 
00169   double d2f12=*(double*) bptr;
00170   bptr+=sizeof(double);
00171 
00172   double d2f22=*(double*) bptr;
00173   bptr+=sizeof(double);
00174 
00175 #if defined(PRINT_DERS)
00176   double d3f111=*(double*) bptr;
00177 #endif
00178   bptr+=sizeof(double);
00179 
00180 #if defined(PRINT_DERS)
00181   double d3f112=*(double*) bptr;
00182 #endif
00183   bptr+=sizeof(double);
00184 
00185 #if defined(PRINT_DERS)
00186   double d3f122=*(double*) bptr;
00187 #endif
00188   bptr+=sizeof(double);
00189 
00190 #if defined(PRINT_DERS)
00191   double d3f222=*(double*) bptr;
00192 #endif
00193   bptr+=sizeof(double);
00194 
00195   memcpy(&xu,bptr,sizeof(double));
00196   bptr+=sizeof(double);
00197   memcpy(&yu,bptr,sizeof(double));
00198   bptr+=sizeof(double);
00199   double * xdot=(double*)bptr;
00200   bptr+=nvar*sizeof(double);
00201   double * ydot=(double*)bptr;
00202 
00203   list.restoreposition(); // save pointer to beginning of record;
00204 
00205   // ****************************************************************
00206   // turn this off if no third derivatives are calculated
00207   // if (!no_third_derivatives)
00208   // {
00209   // save for second reverse pass
00210   // save identifier 1
00211      test_smartlist & list2 = f1b2gradlist->list2;
00212 
00213   size_t total_bytes=2*nvar*sizeof(double);
00214 // string identifier debug stuff
00215 #if defined(SAFE_ALL)
00216   char ids[]="FW";
00217   size_t slen=strlen(ids);
00218   total_bytes+=slen;
00219 #endif
00220 
00221 #ifndef OPT_LIB
00222   assert(total_bytes <= INT_MAX);
00223 #endif
00224 
00225   list2.check_buffer_size((int)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   int 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   test_smartlist & list=f1b2gradlist->list;
00394   // !!!!!!!!!!!!!!!!!!!!!! change here
00395   size_t total_bytes=3*sizeof(df1b2_header)+sizeof(char*)
00396      +(2*nvar+11)*sizeof(double);
00397   //int total_bytes=3*sizeof(df1b2_header)+sizeof(char*)
00398    // +2*(nvar+1)*sizeof(double);
00399 // string identifier debug stuff
00400 #if defined(SAFE_ALL)
00401   char ids[]="UZ";
00402   size_t slen=strlen(ids);
00403   total_bytes+=slen;
00404 #endif
00405 
00406 #ifndef OPT_LIB
00407   assert(total_bytes <= INT_MAX);
00408 #endif
00409 
00410   list.check_buffer_size((int)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   int i;
00537 
00538   for (i=0;i<nvar;i++)
00539   {
00540     z_bar_tilde[i]=0;
00541     z_dot_bar_tilde[i]=0;
00542   }
00543 
00544   // start with x and add y
00545   for (i=0;i<nvar;i++)
00546   {
00547     *x_tilde+=(d2f11)*zbar[i]*x_bar_tilde[i];
00548     z_bar_tilde[i]+=(df1)*x_bar_tilde[i];
00549     *y_tilde+=(d2f12)*zbar[i]*x_bar_tilde[i];
00550   }
00551 
00552   for (i=0;i<nvar;i++)
00553   {
00554     *x_tilde+=(d2f11)*zdotbar[i]*x_dot_bar_tilde[i];
00555     *y_tilde+=(d2f12)*zdotbar[i]*x_dot_bar_tilde[i];
00556     z_dot_bar_tilde[i]+=(df1)*x_dot_bar_tilde[i];
00557   }
00558 
00559   for (i=0;i<nvar;i++)
00560   {
00561     x_dot_tilde[i]+=(d2f11)*zdotbar[i]*x_bar_tilde[i];
00562     z_dot_bar_tilde[i]+=(d2f11)*xdot[i]*x_bar_tilde[i];
00563     *x_tilde+=(d3f111)*xdot[i]*zdotbar[i]*x_bar_tilde[i];
00564     *y_tilde+=(d3f112)*xdot[i]*zdotbar[i]*x_bar_tilde[i];
00565   }
00566   // start with y and add x
00567   for (i=0;i<nvar;i++)
00568   {
00569     *y_tilde+=(d2f22)*zbar[i]*y_bar_tilde[i];
00570     *x_tilde+=(d2f12)*zbar[i]*y_bar_tilde[i];
00571     z_bar_tilde[i]+=(df2)*y_bar_tilde[i];
00572   }
00573 
00574   for (i=0;i<nvar;i++)
00575   {
00576     *y_tilde+=(d2f22)*zdotbar[i]*y_dot_bar_tilde[i];
00577     *x_tilde+=(d2f12)*zdotbar[i]*y_dot_bar_tilde[i];
00578     z_dot_bar_tilde[i]+=(df2)*y_dot_bar_tilde[i];
00579   }
00580 
00581   for (i=0;i<nvar;i++)
00582   {
00583     y_dot_tilde[i]+=(d2f22)*zdotbar[i]*y_bar_tilde[i];
00584     z_dot_bar_tilde[i]+=(d2f22)*ydot[i]*y_bar_tilde[i];
00585     *y_tilde+=(d3f222)*ydot[i]*zdotbar[i]*y_bar_tilde[i];
00586     *x_tilde+=(d3f122)*ydot[i]*zdotbar[i]*y_bar_tilde[i];
00587   }
00588   for (i=0;i<nvar;i++)
00589   {
00590     *x_tilde+=(d3f112)*ydot[i]*zdotbar[i]*x_bar_tilde[i];
00591     *y_tilde+=(d3f122)*ydot[i]*zdotbar[i]*x_bar_tilde[i];
00592     y_dot_tilde[i]+=(d2f12)*zdotbar[i]*x_bar_tilde[i];
00593     z_dot_bar_tilde[i]+=(d2f12)*ydot[i]*x_bar_tilde[i];
00594   }
00595   for (i=0;i<nvar;i++)
00596   {
00597     *x_tilde+=(d3f112)*xdot[i]*zdotbar[i]*y_bar_tilde[i];
00598     *y_tilde+=(d3f122)*xdot[i]*zdotbar[i]*y_bar_tilde[i];
00599     x_dot_tilde[i]+=(d2f12)*zdotbar[i]*y_bar_tilde[i];
00600     z_dot_bar_tilde[i]+=(d2f12)*xdot[i]*y_bar_tilde[i];
00601   }
00602 #if defined(__DERCHECK__)
00603   if (derchecker->node_number)
00604   {
00605     if (derchecker->counter == derchecker->node_number)
00606     {
00607       if (derchecker->pass_number==1) // increment the variable of interest
00608       {
00609         switch(derchecker->vartype)
00610         {
00611         case 1:
00612           if (!derchecker->dotflag)
00613             derchecker->der_value=
00614               px->u_bar_tilde[derchecker->index-1];
00615           else
00616             derchecker->der_value=
00617               px->u_dot_bar_tilde[derchecker->index-1];
00618           break;
00619         case 2:
00620           if (!derchecker->dotflag)
00621             derchecker->der_value=
00622               py->u_bar_tilde[derchecker->index-1];
00623           else
00624             derchecker->der_value=
00625               py->u_dot_bar_tilde[derchecker->index-1];
00626           break;
00627         case 3:
00628           if (!derchecker->dotflag)
00629             derchecker->der_value=
00630               pz->u_bar_tilde[derchecker->index-1];
00631           else
00632             derchecker->der_value=
00633               pz->u_dot_bar_tilde[derchecker->index-1];
00634           break;
00635         default:
00636           cerr << "Invalid index value for dercheck_index was "
00637                << derchecker->index << endl;
00638         }
00639       }
00640     }
00641   }
00642 #endif
00643 #if defined(PRINT_DERS)
00644  print_derivatives(pz,"z");
00645  print_derivatives(px,"x");
00646  print_derivatives(py,"y");
00647 #endif
00648 }
00649 
00654 void read_pass2_3_dvdv(void)
00655 {
00656   // We are going backword for bptr and forward for bptr2
00657   // the current entry+2 in bptr is the size of the record i.e
00658   // points to the next record
00659   int nvar=df1b2variable::nvar;
00660   fixed_smartlist & nlist=f1b2gradlist->nlist;
00661   test_smartlist& list=f1b2gradlist->list;
00662    // nlist-=sizeof(int);
00663   // get record size
00664   int num_bytes=nlist.bptr->numbytes;
00665   // backup the size of the record
00666   list-=num_bytes;
00667   list.saveposition(); // save pointer to beginning of record;
00668   // save the pointer to the beginning of the record
00669   double xu;
00670   double yu;
00671   //df1b2_header x,z;
00672   //df1b2function2 * pf;
00673 
00674   // get info from tape1
00675   // get info from tape1
00676 #if defined(SAFE_ALL)
00677   checkidentiferstring("UZ",list);
00678 #endif
00679  /*
00680   df1b2_header * px=(df1b2_header *) list.bptr;
00681   list.bptr+=sizeof(df1b2_header);
00682   df1b2_header * py=(df1b2_header *) list.bptr;
00683   list.bptr+=sizeof(df1b2_header);
00684   df1b2_header * pz=(df1b2_header *) list.bptr;
00685   list.bptr+=sizeof(df1b2_header);
00686   pf=*(df1b2function2 **) list.bptr;
00687   list.bptr+=sizeof(char*);
00688   memcpy(&xu,list.bptr,sizeof(double));
00689   list.bptr+=sizeof(double);
00690   memcpy(&yu,list.bptr,sizeof(double));
00691   list.bptr+=sizeof(double);
00692   xdot=(double*)list.bptr;
00693   list.bptr+=nvar*sizeof(double);
00694   ydot=(double*)list.bptr;
00695  */
00696   df1b2_header * px=(df1b2_header *) list.bptr;
00697   list.bptr+=sizeof(df1b2_header);
00698   df1b2_header * py=(df1b2_header *) list.bptr;
00699   list.bptr+=sizeof(df1b2_header);
00700   df1b2_header * pz=(df1b2_header *) list.bptr;
00701   list.bptr+=sizeof(df1b2_header);
00702   //pf=*(df1b2function2 **) list.bptr;
00703   //list.bptr+=sizeof(char*);
00704 
00705   double df1=*(double*) list.bptr;
00706   list.bptr+=sizeof(double);
00707 
00708   double df2=*(double*) list.bptr;
00709   list.bptr+=sizeof(double);
00710 
00711   double d2f11=*(double*) list.bptr;
00712   list.bptr+=sizeof(double);
00713 
00714   double d2f12=*(double*) list.bptr;
00715   list.bptr+=sizeof(double);
00716 
00717   double d2f22=*(double*) list.bptr;
00718   list.bptr+=sizeof(double);
00719 
00720 #if defined(PRINT_DERS)
00721   double d3f111=*(double*) list.bptr;
00722 #endif
00723   list.bptr+=sizeof(double);
00724 
00725 #if defined(PRINT_DERS)
00726   double d3f112=*(double*) list.bptr;
00727 #endif
00728   list.bptr+=sizeof(double);
00729 
00730 #if defined(PRINT_DERS)
00731   double d3f122=*(double*) list.bptr;
00732 #endif
00733   list.bptr+=sizeof(double);
00734 
00735 #if defined(PRINT_DERS)
00736   double d3f222=*(double*) list.bptr;
00737 #endif
00738   list.bptr+=sizeof(double);
00739 
00740   memcpy(&xu,list.bptr,sizeof(double));
00741   list.bptr+=sizeof(double);
00742   memcpy(&yu,list.bptr,sizeof(double));
00743   list.bptr+=sizeof(double);
00744   double * xdot=(double*)list.bptr;
00745   list.bptr+=nvar*sizeof(double);
00746   double * ydot=(double*)list.bptr;
00747 
00748   list.restoreposition(); // save pointer to beginning of record;
00749   int i;
00750 #if defined(PRINT_DERS)
00751  print_derivatives(funname,(f),(df1),
00752   (df2),(d2f11),(d2f12),(d2f22),
00753   (d3f111),(d3f112),(d3f122),
00754   (d3f222),1);
00755  print_derivatives(pz,"z");
00756  print_derivatives(px,"x");
00757  print_derivatives(py,"y");
00758 #endif
00759 
00760   *(px->u_tilde)+=(df1)* *(pz->u_tilde);
00761   *(py->u_tilde)+=(df2)* *(pz->u_tilde);
00762   for (i=0;i<nvar;i++)
00763   {
00764     *(px->u_tilde)+=(d2f11)*xdot[i]*pz->u_dot_tilde[i];
00765     *(py->u_tilde)+=(d2f12)*xdot[i]*pz->u_dot_tilde[i];
00766     *(py->u_tilde)+=(d2f22)*ydot[i]*pz->u_dot_tilde[i];
00767     *(px->u_tilde)+=(d2f12)*ydot[i]*pz->u_dot_tilde[i];
00768   }
00769   for (i=0;i<nvar;i++)
00770   {
00771     px->u_dot_tilde[i]+=(df1)*pz->u_dot_tilde[i];
00772     py->u_dot_tilde[i]+=(df2)*pz->u_dot_tilde[i];
00773   }
00774   *(pz->u_tilde)=0;
00775   for (i=0;i<nvar;i++)
00776   {
00777     pz->u_dot_tilde[i]=0;
00778   }
00779 #if defined(PRINT_DERS)
00780  print_derivatives(pz,"z");
00781  print_derivatives(px,"x");
00782  print_derivatives(py,"y");
00783 #endif
00784 }