ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
df1b2min3.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 
14  {
16  df1b2variable z;
17  double * yd=y.get_u_dot();
18  double * zd=z.get_u_dot();
19  *z.get_u()=*y.get_u()-x;
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_minusvc(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  //int nvar=df1b2variable::nvar;
43 
44  size_t total_bytes=2*sizeof(df1b2_header);
45 // string identifier debug stuff
46 #if defined(SAFE_ALL)
47  char ids[]="LK";
48  int slen=strlen(ids);
49  total_bytes+=slen;
50 #endif
51  list.check_buffer_size(total_bytes);
52  void * tmpptr=list.bptr;
53 #if defined(SAFE_ALL)
54  memcpy(list,ids,slen);
55 #endif
56 // end of string identifier debug stuff
57 
58  memcpy(list,(df1b2_header*)(py),sizeof(df1b2_header));
59  memcpy(list,(df1b2_header*)(pz),sizeof(df1b2_header));
60  // ***** write record size
63  ++nlist;
64  return 0;
65  }
66 
67 
68 void read_pass2_1_minusvc(void);
69 void read_pass2_2_minusvc(void);
70 void read_pass2_3_minusvc(void);
71 
73 {
75  {
76  case 1:
78  break;
79  case 2:
81  break;
82  case 3:
84  break;
85  default:
86  cerr << "illegal value for df1b2variable::pass = "
88  ad_exit(1);
89  }
90 }
91 
93 {
94  // We are going backword for bptr and nbptr
95  // and forward for bptr2 and nbptr2
96  // the current entry+2 in bptr is the size of the record i.e
97  // points to the next record
98  unsigned int nvar=df1b2variable::nvar;
100  int num_bytes=f1b2gradlist->nlist.bptr->numbytes;
101  list-=num_bytes;
102  list.saveposition(); // save pointer to beginning of record;
103 
104  // get info from tape1
105 #if defined(SAFE_ALL)
107 #endif
108  char * bptr=f1b2gradlist->list.bptr;
109  df1b2_header * py=(df1b2_header *) bptr;
110  bptr+=sizeof(df1b2_header);
111  df1b2_header * pz=(df1b2_header *) bptr;
112 
113  list.restoreposition(); // save pointer to beginning of record;
114 
115  // ****************************************************************
116  // turn this off if no third derivatives are calculated
117  // if (!no_third_derivatives)
118  // {
119  // save for second reverse pass
120  // save identifier 1
121 
122  for (unsigned int i=0;i<nvar;i++)
123  {
124  py->u_bar[i]+=pz->u_bar[i];
125  }
126  for (unsigned int i=0;i<nvar;i++)
127  {
128  py->u_dot_bar[i]+=pz->u_dot_bar[i];
129  }
130 
131  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
132  for (unsigned int i=0;i<nvar;i++)
133  {
134  pz->u_bar[i]=0;
135  }
136  for (unsigned int i=0;i<nvar;i++)
137  {
138  pz->u_dot_bar[i]=0;
139  }
140 }
141 
143 {
144  //const int nlist_record_size=sizeof(int)+sizeof(char*);
145  // We are going forward for bptr and backword for bptr2
146  //
147  // list 1
148  //
149  unsigned int nvar=df1b2variable::nvar;
151 
152  size_t total_bytes=2*sizeof(df1b2_header);
153 // string identifier debug stuff
154 #if defined(SAFE_ALL)
155  char ids[]="BY";
156  int slen=strlen(ids);
157  total_bytes+=slen;
158 #endif
159  list.check_buffer_size(total_bytes);
160 // end of string identifier debug stuff
161 
162  list.saveposition(); // save pointer to beginning of record;
164  // get record size
165  int num_bytes=nlist.bptr->numbytes;
166  // get info from tape1
167 #if defined(SAFE_ALL)
168  checkidentiferstring("LK",list);
169 #endif
170  df1b2_header * py=(df1b2_header *) list.bptr;
171  list.bptr+=sizeof(df1b2_header);
172  df1b2_header * pz=(df1b2_header *) list.bptr;
173  list.restoreposition(num_bytes); // save pointer to beginning of record;
174 
175  double * y_bar_tilde=py->get_u_bar_tilde();
176  double * y_dot_bar_tilde=py->get_u_dot_bar_tilde();
177  double * z_bar_tilde=pz->get_u_bar_tilde();
178  double * z_dot_bar_tilde=pz->get_u_dot_bar_tilde();
179  // Do second "reverse-reverse" pass calculations
180 
181  for (unsigned int i=0;i<nvar;i++)
182  {
183  z_bar_tilde[i]=0;
184  z_dot_bar_tilde[i]=0;
185  }
186 
187 
188  // start with y and add x
189  for (unsigned int i=0;i<nvar;i++)
190  {
191  z_bar_tilde[i]+=y_bar_tilde[i];
192  }
193 
194  for (unsigned int i=0;i<nvar;i++)
195  {
196  z_dot_bar_tilde[i]+=y_dot_bar_tilde[i];
197  }
198 }
199 
201 {
202  // We are going backword for bptr and forward for bptr2
203  // the current entry+2 in bptr is the size of the record i.e
204  // points to the next record
205  unsigned int nvar=df1b2variable::nvar;
208  // nlist-=sizeof(int);
209  // get record size
210  int num_bytes=nlist.bptr->numbytes;
211  // backup the size of the record
212  list-=num_bytes;
213  list.saveposition(); // save pointer to beginning of record;
214  // save the pointer to the beginning of the record
215  //df1b2_header x,z;
216 
217  // get info from tape1
218  // get info from tape1
219 #if defined(SAFE_ALL)
220  checkidentiferstring("LK",list);
221 #endif
222  df1b2_header * py=(df1b2_header *) list.bptr;
223  list.bptr+=sizeof(df1b2_header);
224  df1b2_header * pz=(df1b2_header *) list.bptr;
225  list.bptr+=sizeof(df1b2_header);
226 
227  list.restoreposition(); // save pointer to beginning of record;
228 
229  // !!!!! changed sign DF feb 7 2010
230  //*(py->u_tilde)-=*(pz->u_tilde);
231  *(py->u_tilde)+=*(pz->u_tilde);
232  for (unsigned int i=0;i<nvar;i++)
233  {
234  py->u_dot_tilde[i]+=pz->u_dot_tilde[i];
235  }
236  *(pz->u_tilde)=0;
237  for (unsigned int i=0;i<nvar;i++)
238  {
239  pz->u_dot_tilde[i]=0;
240  }
241 }
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_3_minusvc(void)
Definition: df1b2min3.cpp:200
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
void read_pass2_1_minusvc(void)
Definition: df1b2min3.cpp:92
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 read_pass2_2_minusvc(void)
Definition: df1b2min3.cpp:142
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
void ad_read_pass2_minusvc(void)
Definition: df1b2min3.cpp:72
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
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 write_pass1_minusvc(const df1b2variable *py, df1b2variable *pz)
Definition: df1b2min3.cpp:33
int numbytes
Definition: df1b2fun.h:594
void saveposition(void)
Definition: df1b2fun.h:552