41 namespace MultiRegions
43 std::string GlobalLinSysIterative::IteratSolverlookupIds[2] = {
44 LibUtilities::SessionReader::RegisterEnumValue(
45 "LinSysIterSolver",
"ConjugateGradient",
47 LibUtilities::SessionReader::RegisterEnumValue(
"LinSysIterSolver",
"GMRES",
51 std::string GlobalLinSysIterative::IteratSolverdef =
52 LibUtilities::SessionReader::RegisterDefaultSolverInfo(
"LinSysIterSolver",
62 GlobalLinSysIterative::GlobalLinSysIterative(
64 const std::shared_ptr<AssemblyMap> &pLocToGloMap)
68 m_useProjection(false), m_numPrevSols(0)
70 m_tolerance = pLocToGloMap->GetIterativeTolerance();
71 m_maxiter = pLocToGloMap->GetMaxIterations();
75 m_expList.lock()->GetComm()->GetRowComm();
76 m_root = (vComm->GetRank()) ?
false :
true;
85 WARNINGL0(
false,
"To use A-conjugate projection, the matrix should be "
86 "symmetric positive definite.");
105 m_expList.lock()->GetComm()->GetRowComm();
113 "' is not defined.\n");
154 const bool isAconjugate)
156 int numIterations = 0;
161 m_linsol->SolveSystem(nGlobal, pInput, pOutput, nDir, tol);
167 m_expList.lock()->GetComm()->GetRowComm();
170 int nNonDir = nGlobal - nDir;
185 cout <<
"No iterations made"
186 <<
" using tolerance of " << tol
222 alpha.get(), n, info);
227 alpha[0] = alphaback[latest];
236 Vmath::Vcopy(nNonDir, pInput.get() + nDir, 1, pb_s.get() + nDir, 1);
246 <<
"-bases projection reduces L2-norm of RHS from "
256 numIterations =
m_linsol->SolveSystem(nGlobal, pb_s, tmpx_s, nDir, tol);
291 const bool isAconjugate)
294 int nNonDir = nGlobal - nDir;
300 m_expList.lock()->GetComm()->GetRowComm();
312 newBasis = newX + nDir;
316 newBasis = tmpAx_s + nDir;
331 tmp = tmpAx_s + nDir, 1);
335 if (i == insertLocation)
337 int skip = i > insertLocation;
351 if (i == insertLocation)
353 int iskip = i > insertLocation;
356 if (j == insertLocation)
358 int jskip = j > insertLocation;
359 tilCoeffMatrix->SetValue(i - iskip, j - jskip,
369 1, tilCoeffMatrix->GetPtr(), 1);
372 int n, info1 = 0, info2 = 0, info3 = 0;
375 n = tilCoeffMatrix->GetRows();
377 tilCoeffMatrix->GetStorageSize());
378 Vmath::Vcopy(tilCoeffMatrix->GetStorageSize(), tilCoeffMatrix->GetPtr(),
379 1, tilCoeffMatrixFactor, 1);
380 Lapack::Dsptrf(
'U', n, tilCoeffMatrixFactor.get(), ipivot.get(), info1);
384 Lapack::Dsptrs(
'U', n, 1, tilCoeffMatrixFactor.get(), ipivot.get(),
385 invMy_s.get(), n, info2);
391 y_s[0] = y_s[latest - (latest > insertLocation)];
398 for (
int i = 0; i <
m_prevBasis.size() - fullbuffer; i++)
400 residual -= y_s[i] * invMy_s[i];
403 cout <<
"SuccessiveRHS: residual " << residual;
404 if (residual < epsilon)
407 cout <<
" < " << epsilon <<
", reject" << endl;
418 1, newCoeffMatrix->GetPtr(), 1);
419 newCoeffMatrix->SetValue(insertLocation, insertLocation, 1.);
422 if (i == insertLocation)
424 int iskip = i > insertLocation;
425 newCoeffMatrix->SetValue(insertLocation, i, y_s[i - iskip]);
432 newCoeffMatrix->SetValue(insertLocation, insertLocation, 1.);
435 newCoeffMatrix->SetValue(insertLocation, i, y_s[i]);
438 newCoeffMatrix->SetValue(i, j,
m_coeffMatrix->GetValue(i, j));
442 n = newCoeffMatrix->GetRows();
444 Vmath::Vcopy(newCoeffMatrix->GetStorageSize(), newCoeffMatrix->GetPtr(), 1,
445 coeffMatrixFactor, 1);
446 Lapack::Dsptrf(
'U', n, coeffMatrixFactor.get(), ipivot.get(), info3);
450 cout <<
" >= " << epsilon <<
", reject (Dsptrf fails)" << endl;
454 cout <<
" >= " << epsilon <<
", accept" << endl;
485 if (
m_map.size() > 0)
491 m_expList.lock()->GetComm()->GetRowComm()->AllReduce(
498 NekDouble new_rhs_mag = (vExchange[0] > 1e-6) ? vExchange[0] : 1.0;
#define ASSERTL0(condition, msg)
#define WARNINGL0(condition, msg)
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
void DefineNekSysLhsEval(FuncPointerT func, ObjectPointerT obj)
void DefineNekSysPrecon(FuncPointerT func, ObjectPointerT obj)
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
const std::weak_ptr< ExpList > m_expList
Local Matrix System.
PreconditionerSharedPtr CreatePrecon(AssemblyMapSharedPtr asmMap)
Create a preconditioner object from the parameters defined in the supplied assembly map.
Array< OneD, int > m_ipivot
std::vector< Array< OneD, NekDouble > > m_prevBasis
LibUtilities::NekLinSysIterSharedPtr m_linsol
PreconditionerSharedPtr m_precon
void DoProjection(const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const int pNumDir, const NekDouble tol, const bool isAconjugate)
projection technique
void UpdateKnownSolutions(const int pGlobalBndDofs, const Array< OneD, const NekDouble > &pSolution, const int pNumDirBndDofs, const bool isAconjugate)
Array< OneD, NekDouble > m_coeffMatrixFactor
int ResetKnownSolutionsToLatestOne()
std::vector< Array< OneD, NekDouble > > m_prevLinSol
Storage for solutions to previous linear problems.
void DoMatrixMultiplyFlag(const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const bool &controlFlag)
virtual ~GlobalLinSysIterative()
bool m_useProjection
Whether to apply projection technique.
virtual void v_SolveLinearSystem(const int pNumRows, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const AssemblyMapSharedPtr &locToGloMap, const int pNumDir) override
Solve the matrix system.
NekDouble m_tolerance
Tolerance of iterative solver.
virtual void v_UniqueMap()=0
void DoPreconditionerFlag(const Array< OneD, NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const bool &controlFlag)
Array< OneD, int > m_map
Global to universal unique map.
NekDouble m_rhs_magnitude
dot product of rhs to normalise stopping criterion
DNekMatSharedPtr m_coeffMatrix
LibUtilities::NekSysOperators m_NekSysOp
std::string m_linSysIterSolver
Iterative solver: Conjugate Gradient, GMRES.
void Set_Rhs_Magnitude(const NekVector< NekDouble > &pIn)
int m_maxiter
maximum iterations
bool m_root
Root if parallel.
NekDouble m_rhs_mag_sm
cnt to how many times rhs_magnitude is called
Describe a linear system.
unsigned int GetDimension() const
Returns the number of dimensions for the point.
static void Dsptrs(const char &uplo, const int &n, const int &nrhs, const double *ap, const int *ipiv, double *b, const int &ldb, int &info)
Solve a real symmetric matrix problem using Bunch-Kaufman pivoting.
static void Dsptrf(const char &uplo, const int &n, double *ap, int *ipiv, int &info)
factor a real packed-symmetric matrix using Bunch-Kaufman pivoting.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
NekLinSysIterFactory & GetNekLinSysIterFactory()
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
static PreconditionerSharedPtr NullPreconditionerSharedPtr
std::shared_ptr< AssemblyMap > AssemblyMapSharedPtr
static const NekDouble kNekUnsetDouble
static const NekDouble kNekSparseNonZeroTol
static const NekDouble kNekZeroTol
The above copyright notice and this permission notice shall be included.
std::shared_ptr< DNekMat > DNekMatSharedPtr
T Dot2(int n, const T *w, const T *x, const int *y)
dot2 (vector times vector times vector): z = w*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)