本文整理汇总了C++中MCWalkerConfiguration类的典型用法代码示例。如果您正苦于以下问题:C++ MCWalkerConfiguration类的具体用法?C++ MCWalkerConfiguration怎么用?C++ MCWalkerConfiguration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MCWalkerConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: accumulate
//NOTE: weights are not handled nicely.
//weight should be done carefully, not valid for DMC
//will add a function to MCWalkerConfiguration to track total weight
void EstimatorManager::accumulate(MCWalkerConfiguration& W)
{
BlockWeight += W.getActiveWalkers();
RealType norm=1.0/W.getGlobalNumWalkers();
for(int i=0; i< Estimators.size(); i++)
Estimators[i]->accumulate(W,W.begin(),W.end(),norm);
}
示例2: sortWalkers
int WalkerControlBase::branch(int iter, MCWalkerConfiguration& W, RealType trigger) {
int prefill_numwalkers = sortWalkers(W);
measureProperties(iter);
W.EnsembleProperty=EnsembleProperty;
//un-biased variance but we use the saimple one
//W.EnsembleProperty.Variance=(e2sum*wsum-esum*esum)/(wsum*wsum-w2sum);
////add to the accumData for block average: REMOVE THIS
//accumData[ENERGY_INDEX] += curData[ENERGY_INDEX]*wgtInv;
//accumData[ENERGY_SQ_INDEX] += curData[ENERGY_SQ_INDEX]*wgtInv;
//accumData[WALKERSIZE_INDEX] += curData[WALKERSIZE_INDEX];
//accumData[WEIGHT_INDEX] += curData[WEIGHT_INDEX];
int nw_tot = copyWalkers(W);
//set Weight and Multiplicity to default values
MCWalkerConfiguration::iterator it(W.begin()),it_end(W.end());
while(it != it_end) {
(*it)->Weight= 1.0;
(*it)->Multiplicity=1.0;
++it;
}
//set the global number of walkers
W.setGlobalNumWalkers(nw_tot);
return prefill_numwalkers;
}
示例3: accumulate
/** accumulate Local energies and collectables
* @param W ensemble
*/
void EstimatorManager::accumulate(MCWalkerConfiguration& W)
{
BlockWeight += W.getActiveWalkers();
RealType norm=1.0/W.getGlobalNumWalkers();
for(int i=0; i< Estimators.size(); i++)
Estimators[i]->accumulate(W,W.begin(),W.end(),norm);
if(Collectables)//collectables are normalized by QMC drivers
Collectables->accumulate_all(W.Collectables,1.0);
}
示例4: sortWalkers
int
WalkerControlMPI::branch(int iter, MCWalkerConfiguration& W, RealType trigger) {
std::fill(curData.begin(),curData.end(),0);
//std::fill(NumPerNode.begin(),NumPerNode.end(),0);
sortWalkers(W);
//update the number of walkers for this node
curData[LE_MAX+MyContext]=NumWalkers;
int nw = copyWalkers(W);
myComm->allreduce(curData);
RealType wgtInv(1.0/curData[WEIGHT_INDEX]);
accumData[ENERGY_INDEX] += curData[ENERGY_INDEX]*wgtInv;
accumData[ENERGY_SQ_INDEX] += curData[ENERGY_SQ_INDEX]*wgtInv;
accumData[WALKERSIZE_INDEX] += curData[WALKERSIZE_INDEX];
accumData[WEIGHT_INDEX] += curData[WEIGHT_INDEX];
Cur_pop=0;
for(int i=0, j=LE_MAX; i<NumContexts; i++,j++) {
Cur_pop+= NumPerNode[i]=static_cast<int>(curData[j]);
}
swapWalkersSimple(W);
//Do not need to use a trigger.
//Cur_min=Nmax;
//Cur_max=0;
//Cur_pop=0;
//for(int i=0, j=LE_MAX; i<NumContexts; i++,j++) {
// Cur_pop+= NumPerNode[i]=static_cast<int>(curData[j]);
// Cur_min = std::min(Cur_min,NumPerNode[i]);
// Cur_max = std::max(Cur_max,NumPerNode[i]);
//}
//int max_diff = std::max(Cur_max*NumContexts-Cur_pop,Cur_pop-Cur_min*NumContexts);
//double diff_pop = static_cast<double>(max_diff)/static_cast<double>(Cur_pop);
//if(diff_pop > trigger) {
// swapWalkersSimple(W);
// //swapWalkersMap(W);
//}
//set Weight and Multiplicity to default values
MCWalkerConfiguration::iterator it(W.begin()),it_end(W.end());
while(it != it_end) {
(*it)->Weight= 1.0;
(*it)->Multiplicity=1.0;
++it;
}
//update the global number of walkers
W.setGlobalNumWalkers(Cur_pop);
return Cur_pop;
}
示例5: XMLReport
/** Write the set of walker configurations to the HDF5 file.
*@param W set of walker configurations
*@param ic the number of frames
*
* \if ic==-1
* use only the last frame for a restart
* \else if ic>=0
* use ic frames from the file for opitimizations
*/
bool
HDFWalkerInput0::put(MCWalkerConfiguration& W, int ic){
if(Counter<0) return false;
int selected = ic;
if(ic<0) {
XMLReport("Will use the last set from " << NumSets << " of configurations.")
selected = NumSets-1;
}
typedef MCWalkerConfiguration::PosType PosType;
typedef MCWalkerConfiguration::PropertyContainer_t ProtertyContainer_t;
typedef Matrix<PosType> PosContainer_t;
int nwt = 0;
int npt = 0;
//2D array of PosTypes (x,y,z) indexed by (walker,particle)
PosContainer_t Pos_temp;
//open the group
char GrpName[128];
sprintf(GrpName,"config%04d",selected);
hid_t group_id = H5Gopen(h_config,GrpName);
HDFAttribIO<PosContainer_t> Pos_in(Pos_temp);
//read the dataset
Pos_in.read(group_id,"coord");
//close the group
H5Gclose(group_id);
/*check to see if the number of walkers and particles is consistent with W */
int nptcl = Pos_temp.cols();
nwt = Pos_temp.rows();
int curWalker = W.getActiveWalkers();
if(curWalker) {
LOGMSG("Adding " << nwt << " walkers to " << curWalker)
W.createWalkers(nwt);
} else {
W.resize(nwt,nptcl);
}
//assign configurations to W
int iw=0;
MCWalkerConfiguration::iterator it = W.begin()+curWalker;
MCWalkerConfiguration::iterator it_end = W.end();
while(it != it_end) {
std::copy(Pos_temp[iw],Pos_temp[iw+1], (*it)->R.begin());
++it;++iw;
}
return true;
}
示例6:
/**
@brief accumulate data for all the estimators
*/
void
ScalarEstimatorManager::accumulate(const MCWalkerConfiguration& W) {
for(MCWalkerConfiguration::const_iterator it = W.begin();
it != W.end(); it++){
RealType wgt = (*it)->Properties(WEIGHT);
WeightSum += wgt;
for(int i=0; i< Estimators.size(); i++)
Estimators[i]->accumulate(**it,wgt);
}
}
示例7: start
void WalkerControlBase::setWalkerID(MCWalkerConfiguration& walkers)
{
start(); //do the normal start
MCWalkerConfiguration::iterator wit(walkers.begin());
MCWalkerConfiguration::iterator wit_end(walkers.end());
for(; wit != wit_end; ++wit)
{
if((*wit)->ID==0)
{
(*wit)->ID=(++NumWalkersCreated)*NumContexts+MyContext;
(*wit)->ParentID=(*wit)->ID;
}
}
}
示例8: getCurrentStatistics
void EstimatorManager::getCurrentStatistics(MCWalkerConfiguration& W
, RealType& eavg, RealType& var)
{
LocalEnergyOnlyEstimator energynow;
energynow.clear();
energynow.accumulate(W,W.begin(),W.end(),1.0);
vector<RealType> tmp(3);
tmp[0]= energynow.scalars[0].result();
tmp[1]= energynow.scalars[0].result2();
tmp[2]= energynow.scalars[0].count();
myComm->allreduce(tmp);
eavg=tmp[0]/tmp[2];
var=tmp[1]/tmp[2]-eavg*eavg;
}
示例9: it
/** accumulate data for all the estimators
*/
void
ScalarEstimatorManager::accumulate(const MCWalkerConfiguration& W) {
RealType wgt_sum=0;
MCWalkerConfiguration::const_iterator it(W.begin()),it_end(W.end());
while(it != it_end) {
RealType wgt = (*it)->Weight;
wgt_sum+= wgt;
for(int i=0; i< Estimators.size(); i++) Estimators[i]->accumulate(**it,wgt);
++it;
}
MyData[WEIGHT_INDEX]+=wgt_sum;
}
示例10: sprintf
bool
HDFWalkerInput0::append(MCWalkerConfiguration& W, int blocks){
if(Counter<0) return false;
//if(nwalkers<0) return put(W,-1);
typedef MCWalkerConfiguration::PosType PosType;
typedef Matrix<PosType> PosContainer_t;
PosContainer_t Pos_temp;
int nw_in=0;
int firstConf=std::max(0,NumSets-blocks);
if(blocks<0) firstConf=0;
for(int iconf=firstConf; iconf<NumSets; iconf++) {
//open the group
char GrpName[128];
sprintf(GrpName,"config%04d",iconf);
hid_t group_id = H5Gopen(h_config,GrpName);
HDFAttribIO<PosContainer_t> Pos_in(Pos_temp);
//read the dataset
Pos_in.read(group_id,"coord");
//close the group
H5Gclose(group_id);
/*check to see if the number of walkers and particles is consistent with W */
int nptcl = Pos_temp.cols();
int nwt = Pos_temp.rows();
int curWalker=0;
if(nptcl != W.getParticleNum()) {
W.resize(nwt,nptcl);
} else {
curWalker=W.getActiveWalkers();
W.createWalkers(nwt);
}
MCWalkerConfiguration::iterator it = W.begin()+curWalker;
for(int iw=0; iw<nwt; iw++) {
//std::copy(Post_temp[iw],Post_temp[iw+1], (*it)->R.begin());
for(int iat=0; iat < nptcl; iat++){
(*it)->R(iat) = Pos_temp(iw,iat);
}
++it;
}
nw_in += nwt;
}
LOGMSG("Total " << nw_in << " walkers are loaded using " << NumSets-firstConf << " blocks.")
return true;
}
示例11: Write2XYZ
void Write2XYZ(MCWalkerConfiguration& W)
{
ofstream fout("bad.xyz");
MCWalkerConfiguration::iterator it(W.begin());
MCWalkerConfiguration::iterator it_end(W.end());
int nptcls(W.getTotalNum());
while(it != it_end) {
fout << nptcls << endl
<< "# E = " << (*it)->Properties(LOCALENERGY)
<< " Wgt= " << (*it)->Weight << endl;
for(int i=0; i<nptcls; i++)
fout << "H " << (*it)->R[i] << endl;
++it;
}
}
示例12: app_log
void CloneManager::makeClones(MCWalkerConfiguration& w,
TrialWaveFunction& psi, QMCHamiltonian& ham)
{
if(wClones.size()) {
app_log() << " Cannot make clones again. Use existing " << NumThreads << " clones" << endl;
return;
}
app_log() << "Number of threads = " << NumThreads << endl;
wClones.resize(NumThreads,0);
psiClones.resize(NumThreads,0);
hClones.resize(NumThreads,0);
wClones[0]=&w;
psiClones[0]=ψ
hClones[0]=&ham;
#if defined(ENABLE_CLONE_PSI_AND_H)
char pname[16];
for(int ip=1; ip<NumThreads; ++ip)
{
sprintf(pname,"%s.c%i",w.getName().c_str(),ip);
wClones[ip]=new MCWalkerConfiguration(w);
wClones[ip]->setName(pname);
psiClones[ip]=psi.makeClone(*wClones[ip]);
hClones[ip]=ham.makeClone(*wClones[ip],*psiClones[ip]);
}
#else
cloneEngine.clone(w,psi,ham,wClones,psiClones,hClones);
#endif
}
示例13: initialize
void
initialize(TrialWaveFunction& Psi, MCWalkerConfiguration& el,
ParticleBase& ion) {
enum {Up = 0, Down};
///add a distance table for ee IndexTypeeractions
IndexType iee = DistanceTable::add(el,"ee");
DistanceTableData* d_ee = DistanceTable::getTable(iee);
///add a distance table for ie interactions
int iei = DistanceTable::add(ion,el,"ie");
DistanceTableData* d_ei = DistanceTable::getTable(iei);
///create molecular orbital
MolecularOrbitals<SlaterTypeOrbitals_t> *MO =
new MolecularOrbitals<SlaterTypeOrbitals_t>;
AtomicOrbitalBuilder<SlaterTypeOrbitals_t> orbitalbuilder;
for(int iat=0; iat<ion.getTotalNum(); iat++) {
orbitalbuilder.add("He",*MO);
}
MO->setTable(d_ei);
typedef SlaterDeterminant<MolecularOrbitals<SlaterTypeOrbitals_t> > Det_t;
Det_t *DetU = new Det_t(*MO,el.first(Up));
DetU->set(el.first(Up),el.last(Up)-el.first(Up));
Det_t* DetD = new Det_t(*MO,el.first(Down));
DetD->set(el.first(Down),el.last(Down)-el.first(Down));
LinearSlaterDeterminant<MolecularOrbitals<SlaterTypeOrbitals_t> >
*asymmpsi
= new LinearSlaterDeterminant<MolecularOrbitals<SlaterTypeOrbitals_t> >;
asymmpsi->add(DetU);
asymmpsi->add(DetD);
Psi.add(asymmpsi,d_ei);
/*
OneBodyJastrow<PadeJastrow<ValueType>,FastWalkerIndex> *Jie
= new OneBodyJastrow<PadeJastrow<ValueType>,FastWalkerIndex>;
Jie->F.push_back(PadeJastrow<ValueType>(1.0,1.0));
Psi.add(Jie,d_ei);
*/
TwoBodyJastrow<PadeJastrow<ValueType>,FastWalkerIndex> *Jee
= new TwoBodyJastrow<PadeJastrow<ValueType>,FastWalkerIndex>;
Jee->F.push_back(PadeJastrow<double>(0.5,1.0));
Jee->F.push_back(PadeJastrow<double>(1.0/6.0,1.0));
Jee->F.push_back(PadeJastrow<double>(1.0/6.0,1.0));
Jee->F.push_back(PadeJastrow<double>(0.5,1.0));
Psi.add(Jee,d_ee);
}
示例14: copyWalkers
int WalkerControlBase::copyWalkers(MCWalkerConfiguration& W) {
//clear the WalkerList to populate them with the good walkers
W.clear();
W.insert(W.begin(), good_w.begin(), good_w.end());
int cur_walker = good_w.size();
for(int i=0; i<good_w.size(); i++) { //,ie+=ncols) {
for(int j=0; j<ncopy_w[i]; j++, cur_walker++)
{
Walker_t* awalker=new Walker_t(*(good_w[i]));
awalker->ID=(++NumWalkersCreated)*NumContexts+MyContext;
awalker->ParentID=good_w[i]->ParentID;
W.push_back(awalker);
}
}
//clear good_w and ncopy_w for the next branch
good_w.clear();
ncopy_w.clear();
return W.getActiveWalkers();
}
示例15: it
int WalkerControlBase::doNotBranch(int iter, MCWalkerConfiguration& W)
{
MCWalkerConfiguration::iterator it(W.begin());
MCWalkerConfiguration::iterator it_end(W.end());
RealType esum=0.0,e2sum=0.0,wsum=0.0,ecum=0.0, w2sum=0.0;
RealType r2_accepted=0.0,r2_proposed=0.0;
for(; it!=it_end; ++it)
{
r2_accepted+=(*it)->Properties(R2ACCEPTED);
r2_proposed+=(*it)->Properties(R2PROPOSED);
RealType e((*it)->Properties(LOCALENERGY));
int nc= std::min(static_cast<int>((*it)->Multiplicity),MaxCopy);
RealType wgt((*it)->Weight);
esum += wgt*e;
e2sum += wgt*e*e;
wsum += wgt;
w2sum += wgt*wgt;
ecum += e;
}
//temp is an array to perform reduction operations
std::fill(curData.begin(),curData.end(),0);
curData[ENERGY_INDEX]=esum;
curData[ENERGY_SQ_INDEX]=e2sum;
curData[WALKERSIZE_INDEX]=W.getActiveWalkers();
curData[WEIGHT_INDEX]=wsum;
curData[EREF_INDEX]=ecum;
curData[R2ACCEPTED_INDEX]=r2_accepted;
curData[R2PROPOSED_INDEX]=r2_proposed;
myComm->allreduce(curData);
measureProperties(iter);
trialEnergy=EnsembleProperty.Energy;
W.EnsembleProperty=EnsembleProperty;
//return the current data
return W.getGlobalNumWalkers();
}