| Cantera 3.0.0

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
13#include "cantera/base/ctexceptions.h"
14
15 namespace 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 */
22 enum class PreconditionerSide {
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
30 class PreconditionerBase
31{
32 public:
33 PreconditionerBase() {}
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
115 protected:
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
Cantera::NotImplementedError
An error indicating that an unimplemented function has been called.
Definition ctexceptions.h:195
Cantera::PreconditionerBase
PreconditionerBase serves as an abstract type to extend different preconditioners.
Definition PreconditionerBase.h:31
Cantera::PreconditionerBase::gamma
virtual double gamma()
Get gamma used in preconditioning.
Definition PreconditionerBase.h:105
Cantera::PreconditionerBase::setGamma
virtual void setGamma(double gamma)
Set gamma used in preconditioning.
Definition PreconditionerBase.h:100
Cantera::PreconditionerBase::m_dim
size_t m_dim
Dimension of the preconditioner.
Definition PreconditionerBase.h:117
Cantera::PreconditionerBase::preconditionerSide
string preconditionerSide() const
Get preconditioner application side for CVODES.
Definition PreconditionerBase.h:54
Cantera::PreconditionerBase::setup
virtual void setup()
Perform preconditioner specific post-reactor setup operations such as factorize.
Definition PreconditionerBase.h:71
Cantera::PreconditionerBase::m_gamma
double m_gamma
gamma value used in M = I - gamma*J
Definition PreconditionerBase.h:120
Cantera::PreconditionerBase::printPreconditioner
virtual void printPreconditioner()
Print preconditioner contents.
Definition PreconditionerBase.h:88
Cantera::PreconditionerBase::solve
virtual void solve(const size_t stateSize, double *rhs_vector, double *output)
Solve a linear system Ax=b where A is the preconditioner.
Definition PreconditionerBase.h:66
Cantera::PreconditionerBase::reset
virtual void reset()
Reset preconditioner parameters as needed.
Definition PreconditionerBase.h:76
Cantera::PreconditionerBase::stateAdjustment
virtual void stateAdjustment(vector< double > &state)
Adjust the state vector based on the preconditioner, e.g., Adaptive preconditioning uses a strictly p...
Definition PreconditionerBase.h:49
Cantera::PreconditionerBase::m_init
bool m_init
bool saying whether or not the preconditioner is initialized
Definition PreconditionerBase.h:123
Cantera::PreconditionerBase::initialize
virtual void initialize(size_t networkSize)
Called during setup for any processes that need to be completed prior to setup functions used in sund...
Definition PreconditionerBase.h:83
Cantera::PreconditionerBase::m_atol
double m_atol
Absolute tolerance of the ODE solver.
Definition PreconditionerBase.h:126
Cantera::PreconditionerBase::setAbsoluteTolerance
virtual void setAbsoluteTolerance(double atol)
Set the absolute tolerance in the solver outside of the network initialization.
Definition PreconditionerBase.h:111
Cantera::PreconditionerBase::setValue
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.
Definition PreconditionerBase.h:41
Cantera::PreconditionerBase::updatePreconditioner
virtual void updatePreconditioner()
Transform Jacobian vector and write into preconditioner, P = (I - gamma * J)
Definition PreconditionerBase.h:94
ctexceptions.h
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
Cantera::PreconditionerSide
PreconditionerSide
Specifies the side of the system on which the preconditioner is applied.
Definition PreconditionerBase.h:22
Cantera::PreconditionerSide::LEFT_PRECONDITION
@ LEFT_PRECONDITION
No preconditioning.
Cantera::PreconditionerSide::BOTH_PRECONDITION
@ BOTH_PRECONDITION
Right side preconditioning.
Cantera::PreconditionerSide::RIGHT_PRECONDITION
@ RIGHT_PRECONDITION
Left side preconditioning.