00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "QMCReadAndEvaluateConfigs.h"
00014
00015 QMCReadAndEvaluateConfigs::QMCReadAndEvaluateConfigs()
00016 {}
00017
00018 QMCReadAndEvaluateConfigs::QMCReadAndEvaluateConfigs(QMCInput *In,
00019 int cfgsToSkip)
00020 {
00021 initialize(In, cfgsToSkip);
00022 }
00023
00024 void QMCReadAndEvaluateConfigs::initialize(QMCInput *In, int cfgsToSkip)
00025 {
00026 Input = In;
00027 configsToSkip = cfgsToSkip;
00028
00029 Jastrow.initialize(Input);
00030
00031 Nelectrons = Input->WF.getNumberElectrons();
00032 Natoms = Input->Molecule.getNumberAtoms();
00033
00034
00035
00036 R.allocate(Nelectrons,3);
00037 R = 0.0;
00038
00039
00040
00041 D2.allocate(Nelectrons,3);
00042 }
00043
00044
00045
00046 void QMCReadAndEvaluateConfigs::rootCalculateProperties(
00047 Array1D < Array1D<double> > & Params, Array1D<QMCProperties> & Properties)
00048 {
00049
00050
00051
00052 #ifdef PARALLEL
00053
00054
00055
00056
00057
00058
00059
00060 int WorkSignal = 1;
00061 MPI_Bcast(&WorkSignal,1,MPI_INT,0,MPI_COMM_WORLD);
00062
00063
00064
00065 int ParamSize[2];
00066 ParamSize[0] = Params.dim1();
00067 ParamSize[1] = Params(0).dim1();
00068 MPI_Bcast(&ParamSize,2,MPI_INT,0,MPI_COMM_WORLD);
00069
00070 int elements = Params.dim1()*Params(0).dim1();
00071 double *PackedParameters = new double[elements];
00072
00073
00074
00075 for(int i=0;i<Params.dim1();i++)
00076 {
00077 for(int j=0;j<Params(i).dim1();j++)
00078 {
00079 PackedParameters[i*Params(0).dim1()+j] = Params(i)(j);
00080 }
00081 }
00082
00083
00084
00085 MPI_Bcast(PackedParameters,elements,MPI_DOUBLE,0,MPI_COMM_WORLD);
00086
00087 delete [] PackedParameters;
00088
00089 #endif
00090
00091 Array1D < QMCProperties > local_properties(Params.dim1());
00092 Properties.allocate(Params.dim1());
00093
00094 for(int i=0;i<Params.dim1();i++)
00095 {
00096 local_properties(i).zeroOut();
00097 Properties(i).zeroOut();
00098 }
00099
00100
00101
00102
00103 locally_CalculateProperties(Params,local_properties);
00104
00105
00106
00107 MPI_reduce(local_properties,Properties);
00108 }
00109
00110
00111
00112 void QMCReadAndEvaluateConfigs::workerCalculateProperties()
00113 {
00114
00115
00116
00117 #ifdef PARALLEL
00118
00119
00120
00121
00122
00123
00124 int ParamSize[2];
00125 MPI_Bcast(ParamSize,2,MPI_INT,0,MPI_COMM_WORLD);
00126
00127 Array1D< Array1D<double> > Params;
00128 Params.allocate(ParamSize[0]);
00129
00130 for(int i=0; i<ParamSize[0]; i++)
00131 {
00132 Params(i).allocate(ParamSize[1]);
00133 }
00134
00135 Array1D<QMCProperties> Properties(ParamSize[0]);
00136
00137 int elements = Params.dim1()*Params(0).dim1();
00138 double *PackedParameters = new double[elements];
00139
00140
00141
00142
00143 MPI_Bcast(PackedParameters,elements,MPI_DOUBLE,0,MPI_COMM_WORLD);
00144
00145
00146
00147 for(int i=0;i<Params.dim1();i++)
00148 {
00149 for(int j=0;j<Params(i).dim1();j++)
00150 {
00151 Params(i)(j) = PackedParameters[i*Params(0).dim1()+j];
00152 }
00153 }
00154
00155 delete [] PackedParameters;
00156
00157 Array1D < QMCProperties > local_properties(Params.dim1());
00158
00159 for(int i=0;i<Params.dim1();i++)
00160 {
00161 local_properties(i).zeroOut();
00162 Properties(i).zeroOut();
00163 }
00164
00165
00166
00167
00168 locally_CalculateProperties(Params,local_properties);
00169
00170
00171
00172 MPI_reduce(local_properties,Properties);
00173 #endif
00174 }
00175
00176
00177
00178 void QMCReadAndEvaluateConfigs::locally_CalculateProperties(
00179 Array1D < Array1D<double> > &Params, Array1D<QMCProperties> & Properties)
00180 {
00181 Input->outputer.open(Input->flags.config_file_name,false);
00182
00183
00184 Properties.allocate(Params.dim1());
00185 for(int j=0;j<Properties.dim1();j++)
00186 {
00187 Properties(j).zeroOut();
00188 }
00189
00190
00191
00192 for (int i=0; i<configsToSkip; i++)
00193 {
00194 Input->outputer.readCorrelatedSamplingConfiguration(R,D1,D2,lnJ,PE,weight);
00195 }
00196
00197
00198
00199 Array1D<int> numBad = Array1D<int>(Params.dim1());
00200 numBad = 0;
00201 while( !Input->outputer.eof() )
00202 {
00203
00204
00205 lnJ = 0.0;
00206 Input->outputer.readCorrelatedSamplingConfiguration(R,D1,D2,lnJ,PE,weight);
00207
00208
00209
00210
00211
00212
00213
00214 if (lnJ != 0)
00215 {
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 for(int i=0; i<Params.dim1(); i++)
00227 {
00228 bool ok = AddNewConfigToProperites(Params(i),Properties(i));
00229 if(!ok) numBad[i]++;
00230 }
00231 }
00232 }
00233 Input->outputer.close();
00234
00235 for(int i=0; i<Params.dim1(); i++)
00236 {
00237 if(numBad[i] != 0){
00238 cout << "Warning: " << numBad[i] << " bad configurations for Param("<<i<<") = " << Params(i);
00239 }
00240 }
00241 }
00242
00243
00244
00245 bool QMCReadAndEvaluateConfigs::AddNewConfigToProperites(
00246 Array1D<double> &Params,QMCProperties &Properties)
00247 {
00248 bool ok = true;
00249
00250
00251 Input->setAIParameters( Params );
00252 Jastrow.evaluate(R);
00253
00254 double E_Local;
00255 double logWeight;
00256
00257 bool Am_I_Valid = true;
00258
00259 if( Am_I_Valid == true )
00260 {
00261
00262
00263
00264
00265 E_Local = calc_E_Local_current();
00266 logWeight = calc_log_weight_current();
00267
00268
00269
00270 if(E_Local > MAXIMUM_ENERGY_VALUE)
00271 {
00272 E_Local = 0.0;
00273 logWeight = 0.0;
00274 ok = false;
00275 }
00276
00277 if(logWeight > MAXIMUM_LOG_WEIGHT_VALUE)
00278 {
00279 logWeight = 0.0;
00280 ok = false;
00281 }
00282 }
00283 else
00284 {
00285
00286
00287
00288 E_Local = MAXIMUM_ENERGY_VALUE;
00289 logWeight = MAXIMUM_LOG_WEIGHT_VALUE;
00290 }
00291
00292
00293
00294 Properties.energy.newSample(E_Local,weight*exp(logWeight));
00295 Properties.logWeights.newSample(logWeight,1.0);
00296
00297 return ok;
00298 }
00299
00300
00301
00302 double QMCReadAndEvaluateConfigs::calc_E_Local_current()
00303 {
00304 double E_Local_current = 0.0;
00305
00306
00307
00308 Array2D<double> * Grad_sum_u_current = Jastrow.getGradientLnJastrow(0);
00309
00310
00311
00312 double Lap_sum_u_current = Jastrow.getLaplacianLnJastrow(0);
00313
00314
00315
00316
00317 Array2D<double> Grad_PsiRatio_current_without_Jastrow(Nelectrons,3);
00318
00319 for(int i=0; i<Nelectrons; i++)
00320 {
00321 for(int j=0; j<3; j++)
00322 {
00323 Grad_PsiRatio_current_without_Jastrow(i,j)=D2(i,j);
00324 }
00325 }
00326
00327
00328
00329
00330 Array2D<double> Grad_PsiRatio_current(Nelectrons,3);
00331
00332 for(int i=0; i<Nelectrons; i++)
00333 {
00334 for(int j=0; j<3; j++)
00335 {
00336 Grad_PsiRatio_current(i,j)=
00337 Grad_PsiRatio_current_without_Jastrow(i,j) +(*Grad_sum_u_current)(i,j);
00338 }
00339 }
00340
00341
00342
00343 double alpha_beta_sum_of_Lap_PsiRatio_current=D1;
00344
00345
00346
00347
00348 double Laplacian_PsiRatio_current = alpha_beta_sum_of_Lap_PsiRatio_current +
00349 Lap_sum_u_current;
00350
00351 for(int i=0; i<Nelectrons; i++)
00352 {
00353 for(int j=0; j<3; j++)
00354 {
00355 Laplacian_PsiRatio_current += (*Grad_sum_u_current)(i,j) *
00356 (2*Grad_PsiRatio_current(i,j)-(*Grad_sum_u_current)(i,j));
00357 }
00358 }
00359
00360
00361
00362
00363 E_Local_current = -0.5 * Laplacian_PsiRatio_current + PE;
00364 return E_Local_current;
00365 }
00366
00367
00368
00369 double QMCReadAndEvaluateConfigs::calc_log_weight_current()
00370 {
00371
00372
00373
00374
00375
00376
00377
00378
00379 double logweight = 2*(Jastrow.getLnJastrow(0) - lnJ);
00380 return logweight;
00381 }
00382
00383
00384
00385 void QMCReadAndEvaluateConfigs::MPI_reduce(
00386 Array1D <QMCProperties> &local_Properties,
00387 Array1D < QMCProperties> &global_Properties)
00388 {
00389 global_Properties.allocate(local_Properties.dim1());
00390
00391 #ifdef PARALLEL
00392
00393 MPI_Reduce(local_Properties.array(),global_Properties.array(),
00394 local_Properties.dim1(),QMCProperties::MPI_TYPE,
00395 QMCProperties::MPI_REDUCE,0,MPI_COMM_WORLD);
00396
00397 #else
00398
00399 for(int i=0;i<local_Properties.dim1();i++)
00400 {
00401 global_Properties(i) = local_Properties(i);
00402 }
00403 #endif
00404 }
00405
00406