86 const std::optional<double> tol,
87 const std::optional<unsigned int> m_its)
89 LOG_SCOPE(
"solve()",
"EigenSparseLinearSolver");
102 std::pair<unsigned int, Real> retval(0,0.);
106 auto do_solve = [
this, &rhs, &solution, tol, m_its]
107 (
auto & e_solver, std::string_view msg) {
108 const int max_its = this->get_int_solver_setting(
"max_its", m_its);
109 const double abs_tol = this->get_real_solver_setting(
"abs_tol", tol);
111 e_solver.setMaxIterations(max_its);
112 e_solver.setTolerance(abs_tol);
115 solution._vec = e_solver.solveWithGuess(rhs._vec,solution._vec);
117 libMesh::out <<
"#iterations: " << e_solver.iterations() <<
" / " << max_its << std::endl;
118 libMesh::out <<
"estimated error: " << e_solver.error() <<
" / " << abs_tol << std::endl;
119 _comp_info = e_solver.info();
120 return std::make_pair(e_solver.iterations(), e_solver.error());
123 using Eigen::DiagonalPreconditioner;
124 using Eigen::IdentityPreconditioner;
125 using Eigen::IncompleteCholesky;
126 using Eigen::IncompleteLUT;
129 switch (this->_solver_type)
134 const int UPLO = Eigen::Lower|Eigen::Upper;
136 switch (this->_preconditioner_type)
140 Eigen::ConjugateGradient<EigenSM,UPLO,IdentityPreconditioner> solver (matrix.
_mat);
141 retval = do_solve(solver,
"Eigen CG solver without preconditioning");
146 Eigen::ConjugateGradient<EigenSM,UPLO,IncompleteLUT<Number,eigen_idx_type>>
147 solver (matrix.
_mat);
148 retval = do_solve(solver,
"Eigen CG solver with Incomplete Cholesky preconditioning");
153 Eigen::ConjugateGradient<
EigenSM,UPLO,
154 IncompleteCholesky<Number,Eigen::Lower,Eigen::AMDOrdering<eigen_idx_type>>>
155 solver (matrix.
_mat);
156 retval = do_solve(solver,
"Eigen CG solver with Incomplete Cholesky preconditioning");
160 libmesh_warning(
"No EigenSparseLinearSolver support for " <<
161 Utility::enum_to_string<PreconditionerType>(this->_preconditioner_type)
162 <<
" preconditioning.");
163 libmesh_fallthrough();
166 Eigen::ConjugateGradient<EigenSM,UPLO,DiagonalPreconditioner<Number>> solver (matrix.
_mat);
167 retval = do_solve(solver,
"Eigen CG solver with Jacobi preconditioning");
177 switch (this->_preconditioner_type)
181 Eigen::BiCGSTAB<EigenSM, IdentityPreconditioner> solver (matrix.
_mat);
182 retval = do_solve(solver,
"Eigen BiCGStab solver");
188 Eigen::BiCGSTAB<EigenSM,IncompleteLUT<Number, eigen_idx_type>>
189 solver (matrix.
_mat);
190 retval = do_solve(solver,
"Eigen BiCGSTAB solver with ILU preconditioning");
194 libmesh_warning(
"No EigenSparseLinearSolver support for " <<
195 Utility::enum_to_string<PreconditionerType>(this->_preconditioner_type)
196 <<
" preconditioning.");
197 libmesh_fallthrough();
200 Eigen::BiCGSTAB<EigenSM,DiagonalPreconditioner<Number>> solver (matrix.
_mat);
201 retval = do_solve(solver,
"Eigen BiCGSTAB solver with Jacobi preconditioning");
211 auto set_restart_and_solve = [
this, &do_solve]
212 (
auto & gm_solver, std::string_view msg)
217 if (this->_solver_configuration)
218 if (
const auto it = this->_solver_configuration->int_valued_data.find(
"gmres_restart");
219 it != this->_solver_configuration->int_valued_data.end())
220 gm_solver.set_restart(it->second);
222 std::ostringstream full_msg;
223 full_msg << msg <<
", restart = " << gm_solver.get_restart();
224 return do_solve(gm_solver, full_msg.str());
227 switch (this->_preconditioner_type)
231 Eigen::GMRES<EigenSM,IdentityPreconditioner> solver (matrix.
_mat);
232 retval = set_restart_and_solve(solver,
"Eigen GMRES solver without preconditioning");
238 Eigen::GMRES<EigenSM,IncompleteLUT<Number, eigen_idx_type>>
239 solver (matrix.
_mat);
240 retval = set_restart_and_solve(solver,
"Eigen GMRES solver with ILU preconditioning");
244 libmesh_warning(
"No EigenSparseLinearSolver support for " <<
245 Utility::enum_to_string<PreconditionerType>(this->_preconditioner_type)
246 <<
" preconditioning.");
247 libmesh_fallthrough();
250 Eigen::GMRES<EigenSM,DiagonalPreconditioner<Number>> solver (matrix.
_mat);
251 retval = set_restart_and_solve(solver,
"Eigen CG solver with Jacobi preconditioning");
273 matrix.
_mat.makeCompressed();
284 Eigen::SparseLU<EigenSM> solver;
289 solver.analyzePattern(matrix.
_mat);
292 solver.factorize(matrix.
_mat);
295 solution._vec = solver.solve(rhs._vec);
300 retval = std::make_pair(1, 0);
303 _comp_info = solver.info();
312 <<
"Continuing with BICGSTAB" << std::endl;
316 return this->solve (matrix,