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.
 

Protected Member Functions

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

Protected Attributes

EigenOption option_
 
std::unique_ptr< EigenLinearSolverBasesolver_
 

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 477 of file EigenLinearSolver.cpp.

479 : option_(option)
480{
481 using Matrix = EigenMatrix::RawMatrixType;
482
483 switch (option_.solver_type)
484 {
486 {
487 using SolverType =
488 Eigen::SparseLU<Matrix, Eigen::COLAMDOrdering<int>>;
489 solver_ = std::make_unique<
490 details::EigenDirectLinearSolver<SolverType>>();
491 return;
492 }
501 return;
503 {
504#ifdef USE_MKL
505 using SolverType = Eigen::PardisoLU<EigenMatrix::RawMatrixType>;
506 solver_.reset(new details::EigenDirectLinearSolver<SolverType>);
507 return;
508#else
509 OGS_FATAL(
510 "The code is not compiled with Intel MKL. Linear solver type "
511 "PardisoLU is not available.");
512#endif
513 }
514 }
515
516 OGS_FATAL("Invalid Eigen linear solver type. Aborting.");
517}
#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:44
SolverType solver_type
Linear solver type.
Definition EigenOption.h:42

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

◆ ~EigenLinearSolver()

MathLib::EigenLinearSolver::~EigenLinearSolver ( )
default

Member Function Documentation

◆ 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 521 of file EigenLinearSolver.cpp.

524{
525 INFO("------------------------------------------------------------------");
526 INFO("*** Eigen solver compute()");
527
528 return solver_->compute(A.getRawMatrix(), option_, linear_solver_behaviour);
529}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35

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

◆ 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 539 of file EigenLinearSolver.cpp.

542{
543 return solver_->compute(A.getRawMatrix(), option_,
544 linear_solver_behaviour) &&
545 solver_->solve(b.getRawVector(), x.getRawVector(), option_);
546}

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

◆ 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 531 of file EigenLinearSolver.cpp.

532{
533 INFO("------------------------------------------------------------------");
534 INFO("*** Eigen solver solve()");
535
536 return solver_->solve(b.getRawVector(), x.getRawVector(), option_);
537}

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

Member Data Documentation

◆ option_

EigenOption MathLib::EigenLinearSolver::option_
protected

Definition at line 75 of file EigenLinearSolver.h.

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

◆ solver_

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

Definition at line 76 of file EigenLinearSolver.h.

Referenced by EigenLinearSolver().


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