ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
df1b2min2.cpp
Go to the documentation of this file.
1 /*
2  * $Id: df1b2min2.cpp 2011-07-27 add by weihai,created by Dave$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
11 #include <df1b2fun.h>
12 
14  {
16  df1b2variable z;
17  double * yd=y.get_u_dot();
18  double * zd=z.get_u_dot();
19  *z.get_u()=x-*y.get_u();
20  for (unsigned int i=0;i<df1b2variable::nvar;i++)
21  {
22  *zd++ = - *yd++;
23  }
24 
25  // WRITE WHATEVER ON TAPE
28  return z;
29  }
30 
31 void ad_read_pass2_minuscv(void);
32 
34  df1b2variable * pz)
35  {
37  ncount++;
38 #if defined(CHECK_COUNT)
39  if (ncount >= ncount_check)
40  cout << ncount << endl;
41 #endif
42 
43  size_t total_bytes=2*sizeof(df1b2_header);
44 // string identifier debug stuff
45 #if defined(SAFE_ALL)
46  char ids[]="GU";
47  int slen=strlen(ids);
48  total_bytes+=slen;
49 #endif
50  list.check_buffer_size(total_bytes);
51  void * tmpptr=list.bptr;
52 #if defined(SAFE_ALL)
53  memcpy(list,ids,slen);
54 #endif
55 // end of string identifier debug stuff
56 
57  memcpy(list,(df1b2_header*)(py),sizeof(df1b2_header));
58  memcpy(list,(df1b2_header*)(pz),sizeof(df1b2_header));
59  // ***** write record size
62  ++nlist;
63  return 0;
64  }
65 
66 
67 void read_pass2_1_minuscv(void);
68 void read_pass2_2_minuscv(void);
69 void read_pass2_3_minuscv(void);
70 
72 {
74  {
75  case 1:
77  break;
78  case 2:
80  break;
81  case 3:
83  break;
84  default:
85  cerr << "illegal value for df1b2variable::pass = "
87  ad_exit(1);
88  }
89 }
90 
92 {
93  // We are going backword for bptr and nbptr
94  // and forward for bptr2 and nbptr2
95  // the current entry+2 in bptr is the size of the record i.e
96  // points to the next record
97  unsigned int nvar=df1b2variable::nvar;
99  int num_bytes=f1b2gradlist->nlist.bptr->numbytes;
100  list-=num_bytes;
101  list.saveposition(); // save pointer to beginning of record;
102 
103  // get info from tape1
104 #if defined(SAFE_ALL)
106 #endif
107  char * bptr=f1b2gradlist->list.bptr;
108  df1b2_header * py=(df1b2_header *) bptr;
109  bptr+=sizeof(df1b2_header);
110  df1b2_header * pz=(df1b2_header *) bptr;
111 
112  list.restoreposition(); // save pointer to beginning of record;
113 
114  // ****************************************************************
115  // turn this off if no third derivatives are calculated
116  // if (!no_third_derivatives)
117  // {
118  // save for second reverse pass
119  // save identifier 1
120 
121  for (unsigned int i=0;i<nvar;i++)
122  {
123  py->u_bar[i]-=pz->u_bar[i];
124  }
125  for (unsigned int i=0;i<nvar;i++)
126  {
127  py->u_dot_bar[i]-=pz->u_dot_bar[i];
128  }
129 
130  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
131  for (unsigned int i=0;i<nvar;i++)
132  {
133  pz->u_bar[i]=0;
134  }
135  for (unsigned int i=0;i<nvar;i++)
136  {
137  pz->u_dot_bar[i]=0;
138  }
139 }
140 
142 {
143  //const int nlist_record_size=sizeof(int)+sizeof(char*);
144  // We are going forward for bptr and backword for bptr2
145  //
146  // list 1
147  //
148  unsigned int nvar=df1b2variable::nvar;
150 
151  size_t total_bytes=2*sizeof(df1b2_header);
152 // string identifier debug stuff
153 #if defined(SAFE_ALL)
154  char ids[]="BY";
155  int slen=strlen(ids);
156  total_bytes+=slen;
157 #endif
158  list.check_buffer_size(total_bytes);
159 // end of string identifier debug stuff
160 
161  list.saveposition(); // save pointer to beginning of record;
163  // get record size
164  int num_bytes=nlist.bptr->numbytes;
165  // get info from tape1
166 #if defined(SAFE_ALL)
167  checkidentiferstring("GU",list);
168 #endif
169  df1b2_header * py=(df1b2_header *) list.bptr;
170  list.bptr+=sizeof(df1b2_header);
171  df1b2_header * pz=(df1b2_header *) list.bptr;
172  list.restoreposition(num_bytes); // save pointer to beginning of record;
173 
174  double * y_bar_tilde=py->get_u_bar_tilde();
175  double * y_dot_bar_tilde=py->get_u_dot_bar_tilde();
176  double * z_bar_tilde=pz->get_u_bar_tilde();
177  double * z_dot_bar_tilde=pz->get_u_dot_bar_tilde();
178  // Do second "reverse-reverse" pass calculations
179 
180  for (unsigned int i=0;i<nvar;i++)
181  {
182  z_bar_tilde[i]=0;
183  z_dot_bar_tilde[i]=0;
184  }
185 
186  // start with y and add x
187  for (unsigned int i=0;i<nvar;i++)
188  {
189  z_bar_tilde[i]-=y_bar_tilde[i];
190  }
191 
192  for (unsigned int i=0;i<nvar;i++)
193  {
194  z_dot_bar_tilde[i]-=y_dot_bar_tilde[i];
195  }
196 }
197 
199 {
200  // We are going backword for bptr and forward for bptr2
201  // the current entry+2 in bptr is the size of the record i.e
202  // points to the next record
203  unsigned int nvar=df1b2variable::nvar;
206  // nlist-=sizeof(int);
207  // get record size
208  int num_bytes=nlist.bptr->numbytes;
209  // backup the size of the record
210  list-=num_bytes;
211  list.saveposition(); // save pointer to beginning of record;
212  // save the pointer to the beginning of the record
213  //df1b2_header x,z;
214 
215  // get info from tape1
216  // get info from tape1
217 #if defined(SAFE_ALL)
218  checkidentiferstring("GU",list);
219 #endif
220  df1b2_header * py=(df1b2_header *) list.bptr;
221  list.bptr+=sizeof(df1b2_header);
222  df1b2_header * pz=(df1b2_header *) list.bptr;
223  list.bptr+=sizeof(df1b2_header);
224 
225  list.restoreposition(); // save pointer to beginning of record;
226 
227  *(py->u_tilde)-=*(pz->u_tilde);
228  for (unsigned int i=0;i<nvar;i++)
229  {
230  py->u_dot_tilde[i]-=pz->u_dot_tilde[i];
231  }
232  *(pz->u_tilde)=0;
233  for (unsigned int i=0;i<nvar;i++)
234  {
235  pz->u_dot_tilde[i]=0;
236  }
237 }
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
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
int adptr_diff(void *x, void *y)
Definition: df1b2fn2.cpp:110
exitptr ad_exit
Definition: gradstrc.cpp:53
double * u_tilde
Definition: df1b2fun.h:199
void ad_read_pass2_minuscv(void)
Definition: df1b2min2.cpp:71
void restoreposition(void)
Definition: df1b2fun.h:560
Description not yet available.
Definition: df1b2fun.h:266
void read_pass2_3_minuscv(void)
Definition: df1b2min2.cpp:198
fixed_smartlist nlist
Definition: df1b2fun.h:754
double * get_u_dot() const
Definition: df1b2fun.h:229
int write_pass1_minuscv(const df1b2variable *py, df1b2variable *pz)
Definition: df1b2min2.cpp:33
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 read_pass2_1_minuscv(void)
Definition: df1b2min2.cpp:91
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 read_pass2_2_minuscv(void)
Definition: df1b2min2.cpp:141
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