100 int niterations =
DoGMRES(nGlobal, pInput, pOutput, nDir);
130 int nNonDir = nGlobal - nDir;
142 bool restarted =
false;
143 bool truncted =
false;
150 for (
int nrestart = 0; nrestart <
m_maxrestart; ++nrestart)
153 DoGmresRestart(restarted, truncted, nGlobal, pInput, pOutput, nDir);
166 Vmath::Svtvp(nNonDir, -1.0, &r0[0] + nDir, 1, &pInput[0] + nDir, 1,
177 cout << std::scientific << std::setw(nwidthcolm)
178 << std::setprecision(nwidthcolm - 8)
184 cout <<
" WITH (GMRES eps = " << eps <<
" REAL eps= " << eps1
189 cout <<
" CONVERGED" << endl;
193 cout <<
" WARNING: Exceeded maxIt" << endl;
206 const bool restarted,
const bool truncted,
const int nGlobal,
210 int nNonDir = nGlobal - nDir;
258 Vmath::Vcopy(nNonDir, &pInput[0] + nDir, 1, &r0[0] + nDir, 1);
291 vExchange =
Vmath::Dot2(nNonDir, &pInput[0] + nDir,
292 &pInput[0] + nDir, &
m_map[0] + nDir);
312 if (truncted && (starttem) > 0)
314 id_start[nd] = starttem;
323 alpha = 1.0 / eta[0];
348 hsingle1 =
m_hes[nd];
353 tmp = Vsingle1 + nDir);
362 starttem = id_start[idtem];
363 endtem = id_end[idtem];
365 DoArnoldi(starttem, endtem, nGlobal, nDir,
w, Vsingle1, Vsingle2,
370 starttem = starttem - 1;
378 eps = eta[nd + 1] * eta[nd + 1];
403 for (
int i = 0; i < nswp; ++i)
406 solution.get(), 1, solution.get(), 1);
415 Vmath::Vadd(nNonDir, solution.get(), 1, &pOutput[0] + nDir, 1,
416 &pOutput[0] + nDir, 1);
423 const int nGlobal,
const int nDir,
434 int nNonDir = nGlobal - nDir;
449 for (
int i = starttem; i < endtem; ++i)
455 hsingle[i] = vExchange;
457 beta = -1.0 * vExchange;
468 hsingle[endtem] =
sqrt(vExchange);
470 alpha = 1.0 / hsingle[endtem];
471 Vmath::Smul(nNonDir, alpha, &
w[0] + nDir, 1, &Vsingle2[0] + nDir, 1);
476 [[maybe_unused]]
const int nGlobal,
477 [[maybe_unused]]
const int nDir,
486 int idtem = endtem - 1;
492 for (
int i = starttem; i < idtem; ++i)
494 temp_dbl = c[i] * hsingle[i] - s[i] * hsingle[i + 1];
495 hsingle[i + 1] = s[i] * hsingle[i] + c[i] * hsingle[i + 1];
496 hsingle[i] = temp_dbl;
499 hh = hsingle[endtem];
505 else if (
abs(hh) >
abs(dd))
508 s[idtem] = 1.0 /
sqrt(1.0 + temp_dbl * temp_dbl);
509 c[idtem] = temp_dbl * s[idtem];
514 c[idtem] = 1.0 /
sqrt(1.0 + temp_dbl * temp_dbl);
515 s[idtem] = temp_dbl * c[idtem];
518 hsingle[idtem] = c[idtem] * hsingle[idtem] - s[idtem] * hsingle[endtem];
519 hsingle[endtem] = 0.0;
521 temp_dbl = c[idtem] * eta[idtem] - s[idtem] * eta[endtem];
522 eta[endtem] = s[idtem] * eta[idtem] + c[idtem] * eta[endtem];
523 eta[idtem] = temp_dbl;
536 int maxid = number - 1;
538 y[maxid] = b[maxid] /
A[maxid][maxid];
539 for (
int i = maxid - 1; i > -1; --i)
542 for (
int j = i + 1; j < number; ++j)
545 sum -= y[j] *
A[j][i];
547 y[i] = sum /
A[i][i];
#define WARNINGL1(condition, msg)
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
NekLinSysIterGMRES(const LibUtilities::SessionReaderSharedPtr &pSession, const LibUtilities::CommSharedPtr &vRowComm, const int nDimen, const NekSysKey &pKey=NekSysKey())
int DoGMRES(const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const int pNumDir)
Actual iterative solve-GMRES.
void DoBackward(const int number, Array< OneD, Array< OneD, NekDouble > > &A, const Array< OneD, const NekDouble > &b, Array< OneD, NekDouble > &y)
Array< OneD, Array< OneD, NekDouble > > m_V_total
Array< OneD, Array< OneD, NekDouble > > m_Upper
int v_SolveSystem(const int nGlobal, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const int nDir, const NekDouble tol, const NekDouble factor) override
static std::string className
int m_KrylovMaxHessMatBand
Array< OneD, Array< OneD, NekDouble > > m_hes
void DoGivensRotation(const int starttem, const int endtem, const int nGlobal, const int nDir, Array< OneD, NekDouble > &c, Array< OneD, NekDouble > &s, Array< OneD, NekDouble > &hsingle, Array< OneD, NekDouble > &eta)
void v_InitObject() override
bool m_NekLinSysRightPrecon
NekDouble DoGmresRestart(const bool restarted, const bool truncted, const int nGlobal, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const int nDir)
Actual iterative gmres solver for one restart.
bool m_NekLinSysLeftPrecon
void DoArnoldi(const int starttem, const int endtem, const int nGlobal, const int nDir, Array< OneD, NekDouble > &w, Array< OneD, NekDouble > &Vsingle1, Array< OneD, NekDouble > &Vsingle2, Array< OneD, NekDouble > &hsingle)
static NekLinSysIterSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const LibUtilities::CommSharedPtr &vRowComm, const int nDimen, const NekSysKey &pKey)
void v_InitObject() override
NekDouble m_rhs_magnitude
Dot product of rhs to normalise stopping criterion.
void Set_Rhs_Magnitude(const NekVector< NekDouble > &pIn)
Array< OneD, int > m_map
Global to universal unique map.
bool m_root
Root if parallel.
LibUtilities::CommSharedPtr m_rowComm
Communicate.
NekDouble m_tolerance
Tolerance of iterative solver.
NekSysOperators m_operator
Operators.
bool m_converged
Whether the iteration has been converged.
int m_maxiter
Maximum iterations.
bool m_NekLinSysLeftPrecon
bool m_NekLinSysRightPrecon
int m_KrylovMaxHessMatBand
void DoNekSysPrecon(InArrayType &inarray, OutArrayType &outarray, const bool &flag=false) const
void DoNekSysLhsEval(InArrayType &inarray, OutArrayType &outarray, const bool &flag=false) const
void AccumulateRegion(std::string, int iolevel=0)
Accumulate elapsed time for a region.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
NekLinSysIterFactory & GetNekLinSysIterFactory()
@ beta
Gauss Radau pinned at x=-1,.
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
static const NekDouble kNekUnsetDouble
std::vector< double > w(NPUPPER)
void Svtvp(int n, const T alpha, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Svtvp (scalar times vector plus vector): z = alpha*x + y.
T Dot2(int n, const T *w, const T *x, const int *y)
dot product
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
void Zero(int n, T *x, const int incx)
Zero vector.
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
scalarT< T > abs(scalarT< T > in)
scalarT< T > sqrt(scalarT< T > in)