ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
df32fun1.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
11 #include <df1b2fun.h>
12 
13 #ifndef OPT_LIB
14  #include <cassert>
15  #include <climits>
16 #endif
17 
18 void ad_read_pass2_dvdv(void);
19 
25  const df1b2variable * _py,df1b2variable * pz,double df_x,
26  double df_y,
27  double df_xx,
28  double df_xy,
29  double df_yy,
30  double df_xxx,
31  double df_xxy,
32  double df_xyy,
33  double df_yyy)
34  {
37  ncount++;
38 #if defined(CHECK_COUNT)
39  if (ncount >= ncount_check)
40  ncount_checker(ncount,ncount_check);
41 #endif
42  size_t nvar=df1b2variable::nvar;
43 
44  size_t total_bytes=3*sizeof(df1b2_header)+sizeof(char*)
45  +(2*nvar+11)*sizeof(double);
46 
47 // string identifier debug stuff
48 #if defined(SAFE_ALL)
49  char ids[]="UZ";
50  size_t slen=strlen(ids);
51  total_bytes+=slen;
52 #endif
53 
54  list.check_buffer_size(total_bytes);
55 
56  void * tmpptr=list.bptr;
57 #if defined(SAFE_ALL)
58  memcpy(list,ids,slen);
59 #endif
60 // end of string identifier debug stuff
61 
62  memcpy(list,(df1b2_header*)(px),sizeof(df1b2_header));
63  memcpy(list,(df1b2_header*)(py),sizeof(df1b2_header));
64  memcpy(list,(df1b2_header*)(pz),sizeof(df1b2_header));
65  //memcpy(list,&pf,sizeof(char *));
66  //*(char**)(list.bptr)=(char*)pf;
67 
68  size_t sizeofdouble = sizeof(double);
69 
70  memcpy(list,&df_x,sizeofdouble);
71  memcpy(list,&df_y,sizeofdouble);
72  memcpy(list,&df_xx,sizeofdouble);
73  memcpy(list,&df_xy,sizeofdouble);
74  memcpy(list,&df_yy,sizeofdouble);
75  memcpy(list,&df_xxx,sizeofdouble);
76  memcpy(list,&df_xxy,sizeofdouble);
77  memcpy(list,&df_xyy,sizeofdouble);
78  memcpy(list,&df_yyy,sizeofdouble);
79 
80  memcpy(list,px->get_u(),sizeofdouble);
81  memcpy(list,py->get_u(),sizeofdouble);
82  memcpy(list,px->get_u_dot(),nvar*sizeofdouble);
83  memcpy(list,py->get_u_dot(),nvar*sizeofdouble);
84  // ***** write record size
87  ++nlist;
88  return 0;
89  }
90 
91 
92 void read_pass2_1_dvdv(void);
93 void read_pass2_2_dvdv(void);
94 void read_pass2_3_dvdv(void);
95 
101 {
103  {
104  case 1:
106  break;
107  case 2:
109  break;
110  case 3:
112  break;
113  default:
114  cerr << "illegal value for df1b2variable::pass = "
116  ad_exit(1);
117  }
118 }
119 
125 {
126  // We are going backword for bptr and nbptr
127  // and forward for bptr2 and nbptr2
128  // the current entry+2 in bptr is the size of the record i.e
129  // points to the next record
130  //char * bptr=f1b2gradlist->bptr;
131  //char * bptr2=f1b2gradlist2->bptr;
132  size_t nvar = df1b2variable::nvar;
134  //f1b2gradlist->nlist-=sizeof(int);
135  int num_bytes=f1b2gradlist->nlist.bptr->numbytes;
136  list-=num_bytes;
137  list.saveposition(); // save pointer to beginning of record;
138  double xu,yu;
139  //ad_dstar xdot,ydot;
140  //df1b2function2 * pf;
141 
142  // get info from tape1
143 #if defined(SAFE_ALL)
145 #endif
146  char * bptr=f1b2gradlist->list.bptr;
147  df1b2_header * px=(df1b2_header *) bptr;
148  bptr+=sizeof(df1b2_header);
149  df1b2_header * py=(df1b2_header *) bptr;
150  bptr+=sizeof(df1b2_header);
151  df1b2_header * pz=(df1b2_header *) bptr;
152  bptr+=sizeof(df1b2_header);
153  //pf=*(df1b2function2 **) bptr;
154  //bptr+=sizeof(char*);
155 
156  double df1=*(double*) bptr;
157  bptr+=sizeof(double);
158 
159  double df2=*(double*) bptr;
160  bptr+=sizeof(double);
161 
162  double d2f11=*(double*) bptr;
163  bptr+=sizeof(double);
164 
165  double d2f12=*(double*) bptr;
166  bptr+=sizeof(double);
167 
168  double d2f22=*(double*) bptr;
169  bptr+=sizeof(double);
170 
171 #if defined(PRINT_DERS)
172  double d3f111=*(double*) bptr;
173 #endif
174  bptr+=sizeof(double);
175 
176 #if defined(PRINT_DERS)
177  double d3f112=*(double*) bptr;
178 #endif
179  bptr+=sizeof(double);
180 
181 #if defined(PRINT_DERS)
182  double d3f122=*(double*) bptr;
183 #endif
184  bptr+=sizeof(double);
185 
186 #if defined(PRINT_DERS)
187  double d3f222=*(double*) bptr;
188 #endif
189  bptr+=sizeof(double);
190 
191  memcpy(&xu,bptr,sizeof(double));
192  bptr+=sizeof(double);
193  memcpy(&yu,bptr,sizeof(double));
194  bptr+=sizeof(double);
195  double * xdot=(double*)bptr;
196  bptr+=nvar*sizeof(double);
197  double * ydot=(double*)bptr;
198 
199  list.restoreposition(); // save pointer to beginning of record;
200 
201  // ****************************************************************
202  // turn this off if no third derivatives are calculated
203  // if (!no_third_derivatives)
204  // {
205  // save for second reverse pass
206  // save identifier 1
207  test_smartlist & list2 = f1b2gradlist->list2;
208 
209  size_t total_bytes=2*nvar*sizeof(double);
210 // string identifier debug stuff
211 #if defined(SAFE_ALL)
212  char ids[]="FW";
213  size_t slen=strlen(ids);
214  total_bytes+=slen;
215 #endif
216 
217  list2.check_buffer_size(total_bytes);
218  void * tmpptr=list2.bptr;
219 #if defined(SAFE_ALL)
220  memcpy(list2,ids,slen);
221 #endif
222 
224  size_t sizeofdouble = sizeof(double);
225  memcpy(list2,pz->get_u_bar(),nvar*sizeofdouble);
226  memcpy(list2,pz->get_u_dot_bar(),nvar*sizeofdouble);
227  *nlist2.bptr=adptr_diff(list2.bptr,tmpptr);
228  ++nlist2;
229  // }
230  //
231  // ****************************************************************
232 #if defined(PRINT_DERS)
233  print_derivatives(funname,(f),(df1),
234  (df2),(d2f11),(d2f12),(d2f22),
235  (d3f111),(d3f112),(d3f122),
236  (d3f222),1);
237  print_derivatives(pz,"z");
238  print_derivatives(px,"x");
239  print_derivatives(py,"y");
240 #endif
241 #if defined(__DERCHECK__)
242  if (derchecker)
243  if (derchecker->node_number)
244  {
245  if (derchecker->counter == derchecker->node_number)
246  {
247  switch (derchecker->pass_number) // increment the variable of interest
248  {
249  case 2:
250  switch(derchecker->vartype)
251  {
252  case 1:
253  if (!derchecker->dotflag)
254  px->u_bar[derchecker->index-1]+=derchecker->delta;
255  else
256  px->u_dot_bar[derchecker->index-1]+=derchecker->delta;
257  break;
258  case 2:
259  if (!derchecker->dotflag)
260  py->u_bar[derchecker->index-1]+=derchecker->delta;
261  else
262  py->u_dot_bar[derchecker->index-1]+=derchecker->delta;
263  break;
264  case 3:
265  if (!derchecker->dotflag)
266  pz->u_bar[derchecker->index-1]+=derchecker->delta;
267  else
268  pz->u_dot_bar[derchecker->index-1]+=derchecker->delta;
269  break;
270  default:
271  cerr << "Invalid index value for dercheck_index was "
272  << derchecker->index << endl;
273  break;
274  }
275  break;
276  case 3:
277  switch(derchecker->vartype)
278  {
279  case 1:
280  if (!derchecker->dotflag)
281  px->u_bar[derchecker->index-1]-=derchecker->delta;
282  else
283  px->u_dot_bar[derchecker->index-1]-=derchecker->delta;
284  break;
285  case 2:
286  if (!derchecker->dotflag)
287  py->u_bar[derchecker->index-1]-=derchecker->delta;
288  else
289  py->u_dot_bar[derchecker->index-1]-=derchecker->delta;
290  break;
291  case 3:
292  if (!derchecker->dotflag)
293  pz->u_bar[derchecker->index-1]-=derchecker->delta;
294  else
295  pz->u_dot_bar[derchecker->index-1]-=derchecker->delta;
296  break;
297  default:
298  cerr << "Invalid index value for dercheck_index was "
299  << derchecker->index << endl;
300  break;
301  }
302  break;
303  }
304  }
305  }
306 #endif
307 
308  // Do first reverse pass calculations
309  size_t i;
310  double* px_u_bari = px->u_bar;
311  double* pz_u_bari = pz->u_bar;
312  for (i=0;i<nvar;i++)
313  {
314  *px_u_bari += df1 * *pz_u_bari;
315 
316  ++px_u_bari;
317  ++pz_u_bari;
318  }
319  double* py_u_bari = py->u_bar;
320  pz_u_bari = pz->u_bar;
321  for (i=0;i<nvar;i++)
322  {
323  *py_u_bari += df2 * *pz_u_bari;
324 
325  ++py_u_bari;
326  ++pz_u_bari;
327  }
328  px_u_bari = px->u_bar;
329  double* pz_u_dot_bari = pz->u_dot_bar;
330  double* xdoti = xdot;
331  double* ydoti = ydot;
332  for (i=0;i<nvar;i++)
333  {
334  *px_u_bari += d2f11 * *xdoti * *pz_u_dot_bari;
335  *px_u_bari += d2f12 * *ydoti * *pz_u_dot_bari;
336 
337  ++px_u_bari;
338  ++pz_u_dot_bari;
339  ++xdoti;
340  ++ydoti;
341 
342 #if defined(ADDEBUG_PRINT)
343  cout << px->u_bar[i] << " " << pz->u_dot_bar[i] << " " << addebug_count
344  << endl;
345 #endif
346  }
347  py_u_bari = py->u_bar;
348  xdoti = xdot;
349  ydoti = ydot;
350  pz_u_dot_bari = pz->u_dot_bar;
351  for (i=0;i<nvar;i++)
352  {
353  //py->u_bar[i]+=(d2f22)(*(px->u),*(py->u))*ydot[i]*pz->u_dot_bar[i];
354  //py->u_bar[i]+=(d2f12)(*(px->u),*(py->u))*xdot[i]*pz->u_dot_bar[i];
355  *py_u_bari += d2f22 * *ydoti * *pz_u_dot_bari;
356  *py_u_bari += d2f12 * *xdoti * *pz_u_dot_bari;
357 
358  ++xdoti;
359  ++ydoti;
360  ++py_u_bari;
361  ++pz_u_dot_bari;
362 
363 #if defined(ADDEBUG_PRINT)
364  cout << py->u_bar[i] << " " << pz->u_dot_bar[i] << " " << addebug_count
365  << endl;
366 #endif
367  }
368  double* px_u_dot_bari = px->u_dot_bar;
369  pz_u_dot_bari = pz->u_dot_bar;
370  for (i=0;i<nvar;i++)
371  {
372  //px->u_dot_bar[i]+=(df1)(*(px->u),*(py->u))*pz->u_dot_bar[i];
373  *px_u_dot_bari += df1 * *pz_u_dot_bari;
374 
375  ++px_u_dot_bari;
376  ++pz_u_dot_bari;
377 #if defined(ADDEBUG_PRINT)
378  cout << px->u_dot_bar[i] << " " << addebug_count << endl;
379  cout << pz->u_dot_bar[i] << " " << addebug_count << endl;
380 #endif
381  }
382  pz_u_dot_bari = pz->u_dot_bar;
383  double* py_u_dot_bari = py->u_dot_bar;
384  for (i=0;i<nvar;i++)
385  {
386  *py_u_dot_bari += df2 * *pz_u_dot_bari;
387 
388  ++py_u_dot_bari;
389  ++pz_u_dot_bari;
390 #if defined(ADDEBUG_PRINT)
391  cout << py->u_dot_bar[i] << " " << addebug_count << endl;
392  cout << pz->u_dot_bar[i] << " " << addebug_count << endl;
393 #endif
394  }
395 
396  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
397  memset(pz->u_dot_bar, 0, nvar * sizeofdouble);
398  memset(pz->u_bar, 0, nvar * sizeofdouble);
399 
400 #if defined(PRINT_DERS)
401  print_derivatives(pz,"z");
402  print_derivatives(px,"x");
403  print_derivatives(py,"y");
404 #endif
405 }
406 
412 {
413  //const int nlist_record_size=sizeof(int)+sizeof(char*);
414  // We are going forward for bptr and backword for bptr2
415  //
416  // list 1
417  //
418  unsigned int nvar=df1b2variable::nvar;
420  // !!!!!!!!!!!!!!!!!!!!!! change here
421  size_t total_bytes=3*sizeof(df1b2_header)+sizeof(char*)
422  +(2*nvar+11)*sizeof(double);
423  //int total_bytes=3*sizeof(df1b2_header)+sizeof(char*)
424  // +2*(nvar+1)*sizeof(double);
425 // string identifier debug stuff
426 #if defined(SAFE_ALL)
427  char ids[]="UZ";
428  size_t slen=strlen(ids);
429  total_bytes+=slen;
430 #endif
431 
432  list.check_buffer_size(total_bytes);
433 
434 // end of string identifier debug stuff
435 
436  list.saveposition(); // save pointer to beginning of record;
438  // nlist-=sizeof(int);
439  // get record size
440  int num_bytes=nlist.bptr->numbytes;
441  // nlist+=nlist_record_size;
442  //
443  // list 2
444  //
447  // get record size
448  int num_bytes2=*nlist2.bptr;
449  --nlist2;
450  // backup the size of the record
451  list2-=num_bytes2;
452  list2.saveposition(); // save pointer to beginning of record;
453  // save the pointer to the beginning of the record
454  // bptr and bptr2 now both point to the beginning of their records
455 
456  double xu,yu;
457  //df1b2_header x,z;
458  //df1b2function2 * pf;
459 
460  // get info from tape1
461  // get info from tape1
462 #if defined(SAFE_ALL)
463  checkidentiferstring("UZ",list);
464  checkidentiferstring("FW",list2);
465 #endif
466  /*
467  df1b2_header * px=(df1b2_header *) list.bptr;
468  list.bptr+=sizeof(df1b2_header);
469  df1b2_header * py=(df1b2_header *) list.bptr;
470  list.bptr+=sizeof(df1b2_header);
471  df1b2_header * pz=(df1b2_header *) list.bptr;
472  list.bptr+=sizeof(df1b2_header);
473  pf=*(df1b2function2 **) list.bptr;
474  list.bptr+=sizeof(char*);
475  memcpy(&xu,list.bptr,sizeof(double));
476  list.bptr+=sizeof(double);
477  memcpy(&yu,list.bptr,sizeof(double));
478  list.bptr+=sizeof(double);
479  xdot=(double*)list.bptr;
480  list.bptr+=nvar*sizeof(double);
481  ydot=(double*)list.bptr;
482  */
483  //char * bptr=f1b2gradlist->list.bptr;
484  df1b2_header * px=(df1b2_header *) list.bptr;
485  list.bptr+=sizeof(df1b2_header);
486  df1b2_header * py=(df1b2_header *) list.bptr;
487  list.bptr+=sizeof(df1b2_header);
488  df1b2_header * pz=(df1b2_header *) list.bptr;
489  list.bptr+=sizeof(df1b2_header);
490  //pf=*(df1b2function2 **) list.bptr;
491  //list.bptr+=sizeof(char*);
492 
493  constexpr size_t sizeofdouble = sizeof(double);
494  double df1=*(double*) list.bptr;
495  list.bptr+=sizeof(double);
496 
497  double df2=*(double*) list.bptr;
498  list.bptr+=sizeofdouble;
499 
500  double d2f11=*(double*) list.bptr;
501  list.bptr+=sizeofdouble;
502 
503  double d2f12=*(double*) list.bptr;
504  list.bptr+=sizeofdouble;
505 
506  double d2f22=*(double*) list.bptr;
507  list.bptr+=sizeofdouble;
508 
509  double d3f111=*(double*) list.bptr;
510  list.bptr+=sizeofdouble;
511 
512  double d3f112=*(double*) list.bptr;
513  list.bptr+=sizeofdouble;
514 
515  double d3f122=*(double*) list.bptr;
516  list.bptr+=sizeofdouble;
517 
518  double d3f222=*(double*) list.bptr;
519  list.bptr+=sizeofdouble;
520 
521  memcpy(&xu,list.bptr,sizeofdouble);
522  list.bptr+=sizeofdouble;
523  memcpy(&yu,list.bptr,sizeofdouble);
524  list.bptr+=sizeofdouble;
525  double * xdot=(double*)list.bptr;
526  list.bptr+=nvar*sizeofdouble;
527  double * ydot=(double*)list.bptr;
528 
529  list.restoreposition(num_bytes); // save pointer to beginning of record;
530 
531  double * zbar;
532  double * zdotbar;
533 
534  zbar=(double*)list2.bptr;
535  zdotbar=(double*)(list2.bptr+nvar*sizeofdouble);
536  list2.restoreposition(); // save pointer to beginning of record;
537 
538  double * x_tilde=px->get_u_tilde();
539  double * x_dot_tilde=px->get_u_dot_tilde();
540  double * x_bar_tilde=px->get_u_bar_tilde();
541  double * x_dot_bar_tilde=px->get_u_dot_bar_tilde();
542  double * y_tilde=py->get_u_tilde();
543  double * y_dot_tilde=py->get_u_dot_tilde();
544  double * y_bar_tilde=py->get_u_bar_tilde();
545  double * y_dot_bar_tilde=py->get_u_dot_bar_tilde();
546  double * z_bar_tilde=pz->get_u_bar_tilde();
547  double * z_dot_bar_tilde=pz->get_u_dot_bar_tilde();
548  // Do second "reverse-reverse" pass calculations
549 #if defined(PRINT_DERS)
550  print_derivatives(funname,(f),(df1),
551  (df2),(d2f11),(d2f12),(d2f22),
552  (d3f111),(d3f112),(d3f122),
553  (d3f222),1);
554  print_derivatives(pz,"z");
555  print_derivatives(px,"x");
556  print_derivatives(py,"y");
557 #endif
558 
559  memset(z_bar_tilde, 0, nvar * sizeofdouble);
560  memset(z_dot_bar_tilde, 0, nvar * sizeofdouble);
561 
562 
563  // start with x and add y
564  double* x_bar_tildei = x_bar_tilde;
565  double* zbari = zbar;
566  double* z_bar_tildei = z_bar_tilde;
567  for (size_t i=0;i<nvar;i++)
568  {
569  *x_tilde += d2f11 * *zbari * *x_bar_tildei;
570  *z_bar_tildei += df1 * *x_bar_tildei;
571  *y_tilde += d2f12 * *zbari * *x_bar_tildei;
572 
573  ++x_bar_tildei;
574  ++zbari;
575  ++z_bar_tildei;
576  }
577 
578  double* x_dot_bar_tildei = x_dot_bar_tilde;
579  double* zdotbari = zdotbar;
580  double* z_dot_bar_tildei = z_dot_bar_tilde;
581  for (size_t i=0;i<nvar;i++)
582  {
583  *x_tilde += d2f11 * *zdotbari * *x_dot_bar_tildei;
584  *y_tilde += d2f12 * *zdotbari * *x_dot_bar_tildei;
585  *z_dot_bar_tildei += df1 * *x_dot_bar_tildei;
586 
587  ++x_dot_bar_tildei;
588  ++zdotbari;
589  ++z_dot_bar_tildei;
590  }
591  x_bar_tildei = x_bar_tilde;
592  zdotbari = zdotbar;
593  double* xdoti = xdot;
594  double* x_dot_tildei = x_dot_tilde;
595  z_dot_bar_tildei = z_dot_bar_tilde;
596  for (size_t i=0;i<nvar;i++)
597  {
598  *x_dot_tildei += d2f11 * *zdotbari * *x_bar_tildei;
599  *z_dot_bar_tildei += d2f11 * *xdoti * *x_bar_tildei;
600  *x_tilde += d3f111 * *xdoti * *zdotbari * *x_bar_tildei;
601  *y_tilde += d3f112 * *xdoti * *zdotbari * *x_bar_tildei;
602 
603  ++x_bar_tildei;
604  ++zdotbari;
605  ++xdoti;
606  ++x_dot_tildei;
607  ++z_dot_bar_tildei;
608  }
609  // start with y and add x
610  double* y_bar_tildei = y_bar_tilde;
611  zbari = zbar;
612  z_bar_tildei = z_bar_tilde;
613  for (size_t i=0;i<nvar;i++)
614  {
615  *y_tilde += d2f22 * *zbari * *y_bar_tildei;
616  *x_tilde += d2f12 * *zbari * *y_bar_tildei;
617  *z_bar_tildei += df2 * *y_bar_tildei;
618 
619  ++y_bar_tildei;
620  ++zbari;
621  ++z_bar_tildei;
622  }
623  double* y_dot_bar_tildei = y_dot_bar_tilde;
624  zdotbari = zdotbar;
625  z_dot_bar_tildei = z_dot_bar_tilde;
626  for (size_t i=0;i<nvar;i++)
627  {
628  *y_tilde += d2f22 * *zdotbari * *y_dot_bar_tildei;
629  *x_tilde += d2f12 * *zdotbari * *y_dot_bar_tildei;
630  *z_dot_bar_tildei += df2 * *y_dot_bar_tildei;
631 
632  ++y_dot_bar_tildei;
633  ++zdotbari;
634  ++z_dot_bar_tildei;
635  }
636  y_bar_tildei = y_bar_tilde;
637  zdotbari = zdotbar;
638  double* ydoti = ydot;
639  double* y_dot_tildei = y_dot_tilde;
640  z_dot_bar_tildei = z_dot_bar_tilde;
641  for (size_t i=0;i<nvar;i++)
642  {
643  *y_dot_tildei += d2f22 * *zdotbari * *y_bar_tildei;
644  *z_dot_bar_tildei += d2f22 * *ydoti * *y_bar_tildei;
645  *y_tilde += d3f222 * *ydoti * *zdotbari * *y_bar_tildei;
646  *x_tilde += d3f122 * *ydoti * *zdotbari * *y_bar_tildei;
647 
648  ++y_bar_tildei;
649  ++zdotbari;
650  ++ydoti;
651  ++y_dot_tildei;
652  ++z_dot_bar_tildei;
653  }
654  x_bar_tildei = x_bar_tilde;
655  ydoti = ydot;
656  zdotbari = zdotbar;
657  y_dot_tildei = y_dot_tilde;
658  z_dot_bar_tildei = z_dot_bar_tilde;
659  for (size_t i=0;i<nvar;i++)
660  {
661  *x_tilde += d3f112 * *ydoti * *zdotbari * *x_bar_tildei;
662  *y_tilde += d3f122 * *ydoti * *zdotbari * *x_bar_tildei;
663  *y_dot_tildei += d2f12 * *zdotbari * *x_bar_tildei;
664  *z_dot_bar_tildei += d2f12 * *ydoti * *x_bar_tildei;
665 
666  ++x_bar_tildei;
667  ++ydoti;
668  ++zdotbari;
669  ++y_dot_tildei;
670  ++z_dot_bar_tildei;
671  }
672  zdotbari = zdotbar;
673  y_bar_tildei = y_bar_tilde;
674  xdoti = xdot;
675  x_dot_tildei = x_dot_tilde;
676  z_dot_bar_tildei = z_dot_bar_tilde;
677  for (size_t i=0;i<nvar;i++)
678  {
679  *x_tilde+= d3f112 * *xdoti * *zdotbari * *y_bar_tildei;
680  *y_tilde+= d3f122 * *xdoti * *zdotbari * *y_bar_tildei;
681  *x_dot_tildei += d2f12 * *zdotbari * *y_bar_tildei;
682  *z_dot_bar_tildei += d2f12 * *xdoti * *y_bar_tildei;
683 
684  ++zdotbari;
685  ++y_bar_tildei;
686  ++xdoti;
687  ++x_dot_tildei;
688  ++z_dot_bar_tildei;
689  }
690 #if defined(__DERCHECK__)
691  if (derchecker->node_number)
692  {
693  if (derchecker->counter == derchecker->node_number)
694  {
695  if (derchecker->pass_number==1) // increment the variable of interest
696  {
697  switch(derchecker->vartype)
698  {
699  case 1:
700  if (!derchecker->dotflag)
701  derchecker->der_value=
702  px->u_bar_tilde[derchecker->index-1];
703  else
704  derchecker->der_value=
705  px->u_dot_bar_tilde[derchecker->index-1];
706  break;
707  case 2:
708  if (!derchecker->dotflag)
709  derchecker->der_value=
710  py->u_bar_tilde[derchecker->index-1];
711  else
712  derchecker->der_value=
713  py->u_dot_bar_tilde[derchecker->index-1];
714  break;
715  case 3:
716  if (!derchecker->dotflag)
717  derchecker->der_value=
718  pz->u_bar_tilde[derchecker->index-1];
719  else
720  derchecker->der_value=
721  pz->u_dot_bar_tilde[derchecker->index-1];
722  break;
723  default:
724  cerr << "Invalid index value for dercheck_index was "
725  << derchecker->index << endl;
726  }
727  }
728  }
729  }
730 #endif
731 #if defined(PRINT_DERS)
732  print_derivatives(pz,"z");
733  print_derivatives(px,"x");
734  print_derivatives(py,"y");
735 #endif
736 }
737 
743 {
744  // We are going backword for bptr and forward for bptr2
745  // the current entry+2 in bptr is the size of the record i.e
746  // points to the next record
747  unsigned int nvar=df1b2variable::nvar;
750  // nlist-=sizeof(int);
751  // get record size
752  int num_bytes=nlist.bptr->numbytes;
753  // backup the size of the record
754  list-=num_bytes;
755  list.saveposition(); // save pointer to beginning of record;
756  // save the pointer to the beginning of the record
757  double xu;
758  double yu;
759  //df1b2_header x,z;
760  //df1b2function2 * pf;
761 
762  // get info from tape1
763  // get info from tape1
764 #if defined(SAFE_ALL)
765  checkidentiferstring("UZ",list);
766 #endif
767  /*
768  df1b2_header * px=(df1b2_header *) list.bptr;
769  list.bptr+=sizeof(df1b2_header);
770  df1b2_header * py=(df1b2_header *) list.bptr;
771  list.bptr+=sizeof(df1b2_header);
772  df1b2_header * pz=(df1b2_header *) list.bptr;
773  list.bptr+=sizeof(df1b2_header);
774  pf=*(df1b2function2 **) list.bptr;
775  list.bptr+=sizeof(char*);
776  memcpy(&xu,list.bptr,sizeof(double));
777  list.bptr+=sizeof(double);
778  memcpy(&yu,list.bptr,sizeof(double));
779  list.bptr+=sizeof(double);
780  xdot=(double*)list.bptr;
781  list.bptr+=nvar*sizeof(double);
782  ydot=(double*)list.bptr;
783  */
784  constexpr size_t sizeofdouble = sizeof(double);
785  df1b2_header * px=(df1b2_header *) list.bptr;
786  list.bptr+=sizeof(df1b2_header);
787  df1b2_header * py=(df1b2_header *) list.bptr;
788  list.bptr+=sizeof(df1b2_header);
789  df1b2_header * pz=(df1b2_header *) list.bptr;
790  list.bptr+=sizeof(df1b2_header);
791  //pf=*(df1b2function2 **) list.bptr;
792  //list.bptr+=sizeof(char*);
793 
794  double df1=*(double*) list.bptr;
795  list.bptr+=sizeofdouble;
796 
797  double df2=*(double*) list.bptr;
798  list.bptr+=sizeofdouble;
799 
800  double d2f11=*(double*) list.bptr;
801  list.bptr+=sizeofdouble;
802 
803  double d2f12=*(double*) list.bptr;
804  list.bptr+=sizeofdouble;
805 
806  double d2f22=*(double*) list.bptr;
807  list.bptr+=sizeofdouble;
808 
809 #if defined(PRINT_DERS)
810  double d3f111=*(double*) list.bptr;
811 #endif
812  list.bptr+=sizeofdouble;
813 
814 #if defined(PRINT_DERS)
815  double d3f112=*(double*) list.bptr;
816 #endif
817  list.bptr+=sizeofdouble;
818 
819 #if defined(PRINT_DERS)
820  double d3f122=*(double*) list.bptr;
821 #endif
822  list.bptr+=sizeofdouble;
823 
824 #if defined(PRINT_DERS)
825  double d3f222=*(double*) list.bptr;
826 #endif
827  list.bptr+=sizeofdouble;
828 
829  memcpy(&xu,list.bptr,sizeofdouble);
830  list.bptr+=sizeofdouble;
831  memcpy(&yu,list.bptr,sizeofdouble);
832  list.bptr+=sizeofdouble;
833  double * xdot=(double*)list.bptr;
834  list.bptr+=nvar*sizeofdouble;
835  double * ydot=(double*)list.bptr;
836 
837  list.restoreposition(); // save pointer to beginning of record;
838 #if defined(PRINT_DERS)
839  print_derivatives(funname,(f),(df1),
840  (df2),(d2f11),(d2f12),(d2f22),
841  (d3f111),(d3f112),(d3f122),
842  (d3f222),1);
843  print_derivatives(pz,"z");
844  print_derivatives(px,"x");
845  print_derivatives(py,"y");
846 #endif
847 
848  *(px->u_tilde)+=(df1)* *(pz->u_tilde);
849  *(py->u_tilde)+=(df2)* *(pz->u_tilde);
850 
851  double* pz_u_dot_tildei = pz->u_dot_tilde;
852  double* xdoti = xdot;
853  double* ydoti = ydot;
854  for (size_t i=0;i<nvar;i++)
855  {
856  *(px->u_tilde) += d2f11 * *xdoti * *pz_u_dot_tildei;
857  *(py->u_tilde) += d2f12 * *xdoti * *pz_u_dot_tildei;
858  *(py->u_tilde) += d2f22 * *ydoti * *pz_u_dot_tildei;
859  *(px->u_tilde) += d2f12 * *ydoti * *pz_u_dot_tildei;
860 
861  ++pz_u_dot_tildei;
862  ++ydoti;
863  ++xdoti;
864  }
865 
866  double* px_u_dot_tildei = px->u_dot_tilde;
867  double* py_u_dot_tildei = py->u_dot_tilde;
868  pz_u_dot_tildei = pz->u_dot_tilde;
869  for (size_t i=0;i<nvar;i++)
870  {
871  *px_u_dot_tildei += df1 * *pz_u_dot_tildei;
872  *py_u_dot_tildei += df2 * *pz_u_dot_tildei;
873 
874  ++px_u_dot_tildei;
875  ++py_u_dot_tildei;
876  ++pz_u_dot_tildei;
877  }
878  *(pz->u_tilde)=0;
879  memset(pz->u_dot_tilde, 0, nvar * sizeofdouble);
880 #if defined(PRINT_DERS)
881  print_derivatives(pz,"z");
882  print_derivatives(px,"x");
883  print_derivatives(py,"y");
884 #endif
885 }
char * bptr
Definition: df1b2fun.h:543
double * get_u_bar_tilde() const
Definition: df1b2fun.h:234
void check_buffer_size(const size_t)
Description not yet available.
Definition: df1b2f10.cpp:185
df1b2_gradlist * f1b2gradlist
Definition: df1b2glo.cpp:49
void memcpy(test_smartlist &dest, void *source, const size_t nsize)
memcpy for test_smartlist
Definition: df1b2f10.cpp:367
void read_pass2_2_dvdv(void)
Description not yet available.
Definition: df32fun1.cpp:411
double * u_bar_tilde
Definition: df1b2fun.h:201
double * u_bar
Definition: df1b2fun.h:197
#define ADUNCONST(type, obj)
Creates a shallow copy of obj that is not CONST.
Definition: fvar.hpp:140
static int passnumber
Definition: df1b2fun.h:289
double * get_u_dot_tilde() const
Definition: df1b2fun.h:233
int adptr_diff(void *x, void *y)
Definition: df1b2fn2.cpp:110
exitptr ad_exit
Definition: gradstrc.cpp:53
void ncount_checker(int ncount, int ncount_check)
double * u_tilde
Definition: df1b2fun.h:199
void restoreposition(void)
Definition: df1b2fun.h:560
Description not yet available.
Definition: df1b2fun.h:266
Description not yet available.
Definition: df1b2fun.h:669
fixed_smartlist nlist
Definition: df1b2fun.h:754
double * u_dot_bar_tilde
Definition: df1b2fun.h:202
Description not yet available.
Definition: df1b2fun.h:602
prnstream & endl(prnstream &)
double * u_dot_bar
Definition: df1b2fun.h:198
test_smartlist list
Definition: df1b2fun.h:753
void print_derivatives(const adstring &s, double f, double df, double d2f, double d3f, int bflag)
Description not yet available.
Definition: df1b2fn3.cpp:27
ADrfptr pf
Definition: df1b2fun.h:595
fixed_smartlist2 nlist2
Definition: df1b2fun.h:756
void read_pass2_3_dvdv(void)
Description not yet available.
Definition: df32fun1.cpp:742
void read_pass2_1_dvdv(void)
Description not yet available.
Definition: df32fun1.cpp:124
Description not yet available.
Definition: df1b2fun.h:527
double * get_u_dot_bar() const
Definition: df1b2fun.h:231
double * get_u_tilde() const
Definition: df1b2fun.h:232
int write_pass1(const df1b2variable *px, const df1b2variable *py, df1b2variable *pz, df1b2function2 *pf)
Description not yet available.
Definition: df1b2f12.cpp:17
double * get_u_dot_bar_tilde() const
Definition: df1b2fun.h:235
static unsigned int nvar
Definition: df1b2fun.h:290
void(* ADrfptr)(void)
Definition: df1b2fun.cpp:139
double * u_dot_tilde
Definition: df1b2fun.h:200
void ad_read_pass2_dvdv(void)
Description not yet available.
Definition: df32fun1.cpp:100
Base class for df1b2variable.
Definition: df1b2fun.h:191
Description not yet available.
fixed_list_entry * bptr
Definition: df1b2fun.h:626
void checkidentiferstring(const char *ids, test_smartlist &list)
Description not yet available.
Definition: df1b2fn5.cpp:256
double * get_u_bar() const
Definition: df1b2fun.h:230
int numbytes
Definition: df1b2fun.h:594
void saveposition(void)
Definition: df1b2fun.h:552
test_smartlist list2
Definition: df1b2fun.h:755