DiracDeterminantBase::ValueType DiracDeterminantBase::logRatio(ParticleSet& P, int iat, ParticleSet::ParticleGradient_t& dG, ParticleSet::ParticleLaplacian_t& dL) { //THIS SHOULD NOT BE CALLED ValueType r=ratio(P,iat,dG,dL); return LogValue = evaluateLogAndPhase(r,PhaseValue); }
AGPDeterminant::ValueType AGPDeterminant::registerData(ParticleSet& P, PooledData<RealType>& buf) { evaluateLogAndStore(P); P.G += myG; P.L += myL; //copy psiM to temporary psiM_temp = psiM; if(UseBuffer) { //add the data: determinant, inverse, gradient and laplacians buf.add(CurrentDet); buf.add(psiM.begin(),psiM.end()); buf.add(phiT.begin(),phiT.end()); buf.add(d2psiU.begin(),d2psiU.end()); buf.add(d2psiD.begin(),d2psiD.end()); buf.add(FirstAddressOfdVU,LastAddressOfdVU); buf.add(FirstAddressOfdVD,LastAddressOfdVD); buf.add(d2Y.begin(),d2Y.end()); buf.add(FirstAddressOfdY,LastAddressOfdY); buf.add(FirstAddressOfG,LastAddressOfG); buf.add(myL.first_address(), myL.last_address()); //buf.add(myL.begin(), myL.end()); } return LogValue = evaluateLogAndPhase(CurrentDet,PhaseValue); }
TrialWaveFunction::RealType TrialWaveFunction::ratioVector(ParticleSet& P, int iat, std::vector<RealType>& ratios) { //TAU_PROFILE("TrialWaveFunction::ratio","(ParticleSet& P,int iat)", TAU_USER); ratios.resize(Z.size(),0); ValueType r(1.0); for (int i=0,ii=0; i<Z.size(); ++i,ii+=2) { ValueType zr=Z[i]->ratio(P,iat); r *= zr; #if defined(QMC_COMPLEX) ratios[i] = abs(zr); #else ratios[i] = zr; #endif } #if defined(QMC_COMPLEX) //return std::exp(evaluateLogAndPhase(r,PhaseValue)); RealType logr=evaluateLogAndPhase(r,PhaseDiff); return std::exp(logr); #else if (r<0) PhaseDiff=M_PI; // else PhaseDiff=0.0; return r; #endif }
void TrialWaveFunction::evaluateRatios(VirtualParticleSet& VP, vector<RealType>& ratios) { #if defined(QMC_COMPLEX) vector<ValueType> t(ratios.size()),r(ratios.size(),1.0);; for (int i=0; i<Z.size(); ++i) { Z[i]->evaluateRatios(VP,t); for (int j=0; j<ratios.size(); ++j) r[j]*=t[j]; } RealType pdiff; for(int j=0; j<ratios.size(); ++j) { RealType logr=evaluateLogAndPhase(r[j],pdiff); ratios[j]=std::exp(logr)*std::cos(pdiff); //ratios[j]=std::abs(r)*std::cos(std::arg(r[j])); } #else std::fill(ratios.begin(),ratios.end(),1.0); vector<ValueType> t(ratios.size()); for (int i=0; i<Z.size(); ++i) { Z[i]->evaluateRatios(VP,t); for (int j=0; j<ratios.size(); ++j) ratios[j]*=t[j]; } #endif }
RNDiracDeterminantBaseAlternate::RealType RNDiracDeterminantBaseAlternate::evaluateLog(ParticleSet& P, ParticleSet::ParticleGradient_t& G, ParticleSet::ParticleLaplacian_t& L) { // cerr<<"I'm calling evaluate log"<<endl; Phi->evaluate(P, FirstIndex, LastIndex, psiM,dpsiM, d2psiM); myG_alternate=0.0; myL_alternate=0.0; // myG=0.0; // myL=0.0; if (NumPtcls==1) { //CurrentDet=psiM(0,0); ValueType det=psiM(0,0); LogValue = evaluateLogAndPhase(det,PhaseValue); // PhaseValue=0.0; alternateLogValue = LogValue + 0.5*std::log(1.0+std::exp(logepsilon-2.0*LogValue)); RealType cp = std::exp(logepsilon -2.0*LogValue); RealType bp = 1.0/(1+cp); ValueType y=1.0/det; psiM(0,0)=y; GradType rv = y*dpsiM(0,0); myG_alternate(FirstIndex) += bp*rv; myL_alternate(FirstIndex) += bp*(y*d2psiM(0,0) + (1-2*bp)*dot(rv,rv)); G(FirstIndex) += rv; L(FirstIndex) += y*d2psiM(0,0) - dot(rv,rv); // myG(FirstIndex) += bp*rv; // myL(FirstIndex) += bp*(y*d2psiM(0,0) + (1-2*bp)*dot(rv,rv)); } else { InverseTimer.start(); LogValue=InvertWithLog(psiM.data(),NumPtcls,NumOrbitals,WorkSpace.data(),Pivot.data(),PhaseValue); // PhaseValue=0.0; alternateLogValue = LogValue + 0.5*std::log(1.0+std::exp(logepsilon-2.0*LogValue)); RealType cp = std::exp(logepsilon -2.0*LogValue); RealType bp = 1.0/(1+cp); InverseTimer.stop(); RatioTimer.start(); for (int i=0, iat=FirstIndex; i<NumPtcls; i++, iat++) { GradType rv=dot(psiM[i],dpsiM[i],NumOrbitals); ValueType lap=dot(psiM[i],d2psiM[i],NumOrbitals); G(iat) += rv; myG_alternate(iat) += bp*rv; ValueType rv2=dot(rv,rv); myL_alternate(iat) += bp*(lap + (1-2*bp)*rv2); L(iat) += lap - rv2; } RatioTimer.stop(); } psiM_temp = psiM; return LogValue; }
/** evaluate the value of a many-body wave function *@param P input configuration containing N particles *@return the value of many-body wave function * *Upon return, the gradient and laplacian operators are added by the components. */ TrialWaveFunction::ValueType TrialWaveFunction::evaluate(ParticleSet& P) { P.G = 0.0; P.L = 0.0; ValueType psi(1.0); for(int i=0; i<Z.size(); i++) { psi *= Z[i]->evaluate(P, P.G, P.L); } //for(int iat=0; iat<P.getTotalNum(); iat++) // cout << P.G[iat] << " " << P.L[iat] << endl; LogValue = evaluateLogAndPhase(psi,PhaseValue); return psi; }
TrialWaveFunction::RealType TrialWaveFunction::alternateRatio(ParticleSet& P) { //TAU_PROFILE("TrialWaveFunction::ratio","(ParticleSet& P,int iat)", TAU_USER); ValueType r(1.0); for (int i=0,ii=0; i<Z.size(); ++i,ii+=2) { r *= Z[i]->alternateRatio(P); } #if defined(QMC_COMPLEX) //return std::exp(evaluateLogAndPhase(r,PhaseValue)); RealType logr=evaluateLogAndPhase(r,PhaseDiff); return std::exp(logr); #else if (r<0) PhaseDiff=M_PI; return r; #endif }
TrialWaveFunction::RealType TrialWaveFunction::ratio(ParticleSet& P,int iat) { ValueType r(1.0); for(int i=0,ii=V_TIMER; i<Z.size(); ++i,ii+=TIMER_SKIP) { myTimers[ii]->start(); r *= Z[i]->ratio(P,iat); myTimers[ii]->stop(); } #if defined(QMC_COMPLEX) //return std::exp(evaluateLogAndPhase(r,PhaseValue)); RealType logr=evaluateLogAndPhase(r,PhaseValue); return std::exp(logr)*std::cos(PhaseValue); #else PhaseValue=evaluatePhase(r); return real(r); #endif }
AGPDeterminant::ValueType AGPDeterminant::evaluateLog(ParticleSet& P, PooledData<RealType>& buf) { if(UseBuffer) { buf.put(CurrentDet); buf.put(psiM.begin(),psiM.end()); buf.put(phiT.begin(),phiT.end()); buf.put(d2psiU.begin(),d2psiU.end()); buf.put(d2psiD.begin(),d2psiD.end()); buf.put(FirstAddressOfdVU,LastAddressOfdVU); buf.put(FirstAddressOfdVD,LastAddressOfdVD); buf.put(d2Y.begin(),d2Y.end()); buf.put(FirstAddressOfdY,LastAddressOfdY); buf.put(FirstAddressOfG,LastAddressOfG); buf.put(myL.first_address(), myL.last_address()); //buf.put(myL.begin(), myL.end()); } return evaluateLogAndPhase(CurrentDet,PhaseValue); //return CurrentDet; }
/** evaluate \f$ frac{\Psi({\bf R}_i^{'})}{\Psi({\bf R}_i)}\f$ * @param P ParticleSet * @param iat index of the particle with a trial move * @param dG total differentcal gradients * @param dL total differential laplacians * @return ratio * * Each OrbitalBase object adds the differential gradients and lapacians. */ TrialWaveFunction::RealType TrialWaveFunction::ratio(ParticleSet& P, int iat , ParticleSet::ParticleGradient_t& dG, ParticleSet::ParticleLaplacian_t& dL) { //TAU_PROFILE("TrialWaveFunction::ratio","(P,iat,dG,dL)", TAU_USER); dG = 0.0; dL = 0.0; ValueType r(1.0); for (int i=0, ii=1; i<Z.size(); ++i, ii+=2) { r *= Z[i]->ratio(P,iat,dG,dL); } #if defined(QMC_COMPLEX) return std::exp(evaluateLogAndPhase(r,PhaseDiff)); #else if (r<0) PhaseDiff=M_PI; // else PhaseDiff=0.0; return r; #endif }
TrialWaveFunction::RealType TrialWaveFunction::ratioGrad(ParticleSet& P ,int iat, GradType& grad_iat ) { //TAU_PROFILE("TrialWaveFunction::ratioGrad","(ParticleSet& P,int iat)", TAU_USER); grad_iat=0.0; ValueType r(1.0); for (int i=0,ii=1; i<Z.size(); ++i,ii+=2) { r *= Z[i]->ratioGrad(P,iat,grad_iat ); } #if defined(QMC_COMPLEX) //return std::exp(evaluateLogAndPhase(r,PhaseValue)); RealType logr=evaluateLogAndPhase(r,PhaseValue); return std::exp(logr); #else if (r<0) PhaseDiff=M_PI; // else PhaseDiff=0.0; return r; #endif }
/** evaluate \f$ frac{\Psi({\bf R}_i^{'})}{\Psi({\bf R}_i)}\f$ * @param P ParticleSet * @param iat index of the particle with a trial move * @param dG total differentcal gradients * @param dL total differential laplacians * @return ratio * * Each OrbitalBase object adds the differential gradients and lapacians. */ TrialWaveFunction::RealType TrialWaveFunction::ratio(ParticleSet& P, int iat, ParticleSet::ParticleGradient_t& dG, ParticleSet::ParticleLaplacian_t& dL) { dG = 0.0; dL = 0.0; ValueType r(1.0); for(int i=0, ii=VGL_TIMER; i<Z.size(); ++i, ii+=TIMER_SKIP) { myTimers[ii]->start(); r *= Z[i]->ratio(P,iat,dG,dL); myTimers[ii]->stop(); } #if defined(QMC_COMPLEX) return std::exp(evaluateLogAndPhase(r,PhaseValue)); #else PhaseValue=evaluatePhase(r); return real(r); #endif }
DiracDeterminantBase::RealType DiracDeterminantBase::evaluateLog(ParticleSet& P, ParticleSet::ParticleGradient_t& G, ParticleSet::ParticleLaplacian_t& L) { // cerr<<"I'm calling evaluate log"<<endl; Phi->evaluate(P, FirstIndex, LastIndex, psiM,dpsiM, d2psiM); if(NumPtcls==1) { //CurrentDet=psiM(0,0); ValueType det=psiM(0,0); ValueType y=1.0/det; psiM(0,0)=y; GradType rv = y*dpsiM(0,0); G(FirstIndex) += rv; L(FirstIndex) += y*d2psiM(0,0) - dot(rv,rv); LogValue = evaluateLogAndPhase(det,PhaseValue); } else { InverseTimer.start(); LogValue=InvertWithLog(psiM.data(),NumPtcls,NumOrbitals,WorkSpace.data(),Pivot.data(),PhaseValue); InverseTimer.stop(); RatioTimer.start(); for(int i=0, iat=FirstIndex; i<NumPtcls; i++, iat++) { GradType rv=dot(psiM[i],dpsiM[i],NumOrbitals); ValueType lap=dot(psiM[i],d2psiM[i],NumOrbitals); G(iat) += rv; L(iat) += lap - dot(rv,rv); } RatioTimer.stop(); } psiM_temp = psiM; return LogValue; }
DiracDeterminantBase::RealType DiracDeterminantTruncation::evaluateLog(ParticleSet& P, ParticleSet::ParticleGradient_t& G, ParticleSet::ParticleLaplacian_t& L) { d_table=DistanceTable::add(P); Phi->evaluate(P, FirstIndex, LastIndex, psiM,dpsiM, d2psiM); ///I think at this point psiM has particles as the first index for (int ptcl=0;ptcl<psiM.extent(1);ptcl++){ particleLists[ptcl].clear(); for (int orbital=0;orbital<psiM.extent(0);orbital++){ if (abs(psiM(orbital,ptcl))>=cutoff){ pair<int,double> temp(orbital,psiM(orbital,ptcl)); particleLists[ptcl].push_back(temp); } } } if(NumPtcls==1) { //CurrentDet=psiM(0,0); ValueType det=psiM(0,0); ValueType y=1.0/det; psiM(0,0)=y; GradType rv = y*dpsiM(0,0); G(FirstIndex) += rv; L(FirstIndex) += y*d2psiM(0,0) - dot(rv,rv); LogValue = evaluateLogAndPhase(det,PhaseValue); } else { psiM_actual=psiM; MatrixOperators::transpose(psiM_actual); MatrixOperators::ABt(psiM_actual,psiM_actual,psiM2); LogValue=InvertWithLog(psiM.data(),NumPtcls,NumOrbitals,WorkSpace.data(),Pivot.data(),PhaseValue); int sign; ValueType new_det=invert_matrix_log(psiM2,sign,true); invert_matrix_log(psiM2,sign,true); ValueType old_det=invert_matrix_log(temp_psiM2,sign,true); ValueType test_det=invert_matrix_log(psiM_actual,sign,true); invert_matrix_log(psiM_actual,sign,true); // cerr<<"init stuff "<<" "<<new_det<<" "<<old_det<<" "<<test_det<<endl; const ValueType* restrict yptr=psiM.data(); const ValueType* restrict d2yptr=d2psiM.data(); const GradType* restrict dyptr=dpsiM.data(); for(int i=0, iat=FirstIndex; i<NumPtcls; i++, iat++) { GradType rv; ValueType lap=0.0; for(int j=0; j<NumOrbitals; j++,yptr++) { rv += *yptr * *dyptr++; lap += *yptr * *d2yptr++; } G(iat) += rv; L(iat) += lap - dot(rv,rv); } } return LogValue; }