OGS
MathLib::EigenLisLinearSolver Class Referencefinal

Detailed Description

Linear solver using Lis library with Eigen matrix and vector objects

Definition at line 30 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)
 

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 25 of file EigenLisLinearSolver.cpp.

27 : lis_options_(lis_options)
28{
29}

Member Function Documentation

◆ 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 47 of file EigenLisLinearSolver.h.

48 {
49 lis_options_ = lis_options;
50 }

References lis_options_.

◆ solve() [1/2]

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

Definition at line 31 of file EigenLisLinearSolver.cpp.

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

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

Referenced by setOption(), and solve().


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