ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
df1b2sum.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 
18  {
21  df1b2variable z;
22  double * xd=x.get_u_dot();
23  double * yd=y.get_u_dot();
24  double * zd=z.get_u_dot();
25  *z.get_u()=*x.get_u()+*y.get_u();
26  for (unsigned int i=0;i<df1b2variable::nvar;i++)
27  {
28  *zd++ = *xd++ + *yd++;
29  }
30 
31  // WRITE WHATEVER ON TAPE
34  return z;
35  }
36 
37 void ad_read_pass2_sum(void);
38 
44  const df1b2variable * _py,df1b2variable * pz)
45  {
48  ncount++;
49 #if defined(CHECK_COUNT)
50  if (ncount >= ncount_check)
51  cout << ncount << endl;
52 #endif
53  //int nvar=df1b2variable::nvar;
54 
55  size_t total_bytes=3*sizeof(df1b2_header);
56 // string identifier debug stuff
57 #if defined(SAFE_ALL)
58  char ids[]="TU";
59  int slen=strlen(ids);
60  total_bytes+=slen;
61 #endif
62  list.check_buffer_size(total_bytes);
63  void * tmpptr=list.bptr;
64 #if defined(SAFE_ALL)
65  memcpy(list,ids,slen);
66 #endif
67 // end of string identifier debug stuff
68 
69  memcpy(list,(df1b2_header*)(px),sizeof(df1b2_header));
70  memcpy(list,(df1b2_header*)(py),sizeof(df1b2_header));
71  memcpy(list,(df1b2_header*)(pz),sizeof(df1b2_header));
72  // ***** write record size
75  ++nlist;
76  return 0;
77  }
78 
79 
80 void read_pass2_1_sum(void);
81 void read_pass2_2_sum(void);
82 void read_pass2_3_sum(void);
83 
89 {
91  {
92  case 1:
94  break;
95  case 2:
97  break;
98  case 3:
100  break;
101  default:
102  cerr << "illegal value for df1b2variable::pass = "
104  ad_exit(1);
105  }
106 }
107 
113 {
114  // We are going backword for bptr and nbptr
115  // and forward for bptr2 and nbptr2
116  // the current entry+2 in bptr is the size of the record i.e
117  // points to the next record
118  unsigned int nvar=df1b2variable::nvar;
120  int num_bytes=f1b2gradlist->nlist.bptr->numbytes;
121  list-=num_bytes;
122  list.saveposition(); // save pointer to beginning of record;
123 
124  // get info from tape1
125 #if defined(SAFE_ALL)
127 #endif
128  char * bptr=f1b2gradlist->list.bptr;
129  df1b2_header * px=(df1b2_header *) bptr;
130  bptr+=sizeof(df1b2_header);
131  df1b2_header * py=(df1b2_header *) bptr;
132  bptr+=sizeof(df1b2_header);
133  df1b2_header * pz=(df1b2_header *) bptr;
134 
135  list.restoreposition(); // save pointer to beginning of record;
136 
137  // ****************************************************************
138  // turn this off if no third derivatives are calculated
139  // if (!no_third_derivatives)
140  // {
141  // save for second reverse pass
142  // save identifier 1
143 
144  double* px_u_bar = px->u_bar;
145  double* pz_u_bar = pz->u_bar;
146  for (unsigned int i=0;i<nvar;i++)
147  {
148  *px_u_bar += *pz_u_bar;
149 
150  ++px_u_bar;
151  ++pz_u_bar;
152  }
153  double* py_u_bar = py->u_bar;
154  pz_u_bar = pz->u_bar;
155  for (unsigned int i=0;i<nvar;i++)
156  {
157  *py_u_bar += *pz_u_bar;
158 
159  ++py_u_bar;
160  ++pz_u_bar;
161  }
162  double* px_u_dot_bar = px->u_dot_bar;
163  double* pz_u_dot_bar = pz->u_dot_bar;
164  for (unsigned int i=0;i<nvar;i++)
165  {
166  *px_u_dot_bar += *pz_u_dot_bar;
167 
168  ++px_u_dot_bar;
169  ++pz_u_dot_bar;
170  }
171  double* py_u_dot_bar = py->u_dot_bar;
172  pz_u_dot_bar = pz->u_dot_bar;
173  for (unsigned int i=0;i<nvar;i++)
174  {
175  *py_u_dot_bar += *pz_u_dot_bar;
176 
177  ++py_u_dot_bar;
178  ++pz_u_dot_bar;
179  }
180 
181  constexpr size_t sizeofdouble = sizeof(double);
182  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
183  memset(pz->u_bar, 0, nvar * sizeofdouble);
184  memset(pz->u_dot_bar, 0, nvar * sizeofdouble);
185 }
186 
192 {
193  //const int nlist_record_size=sizeof(int)+sizeof(char*);
194  // We are going forward for bptr and backword for bptr2
195  //
196  // list 1
197  //
198  unsigned int nvar=df1b2variable::nvar;
200 
201  size_t total_bytes=3*sizeof(df1b2_header);
202 // string identifier debug stuff
203 #if defined(SAFE_ALL)
204  char ids[]="BY";
205  int slen=strlen(ids);
206  total_bytes+=slen;
207 #endif
208  list.check_buffer_size(total_bytes);
209 // end of string identifier debug stuff
210 
211  list.saveposition(); // save pointer to beginning of record;
213  // get record size
214  int num_bytes=nlist.bptr->numbytes;
215  // get info from tape1
216 #if defined(SAFE_ALL)
217  checkidentiferstring("TU",list);
218 #endif
219  df1b2_header * px=(df1b2_header *) list.bptr;
220  list.bptr+=sizeof(df1b2_header);
221  df1b2_header * py=(df1b2_header *) list.bptr;
222  list.bptr+=sizeof(df1b2_header);
223  df1b2_header * pz=(df1b2_header *) list.bptr;
224  list.restoreposition(num_bytes); // save pointer to beginning of record;
225 
226  double * x_bar_tilde=px->get_u_bar_tilde();
227  double * x_dot_bar_tilde=px->get_u_dot_bar_tilde();
228  double * y_bar_tilde=py->get_u_bar_tilde();
229  double * y_dot_bar_tilde=py->get_u_dot_bar_tilde();
230  double * z_bar_tilde=pz->get_u_bar_tilde();
231  double * z_dot_bar_tilde=pz->get_u_dot_bar_tilde();
232  // Do second "reverse-reverse" pass calculations
233  constexpr size_t sizeofdouble = sizeof(double);
234  memset(z_bar_tilde, 0, nvar * sizeofdouble);
235  memset(z_dot_bar_tilde, 0, nvar * sizeofdouble);
236 
237  // start with x and add y
238  for (unsigned int i=0;i<nvar;i++)
239  {
240  z_bar_tilde[i]+=x_bar_tilde[i];
241  }
242 
243  for (unsigned int i=0;i<nvar;i++)
244  {
245  z_dot_bar_tilde[i]+=x_dot_bar_tilde[i];
246  }
247 
248  // start with y and add x
249  for (unsigned int i=0;i<nvar;i++)
250  {
251  z_bar_tilde[i]+=y_bar_tilde[i];
252  }
253 
254  for (unsigned int i=0;i<nvar;i++)
255  {
256  z_dot_bar_tilde[i]+=y_dot_bar_tilde[i];
257  }
258 }
259 
265 {
266  // We are going backword for bptr and forward for bptr2
267  // the current entry+2 in bptr is the size of the record i.e
268  // points to the next record
269  unsigned int nvar=df1b2variable::nvar;
272  // nlist-=sizeof(int);
273  // get record size
274  int num_bytes=nlist.bptr->numbytes;
275  // backup the size of the record
276  list-=num_bytes;
277  list.saveposition(); // save pointer to beginning of record;
278  // save the pointer to the beginning of the record
279  //df1b2_header x,z;
280 
281  // get info from tape1
282  // get info from tape1
283 #if defined(SAFE_ALL)
284  checkidentiferstring("TU",list);
285 #endif
286  df1b2_header * px=(df1b2_header *) list.bptr;
287  list.bptr+=sizeof(df1b2_header);
288  df1b2_header * py=(df1b2_header *) list.bptr;
289  list.bptr+=sizeof(df1b2_header);
290  df1b2_header * pz=(df1b2_header *) list.bptr;
291  list.bptr+=sizeof(df1b2_header);
292 
293  list.restoreposition(); // save pointer to beginning of record;
294 
295  *(px->u_tilde)+=*(pz->u_tilde);
296  *(py->u_tilde)+=*(pz->u_tilde);
297  for (unsigned int i=0;i<nvar;i++)
298  {
299  px->u_dot_tilde[i]+=pz->u_dot_tilde[i];
300  py->u_dot_tilde[i]+=pz->u_dot_tilde[i];
301  }
302  *(pz->u_tilde)=0;
303  constexpr size_t sizeofdouble = sizeof(double);
304  memset(pz->u_dot_tilde, 0, nvar * sizeofdouble);
305 }
char * bptr
Definition: df1b2fun.h:543
double * get_u_bar_tilde() const
Definition: df1b2fun.h:234
void read_pass2_1_sum(void)
Description not yet available.
Definition: df1b2sum.cpp:112
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
double * u_bar
Definition: df1b2fun.h:197
double * get_u() const
Definition: df1b2fun.h:228
#define x
#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
int adptr_diff(void *x, void *y)
Definition: df1b2fn2.cpp:110
d3_array operator+(const d3_array &a, const d3_array &b)
Returns d3_array results with computed elements addition of a(i, j, k) + b(i, j, k).
Definition: d3arr2a.cpp:132
exitptr ad_exit
Definition: gradstrc.cpp:53
double * u_tilde
Definition: df1b2fun.h:199
void restoreposition(void)
Definition: df1b2fun.h:560
Description not yet available.
Definition: df1b2fun.h:266
fixed_smartlist nlist
Definition: df1b2fun.h:754
double * get_u_dot() const
Definition: df1b2fun.h:229
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
ADrfptr pf
Definition: df1b2fun.h:595
static int no_derivatives
Definition: df1b2fun.h:759
void ad_read_pass2_sum(void)
Description not yet available.
Definition: df1b2sum.cpp:88
Description not yet available.
Definition: df1b2fun.h:527
void read_pass2_2_sum(void)
Description not yet available.
Definition: df1b2sum.cpp:191
double * get_u_dot_bar_tilde() const
Definition: df1b2fun.h:235
void read_pass2_3_sum(void)
Description not yet available.
Definition: df1b2sum.cpp:264
static unsigned int nvar
Definition: df1b2fun.h:290
void(* ADrfptr)(void)
Definition: df1b2fun.cpp:139
double * u_dot_tilde
Definition: df1b2fun.h:200
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
int numbytes
Definition: df1b2fun.h:594
int write_pass1_sum(double x, const df1b2variable *py, df1b2variable *pz)
Description not yet available.
Definition: df1b2sumc.cpp:41
void saveposition(void)
Definition: df1b2fun.h:552