ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
df1b2min.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_minus(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 
54  size_t total_bytes=3*sizeof(df1b2_header);
55 // string identifier debug stuff
56 #if defined(SAFE_ALL)
57  char ids[]="TU";
58  int slen=strlen(ids);
59  total_bytes+=slen;
60 #endif
61  list.check_buffer_size(total_bytes);
62  void * tmpptr=list.bptr;
63 #if defined(SAFE_ALL)
64  memcpy(list,ids,slen);
65 #endif
66 // end of string identifier debug stuff
67 
68  memcpy(list,(df1b2_header*)(px),sizeof(df1b2_header));
69  memcpy(list,(df1b2_header*)(py),sizeof(df1b2_header));
70  memcpy(list,(df1b2_header*)(pz),sizeof(df1b2_header));
71  // ***** write record size
74  ++nlist;
75  return 0;
76  }
77 
78 
79 void read_pass2_1_minus(void);
80 void read_pass2_2_minus(void);
81 void read_pass2_3_minus(void);
82 
88 {
90  {
91  case 1:
93  break;
94  case 2:
96  break;
97  case 3:
99  break;
100  default:
101  cerr << "illegal value for df1b2variable::pass = "
103  ad_exit(1);
104  }
105 }
106 
112 {
113  // We are going backword for bptr and nbptr
114  // and forward for bptr2 and nbptr2
115  // the current entry+2 in bptr is the size of the record i.e
116  // points to the next record
117  unsigned int nvar=df1b2variable::nvar;
119  int num_bytes=f1b2gradlist->nlist.bptr->numbytes;
120  list-=num_bytes;
121  list.saveposition(); // save pointer to beginning of record;
122 
123  // get info from tape1
124 #if defined(SAFE_ALL)
126 #endif
127  char * bptr=f1b2gradlist->list.bptr;
128  df1b2_header * px=(df1b2_header *) bptr;
129  bptr+=sizeof(df1b2_header);
130  df1b2_header * py=(df1b2_header *) bptr;
131  bptr+=sizeof(df1b2_header);
132  df1b2_header * pz=(df1b2_header *) bptr;
133 
134  list.restoreposition(); // save pointer to beginning of record;
135 
136  // ****************************************************************
137  // turn this off if no third derivatives are calculated
138  // if (!no_third_derivatives)
139  // {
140  // save for second reverse pass
141  // save identifier 1
142 
143  for (unsigned int i=0;i<nvar;i++)
144  {
145  px->u_bar[i]+=pz->u_bar[i];
146  }
147  for (unsigned int i=0;i<nvar;i++)
148  {
149  py->u_bar[i]-=pz->u_bar[i];
150  }
151  for (unsigned int i=0;i<nvar;i++)
152  {
153  px->u_dot_bar[i]+=pz->u_dot_bar[i];
154  }
155  for (unsigned int i=0;i<nvar;i++)
156  {
157  py->u_dot_bar[i]-=pz->u_dot_bar[i];
158  }
159 
160  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
161  for (unsigned int i=0;i<nvar;i++)
162  {
163  pz->u_bar[i]=0;
164  }
165  for (unsigned int i=0;i<nvar;i++)
166  {
167  pz->u_dot_bar[i]=0;
168  }
169 }
170 
176 {
177  //const int nlist_record_size=sizeof(int)+sizeof(char*);
178  // We are going forward for bptr and backword for bptr2
179  //
180  // list 1
181  //
182  unsigned int nvar=df1b2variable::nvar;
184 
185  size_t total_bytes=3*sizeof(df1b2_header);
186 // string identifier debug stuff
187 #if defined(SAFE_ALL)
188  char ids[]="BY";
189  int slen=strlen(ids);
190  total_bytes+=slen;
191 #endif
192  list.check_buffer_size(total_bytes);
193 // end of string identifier debug stuff
194 
195  list.saveposition(); // save pointer to beginning of record;
197  // get record size
198  int num_bytes=nlist.bptr->numbytes;
199  // get info from tape1
200 #if defined(SAFE_ALL)
201  checkidentiferstring("TU",list);
202 #endif
203  df1b2_header * px=(df1b2_header *) list.bptr;
204  list.bptr+=sizeof(df1b2_header);
205  df1b2_header * py=(df1b2_header *) list.bptr;
206  list.bptr+=sizeof(df1b2_header);
207  df1b2_header * pz=(df1b2_header *) list.bptr;
208  list.restoreposition(num_bytes); // save pointer to beginning of record;
209 
210  double * x_bar_tilde=px->get_u_bar_tilde();
211  double * x_dot_bar_tilde=px->get_u_dot_bar_tilde();
212  double * y_bar_tilde=py->get_u_bar_tilde();
213  double * y_dot_bar_tilde=py->get_u_dot_bar_tilde();
214  double * z_bar_tilde=pz->get_u_bar_tilde();
215  double * z_dot_bar_tilde=pz->get_u_dot_bar_tilde();
216  // Do second "reverse-reverse" pass calculations
217 
218  for (unsigned int i=0;i<nvar;i++)
219  {
220  z_bar_tilde[i]=0;
221  z_dot_bar_tilde[i]=0;
222  }
223 
224  // start with x and add y
225  for (unsigned int i=0;i<nvar;i++)
226  {
227  z_bar_tilde[i]+=x_bar_tilde[i];
228  }
229 
230  for (unsigned int i=0;i<nvar;i++)
231  {
232  z_dot_bar_tilde[i]+=x_dot_bar_tilde[i];
233  }
234 
235  // start with y and add x
236  for (unsigned int i=0;i<nvar;i++)
237  {
238  z_bar_tilde[i]-=y_bar_tilde[i];
239  }
240 
241  for (unsigned int i=0;i<nvar;i++)
242  {
243  z_dot_bar_tilde[i]-=y_dot_bar_tilde[i];
244  }
245 }
246 
252 {
253  // We are going backword for bptr and forward for bptr2
254  // the current entry+2 in bptr is the size of the record i.e
255  // points to the next record
256  unsigned int nvar=df1b2variable::nvar;
259  // nlist-=sizeof(int);
260  // get record size
261  int num_bytes=nlist.bptr->numbytes;
262  // backup the size of the record
263  list-=num_bytes;
264  list.saveposition(); // save pointer to beginning of record;
265  // save the pointer to the beginning of the record
266  //df1b2_header x,z;
267 
268  // get info from tape1
269  // get info from tape1
270 #if defined(SAFE_ALL)
271  checkidentiferstring("TU",list);
272 #endif
273  df1b2_header * px=(df1b2_header *) list.bptr;
274  list.bptr+=sizeof(df1b2_header);
275  df1b2_header * py=(df1b2_header *) list.bptr;
276  list.bptr+=sizeof(df1b2_header);
277  df1b2_header * pz=(df1b2_header *) list.bptr;
278  list.bptr+=sizeof(df1b2_header);
279 
280  list.restoreposition(); // save pointer to beginning of record;
281 
282  *(px->u_tilde)+=*(pz->u_tilde);
283  *(py->u_tilde)-=*(pz->u_tilde);
284  for (unsigned int i=0;i<nvar;i++)
285  {
286  px->u_dot_tilde[i]+=pz->u_dot_tilde[i];
287  py->u_dot_tilde[i]-=pz->u_dot_tilde[i];
288  }
289  *(pz->u_tilde)=0;
290  for (unsigned int i=0;i<nvar;i++)
291  {
292  pz->u_dot_tilde[i]=0;
293  }
294 }
char * bptr
Definition: df1b2fun.h:543
double * get_u_bar_tilde() const
Definition: df1b2fun.h:234
void read_pass2_2_minus(void)
Description not yet available.
Definition: df1b2min.cpp:175
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_1_minus(void)
Description not yet available.
Definition: df1b2min.cpp:111
double * u_bar
Definition: df1b2fun.h:197
double * get_u() const
Definition: df1b2fun.h:228
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:152
#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
void read_pass2_3_minus(void)
Description not yet available.
Definition: df1b2min.cpp:251
int adptr_diff(void *x, void *y)
Definition: df1b2fn2.cpp:110
exitptr ad_exit
Definition: gradstrc.cpp:53
void ad_read_pass2_minus(void)
Description not yet available.
Definition: df1b2min.cpp:87
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
int write_pass1_minus(const df1b2variable *px, const df1b2variable *py, df1b2variable *pz)
Description not yet available.
Definition: df1b2min.cpp:43
ADrfptr pf
Definition: df1b2fun.h:595
static int no_derivatives
Definition: df1b2fun.h:759
Description not yet available.
Definition: df1b2fun.h:527
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
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
void saveposition(void)
Definition: df1b2fun.h:552