/** reimplement simple table format used by NonLocalPPotential */ void ECPotentialBuilder::useSimpleTableFormat() { SpeciesSet& Species(IonConfig.getSpeciesSet()); int ng(Species.getTotalNum()); int icharge(Species.addAttribute("charge")); for(int ig=0; ig<ng;ig++) { vector<RealType> grid_temp, pp_temp; string species(Species.speciesName[ig]); string fname = species+".psf"; ifstream fin(fname.c_str(),ios_base::in); if(!fin){ ERRORMSG("Could not open file " << fname) exit(-1); } // Read Number of potentials (local and non) for this atom int npotentials; fin >> npotentials; RealType r, f1; int lmax=-1; int numnonloc=0; RealType rmax(0.0); app_log() << " ECPotential for " << species << endl; NonLocalECPComponent* mynnloc=0; typedef OneDimCubicSpline<RealType> CubicSplineFuncType; for (int ij=0; ij<npotentials; ij++){ int angmom,npoints; fin >> angmom >> npoints; OneDimNumGridFunctor<RealType> inFunc; inFunc.put(npoints,fin); if(angmom < 0) {//local potential, input is rescale by -r/z RealType zinv=-1.0/Species(icharge,ig); int ng=npoints-1; RealType rf=5.0; ng=static_cast<int>(rf*100)+1;//use 1e-2 resolution GridType * agrid= new LinearGrid<RealType>; agrid->set(0,rf,ng); vector<RealType> pp_temp(ng); pp_temp[0]=0.0; for (int j=1; j<ng; j++){ RealType r((*agrid)[j]); pp_temp[j]=r*zinv*inFunc.splint(r); } pp_temp[ng-1]=1.0; RadialPotentialType *app = new RadialPotentialType(agrid,pp_temp); app->spline(); localPot[ig]=app; app_log() << " LocalECP l=" << angmom << endl; app_log() << " Linear grid=[0," << rf << "] npts=" << ng << endl; hasLocalPot=true; //will create LocalECPotential } else { hasNonLocalPot=true; //will create NonLocalECPotential if(mynnloc == 0) mynnloc = new NonLocalECPComponent; RealType rf=inFunc.rmax(); GridType * agrid= new LinearGrid<RealType>; int ng=static_cast<int>(rf*100)+1; agrid->set(0.0,rf,ng); app_log() << " NonLocalECP l=" << angmom << " rmax = " << rf << endl; app_log() << " Linear grid=[0," << rf << "] npts=" << ng << endl; vector<RealType> pp_temp(ng); //get the value pp_temp[0]=inFunc(0); for (int j=1; j<ng; j++){ pp_temp[j]=inFunc.splint((*agrid)[j]); } RadialPotentialType *app = new RadialPotentialType(agrid,pp_temp); app->spline(); mynnloc->add(angmom,app); lmax=std::max(lmax,angmom); rmax=std::max(rmax,rf); numnonloc++; } if(mynnloc) { mynnloc->lmax=lmax; mynnloc->Rmax=rmax; app_log() << " Maximum cutoff of NonLocalECP " << rmax << endl; } } fin.close(); if(mynnloc) { nonLocalPot[ig]=mynnloc; int numsgridpts=0; string fname = species+".sgr"; ifstream fin(fname.c_str(),ios_base::in); if(!fin){ app_error() << "Could not open file " << fname << endl; exit(-1); } PosType xyz; RealType weight; while(fin >> xyz >> weight){ mynnloc->addknot(xyz,weight); numsgridpts++; } //cout << "Spherical grid : " << numsgridpts << " points" <<endl; mynnloc->resize_warrays(numsgridpts,numnonloc,lmax); } }//species }
/** advance all the walkers with killnode==no * @param nat number of particles to move * * When killnode==no, any move resulting in node-crossing is treated * as a normal rejection. */ void DMCUpdatePbyPWithKill::advanceWalkers(WalkerIter_t it, WalkerIter_t it_end, bool measure) { app_error() << " DMCUpdatePbyPWithKill::advanceWalkers in not implemented." << endl; }
bool JastrowBuilder::addTwoBody(xmlNodePtr cur) { app_log() << " JastrowBuilder::addTwoBody "<< endl; bool success=false; bool useSpline = (targetPtcl.Lattice.BoxBConds[0] && transformOpt == "yes"); bool ignoreSpin = (spinOpt == "no"); OrbitalConstraintsBase* control=0; if(funcOpt == "any") { app_log() << " Using generic Jastrow Function Builder " <<endl; control=new AnyConstraints(targetPtcl,targetPsi); } else if(funcOpt == "pade") { app_log() << " Using analytic Pade Jastrow Functor " <<endl; control = new PadeConstraints(targetPtcl,targetPsi,ignoreSpin); } else if(funcOpt == "rpa") { if(targetPtcl.Lattice.SuperCellEnum == SUPERCELL_OPEN) { app_warning() << " RPA is requested for an open system. Please choose other functors." << endl; return false; } else control = new RPAPBCConstraints(targetPtcl,targetPsi,ignoreSpin); } else if(funcOpt == "poly") { app_log() << " Using analytic Polynomial expansion Jastrow Functor " <<endl; control = new PolyConstraints(targetPtcl,targetPsi,ignoreSpin); } else if(funcOpt == "scaledpade") { app_log() << " Using analytic Scaled Pade Jastrow Functor " <<endl; control = new ScaledPadeConstraints(targetPtcl,targetPsi,ignoreSpin); } else //known analytic function { OrbitalBuilderBase* jbuilder=0; jbuilder = new JAABuilder(targetPtcl,targetPsi); Children.push_back(jbuilder); return jbuilder->put(cur); } success=control->put(cur); if(!success) { app_error() << " Failed to buld " << nameOpt << " Jastrow function " << endl; delete control; return false; } OrbitalBase* j2=control->createTwoBody(); if(j2== 0) { app_error() << " JastrowBuilder::addTwoBody failed to create a two body Jastrow" << endl; delete control; } enum {MULTIPLE=0, LONGRANGE, ONEBODY, TWOBODY, THREEBODY, FOURBODY}; if(control->JComponent[MULTIPLE]) { //create a combo orbital ComboOrbital* jcombo=new ComboOrbital(control); jcombo->Psi.push_back(j2); if(control->JComponent[ONEBODY] && sourceOpt != targetPtcl.getName()) { app_log() << " Adding one-body Jastrow function dependent upon two-body " << funcOpt << endl; map<string,ParticleSet*>::iterator pa_it(ptclPool.find(sourceOpt)); if(pa_it != ptclPool.end()) { OrbitalBase* j1=control->createOneBody(*((*pa_it).second)); if(j1) jcombo->Psi.push_back(j1); } } if(control->JComponent[LONGRANGE]) { app_log() << " Adding long-range component of " << funcOpt << " Jastrow function "<< endl; control->addExtra2ComboOrbital(jcombo); } targetPsi.addOrbital(jcombo); } else { targetPsi.addOrbital(j2); } control->addOptimizables(targetPsi.VarList); Children.push_back(control); return success; }
bool JastrowBuilder::addThreeBody(xmlNodePtr cur) { if(sourceOpt == targetPtcl.getName()) { app_warning() << " Three-Body Jastrow Function needs a source different from " << targetPtcl.getName() << endl; app_warning() << " Exit JastrowBuilder::addOneBody." << endl; return false; } PtclPoolType::iterator pit(ptclPool.find(sourceOpt)); if(pit == ptclPool.end()) { app_error() << " JastrowBuilder::addThreeBody requires a center. " << sourceOpt << " is invalid " << endl; return false; } app_log() << " JastrowBuilder::addThreeBody source="<< sourceOpt << endl; xmlNodePtr basisPtr=NULL; xmlNodePtr coeffPtr=NULL; cur = cur->xmlChildrenNode; string diagOnly("no"); while(cur != NULL) { string cname((const char*)(cur->name)); if(cname == basisset_tag) { basisPtr=cur; } else if(cname.find("coeff")<cname.size()) { coeffPtr=cur; OhmmsAttributeSet oAttrib; oAttrib.add(diagOnly,"diagonal"); oAttrib.put(cur); } cur=cur->next; } if(basisPtr == NULL) { app_error() << " JastrowBuilder::addThreeBody exit. Missing <basisset/>"<< endl; return false; } ParticleSet* sourcePtcl=(*pit).second; JastrowBasisBuilder* basisBuilder = new JastrowBasisBuilder(targetPtcl,*sourcePtcl,funcOpt,transformOpt == "yes"); basisBuilder->put(basisPtr); if(diagOnly == "yes") { app_log() << "\n creating Three-Body Jastrow function using only diagnoal blocks." << endl; ThreeBodyBlockSparse* J3 = new ThreeBodyBlockSparse(*sourcePtcl, targetPtcl); J3->setBasisSet(basisBuilder->myBasisSet); J3->put(coeffPtr,targetPsi.VarList); J3->setBlocks(basisBuilder->SizeOfBasisPerCenter); targetPsi.addOrbital(J3); } else { app_log() << "\n creating Three-Body Jastrow function using a complete Geminal matrix." << endl; ThreeBodyGeminal* J3 = new ThreeBodyGeminal(*sourcePtcl, targetPtcl); J3->setBasisSet(basisBuilder->myBasisSet); J3->put(coeffPtr,targetPsi.VarList); targetPsi.addOrbital(J3); } //if(jbuilder) //{ // jbuilder->put(cur); // Children.push_back(jbuilder); // return true; //} // } else if (jasttype == "Three-Body-Pade") { // app_log() << "\n creating Three-Body-Pade Jastrow function " << endl; // string source_name("i"); // const xmlChar* iptr = xmlGetProp(cur, (const xmlChar *)"source"); // //if(iptr != NULL) source_name=(const char*)iptr; // PtclPoolType::iterator pit(ptclPool.find(source_name)); // if(pit != ptclPool.end()) { // jbuilder = new ThreeBodyPadeBuilder(*targetPtcl,*targetPsi,*((*pit).second)); // } // } return true; }
/* * main - The shell's main routine */ int main(int argc, char **argv) { char c; char cmdline[MAXLINE]; /* cmdline for fgets */ int emit_prompt = 1; /* emit prompt (default) */ /* Redirect stderr to stdout (so that driver will get all output * on the pipe connected to stdout) */ dup2(1, 2); /* Parse the command line */ while ((c = getopt(argc, argv, "hvp")) != EOF) { switch (c) { case 'h': /* print help message */ usage(); break; case 'v': /* emit additional diagnostic info */ verbose = 1; break; case 'p': /* don't print a prompt */ emit_prompt = 0; /* handy for automatic testing */ break; default: usage(); } } /* Install the signal handlers */ /* These are the ones you will need to implement */ Signal(SIGINT, sigint_handler); /* ctrl-c */ Signal(SIGTSTP, sigtstp_handler); /* ctrl-z */ Signal(SIGCHLD, sigchld_handler); /* Terminated or stopped child */ Signal(SIGTTIN, SIG_IGN); Signal(SIGTTOU, SIG_IGN); /* This one provides a clean way to kill the shell */ Signal(SIGQUIT, sigquit_handler); /* Initialize the job list */ initjobs(job_list); /* Execute the shell's read/eval loop */ while (1) { if (emit_prompt) { printf("%s", prompt); fflush(stdout); } if ((fgets(cmdline, MAXLINE, stdin) == NULL) && ferror(stdin)) app_error("fgets error"); if (feof(stdin)) { /* End of file (ctrl-d) */ printf ("\n"); fflush(stdout); fflush(stderr); exit(0); } /* Remove the trailing newline */ cmdline[strlen(cmdline)-1] = '\0'; /* Evaluate the command line */ eval(cmdline); fflush(stdout); fflush(stdout); } exit(0); /* control never reaches here */ }
bool ECPComponentBuilder::parseCasino(const std::string& fname, xmlNodePtr cur) { app_log() << " Start ECPComponentBuilder::parseCasino" << endl; RealType rmax=2.0; Llocal=-1; Lmax=-1; OhmmsAttributeSet aAttrib; aAttrib.add(rmax,"cutoff"); aAttrib.add(Llocal,"l-local"); aAttrib.add(Lmax,"lmax"); aAttrib.add(Nrule,"nrule"); aAttrib.put(cur); //const xmlChar* rptr=xmlGetProp(cur,(const xmlChar*)"cutoff"); //if(rptr != NULL) rmax = atof((const char*)rptr); //app_log() << " Creating a Linear Grid Rmax=" << rmax << endl; //const RealType d=5e-4; //LinearGrid<RealType>* agrid = new LinearGrid<RealType>; //int ng=static_cast<int>(rmax/d)+1; //agrid->set(0,rmax,ng); ifstream fin(fname.c_str(),ios_base::in); if(!fin) { app_error() << "Could not open file " << fname << endl; APP_ABORT("ECPComponentBuilder::parseCasino"); } if(pp_nonloc==0) pp_nonloc=new NonLocalECPComponent; OhmmsAsciiParser aParser; int atomNumber=0; int npts=0, idummy; string eunits("rydberg"); app_log() << " ECPComponentBuilder::parseCasino" <<endl; aParser.skiplines(fin,1);//Header aParser.skiplines(fin,1);//Atomic number and pseudo-charge aParser.getValue(fin,atomNumber,Zeff); app_log() << " Atomic number = " << atomNumber << " Zeff = " << Zeff << endl; aParser.skiplines(fin,1);//Energy units (rydberg/hartree/ev): aParser.getValue(fin,eunits); app_log() << " Unit of the potentials = " << eunits << endl; RealType Vprefactor = (eunits == "rydberg")?0.5:1.0; aParser.skiplines(fin,1);//Angular momentum of local component (0=s,1=p,2=d..) aParser.getValue(fin,idummy); if(Lmax<0) Lmax=idummy; aParser.skiplines(fin,1);//NLRULE override (1) VMC/DMC (2) config gen (0 ==> input/default value) aParser.skiplines(fin,1);//0 0, not sure what to do yet aParser.skiplines(fin,1);//Number of grid points aParser.getValue(fin,npts); app_log() << " Input Grid size = " << npts << endl; vector<RealType> temp(npts); aParser.skiplines(fin,1);//R(i) in atomic units aParser.getValues(fin,temp.begin(),temp.end()); //create a global grid of numerical type grid_global= new NumericalGrid<RealType>(temp); Matrix<RealType> vnn(Lmax+1,npts); for(int l=0; l<=Lmax; l++) { aParser.skiplines(fin,1); aParser.getValues(fin,vnn[l],vnn[l]+npts); } vector<int> angList(Lmax+1); for(int l=0; l<=Lmax; l++) angList[l]=l; // Now, check to see what maximum cutoff should be if(vnn.size()>1) { const double tolerance=1.0e-5; double rc_check = grid_global->r(npts-1); for (int j=npts-1; j>0; j++) { bool closeEnough = true; for (int i=0; i<vnn.rows(); i++) for (int k=i+1; k<vnn.rows(); k++) if (std::fabs(vnn[i][j] - vnn[k][j]) > tolerance) closeEnough = false; if (!closeEnough) { rc_check = grid_global->r(j); break; } } app_log() << " Maxium cutoff for non-local pseudopotentials " << rc_check << endl; } doBreakUp(angList,vnn,rmax,Vprefactor); SetQuadratureRule(Nrule); app_log() << " Non-local pseudopotential parameters" <<endl; pp_nonloc->print(app_log()); return true; }
void EinsplineSet::evaluate (const ParticleSet& P, int iat, ValueVector_t& psi) { app_error() << "Should never instantiate EinsplineSet.\n"; abort(); }
/* * eval_mm_util - Evaluate the space utilization of the student's package * The idea is to remember the high water mark "hwm" of the heap for * an optimal allocator, i.e., no gaps and no internal fragmentation. * Utilization is the ratio hwm/heapsize, where heapsize is the * size of the heap in bytes after running the student's malloc * package on the trace. Note that our implementation of mem_sbrk() * doesn't allow the students to decrement the brk pointer, so brk * is always the high water mark of the heap. * */ static double eval_mm_util(trace_t *trace, int tracenum, range_t **ranges) { int i; int index; int size, newsize, oldsize; int max_total_size = 0; int total_size = 0; char *p; char *newp, *oldp; /* initialize the heap and the mm malloc package */ mem_reset_brk(); if (mm_init() < 0) app_error("mm_init failed in eval_mm_util"); for (i = 0; i < trace->num_ops; i++) { switch (trace->ops[i].type) { case ALLOC: /* mm_alloc */ index = trace->ops[i].index; size = trace->ops[i].size; if ((p = mm_malloc(size)) == NULL) app_error("mm_malloc failed in eval_mm_util"); /* Remember region and size */ trace->blocks[index] = p; trace->block_sizes[index] = size; /* Keep track of current total size * of all allocated blocks */ total_size += size; /* Update statistics */ max_total_size = (total_size > max_total_size) ? total_size : max_total_size; break; case REALLOC: /* mm_realloc */ index = trace->ops[i].index; newsize = trace->ops[i].size; oldsize = trace->block_sizes[index]; oldp = trace->blocks[index]; if ((newp = mm_realloc(oldp,newsize)) == NULL) app_error("mm_realloc failed in eval_mm_util"); /* Remember region and size */ trace->blocks[index] = newp; trace->block_sizes[index] = newsize; /* Keep track of current total size * of all allocated blocks */ total_size += (newsize - oldsize); /* Update statistics */ max_total_size = (total_size > max_total_size) ? total_size : max_total_size; break; case FREE: /* mm_free */ index = trace->ops[i].index; size = trace->block_sizes[index]; p = trace->blocks[index]; mm_free(p); /* Keep track of current total size * of all allocated blocks */ total_size -= size; break; default: app_error("Nonexistent request type in eval_mm_util"); } } return ((double)max_total_size / (double)mem_heapsize()); }
bool LRTwoBodyJastrow::put(xmlNodePtr cur, VarRegistry<RealType>& vlist) { if(skRef == 0) { app_error() << " LRTowBodyJastrow should not be used for non periodic systems." << endl; return false; } std::map<int,std::vector<int>*>& kpts_sorted(skRef->KLists.kpts_sorted); Fk_symm.resize(kpts_sorted.size()); bool foundCoeff=false; xmlNodePtr tcur=cur->children; while(tcur != NULL) { string cname((const char*)(tcur->name)); if(cname == "parameter") { const xmlChar* kptr=xmlGetProp(tcur,(const xmlChar *)"name"); const xmlChar* idptr=xmlGetProp(tcur,(const xmlChar *)"id"); if(idptr!= NULL && kptr != NULL) { int ik=atoi((const char*)kptr); if(ik<Fk_symm.size()) { // only accept valid ik RealType x; putContent(x,tcur); Fk_symm[ik]=x; vlist.add((const char*)idptr,Fk_symm.data()+ik); } foundCoeff=true; } } tcur=tcur->next; } Fk.resize(NumKpts); if(foundCoeff) { reset(); } else { std::map<int,std::vector<int>*>::iterator it(kpts_sorted.begin()); int uniqueK=0; while(it != kpts_sorted.end()) { std::vector<int>::iterator vit((*it).second->begin()); int ik=(*vit); Fk_symm[uniqueK]=Fk[ik]=-1.0*handler->Fk[ik]; ++vit; while(vit != (*it).second->end()) { int ik=(*vit); Fk[ik]=-1.0*handler->Fk[ik]; ++vit; } ++it;++uniqueK; } char coeffname[128]; for(int ik=0; ik<Fk_symm.size(); ik++) { sprintf(coeffname,"rpa_k%d",ik); vlist.add(coeffname,Fk_symm.data()+ik); std::ostringstream kname,val; kname << ik; val<<Fk_symm[ik]; xmlNodePtr p_ptr = xmlNewTextChild(cur,NULL,(const xmlChar*)"parameter", (const xmlChar*)val.str().c_str()); xmlNewProp(p_ptr,(const xmlChar*)"id",(const xmlChar*)coeffname); xmlNewProp(p_ptr,(const xmlChar*)"name",(const xmlChar*)kname.str().c_str()); } } app_log() << " Long-range Two-Body Jastrow coefficients " << endl; for(int ikpt=0; ikpt<NumKpts; ikpt++) { app_log() << skRef->KLists.ksq[ikpt] << " " << Fk[ikpt] << endl; } return true; }
void PWOrbitalSet::resetTargetParticleSet(ParticleSet& P) { app_error() << "PWOrbitalSet::resetTargetParticleSet not yet coded." << endl; OHMMS::Controller->abort(); }
void LRTwoBodyJastrow::update(ParticleSet& P, ParticleSet::ParticleGradient_t& dG, ParticleSet::ParticleLaplacian_t& dL, int iat) { app_error() << "LRTwoBodyJastrow::update is INCOMPLETE " << endl; }
/** evaluate curData and mark the bad/good walkers */ void WalkerControlBase::sortWalkers(MCWalkerConfiguration& W) { MCWalkerConfiguration::iterator it(W.begin()); vector<Walker_t*> bad; NumWalkers=0; 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; //RealType sigma=std::max(5.0*targetVar,targetEnergyBound); //RealType ebar= targetAvg; while(it != it_end) { 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); /// HACK HACK HACK //RealType wgt((*it)->Weight); RealType wgt = (RealType)nc; esum += wgt*e; e2sum += wgt*e*e; wsum += wgt; w2sum += wgt*wgt; ecum += e; if(nc) { NumWalkers += nc; good_w.push_back(*it); ncopy_w.push_back(nc-1); } else { bad.push_back(*it); } ++it; } //temp is an array to perform reduction operations std::fill(curData.begin(),curData.end(),0); //evaluate variance of this block //curVar=(e2sum-esum*esum/wsum)/wsum; //THIS IS NOT USED ANYMORE:BELOW //if(curVar>sigma) { // app_error() << "Unphysical block variance is detected. Stop simulations." << endl; // Write2XYZ(W); // //Does not work some reason // //OHMMS::Controller->abort(); //#if defined(HAVE_MPI) // OOMPI_COMM_WORLD.Abort(); //#else // abort(); //#endif // } //THIS IS NOT USED ANYMORE:ABOVE //update curData 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; ////this should be move //W.EnsembleProperty.NumSamples=curData[WALKERSIZE_INDEX]; //W.EnsembleProperty.Weight=curData[WEIGHT_INDEX]; //W.EnsembleProperty.Energy=(esum/=wsum); //W.EnsembleProperty.Variance=(e2sum/wsum-esum*esum); //W.EnsembleProperty.Variance=(e2sum*wsum-esum*esum)/(wsum*wsum-w2sum); //remove bad walkers empty the container for(int i=0; i<bad.size(); i++) delete bad[i]; if(good_w.empty()) { app_error() << "All the walkers have died. Abort. " << endl; APP_ABORT("WalkerControlBase::sortWalkers"); } int sizeofgood = good_w.size(); //check if the projected number of walkers is too small or too //large if(NumWalkers>Nmax) { int nsub=0; int nsub_target=NumWalkers-static_cast<int>(0.9*Nmax); int i=0; while(i< sizeofgood && nsub<nsub_target) { if(ncopy_w[i]) { ncopy_w[i]--; nsub++; } ++i; } NumWalkers -= nsub; } else if(NumWalkers < Nmin) { int nadd=0; int nadd_target = static_cast<int>(Nmin*1.1)-NumWalkers; if(nadd_target> sizeofgood) { app_warning() << "The number of walkers is running low. Requested walkers " << nadd_target << " good walkers = " << sizeofgood << endl; } int i=0; while(i< sizeofgood && nadd<nadd_target) { ncopy_w[i]++; ++nadd; ++i; } NumWalkers += nadd; } }
/** Separate local from non-local potentials * @param angList angular momentum list * @param vnn semilocal tables of size (angList.size(),global_grid->size()) * @param rmax cutoff radius * @param Vprefactor conversion factor to Hartree */ void ECPComponentBuilder::doBreakUp(const vector<int>& angList, const Matrix<RealType>& vnn, RealType rmax, RealType Vprefactor) { app_log() << " Creating a Linear Grid Rmax=" << rmax << endl; //this is a new grid RealType d=1e-4; LinearGrid<RealType>* agrid = new LinearGrid<RealType>; // If the global grid is already linear, do not interpolate the data int ng; if (grid_global->getGridTag() == LINEAR_1DGRID) { ng = (int)std::ceil(rmax/grid_global->Delta) + 1; app_log() << " Using global grid with delta = " << grid_global->Delta << endl; rmax = grid_global->Delta * (ng-1); agrid->set(0.0,rmax,ng); // fprintf (stderr, " grid_global delta = %1.10e agrid delta = %1.12e\n", // grid_global->Delta, agrid->Delta); } else { ng=static_cast<int>(rmax/d)+1; agrid->set(0,rmax,ng); } // This is critical!!! // If d is not reset, we generate an error in the interpolated PP! d = agrid->Delta; int ngIn=vnn.cols()-2; if (Llocal == -1 && Lmax > 0) { app_error() << "The local channel is not specified in the pseudopotential file.\n" << "Please add \'l-local=\"n\"\' attribute the semilocal section of the fsatom XML file.\n"; APP_ABORT("ECPComponentBuilder::doBreakUp"); // Llocal = Lmax; } //find the index of local int iLlocal=-1; for(int l=0; l<angList.size(); l++) if(angList[l] == Llocal) iLlocal=l; vector<RealType> newP(ng),newPin(ngIn); for(int l=0; l<angList.size(); l++) { if(angList[l] == Llocal) continue; const RealType* restrict vp=vnn[angList[l]]; const RealType* restrict vpLoc=vnn[iLlocal]; int ll=angList[l]; for(int i=0; i<ngIn; i++) newPin[i]=Vprefactor*(vp[i]-vpLoc[i]); OneDimCubicSpline<RealType> infunc(grid_global,newPin); infunc.spline(0,0.0,ngIn-1,0.0); RealType r=d; for(int i=1; i<ng-1; i++) { newP[i]=infunc.splint(r)/r; r+=d; } newP[0]=newP[1]; newP[ng-1]=0.0; RadialPotentialType *app = new RadialPotentialType(agrid,newP); app->spline(); pp_nonloc->add(angList[l],app); } NumNonLocal=Lmax; if (Llocal == Lmax) Lmax--; if(NumNonLocal) { pp_nonloc->lmax=Lmax; pp_nonloc->Rmax=rmax; } else { //only one component, remove non-local potentials delete pp_nonloc; pp_nonloc=0; } { // Spline local potential on original grid newPin[0]=0.0; RealType vfac=-Vprefactor/Zeff; const RealType* restrict vpLoc=vnn[iLlocal]; for(int i=0; i<ngIn; i++) newPin[i]=vfac*vpLoc[i]; double dy0 = (newPin[1] - newPin[0])/((*grid_global)[1]-(*grid_global)[0]); OneDimCubicSpline<RealType> infunc(grid_global,newPin); infunc.spline(0,dy0,ngIn-1,0.0); int m = grid_global->size(); double loc_max = grid_global->r(m-1); int nloc = (int)std::floor(loc_max / d); loc_max = (nloc-1) * d; LinearGrid<RealType>* grid_loc = new LinearGrid<RealType>; grid_loc->set(0.0, loc_max, nloc); app_log() << " Making L=" << Llocal << " a local potential with a radial cutoff of " << loc_max << endl; RealType r=d; vector<RealType> newPloc(nloc); for(int i=1; i<nloc-1; i++) { newPloc[i]=infunc.splint(r); r+=d; } newPloc[0] = 0.0; newPloc[nloc-1] = 1.0; pp_loc = new RadialPotentialType(grid_loc,newPloc); pp_loc->spline(0, dy0, nloc-1, 0.0); // for (double r=0.0; r<3.50001; r+=0.001) // fprintf (stderr, "%10.5f %10.5f\n", r, pp_loc->splint(r)); } }
SPOSetBase* EinsplineSetBuilder::createSPOSet(xmlNodePtr cur) { //use 2 bohr as the default when truncated orbitals are used based on the extend of the ions BufferLayer=2.0; OhmmsAttributeSet attribs; int numOrbs = 0; qafm=0; int sortBands(1); string sourceName; string spo_prec("double"); string truncate("no"); #if defined(QMC_CUDA) string useGPU="yes"; #else string useGPU="no"; #endif attribs.add (H5FileName, "href"); attribs.add (TileFactor, "tile"); attribs.add (sortBands, "sort"); attribs.add (qafm, "afmshift"); attribs.add (TileMatrix, "tilematrix"); attribs.add (TwistNum, "twistnum"); attribs.add (givenTwist, "twist"); attribs.add (sourceName, "source"); attribs.add (MeshFactor, "meshfactor"); attribs.add (useGPU, "gpu"); attribs.add (spo_prec, "precision"); attribs.add (truncate, "truncate"); attribs.add (BufferLayer, "buffer"); attribs.put (XMLRoot); attribs.add (numOrbs, "size"); attribs.add (numOrbs, "norbs"); attribs.put (cur); /////////////////////////////////////////////// // Read occupation information from XML file // /////////////////////////////////////////////// cur = cur->children; int spinSet = -1; vector<int> Occ_Old(0,0); Occ.resize(0,0); bool NewOcc(false); while (cur != NULL) { string cname((const char*)(cur->name)); if(cname == "occupation") { string occ_mode("ground"); occ_format="energy"; particle_hole_pairs=0; OhmmsAttributeSet oAttrib; oAttrib.add(occ_mode,"mode"); oAttrib.add(spinSet,"spindataset"); oAttrib.add(occ_format,"format"); oAttrib.add(particle_hole_pairs,"pairs"); oAttrib.put(cur); if(occ_mode == "excited") { putContent(Occ,cur); } else if(occ_mode != "ground") { app_error() << "Only ground state occupation currently supported " << "in EinsplineSetBuilder.\n"; APP_ABORT("EinsplineSetBuilder::createSPOSet"); } } cur = cur->next; } if (Occ != Occ_Old) { NewOcc=true; Occ_Old = Occ; } else NewOcc=false; #if defined(QMC_CUDA) app_log() << "\t QMC_CUDA=1 Overwriting the precision of the einspline storage on the host.\n"; spo_prec="double"; //overwrite #endif H5OrbSet aset(H5FileName, spinSet, numOrbs); std::map<H5OrbSet,SPOSetBase*,H5OrbSet>::iterator iter; iter = SPOSetMap.find (aset); if ((iter != SPOSetMap.end() ) && (!NewOcc) && (qafm==0)) { qafm=0; app_log() << "SPOSet parameters match in EinsplineSetBuilder: " << "cloning EinsplineSet object.\n"; return iter->second->makeClone(); } // The tiling can be set by a simple vector, (e.g. 2x2x2), or by a // full 3x3 matrix of integers. If the tilematrix was not set in // the input file... bool matrixNotSet = true; for (int i=0; i<3; i++) for (int j=0; j<3; j++) matrixNotSet = matrixNotSet && (TileMatrix(i,j) == 0); // then set the matrix to what may have been specified in the // tiling vector if (matrixNotSet) for (int i=0; i<3; i++) for (int j=0; j<3; j++) TileMatrix(i,j) = (i==j) ? TileFactor(i) : 0; if (myComm->rank() == 0) fprintf (stderr, " [ %2d %2d %2d\n %2d %2d %2d\n %2d %2d %2d ]\n", TileMatrix(0,0), TileMatrix(0,1), TileMatrix(0,2), TileMatrix(1,0), TileMatrix(1,1), TileMatrix(1,2), TileMatrix(2,0), TileMatrix(2,1), TileMatrix(2,2)); if (numOrbs == 0) { app_error() << "You must specify the number of orbitals in the input file.\n"; APP_ABORT("EinsplineSetBuilder::createSPOSet"); } else app_log() << " Reading " << numOrbs << " orbitals from HDF5 file.\n"; Timer mytimer; mytimer.restart(); ///////////////////////////////////////////////////////////////// // Read the basic orbital information, without reading all the // // orbitals themselves. // ///////////////////////////////////////////////////////////////// if (myComm->rank() == 0) if (!ReadOrbitalInfo()) { app_error() << "Error reading orbital info from HDF5 file. Aborting.\n"; APP_ABORT("EinsplineSetBuilder::createSPOSet"); } app_log() << "TIMER EinsplineSetBuilder::ReadOrbitalInfo " << mytimer.elapsed() << endl; myComm->barrier(); mytimer.restart(); BroadcastOrbitalInfo(); app_log() << "TIMER EinsplineSetBuilder::BroadcastOrbitalInfo " << mytimer.elapsed() << endl; app_log().flush(); /////////////////////////////////////////////////////////////////// // Now, analyze the k-point mesh to figure out the what k-points // // are needed // /////////////////////////////////////////////////////////////////// PrimCell.set(Lattice); SuperCell.set(SuperLattice); for (int iat=0; iat<AtomicOrbitals.size(); iat++) AtomicOrbitals[iat].Lattice = Lattice; // Copy supercell into the ParticleSets // app_log() << "Overwriting XML lattice with that from the ESHDF file.\n"; // PtclPoolType::iterator piter; // for(piter = ParticleSets.begin(); piter != ParticleSets.end(); piter++) // piter->second->Lattice.copy(SuperCell); AnalyzeTwists2(); ////////////////////////////////// // Create the OrbitalSet object ////////////////////////////////// if (HaveLocalizedOrbs) OrbitalSet = new EinsplineSetLocal; #ifdef QMC_CUDA else if (AtomicOrbitals.size() > 0) { if (UseRealOrbitals) OrbitalSet = new EinsplineSetHybrid<double>; else OrbitalSet = new EinsplineSetHybrid<complex<double> >; } #endif else { if (UseRealOrbitals) OrbitalSet = new EinsplineSetExtended<double>; else OrbitalSet = new EinsplineSetExtended<complex<double> >; } //set the internal parameters setTiling(OrbitalSet,numOrbs); if (HaveLocalizedOrbs) { EinsplineSetLocal *restrict orbitalSet = dynamic_cast<EinsplineSetLocal*>(OrbitalSet); #pragma omp critical(read_einspline_orbs) { if ((spinSet == LastSpinSet) && (numOrbs <= NumOrbitalsRead) && (!NewOcc) ) CopyBands(numOrbs); else { // Now, figure out occupation for the bands and read them OccupyBands(spinSet, sortBands); ReadBands (spinSet, orbitalSet); } } // Now, store what we have read LastOrbitalSet = OrbitalSet; LastSpinSet = spinSet; NumOrbitalsRead = numOrbs; } else // Otherwise, use EinsplineSetExtended { mytimer.restart(); bool use_single= (spo_prec == "single" || spo_prec == "float"); if (UseRealOrbitals) { OccupyBands(spinSet, sortBands); //check if a matching BsplineReaderBase exists BsplineReaderBase* spline_reader=0; //if(TargetPtcl.Lattice.SuperCellEnum != SUPERCELL_BULK && truncate=="yes") if(truncate=="yes") { if(use_single) { if(TargetPtcl.Lattice.SuperCellEnum == SUPERCELL_OPEN) spline_reader= new SplineMixedAdoptorReader<SplineOpenAdoptor<float,double,3> >(this); else if(TargetPtcl.Lattice.SuperCellEnum == SUPERCELL_SLAB) spline_reader= new SplineMixedAdoptorReader<SplineMixedAdoptor<float,double,3> >(this); else spline_reader= new SplineAdoptorReader<SplineR2RAdoptor<float,double,3> >(this); } else { if(TargetPtcl.Lattice.SuperCellEnum == SUPERCELL_OPEN) spline_reader= new SplineMixedAdoptorReader<SplineOpenAdoptor<double,double,3> >(this); else if(TargetPtcl.Lattice.SuperCellEnum == SUPERCELL_SLAB) spline_reader= new SplineMixedAdoptorReader<SplineMixedAdoptor<double,double,3> >(this); else spline_reader= new SplineAdoptorReader<SplineR2RAdoptor<double,double,3> >(this); } } else { if(use_single) spline_reader= new SplineAdoptorReader<SplineR2RAdoptor<float,double,3> >(this); } if(spline_reader) { HasCoreOrbs=bcastSortBands(NumDistinctOrbitals,myComm->rank()==0); SPOSetBase* bspline_zd=spline_reader->create_spline_set(spinSet,OrbitalSet); delete spline_reader; if(bspline_zd) SPOSetMap[aset] = bspline_zd; return bspline_zd; } else { app_log() << ">>>> Creating EinsplineSetExtended<double> <<<< " << endl; EinsplineSetExtended<double> *restrict orbitalSet = dynamic_cast<EinsplineSetExtended<double>* > (OrbitalSet); if (Format == ESHDF) ReadBands_ESHDF(spinSet,orbitalSet); else ReadBands(spinSet, orbitalSet); } } else { OccupyBands(spinSet, sortBands); BsplineReaderBase* spline_reader=0; if(truncate == "yes") { app_log() << " Truncated orbitals with multiple kpoints are not supported yet!" << endl; } if(use_single) { #if defined(QMC_COMPLEX) spline_reader= new SplineAdoptorReader<SplineC2CPackedAdoptor<float,double,3> >(this); #else spline_reader= new SplineAdoptorReader<SplineC2RPackedAdoptor<float,double,3> >(this); #endif } if(spline_reader) { RotateBands_ESHDF(spinSet, dynamic_cast<EinsplineSetExtended<complex<double> >*>(OrbitalSet)); HasCoreOrbs=bcastSortBands(NumDistinctOrbitals,myComm->rank()==0); SPOSetBase* bspline_zd=spline_reader->create_spline_set(spinSet,OrbitalSet); delete spline_reader; if(bspline_zd) SPOSetMap[aset] = bspline_zd; return bspline_zd; } else { EinsplineSetExtended<complex<double> > *restrict orbitalSet = dynamic_cast<EinsplineSetExtended<complex<double> >*>(OrbitalSet); if (Format == ESHDF) ReadBands_ESHDF(spinSet,orbitalSet); else ReadBands(spinSet, orbitalSet); } } app_log() << "TIMER EinsplineSetBuilder::ReadBands " << mytimer.elapsed() << endl; } #ifndef QMC_COMPLEX if (myComm->rank()==0 && OrbitalSet->MuffinTins.size() > 0) { FILE *fout = fopen ("TestMuffins.dat", "w"); Vector<double> phi(numOrbs), lapl(numOrbs); Vector<PosType> grad(numOrbs); ParticleSet P; P.R.resize(6); for (int i=0; i<P.R.size(); i++) P.R[i] = PosType (0.0, 0.0, 0.0); PosType N = 0.25*PrimCell.a(0) + 0.25*PrimCell.a(1) + 0.25*PrimCell.a(2); for (double x=-1.0; x<=1.0; x+=0.0000500113412) { // for (double x=-0.003; x<=0.003; x+=0.0000011329343481381) { P.R[0] = x * (PrimCell.a(0) + 0.914*PrimCell.a(1) + 0.781413*PrimCell.a(2)); double r = std::sqrt(dot(P.R[0], P.R[0])); double rN = std::sqrt(dot(P.R[0]-N, P.R[0]-N)); OrbitalSet->evaluate(P, 0, phi, grad, lapl); // OrbitalSet->evaluate(P, 0, phi); fprintf (fout, "%1.12e ", r*x/std::fabs(x)); for (int j=0; j<numOrbs; j++) { double gmag = std::sqrt(dot(grad[j],grad[j])); fprintf (fout, "%16.12e ", /*phi[j]*phi[j]**/(-5.0/r -0.5*lapl[j]/phi[j])); // double E = -5.0/r -0.5*lapl[j]/phi[j]; fprintf (fout, "%16.12e ", phi[j]); fprintf (fout, "%16.12e ", gmag); } fprintf (fout, "\n"); } fclose(fout); } #endif SPOSetMap[aset] = OrbitalSet; if (sourceName.size() && (ParticleSets.find(sourceName) == ParticleSets.end())) { app_log() << " EinsplineSetBuilder creates a ParticleSet " << sourceName << endl; ParticleSet* ions=new ParticleSet; ions->Lattice=TargetPtcl.Lattice; ESHDFIonsParser ap(*ions,H5FileID,myComm); ap.put(XMLRoot); ap.expand(TileMatrix); ions->setName(sourceName); ParticleSets[sourceName]=ions; //overwrite the lattice and assign random if(TargetPtcl.Lattice.SuperCellEnum) { TargetPtcl.Lattice=ions->Lattice; makeUniformRandom(TargetPtcl.R); TargetPtcl.R.setUnit(PosUnit::LatticeUnit); TargetPtcl.convert2Cart(TargetPtcl.R); TargetPtcl.createSK(); } } #ifdef QMC_CUDA if (useGPU == "yes" || useGPU == "1") { app_log() << "Initializing GPU data structures.\n"; OrbitalSet->initGPU(); } #endif return OrbitalSet; }
bool AGPDeterminantBuilder::put(xmlNodePtr cur) { if(agpDet) { app_error() << " AGPDeterminantBuilder::put exits. AGPDeterminant has been already created." << endl; return false; } app_log() << " AGPDeterminantBuilder Creating AGPDeterminant." << endl; xmlNodePtr curRoot=cur; bool success=true; string cname, tname; xmlNodePtr bPtr=NULL; xmlNodePtr cPtr=NULL; xmlNodePtr uPtr=NULL; OhmmsAttributeSet oAttrib; oAttrib.add(funcOpt,"function"); oAttrib.add(transformOpt,"transform"); oAttrib.put(cur); cur = cur->children; while(cur != NULL) { getNodeName(cname,cur); if(cname == basisset_tag) { bPtr=cur; } else if(cname.find("coeff")<cname.size()) { cPtr=cur; } else if(cname.find("un")<cname.size()) { uPtr=cur; } cur=cur->next; } if(bPtr == NULL || cPtr == NULL) { app_error() << " AGPDeterminantBuilder::put Cannot create AGPDeterminant. " << endl; app_error() << " Missing <basisset/> or <coefficients/>" << endl; return false; } if(myBasisSetFactory == 0) { myBasisSetFactory = new BasisSetFactory(targetPtcl,targetPsi,ptclPool); myBasisSetFactory->createBasisSet(bPtr,curRoot); } // mmorales: this needs to be fixed after changes to BasisSetfactory // BasisSetBase<RealType>* myBasisSet=myBasisSetFactory->getBasisSet(); BasisSetBase<RealType>* myBasisSet; //=myBasisSetFactory->getBasisSet(); int nup=targetPtcl.first(1), ndown=0; if(targetPtcl.groups()>1) ndown = targetPtcl.first(2)-nup; myBasisSet->resize(nup+ndown); agpDet = new AGPDeterminant(myBasisSet); agpDet->resize(nup,ndown); //set Lambda: possible to move to AGPDeterminant int offset=1; xmlNodePtr tcur=cPtr->xmlChildrenNode; while(tcur != NULL) { if(xmlStrEqual(tcur->name,(const xmlChar*)"lambda")) { int i=atoi((const char*)(xmlGetProp(tcur,(const xmlChar*)"i"))); int j=atoi((const char*)(xmlGetProp(tcur,(const xmlChar*)"j"))); double c=atof((const char*)(xmlGetProp(tcur,(const xmlChar*)"c"))); agpDet->Lambda(i-offset,j-offset)=c; if(i != j) { agpDet->Lambda(j-offset,i-offset)=c; } } tcur=tcur->next; } if(uPtr != NULL) { tcur=uPtr->xmlChildrenNode; while(tcur != NULL) { if(xmlStrEqual(tcur->name,(const xmlChar*)"lambda")) { int i=atoi((const char*)(xmlGetProp(tcur,(const xmlChar*)"i"))); int j=atoi((const char*)(xmlGetProp(tcur,(const xmlChar*)"j"))); double c=atof((const char*)(xmlGetProp(tcur,(const xmlChar*)"c"))); agpDet->LambdaUP(j-offset,i-offset)=c; } tcur=tcur->next; } app_log() << " AGPDeterminantBuilder::put Coefficients for the unpaired electrons " << endl; app_log() << agpDet->LambdaUP << endl; } if(agpDet) targetPsi.addOrbital(agpDet,"AGP"); return success; }
/* * eval_mm_valid - Check the mm malloc package for correctness */ static int eval_mm_valid(trace_t *trace, int tracenum, range_t **ranges) { int i, j; int index; int size; int oldsize; char *newp; char *oldp; char *p; /* Reset the heap and free any records in the range list */ mem_reset_brk(); clear_ranges(ranges); /* Call the mm package's init function */ if (mm_init() < 0) { malloc_error(tracenum, 0, "mm_init failed."); return 0; } /* Interpret each operation in the trace in order */ for (i = 0; i < trace->num_ops; i++) { index = trace->ops[i].index; size = trace->ops[i].size; switch (trace->ops[i].type) { case ALLOC: /* mm_malloc */ /* Call the student's malloc */ if ((p = mm_malloc(size)) == NULL) { malloc_error(tracenum, i, "mm_malloc failed."); return 0; } /* * Test the range of the new block for correctness and add it * to the range list if OK. The block must be be aligned properly, * and must not overlap any currently allocated block. */ if (add_range(ranges, p, size, tracenum, i) == 0) return 0; /* ADDED: cgw * fill range with low byte of index. This will be used later * if we realloc the block and wish to make sure that the old * data was copied to the new block */ memset(p, index & 0xFF, size); /* Remember region */ trace->blocks[index] = p; trace->block_sizes[index] = size; break; case REALLOC: /* mm_realloc */ /* Call the student's realloc */ oldp = trace->blocks[index]; if ((newp = mm_realloc(oldp, size)) == NULL) { malloc_error(tracenum, i, "mm_realloc failed."); return 0; } /* Remove the old region from the range list */ remove_range(ranges, oldp); /* Check new block for correctness and add it to range list */ if (add_range(ranges, newp, size, tracenum, i) == 0) return 0; /* ADDED: cgw * Make sure that the new block contains the data from the old * block and then fill in the new block with the low order byte * of the new index */ oldsize = trace->block_sizes[index]; if (size < oldsize) oldsize = size; for (j = 0; j < oldsize; j++) { if (newp[j] != (index & 0xFF)) { malloc_error(tracenum, i, "mm_realloc did not preserve the " "data from old block"); return 0; } } memset(newp, index & 0xFF, size); /* Remember region */ trace->blocks[index] = newp; trace->block_sizes[index] = size; break; case FREE: /* mm_free */ /* Remove region from list and call student's free function */ p = trace->blocks[index]; remove_range(ranges, p); mm_free(p); break; default: app_error("Nonexistent request type in eval_mm_valid"); } } /* As far as we know, this is a valid malloc package */ return 1; }
/** build a Local Pseudopotential * * For numerical stability, the radial function of the local pseudopotential is stored * as \f$rV(r)/Z_{eff}/Z_{e}\f$ for the distance r and \f$Z_e = -1\f$. * The coulomb factor $Z_{e}Z_{eff}/r$ is applied by LocalECPotential * (see LocalECPotential::evaluate). */ void ECPComponentBuilder::buildLocal(xmlNodePtr cur) { if(pp_loc) return; //something is wrong string vFormat("V"); const xmlChar* vptr=xmlGetProp(cur,(const xmlChar*)"format"); if(vptr != NULL) { vFormat=(const char*)vptr; } int vPowerCorrection=1; if(vFormat == "r*V") { app_log() << " Local pseudopotential format = r*V" << endl; vPowerCorrection=0; } else { app_log() << " Local pseudopotential format = V" << endl; } typedef GaussianTimesRN<RealType> InFuncType; GridType* grid_local=0; InFuncType vr; bool bareCoulomb=true; cur=cur->children; while(cur != NULL) { string cname((const char*)cur->name); if(cname == "grid") { grid_local=createGrid(cur,true); } else if(cname == "basisGroup") { vr.putBasisGroup(cur,vPowerCorrection); bareCoulomb=false; } else if(cname == "data") { pp_loc=createVrWithData(cur,grid_local,vPowerCorrection); app_log() << " Local pseduopotential in a <data/>" << endl; return; } cur=cur->next; } if(grid_local == 0) { if(grid_global == 0) { APP_ABORT("ECPComponentBuilder::buildLocal Missing grid information. "); } grid_local=grid_global; } if(grid_local->GridTag == CUSTOM_1DGRID) { APP_ABORT("ECPComponentBuilder::buildLocal Custom grid is used. Need to recast to the linear grid"); } else { vector<RealType> v; if(bareCoulomb) { app_log() << " Bare Coulomb potential is used." << endl; grid_local->set(0.0,1.,3); v.resize(3); for(int ig=0; ig<3; ig++) v[ig]=1.0; pp_loc=new RadialPotentialType(grid_local,v); pp_loc->spline(0,0.0,2,0.0); } else { app_log() << " Guassian basisGroup is used: base power " << vr.basePower << endl; const RealType eps=1e-12;//numeric_limits<RealType>::epsilon();//1e-12; RealType zinv=1.0/Zeff; RealType r=10.; bool ignore=true; int last=grid_local->size()-1; while(ignore&&last) { r=(*grid_local)[last]; ignore=(abs(zinv*vr.f(r))<eps); --last; } if(last ==0) { app_error() << " Illegal Local Pseudopotential " <<endl; } //Add the reset values here int ng=static_cast<int>(r/1e-3)+1; app_log() << " Use a Linear Grid: [0,"<< r << "] Number of points = " << ng << endl; grid_local->set(0.0,r,ng); v.resize(ng); for(int ig=1; ig<ng-1; ig++) { double r=(*grid_local)[ig]; v[ig]=1.0-zinv*vr.f(r); } v[0]=2.0*v[1]-v[2]; v[ng-1]=1.0; pp_loc=new RadialPotentialType(grid_local,v); pp_loc->spline(); //use the fixed conditions } } }
/** create a SlaterDeterminant * @param cur xmlnode containing \<slaterdeterminant\> * @return a SlaterDeterminant * * @warning MultiSlaterDeterminant is not working yet. */ SPOSetBase* SplineSetBuilder::createSPOSet(xmlNodePtr cur){ string hrefname("NONE"); int norb(0); int degeneracy(1); OhmmsAttributeSet aAttrib; aAttrib.add(norb,"orbitals"); aAttrib.add(degeneracy,"degeneracy"); aAttrib.add(hrefname,"href"); aAttrib.put(cur); if(norb ==0) { app_error() << "SplineSetBuilder::createSPOSet failed. Check the attribte orbitals." << endl; return 0; } app_log() << " Degeneracy = " << degeneracy << endl; std::vector<int> npts(3); npts[0]=GridXYZ->nX; npts[1]=GridXYZ->nY; npts[2]=GridXYZ->nZ; std::vector<RealType> inData(npts[0]*npts[1]*npts[2]); SPOSetType* psi= new SPOSetType(norb); vector<int> occSet(norb); for(int i=0; i<norb; i++) occSet[i]=i; cur=cur->children; while(cur != NULL) { string cname((const char*)(cur->name)); if(cname == "occupation") { string occ_mode("ground"); const xmlChar* o=xmlGetProp(cur,(const xmlChar*)"mode"); if(o!= NULL) occ_mode = (const char*)o; //Do nothing if mode == ground if(occ_mode == "excited") { vector<int> occ_in, occRemoved; putContent(occ_in,cur); for(int k=0; k<occ_in.size(); k++) { if(occ_in[k]<0) occRemoved.push_back(-occ_in[k]-1); } int kpopd=0; for(int k=0; k<occ_in.size(); k++) { if(occ_in[k]>0) occSet[occRemoved[kpopd++]]=occ_in[k]-1; } } hid_t h_file = H5Fopen(hrefname.c_str(),H5F_ACC_RDWR,H5P_DEFAULT); const xmlChar* h5path = xmlGetProp(cur,(const xmlChar*)"h5path"); string hroot("/eigenstates_3/twist_0"); if(h5path != NULL) hroot=(const char*)h5path; char wfname[128],wfshortname[16]; for(int iorb=0; iorb<norb; iorb++) { sprintf(wfname,"%s/band_%d/eigenvector",hroot.c_str(),occSet[iorb]/degeneracy); sprintf(wfshortname,"b%d",occSet[iorb]/degeneracy); SPOType* neworb=0; map<string,SPOType*>::iterator it(NumericalOrbitals.find(wfshortname)); if(it == NumericalOrbitals.end()) { neworb=new SPOType(GridXYZ); HDFAttribIO<std::vector<RealType> > dummy(inData,npts); dummy.read(h_file,wfname); //neworb->reset(inData.begin(), inData.end(), targetPtcl.Lattice.BoxBConds[0]); neworb->reset(inData.begin(), inData.end(), targetPtcl.Lattice.SuperCellEnum); NumericalOrbitals[wfshortname]=neworb; app_log() << " Reading spline function " << wfname << endl; } else { neworb = (*it).second; app_log() << " Reusing spline function " << wfname << endl; } psi->add(neworb); } H5Fclose(h_file); } cur=cur->next; } SPOType* aorb=(*NumericalOrbitals.begin()).second; string fname("spline3d.vti"); std::ofstream dfile(fname.c_str()); dfile.setf(ios::scientific, ios::floatfield); dfile.setf(ios::left,ios::adjustfield); dfile.precision(10); dfile << "<?xml version=\"1.0\"?>" << endl; dfile << "<VTKFile type=\"ImageData\" version=\"0.1\">" << endl; dfile << " <ImageData WholeExtent=\"0 " << npts[0]-2 << " 0 " << npts[1]-2 << " 0 " << npts[2]-2 << "\" Origin=\"0 0 0\" Spacing=\"1 1 1\">"<< endl; dfile << " <Piece Extent=\"0 " << npts[0]-2 << " 0 " << npts[1]-2 << " 0 " << npts[2]-2 << "\">" << endl; dfile << " <PointData Scalars=\"wfs\">" << endl; dfile << " <DataArray type=\"Float32\" Name=\"wfs\">" << endl; int ng=0; GradType grad; ValueType lap; for(int ix=0; ix<npts[0]-1; ix++) { double x(GridXYZ->gridX->operator()(ix)); for(int iy=0; iy<npts[1]-1; iy++) { double y(GridXYZ->gridY->operator()(iy)); for(int iz=0; iz<npts[2]-1; iz++, ng++) { PosType p(x,y,GridXYZ->gridZ->operator()(iz)); //aorb.setgrid(p); //Timing with the ofstream is not correct. //Uncomment the line below and comment out the next two line. //double t=aorb.evaluate(p,grad,lap); dfile << setw(20) << aorb->evaluate(p,grad,lap); if(ng%5 == 4) dfile << endl; } } } dfile << " </DataArray>" << endl; dfile << " </PointData>" << endl; dfile << " </Piece>" << endl; dfile << " </ImageData>" << endl; dfile << "</VTKFile>" << endl; abort(); return psi; }
/* * main - The shell's main routine * * Requires: * argc should be less than MAXARGS arguments. * argv should contain less than MAXARGS arguments. * * Effects: * Runs an interactive command-line interpreter that runs programs on * behalf of the user. It waits for a command line and then carries out * the action of that command line. The shell executes built-in commands * immediately, but also can execute user programs by forking child * processes. It manages jobs running the foreground and background. */ int main(int argc, char **argv) { int c; char cmdline[MAXLINE]; char *path = NULL; bool emit_prompt = true; // Emit a prompt by default. /* * Redirect stderr to stdout (so that driver will get all output * on the pipe connected to stdout). */ dup2(1, 2); // Parse the command line. while ((c = getopt(argc, argv, "hvp")) != -1) { switch (c) { case 'h': // Print a help message. usage(); break; case 'v': // Emit additional diagnostic info. verbose = true; break; case 'p': // Don't print a prompt. // This is handy for automatic testing. emit_prompt = false; break; default: usage(); } } // Install the signal handlers. // These are the ones you will need to implement: Signal(SIGINT, sigint_handler); // ctrl-c Signal(SIGTSTP, sigtstp_handler); // ctrl-z Signal(SIGCHLD, sigchld_handler); // Terminated or stopped child // This one provides a clean way to kill the shell. Signal(SIGQUIT, sigquit_handler); // Initialize the search path. path = getenv("PATH"); initpath(path); // Initialize the jobs list. initjobs(jobs); // Execute the shell's read/eval loop. while (true) { // Read the command line. if (emit_prompt) { printf("%s", prompt); fflush(stdout); } if ((fgets(cmdline, MAXLINE, stdin) == NULL) && ferror(stdin)){ app_error("fgets error");} if (feof(stdin)) { // End of file (ctrl-d) fflush(stdout); exit(0); } // Evaluate the command line. eval(cmdline); fflush(stdout); fflush(stdout); } // Control never reaches here. assert(false); }
/** The read routine - get data from XML and H5. Process it and build orbitals. * * - parameters * -- num_tiwsts * -- num_bands * -- complex_coefficients * -- maximum_ecut * - basis */ bool PWOrbitalBuilder::createPWBasis(xmlNodePtr cur) { //recycle int and double reader int idata; double ddata; HDFAttribIO<int> hdfint(idata); HDFAttribIO<double> hdfdbl(ddata); //start of parameters hid_t grp_id = H5Gopen(hfileID,myParam->paramTag.c_str()); hdfint.read(grp_id,"num_twists"); int nkpts = idata; hdfint.read(grp_id,"num_bands"); int nbands = idata; myParam->numBands = nbands; hdfint.read(grp_id,"complex_coefficients"); bool h5coefsreal = (idata==0); hdfdbl.read(grp_id,"maximum_ecut"); RealType h5ecut = ddata; RealType ecut = ddata; H5Gclose(grp_id); //end of parameters //check if input parameters are valid int nup=targetPtcl.last(0); int ndown=targetPtcl.getTotalNum()-nup; if(nbands < nup || nbands < ndown){ app_error() << "Not enough bands in h5 file" << endl; OHMMS::Controller->abort(); } string tname=myParam->getTwistAngleName(); //hid_t es_grp_id = H5Gopen(hfile,myParam->eigTag.c_str()); //hid_t twist_grp_id = H5Gopen(es_grp_id,tname.c_str()); HDFAttribIO<PosType> hdfobj_twist(TwistAngle); hdfobj_twist.read(hfileID,tname.c_str()); #if defined(ENABLE_SMARTPOINTER) if(myBasisSet.get() ==0) { myBasisSet.reset(new PWBasis(TwistAngle)); } #else if(myBasisSet==0) { myBasisSet = new PWBasis(TwistAngle); } #endif //Read the planewave basisset. //Note that the same data is opened here for each twist angle-avoids duplication in the //h5 file (which may become very large). //return the ecut to be used by the basis set RealType real_ecut = myParam->getEcut(ecut); grp_id = H5Gopen(hfileID,myParam->basisTag.c_str()); //create at least one basis set but do resize the containers int nh5gvecs=myBasisSet->readbasis(grp_id,real_ecut,targetPtcl.Lattice, myParam->pwTag, myParam->pwMultTag); H5Gclose(grp_id); //Close PW Basis group app_log() << " num_twist = " << nkpts << endl; app_log() << " twist angle = " << TwistAngle << endl; app_log() << " num_bands = " << nbands << endl; app_log() << " input maximum_ecut = " << ecut << endl; app_log() << " current maximum_ecut = " << real_ecut << endl; app_log() << " num_planewaves = " << nh5gvecs<< endl; return true; }
bool HDFWalkerInput_0_0::put(xmlNodePtr cur) { hid_t h_file = H5Fopen(FileName.c_str(),H5F_ACC_RDWR,H5P_DEFAULT); hid_t h_config = H5Gopen(h_file,"config_collection"); if(h_config<0) { app_error() << " HDFWalkerInput_0_0::put config_collection is not found in " << FileName << "." << endl; H5Fclose(h_file); return false; } int NumSets=0; hid_t h1=H5Dopen(h_config,"NumOfConfigurations"); if(h1>-1) { H5Dread(h1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,&(NumSets)); H5Dclose(h1); } if(!NumSets) { //resolve the integer and long problem with 64bit hsize_t nset; H5Gget_num_objs(h_config,&nset); NumSets=nset; } if(!NumSets) { app_error() << " HDFWalkerInput_0_0::put " << FileName << " does not contain walkers!" << endl; H5Gclose(h_config); H5Gclose(h_file); return false; } //select the last block int 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 groups H5Gclose(group_id); H5Gclose(h_config); H5Fclose(h_file); /*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 = targetW.getActiveWalkers(); if(curWalker) { app_log() << "HDFWalkerInput_0_0::put Adding " << nwt << " walkers to " << curWalker << endl; targetW.createWalkers(nwt); } else { app_log() << "HDFWalkerInput_0_0::put Creating " << nwt << " walkers." << endl; targetW.resize(nwt,nptcl); } //assign configurations to W int iw=0; MCWalkerConfiguration::iterator it = targetW.begin()+curWalker; MCWalkerConfiguration::iterator it_end = targetW.end(); while(it != it_end) { std::copy(Pos_temp[iw],Pos_temp[iw+1], (*it)->R.begin()); ++it;++iw; } return true; }