ADMB Documentation  11.1.2246
 All Classes Files Functions Variables Typedefs Friends Defines
df33fun1.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: df33fun1.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 #include "df33fun.h"
00013 
00014 void ad_read_pass2_dvdvdv(void);
00015 
00020  int df1b2_gradlist::write_pass1(const df1b2variable * _px,
00021    const df1b2variable * _py,const df1b2variable * pw,
00022    const df1b2variable * pz,
00023    double df_x, double df_y, double df_z,
00024    double df_xx, double df_xy,double df_xz,double df_yy,
00025    double df_yz,double df_zz,
00026    double df_xxx,
00027    double df_xxy,
00028    double df_xxz,
00029    double df_xyy,
00030    double df_xyz,
00031    double df_xzz,
00032    double df_yyy,
00033    double df_yyz,
00034    double df_yzz,
00035    double df_zzz)
00036  {
00037    ADUNCONST(df1b2variable*,px)
00038    ADUNCONST(df1b2variable*,py)
00039    ncount++;
00040 #if defined(CHECK_COUNT)
00041   if (ncount >= ncount_check)
00042     ncount_checker(ncount,ncount_check);
00043 #endif
00044    int nvar=df1b2variable::nvar;
00045 
00046    int total_bytes=4*sizeof(df1b2_header)+sizeof(char*)
00047      +(3*nvar+22)*sizeof(double);
00048 
00049 // string identifier debug stuff
00050 #if defined(SAFE_ALL)
00051   char ids[]="U8";
00052   int slen=strlen(ids);
00053   total_bytes+=slen;
00054 #endif
00055   list.check_buffer_size(total_bytes);
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*)(pw),sizeof(df1b2_header));
00065    memcpy(list,(df1b2_header*)(pz),sizeof(df1b2_header));
00066    //memcpy(list,&pf,sizeof(char *));
00067    //*(char**)(list.bptr)=(char*)pf;
00068 
00069   /*
00070    memcpy(list,&df_x,sizeof(double));
00071    memcpy(list,&df_y,sizeof(double));
00072    memcpy(list,&df_xx,sizeof(double));
00073    memcpy(list,&df_xy,sizeof(double));
00074    memcpy(list,&df_yy,sizeof(double));
00075    memcpy(list,&df_xxx,sizeof(double));
00076    memcpy(list,&df_xxy,sizeof(double));
00077    memcpy(list,&df_xyy,sizeof(double));
00078    memcpy(list,&df_yyy,sizeof(double));
00079   */
00080    memcpy(list,&df_x,sizeof(double));
00081    memcpy(list,&df_y,sizeof(double));
00082    memcpy(list,&df_z,sizeof(double));
00083    memcpy(list,&df_xx,sizeof(double));
00084    memcpy(list,&df_xy,sizeof(double));
00085    memcpy(list,&df_xz,sizeof(double));
00086    memcpy(list,&df_yy,sizeof(double));
00087    memcpy(list,&df_yz,sizeof(double));
00088    memcpy(list,&df_zz,sizeof(double));
00089    memcpy(list,&df_xxx,sizeof(double));
00090    memcpy(list,&df_xxy,sizeof(double));
00091    memcpy(list,&df_xxz,sizeof(double));
00092    memcpy(list,&df_xyy,sizeof(double));
00093    memcpy(list,&df_xyz,sizeof(double));
00094    memcpy(list,&df_xzz,sizeof(double));
00095    memcpy(list,&df_yyy,sizeof(double));
00096    memcpy(list,&df_yyz,sizeof(double));
00097    memcpy(list,&df_yzz,sizeof(double));
00098    memcpy(list,&df_zzz,sizeof(double));
00099 
00100    memcpy(list,px->get_u(),sizeof(double));
00101    memcpy(list,py->get_u(),sizeof(double));
00102    memcpy(list,pw->get_u(),sizeof(double));
00103    memcpy(list,px->get_u_dot(),nvar*sizeof(double));
00104    memcpy(list,py->get_u_dot(),nvar*sizeof(double));
00105    memcpy(list,pw->get_u_dot(),nvar*sizeof(double));
00106    // ***** write  record size
00107    nlist.bptr->numbytes=adptr_diff(list.bptr,tmpptr);
00108    nlist.bptr->pf=(ADrfptr)(&ad_read_pass2_dvdvdv);
00109    ++nlist;
00110    return 0;
00111  }
00112 
00113 
00114 void read_pass2_1_dvdvdv(void);
00115 void read_pass2_2_dvdvdv(void);
00116 void read_pass2_3_dvdvdv(void);
00117 
00122 void ad_read_pass2_dvdvdv(void)
00123 {
00124   switch(df1b2variable::passnumber)
00125   {
00126   case 1:
00127     read_pass2_1_dvdvdv();
00128     break;
00129   case 2:
00130     read_pass2_2_dvdvdv();
00131     break;
00132   case 3:
00133     read_pass2_3_dvdvdv();
00134     break;
00135   default:
00136     cerr << "illegal value for df1b2variable::pass = "
00137          << df1b2variable::passnumber << endl;
00138     exit(1);
00139   }
00140 }
00141 
00146 void read_pass2_1_dvdvdv(void)
00147 {
00148   // We are going backword for bptr and nbptr
00149   // and  forward for bptr2 and nbptr2
00150   // the current entry+2 in bptr is the size of the record i.e
00151   // points to the next record
00152   //char * bptr=f1b2gradlist->bptr;
00153   //char * bptr2=f1b2gradlist2->bptr;
00154   int nvar=df1b2variable::nvar;
00155   test_smartlist& list=f1b2gradlist->list;
00156   //f1b2gradlist->nlist-=sizeof(int);
00157   int num_bytes=f1b2gradlist->nlist.bptr->numbytes;
00158   list-=num_bytes;
00159   list.saveposition(); // save pointer to beginning of record;
00160   double xu,yu,wu;
00161   //ad_dstar xdot,ydot;
00162   //df1b2function2 * pf;
00163 
00164   // get info from tape1
00165 #if defined(SAFE_ARRAYS)
00166   checkidentiferstring("U8",f1b2gradlist->list);
00167 #endif
00168   char * bptr=f1b2gradlist->list.bptr;
00169   df1b2_header * px=(df1b2_header *) bptr;
00170   bptr+=sizeof(df1b2_header);
00171   df1b2_header * py=(df1b2_header *) bptr;
00172   bptr+=sizeof(df1b2_header);
00173   df1b2_header * pw=(df1b2_header *) bptr;
00174   bptr+=sizeof(df1b2_header);
00175   df1b2_header * pz=(df1b2_header *) bptr;
00176   bptr+=sizeof(df1b2_header);
00177   //pf=*(df1b2function2 **) bptr;
00178   //bptr+=sizeof(char*);
00179 
00180   double df1=*(double*) bptr;
00181   bptr+=sizeof(double);
00182 
00183   double df2=*(double*) bptr;
00184   bptr+=sizeof(double);
00185 
00186   double df3=*(double*) bptr;
00187   bptr+=sizeof(double);
00188 
00189   double d2f11=*(double*) bptr;
00190   bptr+=sizeof(double);
00191 
00192   double d2f12=*(double*) bptr;
00193   bptr+=sizeof(double);
00194 
00195   double d2f13=*(double*) bptr;
00196   bptr+=sizeof(double);
00197 
00198   double d2f22=*(double*) bptr;
00199   bptr+=sizeof(double);
00200 
00201   double d2f23=*(double*) bptr;
00202   bptr+=sizeof(double);
00203 
00204   double d2f33=*(double*) bptr;
00205   bptr+=sizeof(double);
00206 
00207 #if defined(PRINT_DERS)
00208   double d3f111=*(double*) bptr;
00209 #endif
00210   bptr+=sizeof(double);
00211 
00212 #if defined(PRINT_DERS)
00213   double d3f112=*(double*) bptr;
00214 #endif
00215   bptr+=sizeof(double);
00216 
00217 #if defined(PRINT_DERS)
00218   double d3f113=*(double*) bptr;
00219 #endif
00220   bptr+=sizeof(double);
00221 
00222 #if defined(PRINT_DERS)
00223   double d3f122=*(double*) bptr;
00224 #endif
00225   bptr+=sizeof(double);
00226 
00227 #if defined(PRINT_DERS)
00228   double d3f123=*(double*) bptr;
00229 #endif
00230   bptr+=sizeof(double);
00231 
00232 #if defined(PRINT_DERS)
00233   double d3f133=*(double*) bptr;
00234 #endif
00235   bptr+=sizeof(double);
00236 
00237 #if defined(PRINT_DERS)
00238   double d3f222=*(double*) bptr;
00239 #endif
00240   bptr+=sizeof(double);
00241 
00242 #if defined(PRINT_DERS)
00243   double d3f223=*(double*) bptr;
00244 #endif
00245   bptr+=sizeof(double);
00246 
00247 #if defined(PRINT_DERS)
00248   double d3f233=*(double*) bptr;
00249 #endif
00250   bptr+=sizeof(double);
00251 
00252 #if defined(PRINT_DERS)
00253   double d3f333=*(double*) bptr;
00254 #endif
00255   bptr+=sizeof(double);
00256 
00257   memcpy(&xu,bptr,sizeof(double));
00258   bptr+=sizeof(double);
00259   memcpy(&yu,bptr,sizeof(double));
00260   bptr+=sizeof(double);
00261   memcpy(&wu,bptr,sizeof(double));
00262   bptr+=sizeof(double);
00263   double * xdot=(double*)bptr;
00264   bptr+=nvar*sizeof(double);
00265   double * ydot=(double*)bptr;
00266   bptr+=nvar*sizeof(double);
00267   double * wdot=(double*)bptr;
00268 
00269   list.restoreposition(); // save pointer to beginning of record;
00270 
00271   // ****************************************************************
00272   // turn this off if no third derivatives are calculated
00273   // if (!no_third_derivatives)
00274   // {
00275   // save for second reverse pass
00276   // save identifier 1
00277      test_smartlist & list2 = f1b2gradlist->list2;
00278 
00279 
00280    int total_bytes=2*nvar*sizeof(double);
00281 // string identifier debug stuff
00282 #if defined(SAFE_ALL)
00283   char ids[]="FX";
00284   int slen=strlen(ids);
00285   total_bytes+=slen;
00286 #endif
00287   list2.check_buffer_size(total_bytes);
00288   void * tmpptr=list2.bptr;
00289 #if defined(SAFE_ALL)
00290   memcpy(list2,ids,slen);
00291 #endif
00292 
00293      fixed_smartlist2 & nlist2 = f1b2gradlist->nlist2;
00294      memcpy(list2,pz->get_u_bar(),nvar*sizeof(double));
00295      memcpy(list2,pz->get_u_dot_bar(),nvar*sizeof(double));
00296      *nlist2.bptr=adptr_diff(list2.bptr,tmpptr);
00297      ++nlist2;
00298   // }
00299   //
00300   // ****************************************************************
00301 #if defined(PRINT_DERS)
00302  print_derivatives(funname,(f),(df1),
00303   (df2),(d2f11),(d2f12),(d2f22),
00304   (d3f111),(d3f112),(d3f122),
00305   (d3f222),1);
00306  print_derivatives(pz,"z");
00307  print_derivatives(px,"x");
00308  print_derivatives(py,"y");
00309 #endif
00310 #if defined(__DERCHECK__)
00311   if (derchecker)
00312   if (derchecker->node_number)
00313   {
00314     if (derchecker->counter == derchecker->node_number)
00315     {
00316       switch (derchecker->pass_number) // increment the variable of interest
00317       {
00318       case 2:
00319         switch(derchecker->vartype)
00320         {
00321         case 1:
00322           if (!derchecker->dotflag)
00323             px->u_bar[derchecker->index-1]+=derchecker->delta;
00324           else
00325             px->u_dot_bar[derchecker->index-1]+=derchecker->delta;
00326           break;
00327         case 2:
00328           if (!derchecker->dotflag)
00329             py->u_bar[derchecker->index-1]+=derchecker->delta;
00330           else
00331             py->u_dot_bar[derchecker->index-1]+=derchecker->delta;
00332           break;
00333         case 3:
00334           if (!derchecker->dotflag)
00335             pz->u_bar[derchecker->index-1]+=derchecker->delta;
00336           else
00337             pz->u_dot_bar[derchecker->index-1]+=derchecker->delta;
00338           break;
00339         default:
00340           cerr << "Invalid index value for dercheck_index was "
00341                << derchecker->index << endl;
00342           break;
00343         }
00344         break;
00345       case 3:
00346         switch(derchecker->vartype)
00347         {
00348         case 1:
00349           if (!derchecker->dotflag)
00350             px->u_bar[derchecker->index-1]-=derchecker->delta;
00351           else
00352             px->u_dot_bar[derchecker->index-1]-=derchecker->delta;
00353           break;
00354         case 2:
00355           if (!derchecker->dotflag)
00356             py->u_bar[derchecker->index-1]-=derchecker->delta;
00357           else
00358             py->u_dot_bar[derchecker->index-1]-=derchecker->delta;
00359           break;
00360         case 3:
00361           if (!derchecker->dotflag)
00362             pz->u_bar[derchecker->index-1]-=derchecker->delta;
00363           else
00364             pz->u_dot_bar[derchecker->index-1]-=derchecker->delta;
00365           break;
00366         default:
00367           cerr << "Invalid index value for dercheck_index was "
00368                << derchecker->index << endl;
00369           break;
00370         }
00371         break;
00372       }
00373     }
00374   }
00375 #endif
00376 
00377   // Do first reverse pass calculations
00378   int i;
00379   for (i=0;i<nvar;i++)
00380   {
00381     px->u_bar[i]+=(df1)*pz->u_bar[i];
00382   }
00383   for (i=0;i<nvar;i++)
00384   {
00385     py->u_bar[i]+=(df2)*pz->u_bar[i];
00386   }
00387   for (i=0;i<nvar;i++)
00388   {
00389     pw->u_bar[i]+=(df3)*pz->u_bar[i];
00390   }
00391   for (i=0;i<nvar;i++)
00392   {
00393     px->u_bar[i]+=(d2f11)*xdot[i]*pz->u_dot_bar[i];
00394     px->u_bar[i]+=(d2f12)*ydot[i]*pz->u_dot_bar[i];
00395     px->u_bar[i]+=(d2f13)*wdot[i]*pz->u_dot_bar[i];
00396   }
00397   for (i=0;i<nvar;i++)
00398   {
00399     py->u_bar[i]+=(d2f12)*xdot[i]*pz->u_dot_bar[i];
00400     py->u_bar[i]+=(d2f22)*ydot[i]*pz->u_dot_bar[i];
00401     py->u_bar[i]+=(d2f13)*wdot[i]*pz->u_dot_bar[i];
00402   }
00403   for (i=0;i<nvar;i++)
00404   {
00405     pw->u_bar[i]+=(d2f13)*xdot[i]*pz->u_dot_bar[i];
00406     pw->u_bar[i]+=(d2f23)*ydot[i]*pz->u_dot_bar[i];
00407     pw->u_bar[i]+=(d2f33)*wdot[i]*pz->u_dot_bar[i];
00408   }
00409   for (i=0;i<nvar;i++)
00410   {
00411     px->u_dot_bar[i]+=(df1)*pz->u_dot_bar[i];
00412   }
00413   for (i=0;i<nvar;i++)
00414   {
00415     py->u_dot_bar[i]+=(df2)*pz->u_dot_bar[i];
00416   }
00417   for (i=0;i<nvar;i++)
00418   {
00419     pw->u_dot_bar[i]+=(df3)*pz->u_dot_bar[i];
00420   }
00421 
00422   for (i=0;i<nvar;i++)
00423   {
00424     pz->u_bar[i]=0;
00425   }
00426   for (i=0;i<nvar;i++)
00427   {
00428     pz->u_dot_bar[i]=0;
00429   }
00430 }
00431 
00436 void read_pass2_2_dvdvdv(void)
00437 {
00438   //const int nlist_record_size=sizeof(int)+sizeof(char*);
00439   // We are going forward for bptr and backword for bptr2
00440   //
00441   // list 1
00442   //
00443   int nvar=df1b2variable::nvar;
00444   test_smartlist & list=f1b2gradlist->list;
00445 
00446   int total_bytes=3*sizeof(df1b2_header)+sizeof(char*)
00447     +2*(nvar+1)*sizeof(double);
00448 // string identifier debug stuff
00449 #if defined(SAFE_ALL)
00450   char ids[]="U8";
00451   int slen=strlen(ids);
00452   total_bytes+=slen;
00453 #endif
00454   list.check_buffer_size(total_bytes);
00455 // end of string identifier debug stuff
00456 
00457   list.saveposition(); // save pointer to beginning of record;
00458   fixed_smartlist & nlist=f1b2gradlist->nlist;
00459    // nlist-=sizeof(int);
00460   // get record size
00461   int num_bytes=nlist.bptr->numbytes;
00462     // nlist+=nlist_record_size;
00463   //
00464   // list 2
00465   //
00466   test_smartlist & list2=f1b2gradlist->list2;
00467   fixed_smartlist2 & nlist2=f1b2gradlist->nlist2;
00468   // get record size
00469   int num_bytes2=*nlist2.bptr;
00470   --nlist2;
00471   // backup the size of the record
00472   list2-=num_bytes2;
00473   list2.saveposition(); // save pointer to beginning of record;
00474   // save the pointer to the beginning of the record
00475   // bptr and bptr2 now both point to the beginning of their records
00476 
00477   double xu,yu,wu;
00478   //df1b2_header x,z;
00479   //df1b2function2 * pf;
00480 
00481   // get info from tape1
00482   // get info from tape1
00483 #if defined(SAFE_ARRAYS)
00484   checkidentiferstring("U8",list);
00485   checkidentiferstring("FX",list2);
00486 #endif
00487   /*
00488   df1b2_header * px=(df1b2_header *) list.bptr;
00489   list.bptr+=sizeof(df1b2_header);
00490   df1b2_header * py=(df1b2_header *) list.bptr;
00491   list.bptr+=sizeof(df1b2_header);
00492   df1b2_header * pz=(df1b2_header *) list.bptr;
00493   list.bptr+=sizeof(df1b2_header);
00494   pf=*(df1b2function2 **) list.bptr;
00495   list.bptr+=sizeof(char*);
00496   memcpy(&xu,list.bptr,sizeof(double));
00497   list.bptr+=sizeof(double);
00498   memcpy(&yu,list.bptr,sizeof(double));
00499   list.bptr+=sizeof(double);
00500   xdot=(double*)list.bptr;
00501   list.bptr+=nvar*sizeof(double);
00502   ydot=(double*)list.bptr;
00503   */
00504   //char * bptr=f1b2gradlist->list.bptr;
00505   df1b2_header * px=(df1b2_header *) list.bptr;
00506   list.bptr+=sizeof(df1b2_header);
00507   df1b2_header * py=(df1b2_header *) list.bptr;
00508   list.bptr+=sizeof(df1b2_header);
00509   df1b2_header * pw=(df1b2_header *) list.bptr;
00510   list.bptr+=sizeof(df1b2_header);
00511   df1b2_header * pz=(df1b2_header *) list.bptr;
00512   list.bptr+=sizeof(df1b2_header);
00513 
00514   double df1=*(double*) list.bptr;
00515   list.bptr+=sizeof(double);
00516 
00517   double df2=*(double*) list.bptr;
00518   list.bptr+=sizeof(double);
00519 
00520   double df3=*(double*) list.bptr;
00521   list.bptr+=sizeof(double);
00522 
00523   double d2f11=*(double*) list.bptr;
00524   list.bptr+=sizeof(double);
00525 
00526   double d2f12=*(double*) list.bptr;
00527   list.bptr+=sizeof(double);
00528 
00529   double d2f13=*(double*) list.bptr;
00530   list.bptr+=sizeof(double);
00531 
00532   double d2f22=*(double*) list.bptr;
00533   list.bptr+=sizeof(double);
00534 
00535   double d2f23=*(double*) list.bptr;
00536   list.bptr+=sizeof(double);
00537 
00538   double d2f33=*(double*) list.bptr;
00539   list.bptr+=sizeof(double);
00540 
00541   double d3f111=*(double*) list.bptr;
00542   list.bptr+=sizeof(double);
00543 
00544   double d3f112=*(double*) list.bptr;
00545   list.bptr+=sizeof(double);
00546 
00547   double d3f113=*(double*) list.bptr;
00548   list.bptr+=sizeof(double);
00549 
00550   double d3f122=*(double*) list.bptr;
00551   list.bptr+=sizeof(double);
00552 
00553   double d3f123=*(double*) list.bptr;
00554   list.bptr+=sizeof(double);
00555 
00556   double d3f133=*(double*) list.bptr;
00557   list.bptr+=sizeof(double);
00558 
00559   double d3f222=*(double*) list.bptr;
00560   list.bptr+=sizeof(double);
00561 
00562   double d3f223=*(double*) list.bptr;
00563   list.bptr+=sizeof(double);
00564 
00565   double d3f233=*(double*) list.bptr;
00566   list.bptr+=sizeof(double);
00567 
00568   double d3f333=*(double*) list.bptr;
00569   list.bptr+=sizeof(double);
00570 
00571   memcpy(&xu,list.bptr,sizeof(double));
00572   list.bptr+=sizeof(double);
00573   memcpy(&yu,list.bptr,sizeof(double));
00574   list.bptr+=sizeof(double);
00575   memcpy(&wu,list.bptr,sizeof(double));
00576   list.bptr+=sizeof(double);
00577   double * xdot=(double*)list.bptr;
00578   list.bptr+=nvar*sizeof(double);
00579   double * ydot=(double*)list.bptr;
00580   list.bptr+=nvar*sizeof(double);
00581   double * wdot=(double*)list.bptr;
00582 
00583   list.restoreposition(num_bytes); // save pointer to beginning of record;
00584 
00585   double * zbar;
00586   double * zdotbar;
00587 
00588 
00589   zbar=(double*)list2.bptr;
00590   zdotbar=(double*)(list2.bptr+nvar*sizeof(double));
00591   list2.restoreposition(); // save pointer to beginning of record;
00592 
00593   double * x_tilde=px->get_u_tilde();
00594   double * x_dot_tilde=px->get_u_dot_tilde();
00595   double * x_bar_tilde=px->get_u_bar_tilde();
00596   double * x_dot_bar_tilde=px->get_u_dot_bar_tilde();
00597   double * y_tilde=py->get_u_tilde();
00598   double * y_dot_tilde=py->get_u_dot_tilde();
00599   double * y_bar_tilde=py->get_u_bar_tilde();
00600   double * y_dot_bar_tilde=py->get_u_dot_bar_tilde();
00601   double * w_tilde=pw->get_u_tilde();
00602   double * w_dot_tilde=pw->get_u_dot_tilde();
00603   double * w_bar_tilde=pw->get_u_bar_tilde();
00604   double * w_dot_bar_tilde=pw->get_u_dot_bar_tilde();
00605   double * z_bar_tilde=pz->get_u_bar_tilde();
00606   double * z_dot_bar_tilde=pz->get_u_dot_bar_tilde();
00607   // Do second "reverse-reverse" pass calculations
00608 #if defined(PRINT_DERS)
00609  print_derivatives(funname,(f),(df1),
00610   (df2),(d2f11),(d2f12),(d2f22),
00611   (d3f111),(d3f112),(d3f122),
00612   (d3f222),1);
00613  print_derivatives(pz,"z");
00614  print_derivatives(px,"x");
00615  print_derivatives(pw,"x");
00616  print_derivatives(py,"y");
00617 #endif
00618 
00619   int i;
00620 
00621   for (i=0;i<nvar;i++)
00622   {
00623     z_bar_tilde[i]=0;
00624     z_dot_bar_tilde[i]=0;
00625   }
00626 
00627   for (i=0;i<nvar;i++)
00628   {
00629     *x_tilde+=(d2f11)*zbar[i]*x_bar_tilde[i];
00630     *y_tilde+=(d2f12)*zbar[i]*x_bar_tilde[i];
00631     *w_tilde+=(d2f13)*zbar[i]*x_bar_tilde[i];
00632 
00633     *x_tilde+=(d2f12)*zbar[i]*y_bar_tilde[i];
00634     *y_tilde+=(d2f22)*zbar[i]*y_bar_tilde[i];
00635     *w_tilde+=(d2f23)*zbar[i]*y_bar_tilde[i];
00636 
00637     *x_tilde+=(d2f13)*zbar[i]*w_bar_tilde[i];
00638     *y_tilde+=(d2f23)*zbar[i]*w_bar_tilde[i];
00639     *w_tilde+=(d2f33)*zbar[i]*w_bar_tilde[i];
00640   }
00641 
00642   for (i=0;i<nvar;i++)
00643   {
00644     *x_tilde+=(d2f11)*zdotbar[i]*x_dot_bar_tilde[i];
00645     *y_tilde+=(d2f12)*zdotbar[i]*x_dot_bar_tilde[i];
00646     *w_tilde+=(d2f13)*zdotbar[i]*x_dot_bar_tilde[i];
00647 
00648     *x_tilde+=(d2f12)*zdotbar[i]*y_dot_bar_tilde[i];
00649     *y_tilde+=(d2f22)*zdotbar[i]*y_dot_bar_tilde[i];
00650     *w_tilde+=(d2f23)*zdotbar[i]*y_dot_bar_tilde[i];
00651 
00652     *x_tilde+=(d2f13)*zdotbar[i]*w_dot_bar_tilde[i];
00653     *y_tilde+=(d2f23)*zdotbar[i]*w_dot_bar_tilde[i];
00654     *w_tilde+=(d2f33)*zdotbar[i]*w_dot_bar_tilde[i];
00655   }
00656 
00657   for (i=0;i<nvar;i++)
00658   {
00659     *x_tilde+=(d3f111)*xdot[i]*zdotbar[i]*x_bar_tilde[i];
00660     *y_tilde+=(d3f112)*xdot[i]*zdotbar[i]*x_bar_tilde[i];
00661     *w_tilde+=(d3f113)*xdot[i]*zdotbar[i]*x_bar_tilde[i];
00662 
00663     *x_tilde+=(d3f112)*xdot[i]*zdotbar[i]*y_bar_tilde[i];
00664     *y_tilde+=(d3f122)*xdot[i]*zdotbar[i]*y_bar_tilde[i];
00665     *w_tilde+=(d3f123)*xdot[i]*zdotbar[i]*y_bar_tilde[i];
00666 
00667     *x_tilde+=(d3f113)*xdot[i]*zdotbar[i]*w_bar_tilde[i];
00668     *y_tilde+=(d3f123)*xdot[i]*zdotbar[i]*w_bar_tilde[i];
00669     *w_tilde+=(d3f133)*xdot[i]*zdotbar[i]*w_bar_tilde[i];
00670 
00671     *x_tilde+=(d3f112)*ydot[i]*zdotbar[i]*x_bar_tilde[i];
00672     *y_tilde+=(d3f122)*ydot[i]*zdotbar[i]*x_bar_tilde[i];
00673     *w_tilde+=(d3f123)*ydot[i]*zdotbar[i]*x_bar_tilde[i];
00674 
00675     *x_tilde+=(d3f122)*ydot[i]*zdotbar[i]*y_bar_tilde[i];
00676     *y_tilde+=(d3f222)*ydot[i]*zdotbar[i]*y_bar_tilde[i];
00677     *w_tilde+=(d3f223)*ydot[i]*zdotbar[i]*y_bar_tilde[i];
00678 
00679     *x_tilde+=(d3f123)*ydot[i]*zdotbar[i]*w_bar_tilde[i];
00680     *y_tilde+=(d3f223)*ydot[i]*zdotbar[i]*w_bar_tilde[i];
00681     *w_tilde+=(d3f233)*ydot[i]*zdotbar[i]*w_bar_tilde[i];
00682 
00683     *x_tilde+=(d3f113)*wdot[i]*zdotbar[i]*x_bar_tilde[i];
00684     *y_tilde+=(d3f123)*wdot[i]*zdotbar[i]*x_bar_tilde[i];
00685     *w_tilde+=(d3f133)*wdot[i]*zdotbar[i]*x_bar_tilde[i];
00686 
00687     *x_tilde+=(d3f123)*wdot[i]*zdotbar[i]*y_bar_tilde[i];
00688     *y_tilde+=(d3f223)*wdot[i]*zdotbar[i]*y_bar_tilde[i];
00689     *w_tilde+=(d3f233)*wdot[i]*zdotbar[i]*y_bar_tilde[i];
00690 
00691     *x_tilde+=(d3f133)*wdot[i]*zdotbar[i]*w_bar_tilde[i];
00692     *y_tilde+=(d3f233)*wdot[i]*zdotbar[i]*w_bar_tilde[i];
00693     *w_tilde+=(d3f333)*wdot[i]*zdotbar[i]*w_bar_tilde[i];
00694   }
00695 
00696   for (i=0;i<nvar;i++)
00697   {
00698     z_bar_tilde[i]+=(df1)*x_bar_tilde[i];
00699     z_bar_tilde[i]+=(df2)*y_bar_tilde[i];
00700     z_bar_tilde[i]+=(df3)*w_bar_tilde[i];
00701   }
00702 
00703   for (i=0;i<nvar;i++)
00704   {
00705     z_dot_bar_tilde[i]+=(df1)*x_dot_bar_tilde[i];
00706     z_dot_bar_tilde[i]+=(df2)*y_dot_bar_tilde[i];
00707     z_dot_bar_tilde[i]+=(df3)*w_dot_bar_tilde[i];
00708   }
00709 
00710   for (i=0;i<nvar;i++)
00711   {
00712     x_dot_tilde[i]+=(d2f11)*zdotbar[i]*x_bar_tilde[i];
00713     y_dot_tilde[i]+=(d2f12)*zdotbar[i]*x_bar_tilde[i];
00714     w_dot_tilde[i]+=(d2f13)*zdotbar[i]*x_bar_tilde[i];
00715 
00716     x_dot_tilde[i]+=(d2f12)*zdotbar[i]*y_bar_tilde[i];
00717     y_dot_tilde[i]+=(d2f22)*zdotbar[i]*y_bar_tilde[i];
00718     w_dot_tilde[i]+=(d2f23)*zdotbar[i]*y_bar_tilde[i];
00719 
00720     x_dot_tilde[i]+=(d2f13)*zdotbar[i]*w_bar_tilde[i];
00721     y_dot_tilde[i]+=(d2f23)*zdotbar[i]*w_bar_tilde[i];
00722     w_dot_tilde[i]+=(d2f33)*zdotbar[i]*w_bar_tilde[i];
00723   }
00724 
00725   for (i=0;i<nvar;i++)
00726   {
00727     z_dot_bar_tilde[i]+=(d2f11)*xdot[i]*x_bar_tilde[i];
00728     z_dot_bar_tilde[i]+=(d2f12)*xdot[i]*y_bar_tilde[i];
00729     z_dot_bar_tilde[i]+=(d2f13)*xdot[i]*w_bar_tilde[i];
00730 
00731     z_dot_bar_tilde[i]+=(d2f12)*ydot[i]*x_bar_tilde[i];
00732     z_dot_bar_tilde[i]+=(d2f22)*ydot[i]*y_bar_tilde[i];
00733     z_dot_bar_tilde[i]+=(d2f23)*ydot[i]*w_bar_tilde[i];
00734 
00735     z_dot_bar_tilde[i]+=(d2f13)*wdot[i]*x_bar_tilde[i];
00736     z_dot_bar_tilde[i]+=(d2f23)*wdot[i]*y_bar_tilde[i];
00737     z_dot_bar_tilde[i]+=(d2f33)*wdot[i]*w_bar_tilde[i];
00738   }
00739 
00740 
00741 #if defined(__DERCHECK__)
00742   if (derchecker->node_number)
00743   {
00744     if (derchecker->counter == derchecker->node_number)
00745     {
00746       if (derchecker->pass_number==1) // increment the variable of interest
00747       {
00748         switch(derchecker->vartype)
00749         {
00750         case 1:
00751           if (!derchecker->dotflag)
00752             derchecker->der_value=
00753               px->u_bar_tilde[derchecker->index-1];
00754           else
00755             derchecker->der_value=
00756               px->u_dot_bar_tilde[derchecker->index-1];
00757           break;
00758         case 2:
00759           if (!derchecker->dotflag)
00760             derchecker->der_value=
00761               py->u_bar_tilde[derchecker->index-1];
00762           else
00763             derchecker->der_value=
00764               py->u_dot_bar_tilde[derchecker->index-1];
00765           break;
00766         case 3:
00767           if (!derchecker->dotflag)
00768             derchecker->der_value=
00769               pz->u_bar_tilde[derchecker->index-1];
00770           else
00771             derchecker->der_value=
00772               pz->u_dot_bar_tilde[derchecker->index-1];
00773           break;
00774         default:
00775           cerr << "Invalid index value for dercheck_index was "
00776                << derchecker->index << endl;
00777         }
00778       }
00779     }
00780   }
00781 #endif
00782 #if defined(PRINT_DERS)
00783  print_derivatives(pz,"z");
00784  print_derivatives(px,"x");
00785  print_derivatives(py,"y");
00786 #endif
00787 }
00788 
00793 void read_pass2_3_dvdvdv(void)
00794 {
00795   // We are going backword for bptr and forward for bptr2
00796   // the current entry+2 in bptr is the size of the record i.e
00797   // points to the next record
00798   int nvar=df1b2variable::nvar;
00799   fixed_smartlist & nlist=f1b2gradlist->nlist;
00800   test_smartlist& list=f1b2gradlist->list;
00801    // nlist-=sizeof(int);
00802   // get record size
00803   int num_bytes=nlist.bptr->numbytes;
00804   // backup the size of the record
00805   list-=num_bytes;
00806   list.saveposition(); // save pointer to beginning of record;
00807   // save the pointer to the beginning of the record
00808   double xu;
00809   double yu;
00810   double wu;
00811   //df1b2_header x,z;
00812   //df1b2function2 * pf;
00813 
00814   // get info from tape1
00815   // get info from tape1
00816 #if defined(SAFE_ARRAYS)
00817   checkidentiferstring("U8",list);
00818 #endif
00819 
00820   df1b2_header * px=(df1b2_header *) list.bptr;
00821   list.bptr+=sizeof(df1b2_header);
00822   df1b2_header * py=(df1b2_header *) list.bptr;
00823   list.bptr+=sizeof(df1b2_header);
00824   df1b2_header * pw=(df1b2_header *) list.bptr;
00825   list.bptr+=sizeof(df1b2_header);
00826   df1b2_header * pz=(df1b2_header *) list.bptr;
00827   list.bptr+=sizeof(df1b2_header);
00828 
00829   double df1=*(double*) list.bptr;
00830   list.bptr+=sizeof(double);
00831 
00832   double df2=*(double*) list.bptr;
00833   list.bptr+=sizeof(double);
00834 
00835   double df3=*(double*) list.bptr;
00836   list.bptr+=sizeof(double);
00837 
00838   double d2f11=*(double*) list.bptr;
00839   list.bptr+=sizeof(double);
00840 
00841   double d2f12=*(double*) list.bptr;
00842   list.bptr+=sizeof(double);
00843 
00844   double d2f13=*(double*) list.bptr;
00845   list.bptr+=sizeof(double);
00846 
00847   double d2f22=*(double*) list.bptr;
00848   list.bptr+=sizeof(double);
00849 
00850   double d2f23=*(double*) list.bptr;
00851   list.bptr+=sizeof(double);
00852 
00853   double d2f33=*(double*) list.bptr;
00854   list.bptr+=sizeof(double);
00855 
00856 #if defined(PRINT_DERS)
00857   double d3f111=*(double*) list.bptr;
00858 #endif
00859   list.bptr+=sizeof(double);
00860 
00861 #if defined(PRINT_DERS)
00862   double d3f112=*(double*) list.bptr;
00863 #endif
00864   list.bptr+=sizeof(double);
00865 
00866 #if defined(PRINT_DERS)
00867   double d3f113=*(double*) list.bptr;
00868 #endif
00869   list.bptr+=sizeof(double);
00870 
00871 #if defined(PRINT_DERS)
00872   double d3f122=*(double*) list.bptr;
00873 #endif
00874   list.bptr+=sizeof(double);
00875 
00876 #if defined(PRINT_DERS)
00877   double d3f123=*(double*) list.bptr;
00878 #endif
00879   list.bptr+=sizeof(double);
00880 
00881 #if defined(PRINT_DERS)
00882   double d3f133=*(double*) list.bptr;
00883 #endif
00884   list.bptr+=sizeof(double);
00885 
00886 #if defined(PRINT_DERS)
00887   double d3f222=*(double*) list.bptr;
00888 #endif
00889   list.bptr+=sizeof(double);
00890 
00891 #if defined(PRINT_DERS)
00892   double d3f223=*(double*) list.bptr;
00893 #endif
00894   list.bptr+=sizeof(double);
00895 
00896 #if defined(PRINT_DERS)
00897   double d3f233=*(double*) list.bptr;
00898 #endif
00899   list.bptr+=sizeof(double);
00900 
00901 #if defined(PRINT_DERS)
00902   double d3f333=*(double*) list.bptr;
00903 #endif
00904   list.bptr+=sizeof(double);
00905 
00906   memcpy(&xu,list.bptr,sizeof(double));
00907   list.bptr+=sizeof(double);
00908   memcpy(&yu,list.bptr,sizeof(double));
00909   list.bptr+=sizeof(double);
00910   memcpy(&wu,list.bptr,sizeof(double));
00911   list.bptr+=sizeof(double);
00912   double * xdot=(double*)list.bptr;
00913   list.bptr+=nvar*sizeof(double);
00914   double * ydot=(double*)list.bptr;
00915   list.bptr+=nvar*sizeof(double);
00916   double * wdot=(double*)list.bptr;
00917 
00918   list.restoreposition(); // save pointer to beginning of record;
00919   int i;
00920 #if defined(PRINT_DERS)
00921  print_derivatives(funname,(f),(df1),
00922   (df2),(d2f11),(d2f12),(d2f22),
00923   (d3f111),(d3f112),(d3f122),
00924   (d3f222),1);
00925  print_derivatives(pz,"z");
00926  print_derivatives(px,"x");
00927  print_derivatives(py,"y");
00928  print_derivatives(pw,"y");
00929 #endif
00930 
00931   *(px->u_tilde)+=(df1)* *(pz->u_tilde);
00932   *(py->u_tilde)+=(df2)* *(pz->u_tilde);
00933   *(pw->u_tilde)+=(df3)* *(pz->u_tilde);
00934 
00935   for (i=0;i<nvar;i++)
00936   {
00937     *(px->u_tilde)+=(d2f11)*xdot[i]*pz->u_dot_tilde[i];
00938     *(py->u_tilde)+=(d2f12)*xdot[i]*pz->u_dot_tilde[i];
00939     *(pw->u_tilde)+=(d2f13)*xdot[i]*pz->u_dot_tilde[i];
00940 
00941     *(px->u_tilde)+=(d2f12)*ydot[i]*pz->u_dot_tilde[i];
00942     *(py->u_tilde)+=(d2f22)*ydot[i]*pz->u_dot_tilde[i];
00943     *(pw->u_tilde)+=(d2f23)*ydot[i]*pz->u_dot_tilde[i];
00944 
00945     *(px->u_tilde)+=(d2f13)*wdot[i]*pz->u_dot_tilde[i];
00946     *(py->u_tilde)+=(d2f23)*wdot[i]*pz->u_dot_tilde[i];
00947     *(pw->u_tilde)+=(d2f33)*wdot[i]*pz->u_dot_tilde[i];
00948   }
00949   for (i=0;i<nvar;i++)
00950   {
00951     px->u_dot_tilde[i]+=(df1)*pz->u_dot_tilde[i];
00952     py->u_dot_tilde[i]+=(df2)*pz->u_dot_tilde[i];
00953     pw->u_dot_tilde[i]+=(df3)*pz->u_dot_tilde[i];
00954   }
00955   *(pz->u_tilde)=0;
00956   for (i=0;i<nvar;i++)
00957   {
00958     pz->u_dot_tilde[i]=0;
00959   }
00960 
00961 
00962 #if defined(PRINT_DERS)
00963  print_derivatives(pz,"z");
00964  print_derivatives(px,"x");
00965  print_derivatives(py,"y");
00966  print_derivatives(pw,"y");
00967 #endif
00968 }