ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
def_eval.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 "fvar.hpp"
12 
13 #include <sys/stat.h>
14 #include <fcntl.h>
15 #include <string.h>
16 
17 #ifdef __TURBOC__
18  #pragma hdrstop
19  #include <iostream.h>
20 #endif
21 
22 #ifdef __ZTC__
23  #include <iostream.hpp>
24 #endif
25 
26 #include <stdio.h>
27 #include <stdlib.h>
28 
29 #ifdef __SUN__
30  #include <iostream.h>
31  #include <sys/stat.h>
32  #include <sys/types.h>
33  #include <unistd.h>
34 #endif
35 
36 #ifndef _MSC_VER
37  #include <iostream>
38  #include <sys/stat.h>
39  #include <sys/types.h>
40  #include <unistd.h>
41 #endif
42 
43 #if defined (__WAT32__)
44  #include <io.h>
45 #endif
46 
47 #include <math.h>
48 
49 #ifdef ISZERO
50  #undef ISZERO
51 #endif
52 #define ISZERO(d) ((d)==0.0)
53 //#define XXX 3.70255042e-17
54 
55  //ofstream gradlog("grad.log");
56 
61  void default_evaluation(void)
62  {
63  // checks to see how many independent variables there are
65  double * zptr = grad_ptr->dep_addr;
66  double z = *zptr;
67  *zptr = 0;
68  // Check to see if first independent variable is a NULL adress
69  if ( grad_ptr->ind_addr1 )
70  {
71  * grad_ptr->ind_addr1 += z * grad_ptr->mult1 ;
72  //gradlog << setprecision(13) << * grad_ptr->ind_addr1 << endl;
73  //if (fabs(* grad_ptr->ind_addr1+XXX)<1.e-16)
74  // cout << setprecision(13) << * grad_ptr->ind_addr1 << endl;
75 #if defined(USE_DDOUBLE)
76  if ( grad_ptr->mult2 !=0)
77 #else
78  if (!ISZERO(grad_ptr->mult2))
79 #endif
80  {
81  * grad_ptr->ind_addr2 += z * grad_ptr->mult2 ;
82  //gradlog << setprecision(13) << * grad_ptr->ind_addr2 << endl;
83  //if (fabs(* grad_ptr->ind_addr2+XXX)<1.e-16)
84  // cout << setprecision(13) << * grad_ptr->ind_addr2 << endl;
85  }
86  }
87  }
88 
94  {
95  // there is one independent variable
97  double z = * grad_ptr->dep_addr;
98  * grad_ptr->dep_addr=0.;
99  * grad_ptr->ind_addr1 += z;
100  //gradlog << setprecision(13) << * grad_ptr->ind_addr1 << endl;
101  //if (fabs(* grad_ptr->ind_addr1+XXX)<1.e-16)
102  //cout << setscientific() << setprecision(13) << * grad_ptr->ind_addr1
103  //<< endl;
104  }
105 
111  {
112  // there is one independent variable
114  double z = * grad_ptr->dep_addr;
115  * grad_ptr->dep_addr=0.;
116  * grad_ptr->ind_addr1 -= z;
117  //gradlog << setprecision(13) << * grad_ptr->ind_addr1 << endl;
118  // if (fabs(* grad_ptr->ind_addr1+XXX)<1.e-16)
119  // cout << setprecision(13) << * grad_ptr->ind_addr1 << endl;
120  }
121 
127 {
128  // there is one independent variable
130 }
131 
137  {
138  //char ch;
139  // there is one independent variable
141  //cout << setprecision(16) << *grad_ptr->dep_addr << endl;
142  //cout << setprecision(16) << *grad_ptr->ind_addr1 << endl;
143  //cout << setprecision(16) << grad_ptr->mult1 << endl;
144  //cin >> ch;
145  double z = * grad_ptr->dep_addr;
146  * grad_ptr->dep_addr=0.;
147  * grad_ptr->ind_addr1 += z * grad_ptr->mult1 ;
148  //gradlog << setprecision(13) << * grad_ptr->ind_addr1 << endl;
149  // if (fabs(* grad_ptr->ind_addr1+XXX)<1.e-16)
150  // cout << setprecision(13) << * grad_ptr->ind_addr1 << endl;
151  }
152 
158  {
159  // there are two independent variables
161  double z = * grad_ptr->dep_addr;
162  * grad_ptr->dep_addr=0.;
163  * grad_ptr->ind_addr1 += z * grad_ptr->mult1 ;
164  * grad_ptr->ind_addr2 += z * grad_ptr->mult2 ;
165  //gradlog << setprecision(13) << * grad_ptr->ind_addr1 << endl;
166  // if (fabs(* grad_ptr->ind_addr1+XXX)<1.e-16)
167  // cout << setprecision(13) << * grad_ptr->ind_addr1 << endl;
168  }
169 
175  {
176  // there are three independent variables
178  grad_stack_entry* grad_ptr = gs->GRAD_STACK1->ptr;
179 
180  double mult3=grad_ptr->mult1 ;
181  double * ind_addr3=grad_ptr->ind_addr1;
182  if (gs->GRAD_STACK1->ptr-- == gs->GRAD_STACK1->ptr_first)
183  {
184  // \todo Need test
185  // back up the file one buffer size and read forward
186  OFF_T offset = (OFF_T)(sizeof(grad_stack_entry) * gs->GRAD_STACK1->length);
187  OFF_T lpos=LSEEK(gs->GRAD_STACK1->_GRADFILE_PTR, -offset, SEEK_CUR);
188 
190  //gradient_structure::get()->GRAD_STACK1->ptr++;
191  }
192 
193  grad_ptr = gs->GRAD_STACK1->ptr;
194  double z = * grad_ptr->dep_addr;
195  * grad_ptr->dep_addr=0.;
196  * grad_ptr->ind_addr1 += z * grad_ptr->mult1 ;
197  * grad_ptr->ind_addr2 += z * grad_ptr->mult2 ;
198  * ind_addr3 += z * mult3 ;
199  }
200 
206  {
207  // there are three independent variables
209  grad_stack_entry* grad_ptr = gs->GRAD_STACK1->ptr;
210 
211  double * ind_addr3=grad_ptr->ind_addr1;
212  double mult3=grad_ptr->mult1 ;
213  double * ind_addr4=grad_ptr->ind_addr2;
214  double mult4=grad_ptr->mult2 ;
215  if (gs->GRAD_STACK1->ptr-- == gs->GRAD_STACK1->ptr_first)
216  {
217  // \todo Need test
218  // back up the file one buffer size and read forward
219  OFF_T offset = (OFF_T)(sizeof(grad_stack_entry) * gs->GRAD_STACK1->length);
220  OFF_T lpos=LSEEK(gs->GRAD_STACK1->_GRADFILE_PTR, -offset, SEEK_CUR);
221 
223  //gradient_structure::get()->GRAD_STACK1->ptr++;
224  }
225 
226  grad_ptr = gs->GRAD_STACK1->ptr;
227  double z = * grad_ptr->dep_addr;
228  * grad_ptr->dep_addr=0.;
229  * grad_ptr->ind_addr1 += z * grad_ptr->mult1 ;
230  * grad_ptr->ind_addr2 += z * grad_ptr->mult2 ;
231  * ind_addr3 += z * mult3 ;
232  * ind_addr4 += z * mult4 ;
233  //gradlog << setprecision(13) << * grad_ptr->ind_addr1 << endl;
234  // if (fabs(* grad_ptr->ind_addr1+XXX)<1.e-16)
235  // cout << setprecision(13) << * grad_ptr->ind_addr1 << endl;
236  //gradlog << setprecision(13) << * grad_ptr->ind_addr2 << endl;
237  // if (fabs(* grad_ptr->ind_addr2+XXX)<1.e-16)
238  // cout << setprecision(13) << * grad_ptr->ind_addr2 << endl;
239  //gradlog << setprecision(13) << * ind_addr3 << endl;
240  // if (fabs(* ind_addr3+XXX)<1.e-16)
241  // cout << setprecision(13) << * ind_addr3 << endl;
242  //gradlog << setprecision(13) << * ind_addr4 << endl;
243  // if (fabs(* ind_addr4+XXX)<1.e-16)
244  // cout << setprecision(13) << * ind_addr4 << endl;
245  }
246 
252  {
253  // there are two independent variables
255  double z = * grad_ptr->dep_addr;
256  * grad_ptr->dep_addr=0.;
257  * grad_ptr->ind_addr1 += z;
258  * grad_ptr->ind_addr2 += z;
259  }
260 
266  {
267  // there are two independent variables
269  double z = * grad_ptr->dep_addr;
270  * grad_ptr->dep_addr=0.;
271  * grad_ptr->ind_addr1 += z;
272  * grad_ptr->ind_addr2 -= z;
273  }
void default_evaluation2(void)
Description not yet available.
Definition: def_eval.cpp:136
double * ind_addr1
Pointer to first independent variable.
Definition: fvar.hpp:900
double mult2
Second mutiplicand in chain rule multipication.
Definition: fvar.hpp:903
void default_evaluation3(void)
Description not yet available.
Definition: def_eval.cpp:157
Holds derivative information for arithmetic operators and math library functions. ...
Definition: fvar.hpp:894
void default_evaluation1m(void)
Description not yet available.
Definition: def_eval.cpp:110
double * ind_addr2
Pointer to second independent variable.
Definition: fvar.hpp:902
void default_evaluation3ind(void)
Description not yet available.
Definition: def_eval.cpp:174
#define LSEEK
Definition: fvar.hpp:75
void default_evaluation4(void)
Description not yet available.
Definition: def_eval.cpp:251
void default_evaluation1(void)
Description not yet available.
Definition: def_eval.cpp:93
#define ISZERO(d)
Definition: def_eval.cpp:52
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void default_evaluation(void)
Description not yet available.
Definition: def_eval.cpp:61
static _THREAD gradient_structure * _instance
#define OFF_T
Definition: fvar.hpp:74
grad_stack_entry * ptr_first
Definition: fvar.hpp:924
double mult1
First mutiplicand in chain rule multipication.
Definition: fvar.hpp:901
grad_stack_entry * ptr
Definition: fvar.hpp:934
int read_grad_stack_buffer(OFF_T &lpos)
Description not yet available.
Definition: gst_read.cpp:76
void default_evaluation4ind(void)
Description not yet available.
Definition: def_eval.cpp:205
size_t length
Definition: fvar.hpp:930
int _GRADFILE_PTR
Definition: fvar.hpp:942
void default_evaluation4m(void)
Description not yet available.
Definition: def_eval.cpp:265
static _THREAD grad_stack * GRAD_STACK1
class for things related to the gradient structures, including dimension of arrays, size of buffers, etc.
double * dep_addr
Pointer to dependent variable.
Definition: fvar.hpp:899
void default_evaluation0(void)
Description not yet available.
Definition: def_eval.cpp:126