43 namespace LibUtilities
50 string NekLinSysIterGMRES::className =
52 "GMRES", NekLinSysIterGMRES::create,
"NekLinSysIterGMRES solver.");
54 NekLinSysIterGMRES::NekLinSysIterGMRES(
60 std::vector<std::string> variables(1);
61 variables[0] = pSession->GetVariable(0);
62 string variable = variables[0];
66 pSession->MatchSolverInfo(
"GMRESRightPrecon",
"False",
70 if (pSession->DefinesGlobalSysSolnInfo(variable,
"GMRESMaxHessMatBand"))
73 pSession->GetGlobalSysSolnInfo(variable,
"GMRESMaxHessMatBand")
85 int GMRESCentralDifference = 0;
86 pSession->LoadParameter(
"GMRESCentralDifference", GMRESCentralDifference,
89 switch (GMRESCentralDifference)
124 boost::ignore_unused(tol);
128 int niterations =
DoGMRES(nGlobal, pInput, pOutput, nDir);
160 int nNonDir = nGlobal - nDir;
172 bool restarted =
false;
173 bool truncted =
false;
182 for (
int nrestart = 0; nrestart <
m_maxrestart; ++nrestart)
185 DoGmresRestart(restarted, truncted, nGlobal, pInput, pOutput, nDir);
198 Vmath::Svtvp(nNonDir, -1.0, &r0[0] + nDir, 1, &pInput[0] + nDir, 1,
207 cout << std::scientific << std::setw(nwidthcolm)
208 << std::setprecision(nwidthcolm - 8)
214 cout <<
" WITH (GMRES eps = " << eps <<
" REAL eps= " << eps1
219 cout <<
" CONVERGED" << endl;
223 cout <<
" WARNING: Exceeded maxIt" << endl;
236 const bool restarted,
const bool truncted,
const int nGlobal,
240 int nNonDir = nGlobal - nDir;
305 Vmath::Vcopy(nNonDir, &pInput[0] + nDir, 1, &r0[0] + nDir, 1);
329 vExchange =
Vmath::Dot2(nNonDir, &pInput[0] + nDir,
330 &pInput[0] + nDir, &
m_map[0] + nDir);
352 if (truncted && (starttem) > 0)
354 id_start[nd] = starttem;
363 alpha = 1.0 / eta[0];
365 Vmath::Smul(nNonDir, alpha, &r0[0] + nDir, 1, &V_total[0][0] + nDir, 1);
376 Vsingle2 = V_total[nd + 1];
381 tmp1 = V_total[nd] + nDir;
382 tmp2 = Vsingle1 + nDir;
387 Vsingle1 = V_total[nd];
391 starttem = id_start[idtem];
392 endtem = id_end[idtem];
394 DoArnoldi(starttem, endtem, nGlobal, nDir, V_total, Vsingle1, Vsingle2,
399 starttem = starttem - 1;
402 hsingle2 = Upper[nd];
407 eps = eta[nd + 1] * eta[nd + 1];
437 for (
int i = 0; i < nswp; ++i)
441 &solution[0] + nDir, 1, &solution[0] + nDir, 1);
446 tmp1 = solution + nDir;
447 tmp2 = solution + nDir;
450 Vmath::Vadd(nNonDir, &solution[0] + nDir, 1, &pOutput[0] + nDir, 1,
451 &pOutput[0] + nDir, 1);
458 const int nGlobal,
const int nDir,
473 int nNonDir = nGlobal - nDir;
497 numbertem = starttem;
498 for (
int i = starttem; i < endtem; ++i)
501 Vmath::Dot2(nNonDir, &w[0] + nDir, &V_local[numbertem][0] + nDir,
505 hsingle[i] = vExchange;
507 beta = -1.0 * vExchange;
509 &w[0] + nDir, 1, &w[0] + nDir, 1);
510 numbertem = numbertem + 1;
520 hsingle[endtem] =
sqrt(vExchange);
522 alpha = 1.0 / hsingle[endtem];
523 Vmath::Smul(nNonDir, alpha, &w[0] + nDir, 1, &Vsingle2[0] + nDir, 1);
528 const int nGlobal,
const int nDir,
534 boost::ignore_unused(nGlobal, nDir);
538 int idtem = endtem - 1;
544 for (
int i = starttem; i < idtem; ++i)
546 temp_dbl = c[i] * hsingle[i] - s[i] * hsingle[i + 1];
547 hsingle[i + 1] = s[i] * hsingle[i] + c[i] * hsingle[i + 1];
548 hsingle[i] = temp_dbl;
551 hh = hsingle[endtem];
557 else if (
abs(hh) >
abs(dd))
560 s[idtem] = 1.0 /
sqrt(1.0 + temp_dbl * temp_dbl);
561 c[idtem] = temp_dbl * s[idtem];
566 c[idtem] = 1.0 /
sqrt(1.0 + temp_dbl * temp_dbl);
567 s[idtem] = temp_dbl * c[idtem];
570 hsingle[idtem] = c[idtem] * hsingle[idtem] - s[idtem] * hsingle[endtem];
571 hsingle[endtem] = 0.0;
573 temp_dbl = c[idtem] * eta[idtem] - s[idtem] * eta[endtem];
574 eta[endtem] = s[idtem] * eta[idtem] + c[idtem] * eta[endtem];
575 eta[idtem] = temp_dbl;
588 int maxid = number - 1;
590 y[maxid] = b[maxid] /
A[maxid][maxid];
592 for (
int i = maxid - 1; i > -1; --i)
596 for (
int j = i + 1; j < number; ++j)
599 sum = sum - y[j] *
A[j][i];
601 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.
void DoArnoldi(const int starttem, const int endtem, const int nGlobal, const int nDir, Array< OneD, Array< OneD, NekDouble >> &V_local, Array< OneD, NekDouble > &Vsingle1, Array< OneD, NekDouble > &Vsingle2, Array< OneD, NekDouble > &hsingle)
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)
virtual 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
int m_KrylovMaxHessMatBand
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)
virtual 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
virtual 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.
NekDouble m_tolerance
Tolerance of iterative solver.
NekSysOperators m_operator
Operators.
LibUtilities::CommSharedPtr m_Comm
Communicate.
bool m_converged
Whether the iteration has been converged.
int m_maxiter
Maximum iterations.
bool m_NekLinSysLeftPrecon
bool m_NekLinSysRightPrecon
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
The above copyright notice and this permission notice shall be included.
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)
dot2 (vector times vector times vector): z = w*x*y
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)