00001
00002
00003
00004
00005
00006
00011 #include <df1b2fun.h>
00012 #ifndef OPT_LIB
00013 #include <cassert>
00014 #include <climits>
00015 #endif
00016
00021 df1b2variable operator * (const df1b2variable& _x,const df1b2variable& _y)
00022 {
00023 ADUNCONST(df1b2variable,x)
00024 ADUNCONST(df1b2variable,y)
00025 df1b2variable z;
00026 double * xd=x.get_u_dot();
00027 double * yd=y.get_u_dot();
00028 double * zd=z.get_u_dot();
00029 double xu=*x.get_u();
00030 double yu=*y.get_u();
00031
00032 *z.get_u()=xu*yu;
00033
00034 for (unsigned int i=0;i<df1b2variable::nvar;i++)
00035 {
00036 *zd++ = yu * *xd++ + xu * *yd++;
00037 }
00038
00039
00040 if (!df1b2_gradlist::no_derivatives)
00041 f1b2gradlist->write_pass1_prod(&x,&y,&z);
00042 return z;
00043 }
00044
00045 void ad_read_pass2_prod(void);
00046
00051 int df1b2_gradlist::write_pass1_prod(const df1b2variable * _px,
00052 const df1b2variable * _py,df1b2variable * pz)
00053 {
00054 ADUNCONST(df1b2variable*,px)
00055 ADUNCONST(df1b2variable*,py)
00056 ncount++;
00057 #if defined(CHECK_COUNT)
00058 if (ncount >= ncount_check)
00059 cout << ncount << endl;
00060 #endif
00061 size_t nvar=df1b2variable::nvar;
00062
00063
00064
00065 size_t total_bytes=3*sizeof(df1b2_header)
00066 +2*(nvar+1)*sizeof(double);
00067
00068 #if defined(SAFE_ALL)
00069 char ids[]="DL";
00070 size_t slen=strlen(ids);
00071 total_bytes+=slen;
00072 #endif
00073
00074 list.check_buffer_size(total_bytes);
00075 void * tmpptr=list.bptr;
00076 #if defined(SAFE_ALL)
00077 memcpy(list,ids,slen);
00078 #endif
00079
00080
00081 memcpy(list,(df1b2_header*)(px),sizeof(df1b2_header));
00082 memcpy(list,(df1b2_header*)(py),sizeof(df1b2_header));
00083 memcpy(list,(df1b2_header*)(pz),sizeof(df1b2_header));
00084
00085
00086 size_t sizeofdouble = sizeof(double);
00087 memcpy(list,px->get_u(),sizeofdouble);
00088 memcpy(list,py->get_u(),sizeofdouble);
00089 memcpy(list,px->get_u_dot(),nvar*sizeofdouble);
00090 memcpy(list,py->get_u_dot(),nvar*sizeofdouble);
00091
00092 nlist.bptr->numbytes=adptr_diff(list.bptr,tmpptr);
00093 nlist.bptr->pf=(ADrfptr)(&ad_read_pass2_prod);
00094 ++nlist;
00095 return 0;
00096 }
00097
00098
00099 void read_pass2_1_prod(void);
00100 void read_pass2_2_prod(void);
00101 void read_pass2_3_prod(void);
00102
00107 void ad_read_pass2_prod(void)
00108 {
00109 switch(df1b2variable::passnumber)
00110 {
00111 case 1:
00112 read_pass2_1_prod();
00113 break;
00114 case 2:
00115 read_pass2_2_prod();
00116 break;
00117 case 3:
00118 read_pass2_3_prod();
00119 break;
00120 default:
00121 cerr << "illegal value for df1b2variable::pass = "
00122 << df1b2variable::passnumber << endl;
00123 exit(1);
00124 }
00125 }
00126
00131 void read_pass2_1_prod(void)
00132 {
00133
00134
00135
00136
00137
00138
00139 size_t nvar=df1b2variable::nvar;
00140 test_smartlist& list=f1b2gradlist->list;
00141
00142 int num_bytes=f1b2gradlist->nlist.bptr->numbytes;
00143 list-=num_bytes;
00144 list.saveposition();
00145 double xu,yu;
00146
00147
00148
00149
00150 #if defined(SAFE_ALL)
00151 checkidentiferstring("DL",f1b2gradlist->list);
00152 #endif
00153 char * bptr=f1b2gradlist->list.bptr;
00154 df1b2_header * px=(df1b2_header *) bptr;
00155 bptr+=sizeof(df1b2_header);
00156 df1b2_header * py=(df1b2_header *) bptr;
00157 bptr+=sizeof(df1b2_header);
00158 df1b2_header * pz=(df1b2_header *) bptr;
00159 bptr+=sizeof(df1b2_header);
00160
00161
00162 memcpy(&xu,bptr,sizeof(double));
00163 bptr+=sizeof(double);
00164 memcpy(&yu,bptr,sizeof(double));
00165 bptr+=sizeof(double);
00166 double * xdot=(double*)bptr;
00167 bptr+=nvar*sizeof(double);
00168 double * ydot=(double*)bptr;
00169
00170 list.restoreposition();
00171
00172
00173
00174
00175
00176
00177
00178 test_smartlist & list2 = f1b2gradlist->list2;
00179
00180 size_t total_bytes=2*nvar*sizeof(double);
00181
00182 #if defined(SAFE_ALL)
00183 char ids[]="QK";
00184 size_t slen=strlen(ids);
00185 total_bytes+=slen;
00186 #endif
00187
00188 list2.check_buffer_size(total_bytes);
00189
00190 void * tmpptr=list2.bptr;
00191 #if defined(SAFE_ALL)
00192 memcpy(list2,ids,slen);
00193 #endif
00194
00195 fixed_smartlist2 & nlist2 = f1b2gradlist->nlist2;
00196 size_t sizeofdouble = sizeof(double);
00197 memcpy(list2,pz->get_u_bar(),nvar*sizeofdouble);
00198 memcpy(list2,pz->get_u_dot_bar(),nvar*sizeofdouble);
00199 *nlist2.bptr=adptr_diff(list2.bptr,tmpptr);
00200 ++nlist2;
00201
00202
00203 for (size_t i=0;i<nvar;i++)
00204 {
00205
00206 px->u_bar[i]+=yu*pz->u_bar[i];
00207 }
00208 for (size_t i=0;i<nvar;i++)
00209 {
00210
00211 py->u_bar[i]+=xu*pz->u_bar[i];
00212 }
00213
00214 for (size_t i=0;i<nvar;i++)
00215 {
00216
00217
00218 px->u_bar[i]+=ydot[i]*pz->u_dot_bar[i];
00219 }
00220
00221 for (size_t i=0;i<nvar;i++)
00222 {
00223
00224
00225 py->u_bar[i]+=xdot[i]*pz->u_dot_bar[i];
00226 }
00227 for (size_t i=0;i<nvar;i++)
00228 {
00229
00230 px->u_dot_bar[i]+=yu*pz->u_dot_bar[i];
00231 }
00232 for (size_t i=0;i<nvar;i++)
00233 {
00234
00235 py->u_dot_bar[i]+=xu*pz->u_dot_bar[i];
00236 }
00237
00238
00239 for (size_t i=0;i<nvar;i++)
00240 {
00241 pz->u_bar[i]=0;
00242 }
00243 for (size_t i=0;i<nvar;i++)
00244 {
00245 pz->u_dot_bar[i]=0;
00246 }
00247 }
00248
00253 void read_pass2_2_prod(void)
00254 {
00255
00256
00257
00258
00259
00260 unsigned int nvar=df1b2variable::nvar;
00261 test_smartlist & list=f1b2gradlist->list;
00262
00263
00264
00265 size_t total_bytes=3*sizeof(df1b2_header)
00266 +2*(nvar+1)*sizeof(double);
00267
00268 #if defined(SAFE_ALL)
00269 char ids[]="DL";
00270 size_t slen=strlen(ids);
00271 total_bytes+=slen;
00272 #endif
00273
00274 list.check_buffer_size(total_bytes);
00275
00276
00277 list.saveposition();
00278 fixed_smartlist & nlist=f1b2gradlist->nlist;
00279
00280
00281 int num_bytes=nlist.bptr->numbytes;
00282
00283
00284
00285 test_smartlist & list2=f1b2gradlist->list2;
00286 fixed_smartlist2 & nlist2=f1b2gradlist->nlist2;
00287
00288 int num_bytes2=*nlist2.bptr;
00289 --nlist2;
00290
00291 list2-=num_bytes2;
00292 list2.saveposition();
00293
00294
00295
00296 double xu,yu;
00297 double * xdot;
00298 double * ydot;
00299
00300
00301
00302
00303
00304 #if defined(SAFE_ALL)
00305 checkidentiferstring("DL",list);
00306 checkidentiferstring("QK",list2);
00307 #endif
00308 df1b2_header * px=(df1b2_header *) list.bptr;
00309 list.bptr+=sizeof(df1b2_header);
00310 df1b2_header * py=(df1b2_header *) list.bptr;
00311 list.bptr+=sizeof(df1b2_header);
00312 df1b2_header * pz=(df1b2_header *) list.bptr;
00313 list.bptr+=sizeof(df1b2_header);
00314
00315
00316 memcpy(&xu,list.bptr,sizeof(double));
00317 list.bptr+=sizeof(double);
00318 memcpy(&yu,list.bptr,sizeof(double));
00319 list.bptr+=sizeof(double);
00320 xdot=(double*)list.bptr;
00321 list.bptr+=nvar*sizeof(double);
00322 ydot=(double*)list.bptr;
00323 list.restoreposition(num_bytes);
00324
00325 double * zbar;
00326 double * zdotbar;
00327
00328 zbar=(double*)list2.bptr;
00329 zdotbar=(double*)(list2.bptr+nvar*sizeof(double));
00330 list2.restoreposition();
00331
00332 double * x_tilde=px->get_u_tilde();
00333 double * x_dot_tilde=px->get_u_dot_tilde();
00334 double * x_bar_tilde=px->get_u_bar_tilde();
00335 double * x_dot_bar_tilde=px->get_u_dot_bar_tilde();
00336 double * y_tilde=py->get_u_tilde();
00337 double * y_dot_tilde=py->get_u_dot_tilde();
00338 double * y_bar_tilde=py->get_u_bar_tilde();
00339 double * y_dot_bar_tilde=py->get_u_dot_bar_tilde();
00340 double * z_bar_tilde=pz->get_u_bar_tilde();
00341 double * z_dot_bar_tilde=pz->get_u_dot_bar_tilde();
00342
00343
00344 for (size_t i=0;i<nvar;i++)
00345 {
00346 z_bar_tilde[i]=0;
00347 z_dot_bar_tilde[i]=0;
00348 }
00349
00350
00351 for (size_t i=0;i<nvar;i++)
00352 {
00353
00354
00355
00356 z_bar_tilde[i]+=yu*x_bar_tilde[i];
00357 *y_tilde+=zbar[i]*x_bar_tilde[i];
00358 }
00359
00360 for (size_t i=0;i<nvar;i++)
00361 {
00362
00363
00364
00365 *y_tilde+=zdotbar[i]*x_dot_bar_tilde[i];
00366 z_dot_bar_tilde[i]+=yu*x_dot_bar_tilde[i];
00367 }
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379 for (size_t i=0;i<nvar;i++)
00380 {
00381
00382
00383
00384 *x_tilde+=zbar[i]*y_bar_tilde[i];
00385 z_bar_tilde[i]+=xu*y_bar_tilde[i];
00386 }
00387
00388 for (size_t i=0;i<nvar;i++)
00389 {
00390
00391
00392
00393 *x_tilde+=zdotbar[i]*y_dot_bar_tilde[i];
00394 z_dot_bar_tilde[i]+=xu*y_dot_bar_tilde[i];
00395 }
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406 for (size_t i=0;i<nvar;i++)
00407 {
00408
00409
00410
00411
00412 y_dot_tilde[i]+=zdotbar[i]*x_bar_tilde[i];
00413 z_dot_bar_tilde[i]+=ydot[i]*x_bar_tilde[i];
00414 }
00415 for (size_t i=0;i<nvar;i++)
00416 {
00417
00418
00419
00420
00421 x_dot_tilde[i]+=zdotbar[i]*y_bar_tilde[i];
00422 z_dot_bar_tilde[i]+=xdot[i]*y_bar_tilde[i];
00423 }
00424 }
00425
00430 void read_pass2_3_prod(void)
00431 {
00432
00433
00434
00435 unsigned int nvar=df1b2variable::nvar;
00436 fixed_smartlist & nlist=f1b2gradlist->nlist;
00437 test_smartlist& list=f1b2gradlist->list;
00438
00439
00440 int num_bytes=nlist.bptr->numbytes;
00441
00442 list-=num_bytes;
00443 list.saveposition();
00444
00445 double xu;
00446 double yu;
00447 double * xdot;
00448 double * ydot;
00449
00450
00451
00452
00453
00454 #if defined(SAFE_ALL)
00455 checkidentiferstring("DL",list);
00456 #endif
00457 df1b2_header * px=(df1b2_header *) list.bptr;
00458 list.bptr+=sizeof(df1b2_header);
00459 df1b2_header * py=(df1b2_header *) list.bptr;
00460 list.bptr+=sizeof(df1b2_header);
00461 df1b2_header * pz=(df1b2_header *) list.bptr;
00462 list.bptr+=sizeof(df1b2_header);
00463
00464
00465 memcpy(&xu,list.bptr,sizeof(double));
00466 list.bptr+=sizeof(double);
00467 memcpy(&yu,list.bptr,sizeof(double));
00468 list.bptr+=sizeof(double);
00469 xdot=(double*)list.bptr;
00470 list.bptr+=nvar*sizeof(double);
00471 ydot=(double*)list.bptr;
00472 list.restoreposition();
00473
00474
00475
00476 *(px->u_tilde)+=yu* *(pz->u_tilde);
00477 *(py->u_tilde)+=xu* *(pz->u_tilde);
00478 for (size_t i=0;i<nvar;i++)
00479 {
00480
00481
00482 *(py->u_tilde)+=xdot[i]*pz->u_dot_tilde[i];
00483
00484
00485 *(px->u_tilde)+=ydot[i]*pz->u_dot_tilde[i];
00486 }
00487 for (size_t i=0;i<nvar;i++)
00488 {
00489
00490
00491 px->u_dot_tilde[i]+=yu*pz->u_dot_tilde[i];
00492 py->u_dot_tilde[i]+=xu*pz->u_dot_tilde[i];
00493 }
00494 *(pz->u_tilde)=0;
00495 for (size_t i=0;i<nvar;i++)
00496 {
00497 pz->u_dot_tilde[i]=0;
00498 }
00499 }