OGS
MathLib::EigenLisLinearSolver Class Referencefinal

Detailed Description

Linear solver using Lis library with Eigen matrix and vector objects

Definition at line 22 of file EigenLisLinearSolver.h.

#include <EigenLisLinearSolver.h>

Public Member Functions

 EigenLisLinearSolver (std::string const &solver_name, std::string const &lis_options)
void setOption (std::string const &lis_options)
bool solve (EigenMatrix &A, EigenVector &b, EigenVector &x)
bool canSolveRectangular () const
 Get, if the solver can handle rectangular equation systems.

Private Member Functions

bool solve (LisMatrix &A, LisVector &b, LisVector &x)

Private Attributes

std::string lis_options_

Constructor & Destructor Documentation

◆ EigenLisLinearSolver()

MathLib::EigenLisLinearSolver::EigenLisLinearSolver ( std::string const & solver_name,
std::string const & lis_options )

Constructor

Parameters
solver_nameA name used as a prefix for command line options if there are such options available.
lis_optionsstring containing the options for LIS library; options will be applied in the solve method.

Definition at line 14 of file EigenLisLinearSolver.cpp.

16 : lis_options_(lis_options)
17{
18}

References lis_options_.

Member Function Documentation

◆ canSolveRectangular()

bool MathLib::EigenLisLinearSolver::canSolveRectangular ( ) const
inline

Get, if the solver can handle rectangular equation systems.

Definition at line 47 of file EigenLisLinearSolver.h.

47{ return false; }

◆ setOption()

void MathLib::EigenLisLinearSolver::setOption ( std::string const & lis_options)
inline

copy linear solvers options

Parameters
lis_optionsstring containing the options for LIS library; options will be applied in the solve method.

Definition at line 39 of file EigenLisLinearSolver.h.

40 {
41 lis_options_ = lis_options;
42 }

References lis_options_.

◆ solve() [1/2]

bool MathLib::EigenLisLinearSolver::solve ( EigenMatrix & A,
EigenVector & b,
EigenVector & x )

Definition at line 20 of file EigenLisLinearSolver.cpp.

22{
23 static_assert(EigenMatrix::RawMatrixType::IsRowMajor,
24 "Sparse matrix is required to be in row major storage.");
25 auto& A = A_.getRawMatrix();
26 auto& b = b_.getRawVector();
27 auto& x = x_.getRawVector();
28
29 if (!A.isCompressed())
30 {
31 A.makeCompressed();
32 }
33 int nnz = A.nonZeros();
34 int* ptr = A.outerIndexPtr();
35 int* col = A.innerIndexPtr();
36 double* data = A.valuePtr();
37 LisMatrix lisA(A_.getNumberOfRows(), nnz, ptr, col, data);
38 LisVector lisb(b.rows(), b.data());
39 LisVector lisx(x.rows(), x.data());
40
41 bool const status = solve(lisA, lisb, lisx);
42
43 for (std::size_t i = 0; i < lisx.size(); i++)
44 {
45 x[i] = lisx[i];
46 }
47
48 return status;
49}
bool solve(EigenMatrix &A, EigenVector &b, EigenVector &x)

References MathLib::EigenMatrix::getNumberOfRows(), MathLib::EigenMatrix::getRawMatrix(), MathLib::EigenVector::getRawVector(), MathLib::LisVector::size(), and solve().

Referenced by solve(), and NumLib::detail::solvePicard().

◆ solve() [2/2]

bool MathLib::EigenLisLinearSolver::solve ( LisMatrix & A,
LisVector & b,
LisVector & x )
private

Definition at line 51 of file EigenLisLinearSolver.cpp.

52{
54
55 INFO("------------------------------------------------------------------");
56 INFO("*** LIS solver computation");
57
58 // Create solver
59 LIS_SOLVER solver;
60 int ierr = lis_solver_create(&solver);
61 if (!checkLisError(ierr))
62 {
63 return false;
64 }
65 lis_solver_set_option(const_cast<char*>(lis_options_.c_str()), solver);
66#ifdef _OPENMP
67 INFO("-> number of threads: {:d}", (int)omp_get_max_threads());
68#endif
69 {
70 int precon;
71 ierr = lis_solver_get_precon(solver, &precon);
72 if (!checkLisError(ierr))
73 {
74 return false;
75 }
76 INFO("-> precon: {:d}", precon);
77 }
78 {
79 int slv;
80 ierr = lis_solver_get_solver(solver, &slv);
81 if (!checkLisError(ierr))
82 {
83 return false;
84 }
85 INFO("-> solver: {:d}", slv);
86 }
87
88 // solve
89 INFO("-> solve");
90 ierr =
91 lis_solve(A.getRawMatrix(), b.getRawVector(), x.getRawVector(), solver);
92 if (!checkLisError(ierr))
93 {
94 return false;
95 }
96
97 LIS_INT linear_solver_status;
98 ierr = lis_solver_get_status(solver, &linear_solver_status);
99 if (!checkLisError(ierr))
100 {
101 return false;
102 }
103
104 INFO("-> status: {:d}", linear_solver_status);
105
106 {
107 int iter = 0;
108 ierr = lis_solver_get_iter(solver, &iter);
109 if (!checkLisError(ierr))
110 {
111 return false;
112 }
113
114 INFO("-> iteration: {:d}", iter);
115 }
116 {
117 double resid = 0.0;
118 ierr = lis_solver_get_residualnorm(solver, &resid);
119 if (!checkLisError(ierr))
120 {
121 return false;
122 }
123 INFO("-> residual: {:g}", resid);
124 }
125 {
126 double time, itime, ptime, p_ctime, p_itime;
127 ierr = lis_solver_get_timeex(solver, &time, &itime, &ptime, &p_ctime,
128 &p_itime);
129 if (!checkLisError(ierr))
130 {
131 return false;
132 }
133 INFO("-> time total (s): {:g}", time);
134 INFO("-> time iterations (s): {:g}", itime);
135 INFO("-> time preconditioning (s): {:g}", ptime);
136 INFO("-> time precond. create (s): {:g}", p_ctime);
137 INFO("-> time precond. iter (s): {:g}", p_itime);
138 }
139
140 // Clear solver
141 ierr = lis_solver_destroy(solver);
142 if (!checkLisError(ierr))
143 {
144 return false;
145 }
146 INFO("------------------------------------------------------------------");
147
148 return linear_solver_status == LIS_SUCCESS;
149}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
bool checkLisError(int err)
Definition LisCheck.h:20
bool finalizeMatrixAssembly(MAT_T &)

References MathLib::checkLisError(), MathLib::finalizeMatrixAssembly(), MathLib::LisMatrix::getRawMatrix(), MathLib::LisVector::getRawVector(), INFO(), and lis_options_.

Member Data Documentation

◆ lis_options_

std::string MathLib::EigenLisLinearSolver::lis_options_
private

Definition at line 51 of file EigenLisLinearSolver.h.

Referenced by EigenLisLinearSolver(), setOption(), and solve().


The documentation for this class was generated from the following files: