OGS
MathLib::EigenLisLinearSolver Class Referencefinal

Detailed Description

Linear solver using Lis library with Eigen matrix and vector objects

Definition at line 29 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 21 of file EigenLisLinearSolver.cpp.

23 : lis_options_(lis_options)
24{
25}

Member Function Documentation

◆ canSolveRectangular()

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

Get, if the solver can handle rectangular equation systems.

Definition at line 54 of file EigenLisLinearSolver.h.

54{ 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 46 of file EigenLisLinearSolver.h.

47 {
48 lis_options_ = lis_options;
49 }

References lis_options_.

◆ solve() [1/2]

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

Definition at line 27 of file EigenLisLinearSolver.cpp.

29{
30 static_assert(EigenMatrix::RawMatrixType::IsRowMajor,
31 "Sparse matrix is required to be in row major storage.");
32 auto& A = A_.getRawMatrix();
33 auto& b = b_.getRawVector();
34 auto& x = x_.getRawVector();
35
36 if (!A.isCompressed())
37 {
38 A.makeCompressed();
39 }
40 int nnz = A.nonZeros();
41 int* ptr = A.outerIndexPtr();
42 int* col = A.innerIndexPtr();
43 double* data = A.valuePtr();
44 LisMatrix lisA(A_.getNumberOfRows(), nnz, ptr, col, data);
45 LisVector lisb(b.rows(), b.data());
46 LisVector lisx(x.rows(), x.data());
47
48 bool const status = solve(lisA, lisb, lisx);
49
50 for (std::size_t i = 0; i < lisx.size(); i++)
51 {
52 x[i] = lisx[i];
53 }
54
55 return status;
56}
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 58 of file EigenLisLinearSolver.cpp.

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

Referenced by setOption(), and solve().


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