00001
00002
00003 #include "QMCEquilibrationArray.h"
00004
00005 QMCEquilibrationArray::QMCEquilibrationArray()
00006 {
00007 over_ten_thousand = 0;
00008 calc_density = false;
00009 nBasisFunc = 0;
00010
00011 ten_thousand_samples.allocate(EQ,2);
00012 zeroOut();
00013 }
00014
00015 void QMCEquilibrationArray::zeroOut()
00016 {
00017 over_ten_thousand = 0;
00018 ten_thousand_samples = 0.0;
00019 for (int i=0; i<EQ; i++)
00020 Eq_Array[i].zeroOut();
00021
00022 ZeroProperties.zeroOut();
00023 decorr_objects = 1;
00024 Eq_Array[0].setStartingStep(1);
00025 }
00026
00027 void QMCEquilibrationArray::setCalcDensity(bool calcDensity,
00028 int nbasisfunctions)
00029 {
00030 calc_density = calcDensity;
00031 nBasisFunc = nbasisfunctions;
00032
00033 for (int i=0; i<EQ; i++)
00034 {
00035 assert(0);
00036
00037 }
00038 }
00039
00040 void QMCEquilibrationArray::setCalcForces(bool calcForces, int dim1, int dim2)
00041 {
00042 calc_forces = calcForces;
00043 for (int i=0; i<EQ; i++)
00044 {
00045 assert(0);
00046
00047
00048
00049
00050 }
00051 }
00052
00053 void QMCEquilibrationArray::newSample(QMCProperties * timeStepProps,
00054 double totalWeights, int nWalkers)
00055 {
00056
00057 for (int i=0; i<decorr_objects; i++)
00058 Eq_Array[i].getProperties()->newSample(timeStepProps, totalWeights,
00059 nWalkers);
00060
00061 if(Eq_Array[over_ten_thousand].getProperties()->energy.getNumberSamples() == 10000)
00062 {
00063 ten_thousand_samples(over_ten_thousand,0) = Eq_Array[over_ten_thousand].getProperties()->energy.getAverage();
00064 ten_thousand_samples(over_ten_thousand,1) = Eq_Array[over_ten_thousand].getProperties()->energy.getBlockStandardDeviation(0);
00065 over_ten_thousand++;
00066 }
00067
00068
00069
00070
00071
00072
00073
00074 unsigned long check = power(2,decorr_objects+6);
00075
00076 if (Eq_Array[0].getProperties()->energy.getNumberSamples() == check-1)
00077 {
00078 Eq_Array[decorr_objects].setStartingStep(check);
00079 decorr_objects++;
00080 }
00081 }
00082
00083 QMCProperties * QMCEquilibrationArray::chooseDecorrObject()
00084 {
00085 int index = getDecorrObjectIndex();
00086 if (index == -1)
00087 return ZeroProperties.getProperties();
00088 else
00089 return Eq_Array[index].getProperties();
00090 }
00091
00092
00093
00094 int QMCEquilibrationArray::getDecorrObjectIndex()
00095 {
00096
00097
00098
00099
00100 if (Eq_Array[0].getProperties()->energy.getNumberSamples() < 20000)
00101 return -1;
00102
00103 double init_hi, init_lo, final_hi, final_lo, final_avg;
00104 int obj = -1;
00105
00106 for (int i=0; i<over_ten_thousand; i++)
00107 {
00108 init_hi = ten_thousand_samples(i,0) + 2*ten_thousand_samples(i,1);
00109 init_lo = ten_thousand_samples(i,0) - 2*ten_thousand_samples(i,1);
00110
00111 final_hi = Eq_Array[i].getProperties()->energy.getAverage() + 2*Eq_Array[i].getProperties()->energy.getBlockStandardDeviation(0);
00112 final_lo = Eq_Array[i].getProperties()->energy.getAverage() - 2*Eq_Array[i].getProperties()->energy.getBlockStandardDeviation(0);
00113 final_avg = Eq_Array[i].getProperties()->energy.getAverage();
00114
00115 if ((final_hi > init_lo && final_hi < init_hi) || (final_lo > init_lo && final_lo < init_hi) || (final_avg > init_lo && final_avg < init_hi))
00116 {
00117 obj = i;
00118 break;
00119 }
00120 }
00121
00122 if ((obj == -1) || (Eq_Array[obj].getProperties()->energy.getNumberSamples() < 20000))
00123 return -1;
00124 else
00125 return obj;
00126 }
00127
00128 Stopwatch * QMCEquilibrationArray::getPropagationStopwatch()
00129 {
00130 int index = getDecorrObjectIndex();
00131 if (index == -1)
00132 return ZeroProperties.getPropagationStopwatch();
00133 else
00134 return Eq_Array[index].getPropagationStopwatch();
00135 }
00136
00137 Stopwatch * QMCEquilibrationArray::getEquilibrationStopwatch()
00138 {
00139 int index = getDecorrObjectIndex();
00140 if (index == -1)
00141 return ZeroProperties.getEquilibrationStopwatch();
00142 else
00143 return Eq_Array[index].getEquilibrationStopwatch();
00144 }
00145
00146 void QMCEquilibrationArray::startTimers()
00147 {
00148 for (int i=0; i<decorr_objects; i++)
00149 Eq_Array[i].getPropagationStopwatch()->start();
00150 for (int j=decorr_objects; j<EQ; j++)
00151 Eq_Array[j].getEquilibrationStopwatch()->start();
00152 ZeroProperties.getEquilibrationStopwatch()->start();
00153 }
00154
00155 void QMCEquilibrationArray::stopTimers()
00156 {
00157 for (int i=0; i<EQ; i++)
00158 {
00159 if (Eq_Array[i].getPropagationStopwatch()->isRunning())
00160 Eq_Array[i].getPropagationStopwatch()->stop();
00161 else if (Eq_Array[i].getEquilibrationStopwatch()->isRunning())
00162 Eq_Array[i].getEquilibrationStopwatch()->stop();
00163 }
00164 if (ZeroProperties.getEquilibrationStopwatch()->isRunning())
00165 ZeroProperties.getEquilibrationStopwatch()->stop();
00166 }
00167
00168 void QMCEquilibrationArray::toXML(ostream& strm)
00169 {
00170
00171 strm << "<QMCEquilibrationArray>" << endl;
00172 strm << "<decorr_objects>\n" << decorr_objects << "\n</decorr_objects>\n";
00173 strm << "<over_ten_thousand>\n" << over_ten_thousand << "\n</over_ten_thousand>\n";
00174 strm << "<ten_thousand_samples>\n";
00175 for (int i=0; i<over_ten_thousand; i++)
00176 strm << ten_thousand_samples(i,0) << "\t" << ten_thousand_samples(i,1) << "\n";
00177 strm << "</ten_thousand_samples>\n";
00178 for (int i=0; i<decorr_objects; i++)
00179 Eq_Array[i].getProperties()->toXML(strm);
00180 strm << "</QMCEquilibrationArray>" << endl;
00181 }
00182
00183 bool QMCEquilibrationArray::readXML(istream& strm)
00184 {
00185 string temp;
00186
00187
00188 strm >> temp;
00189 if (temp != "<QMCEquilibrationArray>")
00190 return false;
00191
00192 strm >> temp;
00193 if (temp != "<decorr_objects>")
00194 return false;
00195 strm >> temp;
00196 decorr_objects = atoi(temp.c_str());
00197 strm >> temp;
00198 if (temp != "</decorr_objects>")
00199 return false;
00200
00201 strm >> temp;
00202 if (temp != "<over_ten_thousand>")
00203 return false;
00204 strm >> temp;
00205 over_ten_thousand = atoi(temp.c_str());
00206 strm >> temp;
00207 if (temp != "</over_ten_thousand>")
00208 return false;
00209
00210 strm >> temp;
00211 if (temp != "<ten_thousand_samples>")
00212 return false;
00213 for (int i=0; i<over_ten_thousand; i++)
00214 {
00215 strm >> temp;
00216 ten_thousand_samples(i,0) = atof(temp.c_str());
00217 strm >> temp;
00218 ten_thousand_samples(i,1) = atof(temp.c_str());
00219 }
00220 strm >> temp;
00221 if (temp != "</ten_thousand_samples>")
00222 return false;
00223
00224 for (int i=0; i<decorr_objects; i++)
00225 if (!Eq_Array[i].getProperties()->readXML(strm))
00226 return false;
00227
00228 strm >> temp;
00229 if (temp != "</QMCEquilibrationArray>")
00230 return false;
00231
00232 Eq_Array[0].setStartingStep(1);
00233
00234 for (int i=1; i<decorr_objects; i++)
00235 {
00236 long step = power(2,i+6);
00237 Eq_Array[i].setStartingStep(step);
00238 }
00239
00240 for (int i=decorr_objects; i<EQ; i++)
00241 Eq_Array[i].getProperties()->zeroOut();
00242
00243 ZeroProperties.zeroOut();
00244
00245 return true;
00246 }
00247
00248 long QMCEquilibrationArray::power(int a, int b)
00249 {
00250 long result = 1;
00251 for (int i=0; i<b; i++)
00252 result *= a;
00253 return result;
00254 }
00255
00256