13 #include <Eigen/Sparse>
18 #include <Eigen/PardisoSupport>
21 #ifdef USE_EIGEN_UNSUPPORTED
22 #include <unsupported/Eigen/src/IterativeSolvers/GMRES.h>
23 #include <unsupported/Eigen/src/IterativeSolvers/Scaling.h>
51 template <
class T_SOLVER>
58 if (!A.isCompressed())
64 if (
solver_.info() != Eigen::Success)
66 ERR(
"Failed during Eigen linear solver initialization");
71 if (
solver_.info() != Eigen::Success)
73 ERR(
"Failed during Eigen linear solve");
85 template <
class T_SOLVER>
91 INFO(
"-> solve with {:s} (precon {:s})",
99 if (!A.isCompressed())
105 if (
solver_.info() != Eigen::Success)
107 ERR(
"Failed during Eigen linear solver initialization");
111 x =
solver_.solveWithGuess(b, x);
112 INFO(
"\t iteration: {:d}/{:d}",
solver_.iterations(),
116 if (
solver_.info() != Eigen::Success)
118 ERR(
"Failed during Eigen linear solve");
132 void EigenIterativeLinearSolver<
134 Eigen::IdentityPreconditioner>>::setRestart(
int const restart)
136 solver_.set_restart(restart);
137 INFO(
"-> set restart value: {:d}", solver_.get_restart());
143 Eigen::DiagonalPreconditioner<double>>>::setRestart(
int const restart)
145 solver_.set_restart(restart);
146 INFO(
"-> set restart value: {:d}", solver_.get_restart());
152 Eigen::IncompleteLUT<double>>>::setRestart(
int const restart)
154 solver_.set_restart(restart);
155 INFO(
"-> set restart value: {:d}", solver_.get_restart());
158 template <
template <
typename,
typename>
class Solver,
typename Precon>
163 return std::make_unique<Slv>();
166 template <
template <
typename,
typename>
class Solver>
174 Eigen::IdentityPreconditioner>();
177 Solver, Eigen::DiagonalPreconditioner<double>>();
183 Eigen::IncompleteLUT<double>>();
185 OGS_FATAL(
"Invalid Eigen preconditioner type.");
189 template <
typename Mat,
typename Precon>
199 return createIterativeSolver<Eigen::BiCGSTAB>(precon_type);
203 return createIterativeSolver<EigenCGSolver>(precon_type);
207 #ifdef USE_EIGEN_UNSUPPORTED
208 return createIterativeSolver<Eigen::GMRES>(precon_type);
211 "The code is not compiled with the Eigen unsupported modules. "
212 "Linear solver type GMRES is not available.");
216 OGS_FATAL(
"Invalid Eigen iterative linear solver type. Aborting.");
239 Eigen::SparseLU<Matrix, Eigen::COLAMDOrdering<int>>;
253 using SolverType = Eigen::PardisoLU<EigenMatrix::RawMatrixType>;
258 "The code is not compiled with Intel MKL. Linear solver type "
259 "PardisoLU is not available.");
264 OGS_FATAL(
"Invalid Eigen linear solver type. Aborting.");
279 if (
auto solver_type =
281 ptSolver->getConfigParameterOptional<std::string>(
"solver_type"))
285 if (
auto precon_type =
287 ptSolver->getConfigParameterOptional<std::string>(
"precon_type"))
291 if (
auto error_tolerance =
293 ptSolver->getConfigParameterOptional<
double>(
"error_tolerance"))
297 if (
auto max_iteration_step =
299 ptSolver->getConfigParameterOptional<
int>(
"max_iteration_step"))
305 ptSolver->getConfigParameterOptional<
bool>(
"scaling"))
307 #ifdef USE_EIGEN_UNSUPPORTED
311 "The code is not compiled with the Eigen unsupported modules. "
312 "scaling is not available.");
317 ptSolver->getConfigParameterOptional<
int>(
"restart"))
319 #ifdef USE_EIGEN_UNSUPPORTED
323 "The code is not compiled with the Eigen unsupported modules. "
324 "GMRES/GMRES option restart is not available.");
331 INFO(
"------------------------------------------------------------------");
332 INFO(
"*** Eigen solver computation");
334 #ifdef USE_EIGEN_UNSUPPORTED
335 std::unique_ptr<Eigen::IterScaling<EigenMatrix::RawMatrixType>> scal;
340 std::make_unique<Eigen::IterScaling<EigenMatrix::RawMatrixType>>();
347 #ifdef USE_EIGEN_UNSUPPORTED
354 INFO(
"------------------------------------------------------------------");
void INFO(char const *fmt, Args const &... args)
void ERR(char const *fmt, Args const &... args)
std::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
EigenMatrix::RawMatrixType Matrix
EigenVector::RawVectorType Vector
virtual bool solve(Matrix &A, Vector const &b, Vector &x, EigenOption &opt)=0
Solves the linear equation system for .
virtual ~EigenLinearSolverBase()=default
void setOption(const BaseLib::ConfigTree &option)
EigenLinearSolver(const std::string &solver_name, BaseLib::ConfigTree const *const option)
bool solve(EigenMatrix &A, EigenVector &b, EigenVector &x)
std::unique_ptr< EigenLinearSolverBase > solver_
Eigen::SparseMatrix< double, Eigen::RowMajor > RawMatrixType
RawMatrixType & getRawMatrix()
Global vector based on Eigen vector.
RawVectorType & getRawVector()
return a raw Eigen vector object
Eigen::VectorXd RawVectorType
Template class for Eigen direct linear solvers.
bool solve(Matrix &A, Vector const &b, Vector &x, EigenOption &opt) override
Solves the linear equation system for .
Template class for Eigen iterative linear solvers.
bool solve(Matrix &A, Vector const &b, Vector &x, EigenOption &opt) override
Solves the linear equation system for .
void setRestart(int const)
std::unique_ptr< EigenLinearSolverBase > createIterativeSolver()
Eigen::ConjugateGradient< Mat, Eigen::Lower, Precon > EigenCGSolver
void ignoreOtherLinearSolvers(const BaseLib::ConfigTree &config, const std::string &solver_name)
Option for Eigen sparse solver.
PreconType precon_type
Preconditioner type.
static std::string getSolverName(SolverType const solver_type)
return a linear solver name from the solver type
PreconType
Preconditioner type.
static PreconType getPreconType(const std::string &precon_name)
SolverType solver_type
Linear solver type.
double error_tolerance
Error tolerance.
static SolverType getSolverType(const std::string &solver_name)
static std::string getPreconName(PreconType const precon_type)
return a preconditioner name from the preconditioner type
int max_iterations
Maximum iteration count.