Chi-Tech
NonLinearSolver.h
Go to the documentation of this file.
1#ifndef CHITECH_CHI_MATH_NON_LINEAR_SOLVER_H
2#define CHITECH_CHI_MATH_NON_LINEAR_SOLVER_H
3
6
7#include <string>
8
9#include <memory>
10#include <utility>
11
12namespace chi_math
13{
14
15/**Implementation of a general non-linear solver.*/
16template <class MatType, class VecType, class SolverType>
18{
19public:
21 typedef std::shared_ptr<NLSolverContext> NLSolverContextPtr;
22
23 explicit NonLinearSolver(NLSolverContextPtr context_ptr,
24 const chi::InputParameters& params =
26 : solver_name_(params.GetParamValue<std::string>("name")),
27 context_ptr_(context_ptr),
28 options_(params)
29 {
30 }
32
35
37
38 bool IsConverged() const { return converged_; }
39 std::string GetConvergedReasonString() const;
40
41 virtual void Setup();
42 virtual void Solve();
43
44protected:
45 bool IsSystemSet() const { return system_set_; }
46
47 // Called in Setup
48 virtual void PreSetupCallback();
49 virtual void SetOptions();
50 virtual void SetSolverContext();
51 virtual void SetConvergenceTest();
52 virtual void SetMonitor();
53 virtual void SetPreconditioner();
54
55 virtual void SetSystemSize() = 0;
56 virtual void SetSystem() = 0;
57 virtual void SetFunction() = 0;
58 virtual void SetJacobian() = 0;
59 virtual void PostSetupCallback();
60
61 // Called in Solver
62 virtual void PreSolveCallback();
63 virtual void SetInitialGuess() = 0;
64 virtual void PostSolveCallback();
65
66 const std::string solver_name_;
67
69
70 MatType J_;
71 MatType P_;
72 VecType r_;
73 VecType x_;
75
76 int64_t num_local_dofs_ = 0;
77 int64_t num_globl_dofs_ = 0;
78
80
81private:
82 bool system_set_ = false;
83 bool converged_ = false;
85};
86
87} // namespace chi_math
88
89#endif // CHITECH_CHI_MATH_NON_LINEAR_SOLVER_H
virtual void SetMonitor()
NonLinearSolverContext< VecType, SolverType > NLSolverContext
NonLinearSolverOptions & ToleranceOptions()
virtual void PostSolveCallback()
virtual void SetConvergenceTest()
virtual void PreSolveCallback()
const std::string solver_name_
virtual void SetSystemSize()=0
std::shared_ptr< NLSolverContext > NLSolverContextPtr
NonLinearSolverOptions options_
virtual void SetOptions()
std::string converged_reason_string_
NonLinearSolver(NLSolverContextPtr context_ptr, const chi::InputParameters &params=NonLinearSolverOptions::GetInputParameters())
std::string GetConvergedReasonString() const
virtual void SetSystem()=0
NLSolverContextPtr context_ptr_
virtual void SetPreconditioner()
virtual void SetFunction()=0
NLSolverContextPtr & GetContext()
virtual void PostSetupCallback()
virtual void SetJacobian()=0
virtual void SetSolverContext()
virtual void PreSetupCallback()
virtual void SetInitialGuess()=0
static chi::InputParameters GetInputParameters()
SolverType
Definition: lbs_structs.h:27