diff --git a/diis.h b/diis.h index e2fb3c5..80832c7 100644 --- a/diis.h +++ b/diis.h @@ -35,17 +35,17 @@ public: DIIS(const int n, const bool core=1); void setup(const int n, const bool core=1); ~DIIS(); - typename LA_traits::normtype extrapolate(T &vec, const U &errvec); //vec is input/output; returns square residual norm + typename LA_traits::normtype extrapolate(T &vec, const U &errvec, bool verbose=false); //vec is input/output; returns square residual norm }; template -DIIS::DIIS(const int n, const bool core) : dim(n), incore(core), bmat(n,n) +DIIS::DIIS(const int n, const bool core) : dim(n), incore(core), bmat(n+1,n+1) { st=incore?NULL: new AuxStorage; errst=incore?NULL: new AuxStorage; stor= incore? new T[dim] : NULL; errstor= incore? new U[dim] : NULL; -bmat= (Ue)0; for(int i=1; i::setup(const int n, const bool core) { dim=n; incore=core; -bmat.resize(n); +bmat.resize(n+1); st=incore?NULL: new AuxStorage; errst=incore?NULL: new AuxStorage; stor= incore? new T[dim] : NULL; errstor= incore? new U[dim] : NULL; -bmat= (Ue)0; for(int i=1; i -typename LA_traits::normtype DIIS::extrapolate(T &vec, const U &errvec) +typename LA_traits::normtype DIIS::extrapolate(T &vec, const U &errvec, bool verbose) { if(!dim) laerror("attempt to extrapolate from uninitialized DIIS"); //if dim exceeded, shift if(aktdim==dim) { cyclicshift=(cyclicshift+1)%dim; - for(int i=1; i::normtype)1000000000; //calculate overlaps of the new error with old ones typename LA_traits::normtype norm=errvec.norm(); -bmat(aktdim-1,aktdim-1)= norm*norm + DIISEPS; +bmat(aktdim,aktdim)= norm*norm + DIISEPS; if(incore) - for(int i=1; iget(tmp,(i+cyclicshift)%dim); - bmat(i,aktdim-1)= errvec.dot(tmp); + errst->get(tmp,(i-1+cyclicshift)%dim); + bmat(i,aktdim)= errvec.dot(tmp); } } //prepare rhs-solution vector -NRVec rhs(dim); +NRVec rhs(dim+1); rhs= (Ue)0; rhs[0]= (Ue)-1; //solve for coefficients @@ -131,19 +131,21 @@ rhs= (Ue)0; rhs[0]= (Ue)-1; //@@@ explicit solution - cf. remarks in Pulay memorial book { NRSMat amat=bmat; -linear_solve(amat,rhs,NULL,aktdim); +linear_solve(amat,rhs,NULL,aktdim+1); } +if(verbose) cout <<"DIIS coefficients: "<get(tmp,(i+cyclicshift)%dim); + st->get(tmp,(i-1+cyclicshift)%dim); vec.axpy(rhs[i],tmp); } }