20 #include "libmesh/libmesh_common.h"
22 #ifdef LIBMESH_HAVE_EIGEN
26 #include "libmesh/eigen_sparse_linear_solver.h"
27 #include "libmesh/libmesh_logging.h"
28 #include "libmesh/enum_to_string.h"
29 #include "libmesh/solver_configuration.h"
30 #include "libmesh/enum_preconditioner_type.h"
31 #include "libmesh/enum_solver_type.h"
34 #include "libmesh/ignore_warnings.h"
35 #include <unsupported/Eigen/IterativeSolvers>
36 #include "libmesh/restore_warnings.h"
45 _comp_info(Eigen::Success)
82 std::pair<unsigned int, Real>
87 const unsigned int m_its)
89 LOG_SCOPE(
"solve()",
"EigenSparseLinearSolver");
102 std::pair<unsigned int, Real> retval(0,0.);
105 switch (this->_solver_type)
110 Eigen::ConjugateGradient<EigenSM> solver (matrix.
_mat);
111 solver.setMaxIterations(m_its);
112 solver.setTolerance(tol);
113 solution._vec = solver.solveWithGuess(rhs._vec,solution._vec);
114 libMesh::out <<
"#iterations: " << solver.iterations() << std::endl;
115 libMesh::out <<
"estimated error: " << solver.error() << std::endl;
116 retval = std::make_pair(solver.iterations(), solver.error());
117 _comp_info = solver.info();
124 Eigen::BiCGSTAB<EigenSM> solver (matrix.
_mat);
125 solver.setMaxIterations(m_its);
126 solver.setTolerance(tol);
127 solution._vec = solver.solveWithGuess(rhs._vec,solution._vec);
128 libMesh::out <<
"#iterations: " << solver.iterations() << std::endl;
129 libMesh::out <<
"estimated error: " << solver.error() << std::endl;
130 retval = std::make_pair(solver.iterations(), solver.error());
131 _comp_info = solver.info();
138 Eigen::GMRES<EigenSM> solver (matrix.
_mat);
139 solver.setMaxIterations(m_its);
140 solver.setTolerance(tol);
145 if (this->_solver_configuration)
147 auto it = this->_solver_configuration->int_valued_data.find(
"gmres_restart");
149 if (it != this->_solver_configuration->int_valued_data.end())
150 solver.set_restart(it->second);
153 libMesh::out <<
"Eigen GMRES solver, restart = " << solver.get_restart() << std::endl;
154 solution._vec = solver.solveWithGuess(rhs._vec, solution._vec);
155 libMesh::out <<
"#iterations: " << solver.iterations() << std::endl;
156 libMesh::out <<
"estimated error: " << solver.error() << std::endl;
157 retval = std::make_pair(solver.iterations(), solver.error());
158 _comp_info = solver.info();
177 matrix.
_mat.makeCompressed();
188 Eigen::SparseLU<EigenSM> solver;
191 solver.analyzePattern(matrix.
_mat);
194 solver.factorize(matrix.
_mat);
197 solution._vec = solver.solve(rhs._vec);
202 retval = std::make_pair(1, 0);
205 _comp_info = solver.info();
214 <<
"Continuing with BICGSTAB" << std::endl;
218 return this->solve (matrix,
231 template <
typename T>
232 std::pair<unsigned int, Real>
237 const unsigned int m_its)
239 LOG_SCOPE(
"adjoint_solve()",
"EigenSparseLinearSolver");
241 libmesh_experimental();
245 std::pair<unsigned int, Real> retval = this->solve (mat_trans,
257 template <
typename T>
258 std::pair<unsigned int, Real>
265 libmesh_not_implemented();
266 return std::make_pair(0,0.0);
271 template <
typename T>
272 std::pair<unsigned int, Real>
280 libmesh_not_implemented();
281 return std::make_pair(0,0.0);
286 template <
typename T>
289 libmesh_not_implemented();
317 template <
typename T>
320 auto it = _convergence_reasons.find(_comp_info);
324 if (it == _convergence_reasons.end())
326 libmesh_warning(
"Warning: unknown Eigen::ComputationInfo: " \
328 <<
" returning CONVERGED_ITS." \
345 #endif // #ifdef LIBMESH_HAVE_EIGEN