98 int niterations =
DoGMRES(nGlobal, pInput, pOutput, nDir);
127 int nNonDir = nGlobal - nDir;
139 bool restarted =
false;
140 bool truncted =
false;
147 for (
int nrestart = 0; nrestart <
m_maxrestart; ++nrestart)
150 DoGmresRestart(restarted, truncted, nGlobal, pInput, pOutput, nDir);
163 Vmath::Vsub(nNonDir, &pInput[0] + nDir, 1, &r0[0] + nDir, 1,
174 cout << std::scientific << std::setw(nwidthcolm)
175 << std::setprecision(nwidthcolm - 8)
181 cout <<
" WITH (GMRES eps = " << eps <<
" REAL eps= " << eps1
186 cout <<
" CONVERGED" << endl;
190 cout <<
" WARNING: Exceeded maxIt" << endl;
203 const bool restarted,
const bool truncted,
const int nGlobal,
207 int nNonDir = nGlobal - nDir;
255 Vmath::Vcopy(nNonDir, &pInput[0] + nDir, 1, &r0[0] + nDir, 1);
288 vExchange =
Vmath::Dot2(nNonDir, &pInput[0] + nDir,
289 &pInput[0] + nDir, &
m_map[0] + nDir);
309 if (truncted && (starttem) > 0)
311 id_start[nd] = starttem;
320 alpha = 1.0 / eta[0];
345 hsingle1 =
m_hes[nd];
350 tmp = Vsingle1 + nDir);
359 starttem = id_start[idtem];
360 endtem = id_end[idtem];
362 DoArnoldi(starttem, endtem, nGlobal, nDir,
w, Vsingle1, Vsingle2,
367 starttem = starttem - 1;
375 eps = eta[nd + 1] * eta[nd + 1];
402 for (
int i = 0; i < nswp; ++i)
405 solution.get(), 1, solution.get(), 1);
414 Vmath::Vadd(nNonDir, solution.get(), 1, &pOutput[0] + nDir, 1,
415 &pOutput[0] + nDir, 1);
422 const int nGlobal,
const int nDir,
433 int nNonDir = nGlobal - nDir;
448 for (
int i = starttem; i < endtem; ++i)
454 hsingle[i] = vExchange;
456 beta = -1.0 * vExchange;
467 hsingle[endtem] =
sqrt(vExchange);
469 alpha = 1.0 / hsingle[endtem];
470 Vmath::Smul(nNonDir, alpha, &
w[0] + nDir, 1, &Vsingle2[0] + nDir, 1);
475 [[maybe_unused]]
const int nGlobal,
476 [[maybe_unused]]
const int nDir,
485 int idtem = endtem - 1;
491 for (
int i = starttem; i < idtem; ++i)
493 temp_dbl = c[i] * hsingle[i] - s[i] * hsingle[i + 1];
494 hsingle[i + 1] = s[i] * hsingle[i] + c[i] * hsingle[i + 1];
495 hsingle[i] = temp_dbl;
498 hh = hsingle[endtem];
504 else if (
abs(hh) >
abs(dd))
507 s[idtem] = 1.0 /
sqrt(1.0 + temp_dbl * temp_dbl);
508 c[idtem] = temp_dbl * s[idtem];
513 c[idtem] = 1.0 /
sqrt(1.0 + temp_dbl * temp_dbl);
514 s[idtem] = temp_dbl * c[idtem];
517 hsingle[idtem] = c[idtem] * hsingle[idtem] - s[idtem] * hsingle[endtem];
518 hsingle[endtem] = 0.0;
520 temp_dbl = c[idtem] * eta[idtem] - s[idtem] * eta[endtem];
521 eta[endtem] = s[idtem] * eta[idtem] + c[idtem] * eta[endtem];
522 eta[idtem] = temp_dbl;
535 int maxid = number - 1;
537 y[maxid] = b[maxid] /
A[maxid][maxid];
538 for (
int i = maxid - 1; i > -1; --i)
541 for (
int j = i + 1; j < number; ++j)
544 sum -= y[j] *
A[j][i];
546 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.
int v_SolveSystem(const int nGlobal, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const int nDir) override
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
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
bool m_GMRESCentralDifference
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
int m_NekLinSysMaxIterations
void Set_Rhs_Magnitude(const Array< OneD, NekDouble > &pIn)
NekDouble m_NekLinSysTolerance
Array< OneD, int > m_map
Global to universal unique map.
LibUtilities::CommSharedPtr m_rowComm
NekSysOperators m_operator
NekDouble m_rhs_magnitude
bool m_NekLinSysLeftPrecon
bool m_GMRESCentralDifference
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)
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.
scalarT< T > abs(scalarT< T > in)
scalarT< T > sqrt(scalarT< T > in)