OGS
MathLib::EigenLinearSolver Class Referencefinal

Detailed Description

Definition at line 26 of file EigenLinearSolver.h.

#include <EigenLinearSolver.h>

Collaboration diagram for MathLib::EigenLinearSolver:
[legend]

Public Member Functions

 EigenLinearSolver (std::string const &solver_name, EigenOption const &option)
 
 ~EigenLinearSolver ()
 
void setOption (const EigenOption &option)
 
EigenOptiongetOption ()
 
bool compute (EigenMatrix &A, MathLib::LinearSolverBehaviour const linear_solver_behaviour)
 
bool solve (EigenVector &b, EigenVector &x)
 
bool solve (EigenMatrix &A, EigenVector &b, EigenVector &x, MathLib::LinearSolverBehaviour const linear_solver_behaviour=MathLib::LinearSolverBehaviour::RECOMPUTE)
 Computes and solves in a single call.
 
bool canSolveRectangular () const
 Get, if the solver can handle rectangular equation systems.
 

Protected Member Functions

void setRestart ()
 
void setL ()
 
void setS ()
 
void setSmoothing ()
 
void setAngle ()
 
void setResidualUpdate ()
 

Protected Attributes

EigenOption option_
 
std::unique_ptr< EigenLinearSolverBasesolver_
 
bool can_solve_rectangular_ = false
 

Constructor & Destructor Documentation

◆ EigenLinearSolver()

MathLib::EigenLinearSolver::EigenLinearSolver ( std::string const & solver_name,
EigenOption const & option )
explicit

Constructor

Parameters
solver_nameA name used as a prefix for command line options if there are such options available.
optionEigen linear solver options.

Definition at line 485 of file EigenLinearSolver.cpp.

487 : option_(option)
488{
489 using Matrix = EigenMatrix::RawMatrixType;
490
491 switch (option_.solver_type)
492 {
494 {
495 using SolverType =
496 Eigen::SparseLU<Matrix, Eigen::COLAMDOrdering<int>>;
497 solver_ = std::make_unique<
498 details::EigenDirectLinearSolver<SolverType>>();
500 return;
501 }
511 return;
516 return;
518 {
519#ifdef USE_MKL
520 using SolverType = Eigen::PardisoLU<EigenMatrix::RawMatrixType>;
521 solver_.reset(new details::EigenDirectLinearSolver<SolverType>);
523 return;
524#else
525 OGS_FATAL(
526 "The code is not compiled with Intel MKL. Linear solver type "
527 "PardisoLU is not available.");
528#endif
529 }
530 }
531
532 OGS_FATAL("Invalid Eigen linear solver type. Aborting.");
533}
#define OGS_FATAL(...)
Definition Error.h:26
std::unique_ptr< EigenLinearSolverBase > solver_
Eigen::SparseMatrix< double, Eigen::RowMajor > RawMatrixType
Definition EigenMatrix.h:31
std::unique_ptr< EigenLinearSolverBase > createIterativeSolver()
PreconType precon_type
Preconditioner type.
Definition EigenOption.h:46
SolverType solver_type
Linear solver type.
Definition EigenOption.h:44

References MathLib::EigenOption::BiCGSTAB, MathLib::EigenOption::BiCGSTABL, can_solve_rectangular_, MathLib::EigenOption::CG, MathLib::details::createIterativeSolver(), MathLib::EigenOption::GMRES, MathLib::EigenOption::IDRS, MathLib::EigenOption::IDRSTABL, MathLib::EigenOption::LeastSquareCG, OGS_FATAL, option_, MathLib::EigenOption::PardisoLU, MathLib::EigenOption::precon_type, solver_, MathLib::EigenOption::solver_type, and MathLib::EigenOption::SparseLU.

◆ ~EigenLinearSolver()

MathLib::EigenLinearSolver::~EigenLinearSolver ( )
default

Member Function Documentation

◆ canSolveRectangular()

bool MathLib::EigenLinearSolver::canSolveRectangular ( ) const
inline

Get, if the solver can handle rectangular equation systems.

Definition at line 75 of file EigenLinearSolver.h.

75{ return can_solve_rectangular_; }

References can_solve_rectangular_.

◆ compute()

bool MathLib::EigenLinearSolver::compute ( EigenMatrix & A,
MathLib::LinearSolverBehaviour const linear_solver_behaviour )

Performs the compute() step of the Eigen linear solver.

I.e., computes the (LU) decomposition in case of a direct solver, or computes the preconditioner of an iterative solver.

Definition at line 537 of file EigenLinearSolver.cpp.

540{
541 INFO("------------------------------------------------------------------");
542 INFO("*** Eigen solver compute()");
543
544 return solver_->compute(A.getRawMatrix(), option_, linear_solver_behaviour);
545}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35

References MathLib::EigenMatrix::getRawMatrix(), INFO(), option_, and solver_.

◆ getOption()

EigenOption & MathLib::EigenLinearSolver::getOption ( )
inline

get linear solver options

Definition at line 48 of file EigenLinearSolver.h.

48{ return option_; }

References option_.

◆ setAngle()

void MathLib::EigenLinearSolver::setAngle ( )
protected

◆ setL()

void MathLib::EigenLinearSolver::setL ( )
protected

◆ setOption()

void MathLib::EigenLinearSolver::setOption ( const EigenOption & option)
inline

copy linear solvers options

Definition at line 43 of file EigenLinearSolver.h.

43{ option_ = option; }

References option_.

◆ setResidualUpdate()

void MathLib::EigenLinearSolver::setResidualUpdate ( )
protected

◆ setRestart()

void MathLib::EigenLinearSolver::setRestart ( )
protected

◆ setS()

void MathLib::EigenLinearSolver::setS ( )
protected

◆ setSmoothing()

void MathLib::EigenLinearSolver::setSmoothing ( )
protected

◆ solve() [1/2]

bool MathLib::EigenLinearSolver::solve ( EigenMatrix & A,
EigenVector & b,
EigenVector & x,
MathLib::LinearSolverBehaviour const linear_solver_behaviour = MathLib::LinearSolverBehaviour::RECOMPUTE )

Computes and solves in a single call.

Definition at line 555 of file EigenLinearSolver.cpp.

558{
559 return solver_->compute(A.getRawMatrix(), option_,
560 linear_solver_behaviour) &&
561 solver_->solve(b.getRawVector(), x.getRawVector(), option_);
562}

References MathLib::EigenMatrix::getRawMatrix(), MathLib::EigenVector::getRawVector(), option_, and solver_.

◆ solve() [2/2]

bool MathLib::EigenLinearSolver::solve ( EigenVector & b,
EigenVector & x )

Solves the linear system for the given right-hand side b and initial guess x.

Precondition
compute() must have been called before. (Not necessarily for every x and b separately, but for every new/changed matrix A.

Definition at line 547 of file EigenLinearSolver.cpp.

548{
549 INFO("------------------------------------------------------------------");
550 INFO("*** Eigen solver solve()");
551
552 return solver_->solve(b.getRawVector(), x.getRawVector(), option_);
553}

References MathLib::EigenVector::getRawVector(), INFO(), option_, and solver_.

Member Data Documentation

◆ can_solve_rectangular_

bool MathLib::EigenLinearSolver::can_solve_rectangular_ = false
protected

Definition at line 80 of file EigenLinearSolver.h.

Referenced by EigenLinearSolver(), and canSolveRectangular().

◆ option_

EigenOption MathLib::EigenLinearSolver::option_
protected

Definition at line 78 of file EigenLinearSolver.h.

Referenced by EigenLinearSolver(), compute(), getOption(), setOption(), solve(), and solve().

◆ solver_

std::unique_ptr<EigenLinearSolverBase> MathLib::EigenLinearSolver::solver_
protected

Definition at line 79 of file EigenLinearSolver.h.

Referenced by EigenLinearSolver(), compute(), solve(), and solve().


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