Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00011 #include <df1b2fun.h>
00012 void read_pass1_init_1(void);
00013 void read_pass1_init_2(void);
00014 void read_pass1_init_3(void);
00015
00016
00017 #if defined(ADDEBUG_PRINT)
00018 extern int addebug_count;
00019 #endif
00020
00021 #ifndef OPT_LIB
00022 #include <cassert>
00023 #include <climits>
00024 #endif
00025
00026 void ad_read_pass1_initialize(void);
00027
00033 void df1b2variable::operator=(double d)
00034 {
00035 initialize();
00036
00037 get_ind_index()=-1;
00038 *u=d;
00039
00040
00041 if (!df1b2_gradlist::no_derivatives)
00042 f1b2gradlist->write_save_pass2_tilde_values(this);
00043 if (!df1b2_gradlist::no_derivatives)
00044 f1b2gradlist->write_pass1_initialize(this);
00045 }
00046
00051 df1b2variable::df1b2variable(double d)
00052 {
00053
00054 ptr = (double*) pool->alloc();
00055
00056 initialize();
00057 double * block=ptr;
00058
00059 get_ind_index()=-1;
00060 ncopies=&(((twointsandptr*)block)->ncopies);
00061 *ncopies=0;
00062 u=block+=2;
00063 u_dot=block+=1;
00064 u_bar=block+=nvar;
00065 u_dot_bar=block+=nvar;
00066 u_tilde=block+=nvar;
00067 u_dot_tilde=block+=1;
00068 u_bar_tilde=block+=nvar;
00069 u_dot_bar_tilde=block+=nvar;
00070 *u=d;
00071 if (!df1b2_gradlist::no_derivatives)
00072 f1b2gradlist->write_pass1_initialize(this);
00073 }
00074
00078 df1b2variable::df1b2variable(void)
00079 {
00080 if (!df1b2variable::noallocate)
00081 {
00082 allocate();
00083 }
00084 else
00085 {
00086 ptr=0;
00087 ncopies=0;
00088 u=0;
00089 u_dot=0;
00090 u_bar=0;
00091 u_dot_bar=0;
00092 u_tilde=0;
00093 u_dot_tilde=0;
00094 u_bar_tilde=0;
00095 u_dot_bar_tilde=0;
00096 }
00097 }
00098
00103 df1b2variable::df1b2variable(const newadkludge* z)
00104 {
00105 ptr=0;
00106 ncopies=0;
00107 #if defined(SAFE_ALL)
00108 u=0;
00109 u_dot=0;
00110 u_bar=0;
00111 u_dot_bar=0;
00112 u_tilde=0;
00113 u_dot_tilde=0;
00114 u_bar_tilde=0;
00115 u_dot_bar_tilde=0;
00116 #endif
00117 }
00118
00123 void df1b2variable::allocate(void)
00124 {
00125
00126 ptr = (double*) pool->alloc();
00127
00128
00129 initialize();
00130 double * block=ptr;
00131
00132 get_ind_index()=-1;
00133 ncopies=&(((twointsandptr*)block)->ncopies);
00134 *ncopies=0;
00135 u=block+=2;
00136 u_dot=block+=1;
00137 u_bar=block+=nvar;
00138 u_dot_bar=block+=nvar;
00139 u_tilde=block+=nvar;
00140 u_dot_tilde=block+=1;
00141 u_bar_tilde=block+=nvar;
00142 u_dot_bar_tilde=block+=nvar;
00143 if (!df1b2_gradlist::no_derivatives)
00144 f1b2gradlist->write_pass1_initialize(this);
00145 }
00146
00151 df1b2variable::df1b2variable(adkludge1 * adkludgexxx)
00152 {
00153
00154 ptr = (double*) pool->alloc();
00155
00156 initialize();
00157 double * block=ptr;
00158 block[blocksize-1]=8219.4;
00159 get_ind_index()=-1;
00160 ncopies=&(((twointsandptr*)block)->ncopies);
00161 *ncopies=0;
00162 u=block+=2;
00163 u_dot=block+=1;
00164 u_bar=block+=nvar;
00165 u_dot_bar=block+=nvar;
00166 u_tilde=block+=nvar;
00167 u_dot_tilde=block+=1;
00168 u_bar_tilde=block+=nvar;
00169 u_dot_bar_tilde=block+=nvar;
00170
00171
00172 }
00173
00174
00175
00176
00181 int df1b2_gradlist::write_pass1_initialize(df1b2variable * pz)
00182 {
00183 char * pg=0;
00184 ncount++;
00185
00186 #if defined(CHECK_COUNT)
00187 if (ncount >= ncount_check)
00188 ncount_checker(ncount,ncount_check);
00189 #endif
00190
00191
00192 size_t total_bytes=sizeof(df1b2_header)+sizeof(char *);
00193
00194
00195 #if defined(SAFE_ALL)
00196 char ids[]="AZ";
00197 size_t slen=strlen(ids);
00198 total_bytes+=slen;
00199 #endif
00200
00201 list.check_buffer_size(total_bytes);
00202 void * tmpptr=list.bptr;
00203
00204 #if defined(SAFE_ALL)
00205 memcpy(list,ids,slen);
00206 #endif
00207
00208
00209 memcpy(list,(df1b2_header*)(pz),sizeof(df1b2_header));
00210
00211
00212 memcpy(list,&pg,sizeof(char *));
00213
00214
00215
00216 nlist.bptr->numbytes=adptr_diff(list.bptr,tmpptr);
00217 nlist.bptr->pf=(ADrfptr)(&ad_read_pass1_initialize);
00218 ++nlist;
00219 return 0;
00220 }
00221
00226 void ad_read_pass1_initialize(void)
00227 {
00228 switch(df1b2variable::passnumber)
00229 {
00230 case 1:
00231 read_pass1_init_1();
00232 break;
00233 case 2:
00234 read_pass1_init_2();
00235 break;
00236 case 3:
00237 read_pass1_init_3();
00238 break;
00239 default:
00240 cerr << "illegal value for df1b2variable::pass = "
00241 << df1b2variable::passnumber << endl;
00242 exit(1);
00243 }
00244 }
00245
00250 void checkidentiferstring(const char * ids,test_smartlist& list)
00251 {
00252 size_t slen=strlen(ids);
00253 char * s=(char*)list.bptr;
00254 int ss=strncmp(ids,s,slen);
00255 if (ss)
00256 {
00257 cerr << "Error in string identifer in list value should be " << ids
00258 << endl << " it appears to be " << s[0] << s[1] << s[2] << s[3]
00259 << " ... " << endl;
00260 ad_exit(1);
00261 }
00262 list.bptr+=slen;
00263 }
00264
00269 void read_pass1_init_1(void)
00270 {
00271
00272
00273
00274 size_t nvar = df1b2variable::nvar;
00275
00276 fixed_smartlist & nlist=f1b2gradlist->nlist;
00277 test_smartlist& list=f1b2gradlist->list;
00278
00279
00280 int num_bytes=nlist.bptr->numbytes;
00281
00282 list-=num_bytes;
00283 list.saveposition();
00284
00285
00286
00287
00288 #if defined(SAFE_ALL)
00289 checkidentiferstring("AZ",list);
00290 #endif
00291 df1b2_header * pz=(df1b2_header *) list.bptr;
00292 list.bptr+=sizeof(df1b2_header);
00293
00294 list.bptr+=sizeof(char*);
00295 list.restoreposition();
00296
00297
00298
00299
00300
00301
00302
00303
00304 fixed_smartlist2& nlist2=f1b2gradlist->nlist2;
00305 test_smartlist& list2=f1b2gradlist->list2;
00306
00307 size_t total_bytes=2*nvar*sizeof(double);
00308
00309
00310 #if defined(SAFE_ALL)
00311 char ids[]="EF";
00312 size_t slen=strlen(ids);
00313 total_bytes+=slen;
00314 #endif
00315
00316 list2.check_buffer_size(total_bytes);
00317
00318 void * tmpptr2=list2.bptr;
00319 #if defined(SAFE_ALL)
00320 memcpy(list2,ids,slen);
00321 #endif
00322
00323 size_t sizeofdouble = sizeof(double);
00324 memcpy(list2,pz->get_u_bar(),nvar*sizeofdouble);
00325
00326 memcpy(list2,pz->get_u_dot_bar(),nvar*sizeofdouble);
00327
00328 *nlist2.bptr=adptr_diff(list2.bptr,tmpptr2);
00329 ++nlist2;
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345 }
00346
00351 void read_pass1_init_2(void)
00352 {
00353
00354
00355
00356
00357
00358 unsigned int nvar = df1b2variable::nvar;
00359 test_smartlist & list=f1b2gradlist->list;
00360
00361 size_t total_bytes=sizeof(df1b2_header)+sizeof(char *);
00362
00363 #if defined(SAFE_ALL)
00364 char ids[]="AZ";
00365 int slen=strlen(ids);
00366 total_bytes+=slen;
00367 #endif
00368
00369 list.check_buffer_size(total_bytes);
00370
00371 list.saveposition();
00372 fixed_smartlist & nlist=f1b2gradlist->nlist;
00373
00374
00375 int num_bytes=nlist.bptr->numbytes;
00376
00377
00378
00379
00380 test_smartlist & list2=f1b2gradlist->list2;
00381 fixed_smartlist2 & nlist2=f1b2gradlist->nlist2;
00382
00383 int num_bytes2=*nlist2.bptr;
00384 --nlist2;
00385
00386 list2-=num_bytes2;
00387
00388
00389
00390
00391
00392
00393 list2.saveposition();
00394 #if defined(SAFE_ALL)
00395 checkidentiferstring("AZ",list);
00396 checkidentiferstring("EF",list2);
00397 #endif
00398 df1b2_header * pz=(df1b2_header *) list.bptr;
00399 list.bptr+=sizeof(df1b2_header);
00400
00401 list.bptr+=sizeof(char*);
00402 list.restoreposition(num_bytes);
00403
00404
00405
00406
00407 list2.restoreposition();
00408
00409 double * z_bar_tilde=pz->get_u_bar_tilde();
00410 double * z_dot_bar_tilde=pz->get_u_dot_bar_tilde();
00411
00412
00413
00414
00415 *pz->get_u_tilde()=0.0;
00416 for (size_t i=0;i<nvar;i++)
00417 {
00418 z_bar_tilde[i]=0;
00419 z_dot_bar_tilde[i]=0;
00420 }
00421 }
00422
00427 void read_pass1_init_3(void)
00428 {
00429
00430
00431
00432 unsigned int nvar = df1b2variable::nvar;
00433 fixed_smartlist & nlist=f1b2gradlist->nlist;
00434 test_smartlist& list=f1b2gradlist->list;
00435
00436
00437 int num_bytes=nlist.bptr->numbytes;
00438
00439 list-=num_bytes;
00440 list.saveposition();
00441
00442
00443
00444
00445
00446 #if defined(SAFE_ALL)
00447 checkidentiferstring("AZ",list);
00448 #endif
00449 df1b2_header * pz=(df1b2_header *) list.bptr;
00450 list.restoreposition();
00451
00452 *(pz->u_tilde)=0;
00453 for (size_t i=0;i<nvar;i++)
00454 {
00455 pz->u_dot_tilde[i]=0;
00456 }
00457 }