7#ifndef LINEARSOLVER_HPP
8#define LINEARSOLVER_HPP
11#include <Eigen/Sparse>
14#include <Eigen/UmfPackSupport>
18#include <Eigen/PardisoSupport>
26#include <boost/algorithm/string.hpp>
39 template<
typename MatrixType>
41 template<
typename MatrixType>
44 template<
typename MatrixType>
51 template<
typename MatrixType>
94 template<
typename MatrixType>
95 using ListSolvers = std::tuple<std::unique_ptr<EigenLUType<MatrixType>>,
96 std::unique_ptr<EigenBiCGStabType<MatrixType>>,
97 std::unique_ptr<PardisoLUType<MatrixType>>,
98 std::unique_ptr<UMFPACKType<MatrixType>>,
99 std::unique_ptr<PastixLUType>,
100 std::unique_ptr<PastixLLTType>>;
104 template<
typename MatrixType>
118 std::cout <<
"[linearsolver] Pardiso not available, reverting to Eigen LU" << std::endl;
124 std::cout <<
"[linearsolver] UMFPACK not available, reverting to Eigen LU" << std::endl;
130 std::cout <<
"[linearsolver] PaStiX not available, reverting to Eigen LU" << std::endl;
190 return m_info_factorize;
206 std::get<0>(m_list_solvers).get()->analyzePattern(A);
211 std::get<1>(m_list_solvers).get()->analyzePattern(A);
217 std::get<2>(m_list_solvers).get()->analyzePattern(A);
225 std::get<3>(m_list_solvers).get()->analyzePattern(A);
233 std::get<4>(m_list_solvers).get()->analyzePattern(A);
239 std::get<5>(m_list_solvers).get()->analyzePattern(A);
257 std::get<0>(m_list_solvers).get()->factorize(A);
258 m_info_factorize = std::get<0>(m_list_solvers).get()->info();
263 std::get<1>(m_list_solvers).get()->factorize(A);
264 m_info_factorize = std::get<1>(m_list_solvers).get()->info();
270 std::get<2>(m_list_solvers).get()->factorize(A);
271 m_info_factorize = std::get<2>(m_list_solvers).get()->info();
279 std::get<3>(m_list_solvers).get()->factorize(A);
280 m_info_factorize = std::get<3>(m_list_solvers).get()->info();
288 std::get<4>(m_list_solvers).get()->factorize(A);
289 m_info_factorize = std::get<4>(m_list_solvers).get()->info();
295 std::get<5>(m_list_solvers).get()->factorize(A);
296 m_info_factorize = std::get<5>(m_list_solvers).get()->info();
305 _check_info(m_info_factorize,
"factorize");
318 template<
typename VectorType>
327 x = std::get<0>(m_list_solvers).get()->solve(
b);
328 m_info_solve = std::get<0>(m_list_solvers).get()->info();
333 x = std::get<1>(m_list_solvers).get()->solve(
b);
334 m_info_solve = std::get<1>(m_list_solvers).get()->info();
340 x = std::get<2>(m_list_solvers).get()->solve(
b);
341 m_info_solve = std::get<2>(m_list_solvers).get()->info();
349 x = std::get<3>(m_list_solvers).get()->solve(
b);
350 m_info_solve = std::get<3>(m_list_solvers).get()->info();
358 x = std::get<4>(m_list_solvers).get()->solve(
b);
359 m_info_solve = std::get<4>(m_list_solvers).get()->info();
365 x = std::get<5>(m_list_solvers).get()->solve(
b);
366 m_info_solve = std::get<5>(m_list_solvers).get()->info();
375 _check_info(m_info_solve,
"solve");
381 template<
typename VectorType>
392 template <
typename VectorType>
399 void _check_info(Eigen::ComputationInfo
const & info, std::string
step)
const
401 if (info != Eigen::Success) {
402 std::cerr <<
"[linearsolver] ERROR in step: " <<
step << std::endl;
403 std::cerr <<
"[linearsolver] Info: " << info <<
" (see Eigen::ComputationInfo for the meaning)" << std::endl;
411 Eigen::ComputationInfo m_info_factorize;
412 Eigen::ComputationInfo m_info_solve;
Class to invoke the Pastix LLT solver.
Definition PastixInterface.hpp:543
Class to invoke the Pastix LU solver.
Definition PastixInterface.hpp:424
This structure is a wrapper to allow a given code to select various linear solvers.
Definition linearsolver.hpp:106
@ Matrix
Definition basis.hpp:67
Eigen::BiCGSTAB< MatrixType, Eigen::IncompleteLUT< double > > EigenBiCGStabType
Definition linearsolver.hpp:42
std::map< SolverName, std::string > map_realname
Map to associate to each solver its proper name.
Definition linearsolver.hpp:77
Eigen::SparseLU< MatrixType > EigenLUType
Definition linearsolver.hpp:40
void factorize(MatrixType &A)
Factorize the matrix.
Definition linearsolver.hpp:251
void compute(MatrixType &A)
Analyze and factorize the matrix.
Definition linearsolver.hpp:310
bool PardisoLUType
Definition linearsolver.hpp:48
bool UMFPACKType
Definition linearsolver.hpp:55
void analyzePattern(MatrixType &A)
Analyze the pattern of the matrix.
Definition linearsolver.hpp:200
SolverName
Enumeration of all available solvers.
Definition linearsolver.hpp:36
std::map< std::string, SolverName > map_solver
Map to associate to each lowercase name a solver.
Definition linearsolver.hpp:69
std::string name() const
Returns the name of the solver.
Definition linearsolver.hpp:182
VectorType compute_and_solve(MatrixType &A, VectorType &b)
Perform all operators to solve Ax=b.
Definition linearsolver.hpp:382
bool PastixLUType
Definition linearsolver.hpp:62
double residual(MatrixType &A, VectorType &b, VectorType &x)
Check relative infinity norm of residual: ||Ax-b||/||b||.
Definition linearsolver.hpp:393
VectorType solve(VectorType &b)
Solve the system Ax=b using the selected solver (after analysis of pattern and computation of matrix)
Definition linearsolver.hpp:319
std::tuple< std::unique_ptr< EigenLUType< MatrixType > >, std::unique_ptr< EigenBiCGStabType< MatrixType > >, std::unique_ptr< PardisoLUType< MatrixType > >, std::unique_ptr< UMFPACKType< MatrixType > >, std::unique_ptr< PastixLUType >, std::unique_ptr< PastixLLTType > > ListSolvers
Definition linearsolver.hpp:100
std::map< SolverName, size_t > map_id
Definition linearsolver.hpp:84
Eigen::ComputationInfo info_solve() const
Returns the information message after the "solve" step.
Definition linearsolver.hpp:194
LinearSolver(const std::string &namesolver)
Constructor.
Definition linearsolver.hpp:111
Eigen::ComputationInfo info_factorize() const
Returns the information message after the "factorize" step.
Definition linearsolver.hpp:188
bool PastixLLTType
Definition linearsolver.hpp:63
@ EigenLU
Definition linearsolver.hpp:36
@ PaStiXLLT
Definition linearsolver.hpp:36
@ PardisoLU
Definition linearsolver.hpp:36
@ PaStiXLU
Definition linearsolver.hpp:36
@ UMFPACK
Definition linearsolver.hpp:36
@ EigenBiCGStab
Definition linearsolver.hpp:36
Definition ddr-magnetostatics.hpp:41