ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
df1b2fn8.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 void read_pass1_minus_eq_1(void);
13 void read_pass1_minus_eq_2(void);
14 void read_pass1_minus_eq_3(void);
15 //#define ADDEBUG_PRINT
16 #if defined(ADDEBUG_PRINT)
17  extern int addebug_count;
18 #endif
19 //#define PRINT_DERS
20 
26 {
28  double * xd=x.get_u_dot();
29  double * zd=get_u_dot();
30  *get_u()-=*x.get_u();
31  for (unsigned int i=0;i<df1b2variable::nvar;i++)
32  {
33  *zd++ -= *xd++;
34  }
35 
36  // WRITE WHATEVER ON TAPE
37  //df1b2tape->set_tapeinfo_header(&x,&z,this,xd);
38  // save stuff for first reverse pass
39  // need &x, &z, this,
42  return *this;
43 }
44 
45 void ad_read_pass1_minus_eq(void);
46 
52  df1b2variable * pz)
53 {
54  ncount++;
55 #if defined(CHECK_COUNT)
56  if (ncount >= ncount_check)
57  ncount_checker(ncount,ncount_check);
58 #endif
59  //int nvar=df1b2variable::nvar;
63 
64  size_t total_bytes=sizeof(df1b2_header)+sizeof(df1b2_header);
65 #if defined(SAFE_ALL)
66  char ids[]="LC";
67  int slen=strlen(ids);
68  total_bytes+=slen;
69 #endif
70  list.check_buffer_size(total_bytes);
71  void * tmpptr=list.bptr;
72 #if defined(SAFE_ALL)
73  memcpy(list,ids,slen);
74 #endif
75 
76  memcpy(list,(df1b2_header*)(px),sizeof(df1b2_header));
77  memcpy(list,(df1b2_header*)(pz),sizeof(df1b2_header));
78 
79  // ***** write record size
80  nlist.bptr->numbytes=adptr_diff(list.bptr,tmpptr);
82  ++nlist;
83  return 0;
84 }
85 
91 {
93  {
94  case 1:
96  break;
97  case 2:
99  break;
100  case 3:
102  break;
103  default:
104  cerr << "illegal value for df1b2variable::pass = "
106  ad_exit(1);
107  }
108 }
109 
115 {
116  // We are going backword for bptr and forward for bptr2
117  // the current entry+2 in bptr is the size of the record i.e
118  // points to the next record
119  unsigned int nvar=df1b2variable::nvar;
122  // nlist-=sizeof(int);
123  // get record size
124  int num_bytes=nlist.bptr->numbytes;
125  // backup the size of the record
126  list-=num_bytes;
127  list.saveposition(); // save pointer to beginning of record;
128  // save the pointer to the beginning of the record
129 #if defined(SAFE_ALL)
130  checkidentiferstring("LC",list);
131 #endif
132 
133  // get info from tape1
134  df1b2_header * px=(df1b2_header *) list.bptr;
135  list.bptr+=sizeof(df1b2_header);
136  df1b2_header * pz=(df1b2_header *) list.bptr;
137 
138  list.restoreposition(); // save pointer to beginning of record;
139 
140  // Do first reverse paSS calculations
141  // ****************************************************************
142  // turn this off if no third derivatives are calculated
143  // if (!no_third_derivatives)
144  // {
145  // save for second reverse pass
146  // save identifier 1
147  // fixed_smartlist2& nlist2=f1b2gradlist->nlist2;
148  // test_smartlist& list2=f1b2gradlist->list2;
149  //int total_bytes=2*nvar*sizeof(double);
150 // string identifier debug stuff
151 #if defined(SAFE_ALL)
152  //char ids[]="KM";
153  //int slen=strlen(ids);
154  //total_bytes+=slen;
155 #endif
156  //list2.check_buffer_size(total_bytes);
157  //void * tmpptr2=list2.bptr;
158 #if defined(SAFE_ALL)
159  //memcpy(list2,ids,slen);
160 #endif
161  //memcpy(list2,pz->get_u_bar(),nvar*sizeof(double));
162  //memcpy(list2,pz->get_u_dot_bar(),nvar*sizeof(double));
163  //*nlist2.bptr=adptr_diff(list2.bptr,tmpptr2);
164  //nlist2++;
165  // }
166  //
167  // ****************************************************************
168 
169  for (unsigned int i=0;i<nvar;i++)
170  {
171  px->u_bar[i]-=pz->u_bar[i];
172  }
173  for (unsigned int i=0;i<nvar;i++)
174  {
175  px->u_dot_bar[i]-=pz->u_dot_bar[i];
176  }
177 #if defined(PRINT_DERS)
178  print_derivatives(px,"x");
179  print_derivatives(pz,"z");
180 #endif
181 }
182 
188 {
189  //const int nlist_record_size=sizeof(int)+sizeof(char*);
190  // We are going forward for bptr and backword for bptr2
191  //
192  // list 1
193  //
194  unsigned int nvar=df1b2variable::nvar;
196 
197  size_t total_bytes=sizeof(df1b2_header)+sizeof(df1b2_header);
198 #if defined(SAFE_ALL)
199  char ids[]="LC";
200  int slen=strlen(ids);
201  total_bytes+=slen;
202 #endif
203  list.check_buffer_size(total_bytes);
204 
205  list.saveposition(); // save pointer to beginning of record;
207  // nlist-=sizeof(int);
208  // get record size
209  int num_bytes=nlist.bptr->numbytes;
210  // nlist+=nlist_record_size;
211  //
212  // list 2
213  //
214  //test_smartlist & list2=f1b2gradlist->list2;
215  //fixed_smartlist2 & nlist2=f1b2gradlist->nlist2;
216  // get record size
217  //int num_bytes2=*nlist2.bptr;
218  //nlist2--;
219  // backup the size of the record
220  //list2-=num_bytes2;
221  //list2.saveposition(); // save pointer to beginning of record;
222  // save the pointer to the beginning of the record
223  // bptr and bptr2 now both point to the beginning of their records
224 #if defined(SAFE_ALL)
225  checkidentiferstring("LC",list);
226  //checkidentiferstring("KM",list2);
227 #endif
228 
229 
230  // get info from tape1
231  df1b2_header * px=(df1b2_header *) list.bptr;
232  list.bptr+=sizeof(df1b2_header);
233  df1b2_header * pz=(df1b2_header *) list.bptr;
234 
235  list.restoreposition(num_bytes); // save pointer to beginning of record;
236 
237 
238  //double * zbar=(double*)list2.bptr;
239  //double * zdotbar=(double*)(list2.bptr+nvar*sizeof(double));
240 
241  double * x_bar_tilde=px->get_u_bar_tilde();
242  double * x_dot_bar_tilde=px->get_u_dot_bar_tilde();
243  double * z_bar_tilde=pz->get_u_bar_tilde();
244  double * z_dot_bar_tilde=pz->get_u_dot_bar_tilde();
245  // Do second "reverse-reverse" pass calculations
246  for (unsigned int i=0;i<nvar;i++)
247  {
248  z_bar_tilde[i]-=x_bar_tilde[i];
249  }
250 
251  for (unsigned int i=0;i<nvar;i++)
252  {
253  z_dot_bar_tilde[i]-=x_dot_bar_tilde[i];
254  }
255  //list2.restoreposition(); // save pointer to beginning of record;
256 #if defined(PRINT_DERS)
257  print_derivatives(px,"x");
258  print_derivatives(pz,"z");
259 #endif
260 }
261 
267 {
268  // We are going backword for bptr and forward for bptr2
269  // the current entry+2 in bptr is the size of the record i.e
270  // points to the next record
271  unsigned int nvar=df1b2variable::nvar;
274  // nlist-=sizeof(int);
275  // get record size
276  int num_bytes=nlist.bptr->numbytes;
277  // backup the size of the record
278  list-=num_bytes;
279  list.saveposition(); // save pointer to beginning of record;
280  // save the pointer to the beginning of the record
281 
282 #if defined(SAFE_ALL)
283  checkidentiferstring("LC",list);
284 #endif
285  // get info from tape1
286  df1b2_header * px=(df1b2_header *) list.bptr;
287  list.bptr+=sizeof(df1b2_header);
288  df1b2_header * pz=(df1b2_header *) list.bptr;
289 
290  list.restoreposition(); // save pointer to beginning of record;
291 
292  // Do first reverse paSS calculations
293 
294  *(px->u_tilde)-=*pz->u_tilde;
295  for (unsigned int i=0;i<nvar;i++)
296  {
297  px->u_dot_tilde[i]-=pz->u_dot_tilde[i];
298  }
299 #if defined(PRINT_DERS)
300  print_derivatives(px,"x");
301  print_derivatives(pz,"z");
302 #endif
303 }
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 ad_read_pass1_minus_eq(void)
Description not yet available.
Definition: df1b2fn8.cpp:90
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
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
fixed_smartlist nlist
Definition: df1b2fun.h:754
double * get_u_dot() const
Definition: df1b2fun.h:229
void read_pass1_minus_eq_3(void)
Description not yet available.
Definition: df1b2fn8.cpp:266
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
static int no_derivatives
Definition: df1b2fun.h:759
void read_pass1_minus_eq_1(void)
Description not yet available.
Definition: df1b2fn8.cpp:114
Description not yet available.
Definition: df1b2fun.h:527
int write_pass1_minuseq(const df1b2variable *px, df1b2variable *pz)
Description not yet available.
Definition: df1b2fn8.cpp:51
double * get_u_dot_bar_tilde() const
Definition: df1b2fun.h:235
static unsigned int nvar
Definition: df1b2fun.h:290
void read_pass1_minus_eq_2(void)
Description not yet available.
Definition: df1b2fn8.cpp:187
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
df1b2variable & operator-=(const df1b2variable &v)
Description not yet available.
Definition: df1b2fn8.cpp:25
int numbytes
Definition: df1b2fun.h:594
void saveposition(void)
Definition: df1b2fun.h:552