Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add GMRES restart option #2910

Merged
merged 3 commits into from Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,7 @@
Sets the number of iterations after which a restart of the GMRES method is performed.
Default value is 30.
This option is only available for the GMRES solver which is part of the unsupported Eigen modules that are available
through OGS_USE_EIGEN_UNSUPPORTED cmake option.

See following links for detail description:
- "Detailed Description" in https://eigen.tuxfamily.org/dox/unsupported/classEigen_1_1GMRES.html
41 changes: 41 additions & 0 deletions MathLib/LinAlg/Eigen/EigenLinearSolver.cpp
Expand Up @@ -92,6 +92,7 @@ class EigenIterativeLinearSolver final : public EigenLinearSolverBase
EigenOption::getPreconName(opt.precon_type));
_solver.setTolerance(opt.error_tolerance);
_solver.setMaxIterations(opt.max_iterations);
MathLib::details::EigenIterativeLinearSolver<T_SOLVER>::setRestart(opt.restart);

if (!A.isCompressed())
{
Expand Down Expand Up @@ -119,8 +120,36 @@ class EigenIterativeLinearSolver final : public EigenLinearSolverBase

private:
T_SOLVER _solver;
void setRestart(int const /*restart*/) {
}
};

/// Specialization for (all) three preconditioners separately
template <>
void EigenIterativeLinearSolver<
Eigen::GMRES<EigenMatrix::RawMatrixType,
Eigen::IdentityPreconditioner>>::setRestart(int const restart)
{
_solver.set_restart(restart);
INFO("-> set restart value: {:d}", _solver.get_restart());
}

template <>
void EigenIterativeLinearSolver<Eigen::GMRES<
EigenMatrix::RawMatrixType,
Eigen::DiagonalPreconditioner<double>>>::setRestart(int const restart)
{
_solver.set_restart(restart);
INFO("-> set restart value: {:d}", _solver.get_restart());
}

template <>
void EigenIterativeLinearSolver<Eigen::GMRES<EigenMatrix::RawMatrixType, Eigen::IncompleteLUT<double>>>::setRestart(int const restart)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joergbuchwald clang-format. Use pre-commit checks.

{
_solver.set_restart(restart);
INFO("-> set restart value: {:d}", _solver.get_restart());
}
joergbuchwald marked this conversation as resolved.
Show resolved Hide resolved

template <template <typename, typename> class Solver, typename Precon>
std::unique_ptr<EigenLinearSolverBase> createIterativeSolver()
{
Expand Down Expand Up @@ -265,6 +294,18 @@ void EigenLinearSolver::setOption(BaseLib::ConfigTree const& option)
"scaling is not available.");
#endif
}
if (auto restart =
//! \ogs_file_param{prj__linear_solvers__linear_solver__eigen__restart}
joergbuchwald marked this conversation as resolved.
Show resolved Hide resolved
ptSolver->getConfigParameterOptional<int>("restart")) {
#ifdef USE_EIGEN_UNSUPPORTED
_option.restart = *restart;
#else
OGS_FATAL(
"The code is not compiled with the Eigen unsupported modules. "
"GMRES/GMRES option restart is not available.");
#endif
}

}

bool EigenLinearSolver::solve(EigenMatrix &A, EigenVector& b, EigenVector &x)
Expand Down
1 change: 1 addition & 0 deletions MathLib/LinAlg/Eigen/EigenLinearSolver.h
Expand Up @@ -59,6 +59,7 @@ class EigenLinearSolver final
protected:
EigenOption _option;
std::unique_ptr<EigenLinearSolverBase> _solver;
void setRestart();
};

} // namespace MathLib
1 change: 1 addition & 0 deletions MathLib/LinAlg/Eigen/EigenOption.cpp
Expand Up @@ -22,6 +22,7 @@ EigenOption::EigenOption()
error_tolerance = 1.e-16;
#ifdef USE_EIGEN_UNSUPPORTED
scaling = false;
restart = 30;
#endif
}

Expand Down
2 changes: 2 additions & 0 deletions MathLib/LinAlg/Eigen/EigenOption.h
Expand Up @@ -47,6 +47,8 @@ struct EigenOption final
#ifdef USE_EIGEN_UNSUPPORTED
/// Scaling the coefficient matrix and the RHS bector
bool scaling;
/// Restart value for the GMRES solver
int restart;
joergbuchwald marked this conversation as resolved.
Show resolved Hide resolved
#endif

/// Constructor
Expand Down