67 "right hand side and solution vectors " << std::endl
68 <<
"have incompatible sizes. RHS has global size " << rhsSize <<
"\n"
69 <<
"while solution has size " << xSize
74 x->getLocalRange(&xLo, &xHi);
76 "right hand side and solution vectors" << std::endl
77 <<
"have incompatible rangees. RHS has local range (" << rhsLo <<
"," << rhsHi <<
")\n"
78 <<
"while solution has range (" << xLo <<
"," << xHi <<
")"
91 KSPGetIterationNumber(
m_solver, &nbIterations);
97 KSPConvergedReason reason;
98 KSPGetConvergedReason (
m_solver, &reason);
103 static constexpr
const char* description[] = {
106 "KSP_DIVERGED_NULL: breakdown when solving the Hessenberg system within GMRES",
107 "KSP_DIVERGED_ITS: requested number of iterations",
108 "KSP_DIVERGED_DTOL: large increase in the residual norm",
109 "KSP_DIVERGED_BREAKDOWN: breakdown in the Krylov method",
110 "KSP_DIVERGED_BREAKDOWN_BICG: breakdown in the KSPBGCS Krylov method",
111 "KSP_DIVERGED_NONSYMMETRIC: the operator or preconditioner was not symmetric for a KSPType that requires symmetry",
112 "KSP_DIVERGED_INDEFINITE_PC: the preconditioner was indefinite for a KSPType that requires it be definite",
113 "KSP_DIVERGED_NANORINF: a not a number of infinity was detected in a vector during the computation",
114 "KSP_DIVERGED_INDEFINITE_MAT: the operator was indefinite for a KSPType that requires it be definite",
115 "KSP_DIVERGED_PC_FAILED: the action of the preconditioner failed for some reason"};
117 "KSP diverged: " << description[-reason]
152 if (S ==
"CG" or S ==
"CONJUGATE GRADIENT")
156 PCSetType (pc, PCBJACOBI);
159 else if (S ==
"BICGSTAB")
163 PCSetType (pc, PCBJACOBI);
166 else if (S ==
"GMRES")
170 PCSetType (pc, PCBJACOBI);
178 PCSetType (pc, PCLU);
184 "unsupported solver type. Will use default value GMRES.\n" <<
185 " Valid types are CG, BICGSTAB, GMRES, and LU (LU for sequential runs only)"
212 KSPSetTolerances (
m_solver, rTol, aTol, dTol, iter);
223 KSPGetTolerances (
m_solver, &rtol, &abstol, &dtol,
nullptr);
224 KSPSetTolerances (
m_solver, rtol, abstol, dtol, maxIterations);
233 KSPGetTolerances (
m_solver,
nullptr, &absTol, &dTol, &iter);
234 KSPSetTolerances (
m_solver, rTol, absTol, dTol, iter);
243 KSPGetTolerances(
m_solver, &relTol,
nullptr, &dtol, &iter);
244 KSPSetTolerances(
m_solver, relTol, aTol, dtol, iter);
253 KSPGetTolerances (
m_solver, &relTol, &absTol,
nullptr, &iter);
254 KSPSetTolerances (
m_solver, relTol, absTol, dTol, iter);
266 KSPCreate(PETSC_COMM_WORLD, &
m_solver);
278 KSPGetTolerances(
m_solver, &rTol, &aTol, &dTol, &iter);
#define CEPS_ABORT_IF(condition, message)
Stops the execution with a message if condition is true. If testing is enabled, only throws a runtime...
#define CEPS_WARNS(message)
Writes a warning in the debug log and in the terminal (stderr).
std::basic_string< CepsChar > CepsString
C++ format string.
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
float CepsReal
Need single precision floating point.
int32_t CepsInt
Need 32 bit integer.
CepsInt CepsIndex
Index rowid etc.
std::shared_ptr< DistributedMatrix > DMatPtr
Short typedef for pointer on dist matrix.
std::shared_ptr< DistributedVector > DVecPtr
Short typedef for pointer on distributed vector.
Profiler * getProfiler() const
Access to profiler.
CepsReal m_relativeTolerance
Stopping criterion for iterative methods (rel diff between iterations)
void setLhsMatrix(DMatPtr lhs)
Set the left-hand side matrix of the system.
void setTolerances(CepsReal rTol, CepsReal aTol, CepsReal dTol, CepsUInt iter)
Sets all stopping criteria of iterative methods at once.
~LinearSystem() override
Destructor.
CepsUInt m_avIterNb
average number of iterations
void setMaxNbIterations(CepsUInt nbIterations)
Stopping criterion for iterative solvers.
LinearSystem()
Default constructor.
void setupWithParameters(InputParameters *params)
Sets the options from text parameters.
void setDivergenceTolerance(CepsReal dTol)
Stopping criterion for iterative solvers: increase in norm of residuals.
DVecPtr m_rhsVector
Right Hand Side (B)
DMatPtr m_lhsMatrix
Left Hand Side (A)
void setAbsoluteTolerance(CepsReal aTol)
Stopping criterion for iterative solvers: absolute norm of residuals.
void setPreconditioningMatrix(DMatPtr preconditioningMatrix)
Sets the preconditioning matrix. If nullptr (default) LHS is used as preconditionner.
CepsUInt m_nSolv
number of calls of the solvers
DMatPtr m_precondMatrix
Preconditioning matrix.
CepsReal m_divergenceTolerance
Stopping criterion for iterative methods (too large diff between iterations)
CepsBool m_isSetUp
Is the solver ready to solve ?
void initialize()
Sets the defaults values.
virtual void solve(DVecPtr solution)
Solve current linear system. Calls the solver's method.
CepsUInt m_maxIterations
Maximum of iterations for iterative methods.
void setUp()
Calls methods of Linear Algebra library in order to prepare the solver.
CepsUInt getMaxNbIterations() const
Stopping criterion for iterative solvers.
void setRelativeTolerance(CepsReal rTol)
Stopping criterion for iterative solvers: relative norm of residuals.
CepsReal m_absoluteTolerance
Stopping criterion for iterative methods (abs diff between iterations)
void setRhsVector(DVecPtr rhs)
Set the right hand side.
CepsSolver m_solver
Underlying solver.
void setType(const CepsString &type)
Set solver type which can be CG, GMRES or LU. (LU for sequential runs only)
void stop(CepsString lbl)
Stops the measure of a labeled chronometer.
void start(CepsString lbl, CepsString dspl="")
Creates or continue a labeled chronometer.
CepsBool isValidPtr(_Type *ptr)
Tells if pointer is not null.
CepsBool isParallel()
Is there more than 1 process currently working ?
CepsString toUpper(const CepsString &s)
Switches all characters to upper case.
std::ofstream & profilingLog()
Get the ProfilingLog used in Ceps.
CepsBool isProfiling()
Check if we are currently profiling on the master proc (always false on slave procs).