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