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