*** empty log message ***
This commit is contained in:
parent
5c1505ba19
commit
bd843de786
29
davidson.h
29
davidson.h
@ -36,7 +36,8 @@ namespace LA {
|
|||||||
template <typename T, typename Matrix>
|
template <typename T, typename Matrix>
|
||||||
extern void davidson(const Matrix &bigmat, NRVec<T> &eivals, NRVec<T> *eivecs, const char *eivecsfile,
|
extern void davidson(const Matrix &bigmat, NRVec<T> &eivals, NRVec<T> *eivecs, const char *eivecsfile,
|
||||||
int nroots=1, const bool verbose=0, const double eps=1e-6,
|
int nroots=1, const bool verbose=0, const double eps=1e-6,
|
||||||
const bool incore=1, int maxit=100, const int maxkrylov = 500);
|
const bool incore=1, int maxit=100, const int maxkrylov = 500,
|
||||||
|
void (*initguess)(NRVec<T> &)=NULL);
|
||||||
|
|
||||||
//@@@options: left eigenvectors by matrix transpose, overridesymmetric (for nrmat)
|
//@@@options: left eigenvectors by matrix transpose, overridesymmetric (for nrmat)
|
||||||
//@@@small matrix gdiagonalize - shift complex roots up (option to gdiagonalize?)
|
//@@@small matrix gdiagonalize - shift complex roots up (option to gdiagonalize?)
|
||||||
@ -50,7 +51,8 @@ extern void davidson(const Matrix &bigmat, NRVec<T> &eivals, NRVec<T> *eivecs, c
|
|||||||
template <typename T, typename Matrix>
|
template <typename T, typename Matrix>
|
||||||
void davidson(const Matrix &bigmat, NRVec<T> &eivals, NRVec<T> *eivecs, const char *eivecsfile,
|
void davidson(const Matrix &bigmat, NRVec<T> &eivals, NRVec<T> *eivecs, const char *eivecsfile,
|
||||||
int nroots, const bool verbose, const double eps,
|
int nroots, const bool verbose, const double eps,
|
||||||
const bool incore, int maxit, const int maxkrylov)
|
const bool incore, int maxit, const int maxkrylov,
|
||||||
|
void (*initguess)(NRVec<T> &))
|
||||||
{
|
{
|
||||||
bool flag=0;
|
bool flag=0;
|
||||||
int n=bigmat.nrows();
|
int n=bigmat.nrows();
|
||||||
@ -82,12 +84,18 @@ int nroot=0;
|
|||||||
int oldnroot;
|
int oldnroot;
|
||||||
smallS=0;
|
smallS=0;
|
||||||
smallH=0;
|
smallH=0;
|
||||||
//guess based on lowest diagonal element of the matrix
|
|
||||||
const T *diagonal = bigmat.diagonalof(vec2,false,true);
|
|
||||||
vec1=0;
|
//default guess based on lowest diagonal element of the matrix
|
||||||
{T t=1e100; int i,j;
|
if(initguess) (*initguess)(vec1);
|
||||||
for(i=0, j= -1; i<n; ++i) if(diagonal[i]<t) {t=diagonal[i]; j=i;}
|
else
|
||||||
vec1[j]=1;}
|
{
|
||||||
|
const T *diagonal = bigmat.diagonalof(vec2,false,true);
|
||||||
|
T t=1e100; int i,j;
|
||||||
|
vec1=0;
|
||||||
|
for(i=0, j= -1; i<n; ++i) if(diagonal[i]<t) {t=diagonal[i]; j=i;}
|
||||||
|
vec1[j]=1;
|
||||||
|
}
|
||||||
|
|
||||||
//init Krylov matrices
|
//init Krylov matrices
|
||||||
bigmat.gemv(0,vec2,'n',1,vec1); //avoid bigmat.operator*(vec), since that needs to allocate another n-sized vector
|
bigmat.gemv(0,vec2,'n',1,vec1); //avoid bigmat.operator*(vec), since that needs to allocate another n-sized vector
|
||||||
@ -192,7 +200,9 @@ for(j=0; j<=krylovsize; ++j)
|
|||||||
if(!incore) s1->get(vec2,j);
|
if(!incore) s1->get(vec2,j);
|
||||||
vec1.axpy(smallV(j,nroot),incore?v1[j]:vec2);
|
vec1.axpy(smallV(j,nroot),incore?v1[j]:vec2);
|
||||||
}
|
}
|
||||||
diagonal = bigmat.diagonalof(vec2,false,true);
|
|
||||||
|
{
|
||||||
|
const T *diagonal = bigmat.diagonalof(vec2,false,true);
|
||||||
eival_n = r[nroot];
|
eival_n = r[nroot];
|
||||||
for(i=0; i<n; ++i)
|
for(i=0; i<n; ++i)
|
||||||
{
|
{
|
||||||
@ -200,6 +210,7 @@ for(i=0; i<n; ++i)
|
|||||||
denom = denom<0?-std::max(0.1,std::abs(denom)):std::max(0.1,std::abs(denom));
|
denom = denom<0?-std::max(0.1,std::abs(denom)):std::max(0.1,std::abs(denom));
|
||||||
vec1[i] /= denom;
|
vec1[i] /= denom;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//orthogonalise to previous vectors
|
//orthogonalise to previous vectors
|
||||||
vec1.normalize();
|
vec1.normalize();
|
||||||
|
Loading…
Reference in New Issue
Block a user