Cantera  3.1.0a1
Loading...
Searching...
No Matches
PreconditionerBase.h
Go to the documentation of this file.
1/**
2 * @file PreconditionerBase.h Declarations for the class
3 * PreconditionerBase which is a virtual base class for
4 * preconditioning systems.
5 */
6
7// This file is part of Cantera. See License.txt in the top-level directory or
8// at https://cantera.org/license.txt for license and copyright information.
9
10#ifndef PRECONDITIONERBASE_H
11#define PRECONDITIONERBASE_H
12
14
15namespace Cantera
16{
17
18/**
19 * Specifies the side of the system on which the preconditioner is applied. Not all
20 * methods are supported by all integrators.
21 */
23 NO_PRECONDITION, //! No preconditioning
24 LEFT_PRECONDITION, //! Left side preconditioning
25 RIGHT_PRECONDITION, //! Right side preconditioning
26 BOTH_PRECONDITION //! Left and right side preconditioning
27};
28
29//! PreconditionerBase serves as an abstract type to extend different preconditioners
31{
32public:
34
35 virtual ~PreconditionerBase() {}
36
37 //! Set a value at the specified row and column of the jacobian triplet vector
38 //! @param row row in the jacobian matrix
39 //! @param col column in the jacobian matrix
40 //! @param value value of the element at row and col
41 virtual void setValue(size_t row, size_t col, double value) {
42 throw NotImplementedError("PreconditionerBase::setValue");
43 }
44
45 //! Adjust the state vector based on the preconditioner, e.g., Adaptive
46 //! preconditioning uses a strictly positive composition when preconditioning which
47 //! is handled by this function
48 //! @param state a vector containing the state to be updated
49 virtual void stateAdjustment(vector<double>& state) {
50 throw NotImplementedError("PreconditionerBase::stateAdjustment");
51 }
52
53 //! Get preconditioner application side for CVODES
54 string preconditionerSide() const {
55 return m_precon_side;
56 }
57
58 virtual void setPreconditionerSide(const string& preconSide) {
59 m_precon_side = preconSide;
60 }
61
62 //! Solve a linear system Ax=b where A is the preconditioner
63 //! @param[in] stateSize length of the rhs and output vectors
64 //! @param[in] rhs_vector right hand side vector used in linear system
65 //! @param[out] output output vector for solution
66 virtual void solve(const size_t stateSize, double* rhs_vector, double* output) {
67 throw NotImplementedError("PreconditionerBase::solve");
68 };
69
70 //! Perform preconditioner specific post-reactor setup operations such as factorize.
71 virtual void setup() {
72 throw NotImplementedError("PreconditionerBase::setup");
73 };
74
75 //! Reset preconditioner parameters as needed
76 virtual void reset() {
77 throw NotImplementedError("PreconditionerBase::reset");
78 };
79
80 //! Called during setup for any processes that need
81 //! to be completed prior to setup functions used in sundials.
82 //! @param networkSize the number of variables in the associated reactor network
83 virtual void initialize(size_t networkSize) {
84 throw NotImplementedError("PreconditionerBase::initialize");
85 };
86
87 //! Print preconditioner contents
88 virtual void printPreconditioner() {
89 throw NotImplementedError("PreconditionerBase::printPreconditioner");
90 };
91
92 //! Transform Jacobian vector and write into
93 //! preconditioner, P = (I - gamma * J)
94 virtual void updatePreconditioner() {
95 throw NotImplementedError("PreconditionerBase::updatePreconditioner");
96 }
97
98 //! Set gamma used in preconditioning
99 //! @param gamma used in M = I - gamma*J
100 virtual void setGamma(double gamma) {
101 m_gamma = gamma;
102 };
103
104 //! Get gamma used in preconditioning
105 virtual double gamma() {
106 return m_gamma;
107 };
108
109 //! Set the absolute tolerance in the solver outside of the network initialization
110 //! @param atol the specified tolerance
111 virtual void setAbsoluteTolerance(double atol) {
112 m_atol = atol;
113 }
114
115protected:
116 //! Dimension of the preconditioner
117 size_t m_dim;
118
119 //! gamma value used in M = I - gamma*J
120 double m_gamma = 1.0;
121
122 //! bool saying whether or not the preconditioner is initialized
123 bool m_init = false;
124
125 //! Absolute tolerance of the ODE solver
126 double m_atol = 0;
127
128 string m_precon_side = "none";
129};
130
131}
132#endif
An error indicating that an unimplemented function has been called.
PreconditionerBase serves as an abstract type to extend different preconditioners.
virtual double gamma()
Get gamma used in preconditioning.
virtual void setGamma(double gamma)
Set gamma used in preconditioning.
size_t m_dim
Dimension of the preconditioner.
string preconditionerSide() const
Get preconditioner application side for CVODES.
virtual void setup()
Perform preconditioner specific post-reactor setup operations such as factorize.
double m_gamma
gamma value used in M = I - gamma*J
virtual void printPreconditioner()
Print preconditioner contents.
virtual void solve(const size_t stateSize, double *rhs_vector, double *output)
Solve a linear system Ax=b where A is the preconditioner.
virtual void reset()
Reset preconditioner parameters as needed.
virtual void stateAdjustment(vector< double > &state)
Adjust the state vector based on the preconditioner, e.g., Adaptive preconditioning uses a strictly p...
bool m_init
bool saying whether or not the preconditioner is initialized
virtual void initialize(size_t networkSize)
Called during setup for any processes that need to be completed prior to setup functions used in sund...
double m_atol
Absolute tolerance of the ODE solver.
virtual void setAbsoluteTolerance(double atol)
Set the absolute tolerance in the solver outside of the network initialization.
virtual void setValue(size_t row, size_t col, double value)
Set a value at the specified row and column of the jacobian triplet vector.
virtual void updatePreconditioner()
Transform Jacobian vector and write into preconditioner, P = (I - gamma * J)
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
PreconditionerSide
Specifies the side of the system on which the preconditioner is applied.
@ LEFT_PRECONDITION
No preconditioning.
@ BOTH_PRECONDITION
Right side preconditioning.
@ RIGHT_PRECONDITION
Left side preconditioning.