Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00011 #include <df1b2fun.h>
00012
00013 df1b2variable operator - (double x, const df1b2variable& _y)
00014 {
00015 ADUNCONST(df1b2variable,y)
00016 df1b2variable z;
00017 double * yd=y.get_u_dot();
00018 double * zd=z.get_u_dot();
00019 *z.get_u()=x-*y.get_u();
00020 for (unsigned int i=0;i<df1b2variable::nvar;i++)
00021 {
00022 *zd++ = - *yd++;
00023 }
00024
00025
00026 if (!df1b2_gradlist::no_derivatives)
00027 f1b2gradlist->write_pass1_minuscv(&y,&z);
00028 return z;
00029 }
00030
00031 void ad_read_pass2_minuscv(void);
00032
00033 int df1b2_gradlist::write_pass1_minuscv(const df1b2variable * _py,
00034 df1b2variable * pz)
00035 {
00036 ADUNCONST(df1b2variable*,py)
00037 ncount++;
00038 #if defined(CHECK_COUNT)
00039 if (ncount >= ncount_check)
00040 cout << ncount << endl;
00041 #endif
00042
00043 size_t total_bytes=2*sizeof(df1b2_header);
00044
00045 #if defined(SAFE_ALL)
00046 char ids[]="GU";
00047 int slen=strlen(ids);
00048 total_bytes+=slen;
00049 #endif
00050 list.check_buffer_size(total_bytes);
00051 void * tmpptr=list.bptr;
00052 #if defined(SAFE_ALL)
00053 memcpy(list,ids,slen);
00054 #endif
00055
00056
00057 memcpy(list,(df1b2_header*)(py),sizeof(df1b2_header));
00058 memcpy(list,(df1b2_header*)(pz),sizeof(df1b2_header));
00059
00060 nlist.bptr->numbytes=adptr_diff(list.bptr,tmpptr);
00061 nlist.bptr->pf=(ADrfptr)(&ad_read_pass2_minuscv);
00062 ++nlist;
00063 return 0;
00064 }
00065
00066
00067 void read_pass2_1_minuscv(void);
00068 void read_pass2_2_minuscv(void);
00069 void read_pass2_3_minuscv(void);
00070
00071 void ad_read_pass2_minuscv(void)
00072 {
00073 switch(df1b2variable::passnumber)
00074 {
00075 case 1:
00076 read_pass2_1_minuscv();
00077 break;
00078 case 2:
00079 read_pass2_2_minuscv();
00080 break;
00081 case 3:
00082 read_pass2_3_minuscv();
00083 break;
00084 default:
00085 cerr << "illegal value for df1b2variable::pass = "
00086 << df1b2variable::passnumber << endl;
00087 exit(1);
00088 }
00089 }
00090
00091 void read_pass2_1_minuscv(void)
00092 {
00093
00094
00095
00096
00097 unsigned int nvar=df1b2variable::nvar;
00098 test_smartlist& list=f1b2gradlist->list;
00099 int num_bytes=f1b2gradlist->nlist.bptr->numbytes;
00100 list-=num_bytes;
00101 list.saveposition();
00102
00103
00104 #if defined(SAFE_ALL)
00105 checkidentiferstring("GU",f1b2gradlist->list);
00106 #endif
00107 char * bptr=f1b2gradlist->list.bptr;
00108 df1b2_header * py=(df1b2_header *) bptr;
00109 bptr+=sizeof(df1b2_header);
00110 df1b2_header * pz=(df1b2_header *) bptr;
00111
00112 list.restoreposition();
00113
00114
00115
00116
00117
00118
00119
00120
00121 for (unsigned int i=0;i<nvar;i++)
00122 {
00123 py->u_bar[i]-=pz->u_bar[i];
00124 }
00125 for (unsigned int i=0;i<nvar;i++)
00126 {
00127 py->u_dot_bar[i]-=pz->u_dot_bar[i];
00128 }
00129
00130
00131 for (unsigned int i=0;i<nvar;i++)
00132 {
00133 pz->u_bar[i]=0;
00134 }
00135 for (unsigned int i=0;i<nvar;i++)
00136 {
00137 pz->u_dot_bar[i]=0;
00138 }
00139 }
00140
00141 void read_pass2_2_minuscv(void)
00142 {
00143
00144
00145
00146
00147
00148 unsigned int nvar=df1b2variable::nvar;
00149 test_smartlist & list=f1b2gradlist->list;
00150
00151 size_t total_bytes=2*sizeof(df1b2_header);
00152
00153 #if defined(SAFE_ALL)
00154 char ids[]="BY";
00155 int slen=strlen(ids);
00156 total_bytes+=slen;
00157 #endif
00158 list.check_buffer_size(total_bytes);
00159
00160
00161 list.saveposition();
00162 fixed_smartlist & nlist=f1b2gradlist->nlist;
00163
00164 int num_bytes=nlist.bptr->numbytes;
00165
00166 #if defined(SAFE_ALL)
00167 checkidentiferstring("GU",list);
00168 #endif
00169 df1b2_header * py=(df1b2_header *) list.bptr;
00170 list.bptr+=sizeof(df1b2_header);
00171 df1b2_header * pz=(df1b2_header *) list.bptr;
00172 list.restoreposition(num_bytes);
00173
00174 double * y_bar_tilde=py->get_u_bar_tilde();
00175 double * y_dot_bar_tilde=py->get_u_dot_bar_tilde();
00176 double * z_bar_tilde=pz->get_u_bar_tilde();
00177 double * z_dot_bar_tilde=pz->get_u_dot_bar_tilde();
00178
00179
00180 for (unsigned int i=0;i<nvar;i++)
00181 {
00182 z_bar_tilde[i]=0;
00183 z_dot_bar_tilde[i]=0;
00184 }
00185
00186
00187 for (unsigned int i=0;i<nvar;i++)
00188 {
00189 z_bar_tilde[i]-=y_bar_tilde[i];
00190 }
00191
00192 for (unsigned int i=0;i<nvar;i++)
00193 {
00194 z_dot_bar_tilde[i]-=y_dot_bar_tilde[i];
00195 }
00196 }
00197
00198 void read_pass2_3_minuscv(void)
00199 {
00200
00201
00202
00203 unsigned int nvar=df1b2variable::nvar;
00204 fixed_smartlist & nlist=f1b2gradlist->nlist;
00205 test_smartlist& list=f1b2gradlist->list;
00206
00207
00208 int num_bytes=nlist.bptr->numbytes;
00209
00210 list-=num_bytes;
00211 list.saveposition();
00212
00213
00214
00215
00216
00217 #if defined(SAFE_ALL)
00218 checkidentiferstring("GU",list);
00219 #endif
00220 df1b2_header * py=(df1b2_header *) list.bptr;
00221 list.bptr+=sizeof(df1b2_header);
00222 df1b2_header * pz=(df1b2_header *) list.bptr;
00223 list.bptr+=sizeof(df1b2_header);
00224
00225 list.restoreposition();
00226
00227 *(py->u_tilde)-=*(pz->u_tilde);
00228 for (unsigned int i=0;i<nvar;i++)
00229 {
00230 py->u_dot_tilde[i]-=pz->u_dot_tilde[i];
00231 }
00232 *(pz->u_tilde)=0;
00233 for (unsigned int i=0;i<nvar;i++)
00234 {
00235 pz->u_dot_tilde[i]=0;
00236 }
00237 }