00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "QMCProperties.h"
00014
00015 #include "QMCInput.h"
00016 #include "QMCDerivativeProperties.h"
00017
00018 QMCProperties::QMCProperties()
00019 {
00020 zeroOut();
00021
00022 #ifdef PARALLEL
00023 if (!mpiTypeCreated)
00024 {
00025 mpiTypeCreated = true;
00026 buildMpiType();
00027 buildMpiReduce();
00028 }
00029 #endif
00030 }
00031
00032 QMCProperties::~QMCProperties()
00033 {
00034 }
00035
00036 void QMCProperties::zeroOut()
00037 {
00038 walkerAge.zeroOut();
00039 weightChange.zeroOut();
00040 growthRate.zeroOut();
00041
00042 energy.zeroOut();
00043 energy2.zeroOut();
00044 kineticEnergy.zeroOut();
00045 potentialEnergy.zeroOut();
00046 neEnergy.zeroOut();
00047 eeEnergy.zeroOut();
00048 logWeights.zeroOut();
00049 acceptanceProbability.zeroOut();
00050 distanceMovedAccepted.zeroOut();
00051 distanceMovedTrial.zeroOut();
00052 }
00053
00054 void QMCProperties::newSample(QMCProperties* newProperties, double weight,
00055 int nwalkers)
00056 {
00057 if(newProperties->walkerAge.getNumberSamples() > 0)
00058 walkerAge.newSample(newProperties->walkerAge.getAverage(), 1.0);
00059 if(newProperties->weightChange.getNumberSamples() > 0)
00060 weightChange.newSample(newProperties->weightChange.getAverage(), 1.0);;
00061 if(newProperties->growthRate.getNumberSamples() > 0)
00062 growthRate.newSample(newProperties->growthRate.getAverage(), 1.0);
00063
00064 if(newProperties->energy.getNumberSamples() > 0)
00065 {
00066 energy.newSample(newProperties->energy.getAverage(), weight);
00067
00068 double e = newProperties->energy.getAverage();
00069 energy2.newSample(e*e, weight);
00070
00071 kineticEnergy.newSample(newProperties->kineticEnergy.getAverage(), weight);
00072 potentialEnergy.newSample(newProperties->potentialEnergy.getAverage(),
00073 weight);
00074 neEnergy.newSample(newProperties->neEnergy.getAverage(), weight);
00075 eeEnergy.newSample(newProperties->eeEnergy.getAverage(), weight);
00076 acceptanceProbability.newSample
00077 (newProperties->acceptanceProbability.getAverage(), weight);
00078 distanceMovedAccepted.newSample
00079 (newProperties->distanceMovedAccepted.getAverage(), weight);
00080 distanceMovedTrial.newSample(newProperties->distanceMovedTrial.getAverage(),
00081 weight);
00082 logWeights.newSample(newProperties->logWeights.getAverage(), nwalkers);
00083 }
00084 }
00085
00086 void QMCProperties::operator = ( const QMCProperties &rhs )
00087 {
00088 walkerAge = rhs.walkerAge;
00089 weightChange = rhs.weightChange;
00090 growthRate = rhs.growthRate;
00091
00092 energy = rhs.energy;
00093 energy2 = rhs.energy2;
00094 kineticEnergy = rhs.kineticEnergy;
00095 potentialEnergy = rhs.potentialEnergy;
00096 neEnergy = rhs.neEnergy;
00097 eeEnergy = rhs.eeEnergy;
00098 logWeights = rhs.logWeights;
00099 acceptanceProbability = rhs.acceptanceProbability;
00100 distanceMovedAccepted = rhs.distanceMovedAccepted;
00101 distanceMovedTrial = rhs.distanceMovedTrial;
00102 }
00103
00104 QMCProperties QMCProperties::operator + ( QMCProperties &rhs )
00105 {
00106 QMCProperties result;
00107
00108 result.weightChange = weightChange + rhs.weightChange;
00109 result.walkerAge = walkerAge + rhs.walkerAge;
00110 result.growthRate = growthRate + rhs.growthRate;
00111
00112 result.energy = energy + rhs.energy;
00113 result.energy2 = energy2 + rhs.energy2;
00114 result.kineticEnergy = kineticEnergy + rhs.kineticEnergy;
00115 result.potentialEnergy = potentialEnergy + rhs.potentialEnergy;
00116 result.neEnergy = neEnergy + rhs.neEnergy;
00117 result.eeEnergy = eeEnergy + rhs.eeEnergy;
00118 result.logWeights = logWeights + rhs.logWeights;
00119 result.acceptanceProbability = acceptanceProbability +
00120 rhs.acceptanceProbability;
00121 result.distanceMovedAccepted = distanceMovedAccepted +
00122 rhs.distanceMovedAccepted;
00123 result.distanceMovedTrial = distanceMovedTrial + rhs.distanceMovedTrial;
00124
00125 return result;
00126 }
00127
00128 void QMCProperties::toXML(ostream& strm)
00129 {
00130
00131 strm << "<QMCProperties>" << endl;
00132
00133
00134 strm << "<Energy>" << endl;
00135 energy.toXML(strm);
00136 strm << "</Energy>" << endl;
00137
00138 if (globalInput.flags.checkpoint_energy_only == 0)
00139 {
00140
00141 strm << "<KineticEnergy>" << endl;
00142 kineticEnergy.toXML(strm);
00143 strm << "</KineticEnergy>" << endl;
00144
00145
00146 strm << "<PotentialEnergy>" << endl;
00147 potentialEnergy.toXML(strm);
00148 strm << "</PotentialEnergy>" << endl;
00149
00150
00151 strm << "<NucElecEnergy>" << endl;
00152 neEnergy.toXML(strm);
00153 strm << "</NucElecEnergy>" << endl;
00154
00155
00156 strm << "<ElecElecEnergy>" << endl;
00157 eeEnergy.toXML(strm);
00158 strm << "</ElecElecEnergy>" << endl;
00159
00160
00161 strm << "<LogWeights>" << endl;
00162 logWeights.toXML(strm);
00163 strm << "</LogWeights>" << endl;
00164
00165
00166 strm << "<AcceptanceProbability>" << endl;
00167 acceptanceProbability.toXML(strm);
00168 strm << "</AcceptanceProbability>" << endl;
00169
00170
00171 strm << "<DistanceMovedAccepted>" << endl;
00172 distanceMovedAccepted.toXML(strm);
00173 strm << "</DistanceMovedAccepted>" << endl;
00174
00175
00176 strm << "<DistanceMovedTrial>" << endl;
00177 distanceMovedTrial.toXML(strm);
00178 strm << "</DistanceMovedTrial>" << endl;
00179
00180
00181 strm << "<walkerAge>" << endl;
00182 walkerAge.toXML(strm);
00183 strm << "</walkerAge>" << endl;
00184
00185
00186 strm << "<weightChange>" << endl;
00187 weightChange.toXML(strm);
00188 strm << "</weightChange>" << endl;
00189
00190
00191 strm << "<growthRate>" << endl;
00192 growthRate.toXML(strm);
00193 strm << "</growthRate>" << endl;
00194 }
00195
00196
00197 strm << "</QMCProperties>" << endl;
00198 }
00199
00200 bool QMCProperties::readXML(istream& strm)
00201 {
00202 string temp;
00203
00204
00205 strm >> temp;
00206 if (temp != "<QMCProperties>")
00207 return false;
00208
00209
00210 strm >> temp;
00211 if (temp != "<Energy>")
00212 return false;
00213 if (!energy.readXML(strm))
00214 return false;
00215 strm >> temp;
00216 if (temp != "</Energy>")
00217 return false;
00218
00219 if (globalInput.flags.checkpoint_energy_only == 0)
00220 {
00221
00222 strm >> temp;
00223 if (temp != "<KineticEnergy>")
00224 return false;
00225 if (!kineticEnergy.readXML(strm))
00226 return false;
00227 strm >> temp;
00228 if (temp != "</KineticEnergy>")
00229 return false;
00230
00231
00232 strm >> temp;
00233 if (temp != "<PotentialEnergy>")
00234 return false;
00235 if (!potentialEnergy.readXML(strm))
00236 return false;
00237 strm >> temp;
00238 if (temp != "</PotentialEnergy>")
00239 return false;
00240
00241
00242 strm >> temp;
00243 if (temp != "<NucElecEnergy>")
00244 return false;
00245 if (!neEnergy.readXML(strm))
00246 return false;
00247 strm >> temp;
00248 if (temp != "</NucElecEnergy>")
00249 return false;
00250
00251
00252 strm >> temp;
00253 if (temp != "<ElecElecEnergy>")
00254 return false;
00255 if (!eeEnergy.readXML(strm))
00256 return false;
00257 strm >> temp;
00258 if (temp != "</ElecElecEnergy>")
00259 return false;
00260
00261
00262 strm >> temp;
00263 if (temp != "<LogWeights>")
00264 return false;
00265 if (!logWeights.readXML(strm))
00266 return false;
00267 strm >> temp;
00268 if (temp != "</LogWeights>")
00269 return false;
00270
00271
00272 strm >> temp;
00273 if (temp != "<AcceptanceProbability>")
00274 return false;
00275 if (!acceptanceProbability.readXML(strm))
00276 return false;
00277 strm >> temp;
00278 if (temp != "</AcceptanceProbability>")
00279 return false;
00280
00281
00282 strm >> temp;
00283 if (temp != "<DistanceMovedAccepted>")
00284 return false;
00285 if (!distanceMovedAccepted.readXML(strm))
00286 return false;
00287 strm >> temp;
00288 if (temp != "</DistanceMovedAccepted>")
00289 return false;
00290
00291
00292 strm >> temp;
00293 if (temp != "<DistanceMovedTrial>")
00294 return false;
00295 if (!distanceMovedTrial.readXML(strm))
00296 return false;
00297 strm >> temp;
00298 if (temp != "</DistanceMovedTrial>")
00299 return false;
00300
00301
00302 strm >> temp;
00303 if (temp != "<walkerAge>")
00304 return false;
00305 if (!walkerAge.readXML(strm))
00306 return false;
00307 strm >> temp;
00308 if (temp != "</walkerAge>")
00309 return false;
00310
00311
00312 strm >> temp;
00313 if (temp != "<weightChange>")
00314 return false;
00315 if (!weightChange.readXML(strm))
00316 return false;
00317 strm >> temp;
00318 if (temp != "</weightChange>")
00319 return false;
00320
00321
00322 strm >> temp;
00323 if (temp != "<growthRate>")
00324 return false;
00325 if (!growthRate.readXML(strm))
00326 return false;
00327 strm >> temp;
00328 if (temp != "</growthRate>")
00329 return false;
00330 }
00331
00332
00333 strm >> temp;
00334 if(temp != "</QMCProperties>")
00335 return false;
00336
00337 return true;
00338 }
00339
00340 ostream& operator <<(ostream& strm, QMCProperties &rhs)
00341 {
00342 strm << endl << "------------------- Energy -------------------" << endl;
00343 rhs.energy.printAll(strm);
00344
00345 strm << endl << "----------------- Energy^2 -------------------" << endl;
00346 strm << rhs.energy2;
00347
00348 strm << endl << "--------------- Kinetic Energy ---------------" << endl;
00349 strm << rhs.kineticEnergy;
00350
00351 strm << endl << "-------------- Potential Energy --------------" << endl;
00352 strm << rhs.potentialEnergy;
00353
00354 strm << endl << "-------------- Nuc-Elec Energy ---------------" << endl;
00355 strm << rhs.neEnergy;
00356
00357 strm << endl << "-------------- Elec-Elec Energy --------------" << endl;
00358 strm << rhs.eeEnergy;
00359
00360 strm << endl << "------------ AcceptanceProbability -----------" << endl;
00361 strm << rhs.acceptanceProbability;
00362
00363 strm << endl << "------------ DistanceMovedAccepted -----------" << endl;
00364 strm << rhs.distanceMovedAccepted;
00365
00366 strm << endl << "------------- DistanceMovedTrial -------------" << endl;
00367 strm << rhs.distanceMovedTrial;
00368
00369 strm << endl << "----------------- Walker Age -----------------" << endl;
00370 strm << rhs.walkerAge;
00371
00372 if(globalInput.flags.run_type == "diffusion"){
00373 strm << endl << "--------------- Weight Change ----------------" << endl;
00374 strm << rhs.weightChange;
00375
00376 strm << endl << "---------------- Growth Rate -----------------" << endl;
00377 strm << rhs.growthRate;
00378
00379 strm << endl << "----------------- logWeights -----------------" << endl;
00380 strm << rhs.logWeights;
00381 }
00382
00383 return strm;
00384 }
00385
00386 #ifdef PARALLEL
00387
00388 bool QMCProperties::mpiTypeCreated = false;
00389
00390 void QMCProperties::buildMpiReduce()
00391 {
00392 MPI_Op_create((MPI_User_function*)Reduce_Function,true,&MPI_REDUCE);
00393 }
00394
00395 void QMCProperties::buildMpiType()
00396 {
00397 QMCProperties indata;
00398
00399
00400
00401 const int NumberOfProperties = 13;
00402
00403 int block_lengths[NumberOfProperties];
00404 MPI_Aint displacements[NumberOfProperties];
00405 MPI_Aint addresses[NumberOfProperties+1];
00406 MPI_Datatype typelist[NumberOfProperties];
00407
00408
00409 for(int i=0; i<NumberOfProperties; i++)
00410 {
00411 typelist[i] = QMCProperty::MPI_TYPE;
00412 block_lengths[i] = 1;
00413 }
00414
00415
00416
00417 MPI_Address(&indata, &addresses[0]);
00418 MPI_Address(&(indata.energy), &addresses[1]);
00419 MPI_Address(&(indata.logWeights), &addresses[2]);
00420 MPI_Address(&(indata.acceptanceProbability), &addresses[3]);
00421 MPI_Address(&(indata.distanceMovedAccepted), &addresses[4]);
00422 MPI_Address(&(indata.distanceMovedTrial), &addresses[5]);
00423 MPI_Address(&(indata.kineticEnergy), &addresses[6]);
00424 MPI_Address(&(indata.potentialEnergy), &addresses[7]);
00425 MPI_Address(&(indata.neEnergy), &addresses[8]);
00426 MPI_Address(&(indata.eeEnergy), &addresses[9]);
00427 MPI_Address(&(indata.walkerAge), &addresses[10]);
00428 MPI_Address(&(indata.weightChange), &addresses[11]);
00429 MPI_Address(&(indata.growthRate), &addresses[12]);
00430 MPI_Address(&(indata.energy2), &addresses[13]);
00431
00432
00433
00434 for(int i=0; i<NumberOfProperties; i++)
00435 {
00436 displacements[i] = addresses[i+1] - addresses[0];
00437 }
00438
00439
00440 #ifdef QMC_OLDMPICH
00441
00442
00443
00444
00445 MPI_Type_struct(NumberOfProperties, block_lengths, displacements, typelist,
00446 &MPI_TYPE);
00447 #else
00448
00449
00450
00451
00452
00453
00454
00455
00456 MPI_Datatype temp;
00457 MPI_Type_struct(NumberOfProperties, block_lengths, displacements, typelist,
00458 &temp);
00459 MPI_Type_create_resized(temp,0,sizeof(QMCProperties),&MPI_TYPE);
00460 #endif
00461
00462 MPI_Type_commit(&MPI_TYPE);
00463 }
00464
00465 MPI_Datatype QMCProperties::MPI_TYPE;
00466
00467 MPI_Op QMCProperties::MPI_REDUCE;
00468
00469 void QMCProperties::Reduce_Function(QMCProperties *in, QMCProperties *inout,
00470 int *len, MPI_Datatype *dptr)
00471 {
00472
00473
00474
00475
00476
00477
00478
00479 for(int i=0; i < *len; i++)
00480 {
00481
00482
00483 inout[i].energy = inout[i].energy + in[i].energy;
00484 inout[i].kineticEnergy = inout[i].kineticEnergy + in[i].kineticEnergy;
00485 inout[i].potentialEnergy = inout[i].potentialEnergy + in[i].potentialEnergy;
00486 inout[i].neEnergy = inout[i].neEnergy + in[i].neEnergy;
00487 inout[i].eeEnergy = inout[i].eeEnergy + in[i].eeEnergy;
00488 inout[i].logWeights = inout[i].logWeights + in[i].logWeights;
00489 inout[i].acceptanceProbability = inout[i].acceptanceProbability +
00490 in[i].acceptanceProbability;
00491 inout[i].distanceMovedAccepted = inout[i].distanceMovedAccepted +
00492 in[i].distanceMovedAccepted;
00493 inout[i].distanceMovedTrial = inout[i].distanceMovedTrial + in[i].distanceMovedTrial;
00494
00495 inout[i].walkerAge = inout[i].walkerAge + in[i].walkerAge;
00496 inout[i].weightChange = inout[i].weightChange + in[i].weightChange;
00497 inout[i].growthRate = inout[i].growthRate + in[i].growthRate;
00498 inout[i].energy2 = inout[i].energy2 + in[i].energy2;
00499 }
00500 }
00501
00502 #endif
00503