From 88611659a30d5532c0ad488589f02a4b19a9480c Mon Sep 17 00:00:00 2001 From: Chulwoo Jung Date: Mon, 8 Dec 2025 21:08:14 -0500 Subject: [PATCH] Appear to be working --- Grid/algorithms/iterative/KrylovSchur.h | 165 ++++++++++++++++++++++-- examples/Example_krylov_schur.cc | 2 +- 2 files changed, 155 insertions(+), 12 deletions(-) diff --git a/Grid/algorithms/iterative/KrylovSchur.h b/Grid/algorithms/iterative/KrylovSchur.h index ee3f78a2..456f2f94 100644 --- a/Grid/algorithms/iterative/KrylovSchur.h +++ b/Grid/algorithms/iterative/KrylovSchur.h @@ -289,10 +289,11 @@ class KrylovSchur { RitzFilter ritzFilter; // how to sort evals public: + RealD *shift; KrylovSchur(LinearOperatorBase &_Linop, GridBase *_Grid, RealD _Tolerance, RitzFilter filter = EvalReSmall) : Linop(_Linop), Grid(_Grid), Tolerance(_Tolerance), ritzFilter(filter), u(_Grid), MaxIter(-1), Nm(-1), Nk(-1), Nstop (-1), - evals (0), ritzEstimates (), evecs (), ssq (0.0), rtol (0.0), beta_k (0.0), approxLambdaMax (0.0) + evals (0), ritzEstimates (), evecs (), ssq (0.0), rtol (0.0), beta_k (0.0), approxLambdaMax (0.0),shift(NULL) { u = Zero(); }; @@ -315,7 +316,12 @@ class KrylovSchur { * - Permutes the Rayleigh quotient according to the eigenvalues. * - Truncate the Krylov-Schur expansion. */ - void operator()(const Field& v0, int _maxIter, int _Nm, int _Nk, int _Nstop, bool doubleOrthog = true) { + void operator()(const Field& v0, int _maxIter, int _Nm, int _Nk, int _Nstop, RealD *_shift=NULL, bool doubleOrthog = true) { + +// RealD shift_=1.; +// shift = &shift_; + if(_shift) shift = _shift; + MaxIter = _maxIter; Nm = _Nm; Nk = _Nk; Nstop = _Nstop; @@ -342,11 +348,129 @@ class KrylovSchur { arnoldiIteration(startVec, Nm, start, doubleOrthog); startVec = u; // original code start = Nk; + + std::cout << GridLogMessage << "b after Arnoldi " << b << std::endl; // checkKSDecomposition(); + RealD gamma; + Field uhat(Grid); + Eigen::MatrixXcd Btilde; + std::vector basis2_s; + Eigen::VectorXcd b_s; +#if 1 +if (shift){ + +if(1){ + Field w(Grid); + + ComplexD coeff,coeff2; + for (int j = 0; j < Nm; j++) { + Linop.Op(basis[j], w); + for (int k = 0; k < Nm; k++) { + coeff2 = innerProduct(basis[k], basis[j]); + coeff = innerProduct(basis[k], w); // coeff = h_{ij}. Note that since {vi} is ONB it's OK to subtract it off after. + std::cout << GridLogMessage << " Rayleigh "< = " << coeff2 << std::endl; + } + coeff = innerProduct(basis[j], u); // coeff = h_{ij}. Note that since {vi} is ONB it's OK to subtract it off after. + std::cout << GridLogMessage << " u "< basisTmp_s = std::vector (basis2_s.begin(), basis2_s.begin() + Nk); + basis2_s = basisTmp_s; + + Eigen::VectorXcd btmp_s = b_s.head(Nk); + b_s = btmp_s; + + Eigen::VectorXcd ghat = g; + ghat = -Q_s * g; + + Eigen::VectorXcd gtmp_s = ghat.head(Nk); + ghat = gtmp_s; + + uhat = utilde; + for (int j = 0; j = " << coeff2 << std::endl; + } + coeff = innerProduct(basis2_s[j], uhat); // coeff = h_{ij}. Note that since {vi} is ONB it's OK to subtract it off after. + coeff2 = innerProduct(uhat,w); + std::cout << GridLogMessage << " uhat "< evecs2; - // constructUR(evecs2, evecs, Qt, Nm); - // constructRU(evecs2, evecs, Q, Nm); - // evecs = evecs2; - // littleEvecs = littleEvecs * Q.adjoint(); // TODO try this and see if it works - // littleEvecs = Q * littleEvecs; // TODO try this and see if it works - // std::cout << GridLogDebug << "Ritz vectors rotated correctly? " << checkEvecRotation() << std::endl; + ComplexD coeff,coeff2; + for (int j = 0; j < Nm; j++) { + Linop.Op(basis[j], w); + for (int k = 0; k < Nm; k++) { + coeff2 = innerProduct(basis[k], basis[j]); + coeff = innerProduct(basis[k], w); // coeff = h_{ij}. Note that since {vi} is ONB it's OK to subtract it off after. + std::cout << GridLogMessage << " Stilde "< = " << coeff2 << std::endl; + } + coeff = innerProduct(basis[j], u); // coeff = h_{ij}. Note that since {vi} is ONB it's OK to subtract it off after. + std::cout << GridLogMessage << " u"<