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