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