*** empty log message ***

This commit is contained in:
jiri 2012-01-24 14:26:28 +00:00
parent 820d92b85f
commit 7fd5c953ff

16
diis.h
View File

@ -28,8 +28,7 @@
namespace LA { namespace LA {
//Pulay memorial book remarks - for numerical stabilization small addition to diagonal //Pulay memorial book remarks - for numerical stabilization small addition to diagonal (but our experience was opposite)
const double DIISEPS=1e-9;
// Typically, T is some solution vector in form of NRVec, NRMat, or NRSMat over double or complex<double> fields // Typically, T is some solution vector in form of NRVec, NRMat, or NRSMat over double or complex<double> fields
// actually it can be anything what has operator=(const T&), clear(), dot() , axpy(), norm() and copyonwrite(), and LA_traits<T>::normtype and elementtype // actually it can be anything what has operator=(const T&), clear(), dot() , axpy(), norm() and copyonwrite(), and LA_traits<T>::normtype and elementtype
@ -44,6 +43,7 @@ class DIIS
int cyclicshift; //circular buffer of last dim vectors int cyclicshift; //circular buffer of last dim vectors
typedef typename LA_traits<T>::elementtype Te; typedef typename LA_traits<T>::elementtype Te;
typedef typename LA_traits<U>::elementtype Ue; typedef typename LA_traits<U>::elementtype Ue;
typedef typename LA_traits<U>::normtype Un;
NRSMat<Ue> bmat; NRSMat<Ue> bmat;
AuxStorage<Te> *st; AuxStorage<Te> *st;
AuxStorage<Ue> *errst; AuxStorage<Ue> *errst;
@ -54,7 +54,7 @@ public:
DIIS(const int n, const bool core=1); DIIS(const int n, const bool core=1);
void setup(const int n, const bool core=1); void setup(const int n, const bool core=1);
~DIIS(); ~DIIS();
typename LA_traits<U>::normtype extrapolate(T &vec, const U &errvec, bool verbose=false); //vec is input/output; returns square residual norm typename LA_traits<U>::normtype extrapolate(T &vec, const U &errvec, bool verbose=false, const Un diiseps=0); //vec is input/output; returns square residual norm
}; };
template<typename T, typename U> template<typename T, typename U>
@ -93,9 +93,8 @@ if(errstor) delete[] errstor;
} }
template<typename T, typename U> template<typename T, typename U>
typename LA_traits<U>::normtype DIIS<T,U>::extrapolate(T &vec, const U &errvec, bool verbose) typename LA_traits<U>::normtype DIIS<T,U>::extrapolate(T &vec, const U &errvec, bool verbose, const Un diiseps)
{ {
if(!dim) laerror("attempt to extrapolate from uninitialized DIIS"); if(!dim) laerror("attempt to extrapolate from uninitialized DIIS");
//if dim exceeded, shift //if dim exceeded, shift
@ -123,10 +122,12 @@ else
if(aktdim==1) return (typename LA_traits<T>::normtype)1; if(aktdim==1) return (typename LA_traits<T>::normtype)1;
//calculate overlaps of the new error with old ones //calculate overlaps of the new error with old ones
typename LA_traits<T>::normtype norm=errvec.norm(); typename LA_traits<T>::normtype norm=errvec.norm();
bmat(aktdim,aktdim)= norm*norm + DIISEPS; bmat(aktdim,aktdim) = norm*norm;
// LV
bmat(aktdim,aktdim) += diiseps;
if(incore) if(incore)
for(int i=1; i<aktdim; ++i) for(int i=1; i<aktdim; ++i)
bmat(i,aktdim)=errvec.dot(errstor[(i+cyclicshift-1)%dim]); bmat(i,aktdim)=errvec.dot(errstor[(i+cyclicshift-1)%dim]);
@ -140,7 +141,6 @@ else
} }
} }
//prepare rhs-solution vector //prepare rhs-solution vector
NRVec<Ue> rhs(dim+1); NRVec<Ue> rhs(dim+1);
rhs= (Ue)0; rhs[0]= (Ue)-1; rhs= (Ue)0; rhs[0]= (Ue)-1;