Cantera  3.2.0a2
Loading...
Searching...
No Matches
BulkKinetics.h
Go to the documentation of this file.
1/**
2 * @file BulkKinetics.h
3 */
4
5// This file is part of Cantera. See License.txt in the top-level directory or
6// at https://cantera.org/license.txt for license and copyright information.
7
8#ifndef CT_BULKKINETICS_H
9#define CT_BULKKINETICS_H
10
11#include "Kinetics.h"
12#include "ThirdBodyCalc.h"
13
14namespace Cantera
15{
16
17//! Specialization of Kinetics for chemistry in a single bulk phase
18//! @ingroup kineticsmgr
19class BulkKinetics : public Kinetics
20{
21public:
22 //! @name Constructors and General Information
23 //! @{
25
26 string kineticsType() const override {
27 return "bulk";
28 }
29
30 //! @}
31
32 //! @name Reaction Mechanism Setup Routines
33 //! @{
34 bool addReaction(shared_ptr<Reaction> r, bool resize=true) override;
35 void addThirdBody(shared_ptr<Reaction> r);
36 void modifyReaction(size_t i, shared_ptr<Reaction> rNew) override;
37 void resizeSpecies() override;
38 void resizeReactions() override;
39 void setMultiplier(size_t i, double f) override;
40 void invalidateCache() override;
41 //! @}
42
43 //! @name Reaction rate constants, rates of progress, and thermodynamic properties
44 //! @{
45 void getFwdRateConstants(double* kfwd) override;
46 void getEquilibriumConstants(double* kc) override;
47 void getRevRateConstants(double* krev, bool doIrreversible=false) override;
48
49 void getDeltaGibbs(double* deltaG) override;
50 void getDeltaEnthalpy(double* deltaH) override;
51 void getDeltaEntropy(double* deltaS) override;
52
53 void getDeltaSSGibbs(double* deltaG) override;
54 void getDeltaSSEnthalpy(double* deltaH) override;
55 void getDeltaSSEntropy(double* deltaS) override;
56 //! @}
57
58 //! @name Derivatives of rate constants and rates of progress
59 //! @{
60 void getDerivativeSettings(AnyMap& settings) const override;
61 void setDerivativeSettings(const AnyMap& settings) override;
62 void getFwdRateConstants_ddT(double* dkfwd) override;
63 void getFwdRatesOfProgress_ddT(double* drop) override;
64 void getRevRatesOfProgress_ddT(double* drop) override;
65 void getNetRatesOfProgress_ddT(double* drop) override;
66 void getFwdRateConstants_ddP(double* dkfwd) override;
67 void getFwdRatesOfProgress_ddP(double* drop) override;
68 void getRevRatesOfProgress_ddP(double* drop) override;
69 void getNetRatesOfProgress_ddP(double* drop) override;
70 void getFwdRateConstants_ddC(double* dkfwd) override;
71 void getFwdRatesOfProgress_ddC(double* drop) override;
72 void getRevRatesOfProgress_ddC(double* drop) override;
73 void getNetRatesOfProgress_ddC(double* drop) override;
74 Eigen::SparseMatrix<double> fwdRatesOfProgress_ddX() override;
75 Eigen::SparseMatrix<double> revRatesOfProgress_ddX() override;
76 Eigen::SparseMatrix<double> netRatesOfProgress_ddX() override;
77 Eigen::SparseMatrix<double> fwdRatesOfProgress_ddCi() override;
78 Eigen::SparseMatrix<double> revRatesOfProgress_ddCi() override;
79 Eigen::SparseMatrix<double> netRatesOfProgress_ddCi() override;
80 //! @}
81
82 //! @name Rate calculation intermediate methods
83 //! @{
84
85 void updateROP() override;
86
87 void getThirdBodyConcentrations(double* concm) override;
88 const vector<double>& thirdBodyConcentrations() const override {
89 return m_concm;
90 }
91
92 //! @}
93
94protected:
95 //! @name Internal service methods
96 //!
97 //! @note These methods are for internal use, and seek to avoid code duplication
98 //! while evaluating terms used for rate constants, rates of progress, and
99 //! their derivatives.
100 //! @{
101
102 //! Multiply rate with third-body collider concentrations
103 void processThirdBodies(double* rop);
104
105 //! Multiply rate with inverse equilibrium constant
106 void applyEquilibriumConstants(double* rop);
107
108 //! Multiply rate with scaled temperature derivatives of the inverse
109 //! equilibrium constant
110 /*!
111 * This (scaled) derivative is handled by a finite difference.
112 */
113 void applyEquilibriumConstants_ddT(double* drkcn);
114
115 //! Process temperature derivative
116 //! @param in rate expression used for the derivative calculation
117 //! @param drop pointer to output buffer
118 void process_ddT(const vector<double>& in, double* drop);
119
120 //! Process pressure derivative
121 //! @param in rate expression used for the derivative calculation
122 //! @param drop pointer to output buffer
123 void process_ddP(const vector<double>& in, double* drop);
124
125 //! Process concentration (molar density) derivative
126 //! @param stoich stoichiometry manager
127 //! @param in rate expression used for the derivative calculation
128 //! @param drop pointer to output buffer
129 //! @param mass_action boolean indicating whether law of mass action applies
130 void process_ddC(StoichManagerN& stoich, const vector<double>& in,
131 double* drop, bool mass_action=true);
132
133 //! Process derivatives
134 //! @param stoich stoichiometry manager
135 //! @param in rate expression used for the derivative calculation
136 //! @param ddX true: w.r.t mole fractions false: w.r.t species concentrations
137 //! @return a sparse matrix of derivative contributions for each reaction of
138 //! dimensions nTotalReactions by nTotalSpecies
139 Eigen::SparseMatrix<double> calculateCompositionDerivatives(
140 StoichManagerN& stoich, const vector<double>& in, bool ddX=true);
141
142 //! Helper function ensuring that all rate derivatives can be calculated
143 //! @param name method name used for error output
144 //! @throw CanteraError if ideal gas assumption does not hold
145 void assertDerivativesValid(const string& name);
146
147 //! @}
148
149 //! Difference between the global reactants order and the global products
150 //! order. Of type "double" to account for the fact that we can have real-
151 //! valued stoichiometries.
152 vector<double> m_dn;
153
154 ThirdBodyCalc m_multi_concm; //!< used with MultiRate evaluator
155
156 //! Third body concentrations
157 vector<double> m_concm;
158
159 //! Activity concentrations, as calculated by ThermoPhase::getActivityConcentrations
160 vector<double> m_act_conc;
161
162 //! Physical concentrations, as calculated by ThermoPhase::getConcentrations
163 vector<double> m_phys_conc;
164
165 //! Derivative settings
167 bool m_jac_skip_falloff;
168 double m_jac_rtol_delta;
169
170 bool m_ROP_ok = false;
171
172 //! Buffers for partial rop results with length nReactions()
173 vector<double> m_rbuf0;
174 vector<double> m_rbuf1;
175 vector<double> m_rbuf2;
176 vector<double> m_kf0; //!< Forward rate constants without perturbation
177 vector<double> m_sbuf0;
178 vector<double> m_state;
179 vector<double> m_grt; //!< Standard chemical potentials for each species
180};
181
182}
183
184#endif
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:431
Specialization of Kinetics for chemistry in a single bulk phase.
bool addReaction(shared_ptr< Reaction > r, bool resize=true) override
Add a single reaction to the mechanism.
void getNetRatesOfProgress_ddC(double *drop) override
Calculate derivatives for net rates-of-progress with respect to molar concentration at constant tempe...
Eigen::SparseMatrix< double > netRatesOfProgress_ddX() override
Calculate derivatives for net rates-of-progress with respect to species mole fractions at constant te...
void getNetRatesOfProgress_ddP(double *drop) override
Calculate derivatives for net rates-of-progress with respect to pressure at constant temperature,...
string kineticsType() const override
Identifies the Kinetics manager type.
Eigen::SparseMatrix< double > revRatesOfProgress_ddCi() override
Calculate derivatives for forward rates-of-progress with respect to species concentration at constant...
void getFwdRateConstants(double *kfwd) override
Return the forward rate constants.
void getDeltaSSGibbs(double *deltaG) override
Return the vector of values for the reaction standard state Gibbs free energy change.
Eigen::SparseMatrix< double > fwdRatesOfProgress_ddX() override
Calculate derivatives for forward rates-of-progress with respect to species mole fractions at constan...
const vector< double > & thirdBodyConcentrations() const override
Provide direct access to current third-body concentration values.
void getDeltaGibbs(double *deltaG) override
Return the vector of values for the reaction Gibbs free energy change.
vector< double > m_phys_conc
Physical concentrations, as calculated by ThermoPhase::getConcentrations.
Eigen::SparseMatrix< double > revRatesOfProgress_ddX() override
Calculate derivatives for reverse rates-of-progress with respect to species mole fractions at constan...
void getFwdRatesOfProgress_ddT(double *drop) override
Calculate derivatives for forward rates-of-progress with respect to temperature at constant pressure,...
void assertDerivativesValid(const string &name)
Helper function ensuring that all rate derivatives can be calculated.
void getFwdRatesOfProgress_ddP(double *drop) override
Calculate derivatives for forward rates-of-progress with respect to pressure at constant temperature,...
void getFwdRateConstants_ddT(double *dkfwd) override
Calculate derivatives for forward rate constants with respect to temperature at constant pressure,...
void setMultiplier(size_t i, double f) override
Set the multiplier for reaction i to f.
void getDeltaSSEntropy(double *deltaS) override
Return the vector of values for the change in the standard state entropies for each reaction.
vector< double > m_dn
Difference between the global reactants order and the global products order.
bool m_jac_skip_third_bodies
Derivative settings.
void getDeltaSSEnthalpy(double *deltaH) override
Return the vector of values for the change in the standard state enthalpies of reaction.
Eigen::SparseMatrix< double > calculateCompositionDerivatives(StoichManagerN &stoich, const vector< double > &in, bool ddX=true)
Process derivatives.
void resizeSpecies() override
Resize arrays with sizes that depend on the total number of species.
vector< double > m_grt
Standard chemical potentials for each species.
vector< double > m_act_conc
Activity concentrations, as calculated by ThermoPhase::getActivityConcentrations.
void getRevRateConstants(double *krev, bool doIrreversible=false) override
Return the reverse rate constants.
void getEquilibriumConstants(double *kc) override
Return a vector of Equilibrium constants.
void getNetRatesOfProgress_ddT(double *drop) override
Calculate derivatives for net rates-of-progress with respect to temperature at constant pressure,...
void processThirdBodies(double *rop)
Multiply rate with third-body collider concentrations.
void applyEquilibriumConstants(double *rop)
Multiply rate with inverse equilibrium constant.
void getDerivativeSettings(AnyMap &settings) const override
Retrieve derivative settings.
void process_ddT(const vector< double > &in, double *drop)
Process temperature derivative.
void getDeltaEnthalpy(double *deltaH) override
Return the vector of values for the reactions change in enthalpy.
void getRevRatesOfProgress_ddT(double *drop) override
Calculate derivatives for reverse rates-of-progress with respect to temperature at constant pressure,...
Eigen::SparseMatrix< double > fwdRatesOfProgress_ddCi() override
Calculate derivatives for forward rates-of-progress with respect to species concentration at constant...
void modifyReaction(size_t i, shared_ptr< Reaction > rNew) override
Modify the rate expression associated with a reaction.
void getFwdRatesOfProgress_ddC(double *drop) override
Calculate derivatives for forward rates-of-progress with respect to molar concentration at constant t...
void process_ddC(StoichManagerN &stoich, const vector< double > &in, double *drop, bool mass_action=true)
Process concentration (molar density) derivative.
void process_ddP(const vector< double > &in, double *drop)
Process pressure derivative.
void getFwdRateConstants_ddP(double *dkfwd) override
Calculate derivatives for forward rate constants with respect to pressure at constant temperature,...
void getRevRatesOfProgress_ddP(double *drop) override
Calculate derivatives for reverse rates-of-progress with respect to pressure at constant temperature,...
void getRevRatesOfProgress_ddC(double *drop) override
Calculate derivatives for reverse rates-of-progress with respect to molar concentration at constant t...
vector< double > m_rbuf0
Buffers for partial rop results with length nReactions()
ThirdBodyCalc m_multi_concm
used with MultiRate evaluator
void applyEquilibriumConstants_ddT(double *drkcn)
Multiply rate with scaled temperature derivatives of the inverse equilibrium constant.
void resizeReactions() override
Finalize Kinetics object and associated objects.
Eigen::SparseMatrix< double > netRatesOfProgress_ddCi() override
Calculate derivatives for net rates-of-progress with respect to species concentration at constant tem...
void getThirdBodyConcentrations(double *concm) override
Return a vector of values of effective concentrations of third-body collision partners of any reactio...
void getDeltaEntropy(double *deltaS) override
Return the vector of values for the reactions change in entropy.
vector< double > m_concm
Third body concentrations.
vector< double > m_kf0
Forward rate constants without perturbation.
void setDerivativeSettings(const AnyMap &settings) override
Set/modify derivative settings.
void getFwdRateConstants_ddC(double *dkfwd) override
Calculate derivatives for forward rate constants with respect to molar concentration at constant temp...
Public interface for kinetics managers.
Definition Kinetics.h:126
This class handles operations involving the stoichiometric coefficients on one side of a reaction (re...
Calculate and apply third-body effects on reaction rates, including non- unity third-body efficiencie...
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595