ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
df1b2sumc.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  {
20  df1b2variable z;
21  double * yd=y.get_u_dot();
22  double * zd=z.get_u_dot();
23  *z.get_u()=x+*y.get_u();
24  for (unsigned int i=0;i<df1b2variable::nvar;i++)
25  {
26  *zd++ = *yd++;
27  }
28 
29  // WRITE WHATEVER ON TAPE
31  f1b2gradlist->write_pass1_sum(x,&y,&z);
32  return z;
33  }
34 
35 void ad_read_pass2_sumc(void);
36 
42  df1b2variable * pz)
43  {
45  ncount++;
46 #if defined(CHECK_COUNT)
47  if (ncount >= ncount_check)
48  cout << ncount << endl;
49 #endif
50 
51  size_t total_bytes=2*sizeof(df1b2_header);
52 // string identifier debug stuff
53 #if defined(SAFE_ALL)
54  char ids[]="TU";
55  int slen=strlen(ids);
56  total_bytes+=slen;
57 #endif
58  list.check_buffer_size(total_bytes);
59  void * tmpptr=list.bptr;
60 #if defined(SAFE_ALL)
61  memcpy(list,ids,slen);
62 #endif
63 // end of string identifier debug stuff
64 
65  memcpy(list,(df1b2_header*)(py),sizeof(df1b2_header));
66  memcpy(list,(df1b2_header*)(pz),sizeof(df1b2_header));
67  // ***** write record size
70  ++nlist;
71  return 0;
72  }
73 
74 
75 void read_pass2_1_sumc(void);
76 void read_pass2_2_sumc(void);
77 void read_pass2_3_sumc(void);
78 
84 {
86  {
87  case 1:
89  break;
90  case 2:
92  break;
93  case 3:
95  break;
96  default:
97  cerr << "illegal value for df1b2variable::pass = "
99  ad_exit(1);
100  }
101 }
102 
108 {
109  // We are going backword for bptr and nbptr
110  // and forward for bptr2 and nbptr2
111  // the current entry+2 in bptr is the size of the record i.e
112  // points to the next record
113  unsigned int nvar=df1b2variable::nvar;
115  int num_bytes=f1b2gradlist->nlist.bptr->numbytes;
116  list-=num_bytes;
117  list.saveposition(); // save pointer to beginning of record;
118 
119  // get info from tape1
120 #if defined(SAFE_ALL)
122 #endif
123  char * bptr=f1b2gradlist->list.bptr;
124  df1b2_header * py=(df1b2_header *) bptr;
125  bptr+=sizeof(df1b2_header);
126  df1b2_header * pz=(df1b2_header *) bptr;
127 
128  list.restoreposition(); // save pointer to beginning of record;
129 
130  // ****************************************************************
131  // turn this off if no third derivatives are calculated
132  // if (!no_third_derivatives)
133  // {
134  // save for second reverse pass
135  // save identifier 1
136 
137  for (unsigned int i=0;i<nvar;i++)
138  {
139  py->u_bar[i]+=pz->u_bar[i];
140  }
141  for (unsigned int i=0;i<nvar;i++)
142  {
143  py->u_dot_bar[i]+=pz->u_dot_bar[i];
144  }
145 
146  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
147  for (unsigned int i=0;i<nvar;i++)
148  {
149  pz->u_bar[i]=0;
150  }
151  for (unsigned int i=0;i<nvar;i++)
152  {
153  pz->u_dot_bar[i]=0;
154  }
155 }
156 
162 {
163  //const int nlist_record_size=sizeof(int)+sizeof(char*);
164  // We are going forward for bptr and backword for bptr2
165  //
166  // list 1
167  //
168  unsigned int nvar=df1b2variable::nvar;
170 
171  size_t total_bytes=2*sizeof(df1b2_header);
172 // string identifier debug stuff
173 #if defined(SAFE_ALL)
174  char ids[]="BY";
175  int slen=strlen(ids);
176  total_bytes+=slen;
177 #endif
178  list.check_buffer_size(total_bytes);
179 // end of string identifier debug stuff
180 
181  list.saveposition(); // save pointer to beginning of record;
183  // get record size
184  int num_bytes=nlist.bptr->numbytes;
185  // get info from tape1
186 #if defined(SAFE_ALL)
187  checkidentiferstring("TU",list);
188 #endif
189  df1b2_header * py=(df1b2_header *) list.bptr;
190  list.bptr+=sizeof(df1b2_header);
191  df1b2_header * pz=(df1b2_header *) list.bptr;
192  list.restoreposition(num_bytes); // save pointer to beginning of record;
193 
194  double * y_bar_tilde=py->get_u_bar_tilde();
195  double * y_dot_bar_tilde=py->get_u_dot_bar_tilde();
196  double * z_bar_tilde=pz->get_u_bar_tilde();
197  double * z_dot_bar_tilde=pz->get_u_dot_bar_tilde();
198  // Do second "reverse-reverse" pass calculations
199 
200  for (unsigned int i=0;i<nvar;i++)
201  {
202  z_bar_tilde[i]=0;
203  z_dot_bar_tilde[i]=0;
204  }
205 
206  // start with y and add x
207  for (unsigned int i=0;i<nvar;i++)
208  {
209  z_bar_tilde[i]+=y_bar_tilde[i];
210  }
211 
212  for (unsigned int i=0;i<nvar;i++)
213  {
214  z_dot_bar_tilde[i]+=y_dot_bar_tilde[i];
215  }
216 }
217 
223 {
224  // We are going backword for bptr and forward for bptr2
225  // the current entry+2 in bptr is the size of the record i.e
226  // points to the next record
227  unsigned int nvar=df1b2variable::nvar;
230  // nlist-=sizeof(int);
231  // get record size
232  int num_bytes=nlist.bptr->numbytes;
233  // backup the size of the record
234  list-=num_bytes;
235  list.saveposition(); // save pointer to beginning of record;
236  // save the pointer to the beginning of the record
237  //df1b2_header x,z;
238 
239  // get info from tape1
240  // get info from tape1
241 #if defined(SAFE_ALL)
242  checkidentiferstring("TU",list);
243 #endif
244  df1b2_header * py=(df1b2_header *) list.bptr;
245  list.bptr+=sizeof(df1b2_header);
246  df1b2_header * pz=(df1b2_header *) list.bptr;
247 
248  list.restoreposition(); // save pointer to beginning of record;
249 
250  *(py->u_tilde)+=*(pz->u_tilde);
251  for (unsigned int i=0;i<nvar;i++)
252  {
253  py->u_dot_tilde[i]+=pz->u_dot_tilde[i];
254  }
255  *(pz->u_tilde)=0;
256  for (unsigned int i=0;i<nvar;i++)
257  {
258  pz->u_dot_tilde[i]=0;
259  }
260 }
char * bptr
Definition: df1b2fun.h:543
double * get_u_bar_tilde() const
Definition: df1b2fun.h:234
void ad_read_pass2_sumc(void)
Description not yet available.
Definition: df1b2sumc.cpp:83
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_sumc(void)
Description not yet available.
Definition: df1b2sumc.cpp:222
double * u_bar
Definition: df1b2fun.h:197
void read_pass2_1_sumc(void)
Description not yet available.
Definition: df1b2sumc.cpp:107
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
void read_pass2_2_sumc(void)
Description not yet available.
Definition: df1b2sumc.cpp:161
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
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
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