OGS
MathLib::details::EigenIterativeLinearSolver< T_SOLVER > Class Template Referencefinal

Detailed Description

template<class T_SOLVER>
class MathLib::details::EigenIterativeLinearSolver< T_SOLVER >

Template class for Eigen iterative linear solvers.

Definition at line 265 of file EigenLinearSolver.cpp.

Inheritance diagram for MathLib::details::EigenIterativeLinearSolver< T_SOLVER >:
[legend]
Collaboration diagram for MathLib::details::EigenIterativeLinearSolver< T_SOLVER >:
[legend]

Public Member Functions

bool computeImpl (Matrix &A, EigenOption &opt, MathLib::LinearSolverBehaviour const linear_solver_behaviour) override
 
bool solveImpl (Vector const &b, Vector &x, EigenOption &opt) override
 
- Public Member Functions inherited from MathLib::EigenLinearSolverBase
virtual ~EigenLinearSolverBase ()=default
 
bool solve (Vector &b, Vector &x, EigenOption &opt)
 
bool compute (Matrix &A, EigenOption &opt, MathLib::LinearSolverBehaviour linear_solver_behaviour)
 

Private Attributes

T_SOLVER solver_
 
Matrix A_
 

Additional Inherited Members

- Public Types inherited from MathLib::EigenLinearSolverBase
using Vector = EigenVector::RawVectorType
 
using Matrix = EigenMatrix::RawMatrixType
 
- Protected Member Functions inherited from MathLib::EigenLinearSolverBase

Member Function Documentation

◆ computeImpl()

template<class T_SOLVER >
bool MathLib::details::EigenIterativeLinearSolver< T_SOLVER >::computeImpl ( Matrix & A,
EigenOption & opt,
MathLib::LinearSolverBehaviour const linear_solver_behaviour )
inlineoverridevirtual

Implements MathLib::EigenLinearSolverBase.

Definition at line 268 of file EigenLinearSolver.cpp.

271 {
272 INFO("-> compute with Eigen iterative linear solver {:s} (precon {:s})",
273 EigenOption::getSolverName(opt.solver_type),
274 EigenOption::getPreconName(opt.precon_type));
275 solver_.setTolerance(opt.error_tolerance);
276 solver_.setMaxIterations(opt.max_iterations);
277
278#ifdef USE_EIGEN_UNSUPPORTED
280 opt.restart);
284 opt.smoothing);
286 opt.angle);
288 T_SOLVER>::setResidualUpdate(opt.residualupdate);
289#endif
290
291 auto compute = [this](Matrix& m)
292 {
293 if (!m.isCompressed())
294 {
295 m.makeCompressed();
296 }
297
298 solver_.compute(m);
299 };
300
301 switch (linear_solver_behaviour)
302 {
304 {
305 // matrix must be copied, because Eigen's linear solver stores a
306 // reference to it cf.
307 // https://libeigen.gitlab.io/docs/classEigen_1_1IterativeSolverBase.html#a7dfa55c55e82d697bde227696a630914
308 A_ = A;
309 compute(A_);
310 break;
311 }
313 {
314 compute(A);
315 break;
316 }
318 OGS_FATAL(
319 "If NumLib::LinearSolverBehaviour::REUSE is set then "
320 "EigenLinearSolver::compute() should never be executed");
321 };
322
323 if (solver_.info() != Eigen::Success)
324 {
325 ERR("Failed during Eigen linear solver initialization");
326 return false;
327 }
328
329 return true;
330 }
#define OGS_FATAL(...)
Definition Error.h:26
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
bool compute(Matrix &A, EigenOption &opt, MathLib::LinearSolverBehaviour linear_solver_behaviour)
EigenMatrix::RawMatrixType Matrix
Template class for Eigen iterative linear solvers.
static std::string getSolverName(SolverType const solver_type)
return a linear solver name from the solver type
static std::string getPreconName(PreconType const precon_type)
return a preconditioner name from the preconditioner type

References MathLib::details::EigenIterativeLinearSolver< T_SOLVER >::A_, MathLib::EigenLinearSolverBase::compute(), ERR(), MathLib::EigenOption::error_tolerance, MathLib::EigenOption::getPreconName(), MathLib::EigenOption::getSolverName(), INFO(), MathLib::EigenOption::max_iterations, OGS_FATAL, MathLib::EigenOption::precon_type, MathLib::RECOMPUTE, MathLib::RECOMPUTE_AND_STORE, MathLib::REUSE, MathLib::details::EigenIterativeLinearSolver< T_SOLVER >::solver_, and MathLib::EigenOption::solver_type.

◆ solveImpl()

template<class T_SOLVER >
bool MathLib::details::EigenIterativeLinearSolver< T_SOLVER >::solveImpl ( Vector const & b,
Vector & x,
EigenOption & opt )
inlineoverridevirtual

Implements MathLib::EigenLinearSolverBase.

Definition at line 332 of file EigenLinearSolver.cpp.

333 {
334 INFO("-> solve with Eigen iterative linear solver {:s} (precon {:s})",
335 EigenOption::getSolverName(opt.solver_type),
336 EigenOption::getPreconName(opt.precon_type));
337
338 x = solver_.solveWithGuess(b, x);
339 INFO("\t iteration: {:d}/{:d}", solver_.iterations(),
340 opt.max_iterations);
341 INFO("\t residual: {:e}\n", solver_.error());
342
343 if (solver_.info() != Eigen::Success)
344 {
345 ERR("Failed during Eigen linear solve");
346 return false;
347 }
348
349 return true;
350 }

References ERR(), MathLib::EigenOption::getPreconName(), MathLib::EigenOption::getSolverName(), INFO(), MathLib::EigenOption::max_iterations, MathLib::EigenOption::precon_type, MathLib::details::EigenIterativeLinearSolver< T_SOLVER >::solver_, and MathLib::EigenOption::solver_type.

Member Data Documentation

◆ A_

template<class T_SOLVER >
Matrix MathLib::details::EigenIterativeLinearSolver< T_SOLVER >::A_
private

◆ solver_


The documentation for this class was generated from the following file: