Chi-Tech
linear_solver.h
Go to the documentation of this file.
1#ifndef CHITECH_CHI_MATH_LINEAR_SOLVER_H
2#define CHITECH_CHI_MATH_LINEAR_SOLVER_H
3
5
6#include <string>
7#include <utility>
8
9#include <memory>
10
11namespace chi_math
12{
13template <class MatType, class VecType>
14struct LinearSolverContext;
15
16/**Implementation of a general linear solver.*/
17template <class MatType, class VecType, class SolverType>
19{
20public:
22 typedef std::shared_ptr<LinSolveContext> LinSolveContextPtr;
23
24protected:
25 const std::string solver_name_;
26 const std::string iterative_method_;
27
29
30 MatType A_;
31 VecType b_;
32 VecType x_;
34
35private:
36 bool system_set_ = false;
37 bool suppress_kspsolve_ = false;
38
39protected:
40 int64_t num_local_dofs_ = 0;
41 int64_t num_globl_dofs_ = 0;
42
44 {
45 double residual_relative = 1.0e-50;
46 double residual_absolute = 1.0e-6;
47 double residual_divergence = 1.0e6;
52
53protected:
54 bool IsSystemSet() const { return system_set_; }
55
56public:
57 explicit LinearSolver(const std::string& iterative_method,
58 LinSolveContextPtr context_ptr)
59 : solver_name_(iterative_method),
60 iterative_method_(iterative_method),
61 context_ptr_(context_ptr)
62 {
63 }
64
65 explicit LinearSolver(std::string solver_name,
66 std::string iterative_method,
67 LinSolveContextPtr context_ptr)
68 : solver_name_(std::move(solver_name)),
69 iterative_method_(std::move(iterative_method)),
70 context_ptr_(context_ptr)
71 {
72 }
73
74 virtual ~LinearSolver();
75
78
80
81 /**Sets a flag to suppress the KSPSolve() method from being called.*/
84
85protected:
86 virtual void PreSetupCallback();
87 virtual void SetOptions();
88 virtual void SetSolverContext();
89 virtual void SetConvergenceTest();
90 virtual void SetMonitor();
91 virtual void SetPreconditioner();
92
93 virtual void SetSystemSize() = 0;
94 virtual void SetSystem() = 0;
95 virtual void PostSetupCallback();
96
97public:
98 virtual void Setup();
99
100protected:
101 virtual void PreSolveCallback();
102 virtual void SetInitialGuess() = 0;
103 virtual void SetRHS() = 0;
104 virtual void PostSolveCallback();
105
106public:
107 virtual void Solve();
108};
109
110} // namespace chi_math
111
112#endif // CHITECH_CHI_MATH_LINEAR_SOLVER_H
virtual void SetSystem()=0
bool GetKSPSolveSuppressionFlag() const
Definition: linear_solver.h:83
virtual void SetSystemSize()=0
virtual void PreSetupCallback()
virtual void SetInitialGuess()=0
void SetKSPSolveSuppressionFlag(bool flag)
Definition: linear_solver.h:82
virtual void SetRHS()=0
virtual void PreSolveCallback()
virtual void Solve()
virtual void SetOptions()
const std::string iterative_method_
Definition: linear_solver.h:26
LinSolveContextPtr & GetContext()
Definition: linear_solver.h:79
virtual void SetPreconditioner()
LinSolveContextPtr context_ptr_
Definition: linear_solver.h:28
const std::string solver_name_
Definition: linear_solver.h:25
bool IsSystemSet() const
Definition: linear_solver.h:54
virtual void SetConvergenceTest()
virtual void Setup()
virtual void SetSolverContext()
virtual void PostSetupCallback()
LinearSolverContext< MatType, VecType > LinSolveContext
Definition: linear_solver.h:21
std::shared_ptr< LinSolveContext > LinSolveContextPtr
Definition: linear_solver.h:22
virtual void PostSolveCallback()
struct chi_math::LinearSolver::ToleranceOptions tolerance_options_
LinearSolver(std::string solver_name, std::string iterative_method, LinSolveContextPtr context_ptr)
Definition: linear_solver.h:65
ToleranceOptions & ToleranceOptions()
Definition: linear_solver.h:76
virtual void SetMonitor()
LinearSolver(const std::string &iterative_method, LinSolveContextPtr context_ptr)
Definition: linear_solver.h:57
SolverType
Definition: lbs_structs.h:27