Cantera  3.0.0
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 "MultiRate.h"
13#include "ThirdBodyCalc.h"
14
15namespace Cantera
16{
17
18//! Specialization of Kinetics for chemistry in a single bulk phase
19//! @ingroup kineticsmgr
20class BulkKinetics : public Kinetics
21{
22public:
23 //! @name Constructors and General Information
24 //! @{
26
27 //! @deprecated To be removed after %Cantera 3.0; code base only uses default.
29
30 string kineticsType() const override {
31 return "bulk";
32 }
33
34 bool isReversible(size_t i) override;
35 //! @}
36
37 //! @name Reaction Mechanism Setup Routines
38 //! @{
39 bool addReaction(shared_ptr<Reaction> r, bool resize=true) override;
40 void addThirdBody(shared_ptr<Reaction> r);
41 void modifyReaction(size_t i, shared_ptr<Reaction> rNew) override;
42 void resizeSpecies() override;
43 void resizeReactions() override;
44 void setMultiplier(size_t i, double f) override;
45 void invalidateCache() override;
46 //! @}
47
48 //! @name Reaction rate constants, rates of progress, and thermodynamic properties
49 //! @{
50 void getFwdRateConstants(double* kfwd) override;
51 void getEquilibriumConstants(double* kc) override;
52 void getRevRateConstants(double* krev, bool doIrreversible=false) override;
53
54 void getDeltaGibbs(double* deltaG) override;
55 void getDeltaEnthalpy(double* deltaH) override;
56 void getDeltaEntropy(double* deltaS) override;
57
58 void getDeltaSSGibbs(double* deltaG) override;
59 void getDeltaSSEnthalpy(double* deltaH) override;
60 void getDeltaSSEntropy(double* deltaS) override;
61 //! @}
62
63 //! @name Derivatives of rate constants and rates of progress
64 //! @{
65 void getDerivativeSettings(AnyMap& settings) const override;
66 void setDerivativeSettings(const AnyMap& settings) override;
67 void getFwdRateConstants_ddT(double* dkfwd) override;
68 void getFwdRatesOfProgress_ddT(double* drop) override;
69 void getRevRatesOfProgress_ddT(double* drop) override;
70 void getNetRatesOfProgress_ddT(double* drop) override;
71 void getFwdRateConstants_ddP(double* dkfwd) override;
72 void getFwdRatesOfProgress_ddP(double* drop) override;
73 void getRevRatesOfProgress_ddP(double* drop) override;
74 void getNetRatesOfProgress_ddP(double* drop) override;
75 void getFwdRateConstants_ddC(double* dkfwd) override;
76 void getFwdRatesOfProgress_ddC(double* drop) override;
77 void getRevRatesOfProgress_ddC(double* drop) override;
78 void getNetRatesOfProgress_ddC(double* drop) override;
79 Eigen::SparseMatrix<double> fwdRatesOfProgress_ddX() override;
80 Eigen::SparseMatrix<double> revRatesOfProgress_ddX() override;
81 Eigen::SparseMatrix<double> netRatesOfProgress_ddX() override;
82 Eigen::SparseMatrix<double> fwdRatesOfProgress_ddCi() override;
83 Eigen::SparseMatrix<double> revRatesOfProgress_ddCi() override;
84 Eigen::SparseMatrix<double> netRatesOfProgress_ddCi() override;
85 //! @}
86
87 //! @name Rate calculation intermediate methods
88 //! @{
89
90 void updateROP() override;
91
92 void getThirdBodyConcentrations(double* concm) override;
93 const vector<double>& thirdBodyConcentrations() const override {
94 return m_concm;
95 }
96
97 //! @}
98
99protected:
100 //! @name Internal service methods
101 //!
102 //! @note These methods are for internal use, and seek to avoid code duplication
103 //! while evaluating terms used for rate constants, rates of progress, and
104 //! their derivatives.
105 //! @{
106
107 //! Multiply rate with third-body collider concentrations
108 void processThirdBodies(double* rop);
109
110 //! Multiply rate with inverse equilibrium constant
111 void applyEquilibriumConstants(double* rop);
112
113 //! Multiply rate with scaled temperature derivatives of the inverse
114 //! equilibrium constant
115 /*!
116 * This (scaled) derivative is handled by a finite difference.
117 */
118 void applyEquilibriumConstants_ddT(double* drkcn);
119
120 //! Process temperature derivative
121 //! @param in rate expression used for the derivative calculation
122 //! @param drop pointer to output buffer
123 void process_ddT(const vector<double>& in, double* drop);
124
125 //! Process pressure derivative
126 //! @param in rate expression used for the derivative calculation
127 //! @param drop pointer to output buffer
128 void process_ddP(const vector<double>& in, double* drop);
129
130 //! Process concentration (molar density) derivative
131 //! @param stoich stoichiometry manager
132 //! @param in rate expression used for the derivative calculation
133 //! @param drop pointer to output buffer
134 //! @param mass_action boolean indicating whether law of mass action applies
135 void process_ddC(StoichManagerN& stoich, const vector<double>& in,
136 double* drop, bool mass_action=true);
137
138 //! Process derivatives
139 //! @param stoich stoichiometry manager
140 //! @param in rate expression used for the derivative calculation
141 //! @param ddX true: w.r.t mole fractions false: w.r.t species concentrations
142 //! @return a sparse matrix of derivative contributions for each reaction of
143 //! dimensions nTotalReactions by nTotalSpecies
144 Eigen::SparseMatrix<double> calculateCompositionDerivatives(
145 StoichManagerN& stoich, const vector<double>& in, bool ddX=true);
146
147 //! Helper function ensuring that all rate derivatives can be calculated
148 //! @param name method name used for error output
149 //! @throw CanteraError if ideal gas assumption does not hold
150 void assertDerivativesValid(const string& name);
151
152 //! @}
153
154 //! Vector of rate handlers
155 vector<unique_ptr<MultiRateBase>> m_bulk_rates;
156 map<string, size_t> m_bulk_types; //!< Mapping of rate handlers
157
158 vector<size_t> m_revindex; //!< Indices of reversible reactions
159 vector<size_t> m_irrev; //!< Indices of irreversible reactions
160
161 //! Difference between the global reactants order and the global products
162 //! order. Of type "double" to account for the fact that we can have real-
163 //! valued stoichiometries.
164 vector<double> m_dn;
165
166 ThirdBodyCalc m_multi_concm; //!< used with MultiRate evaluator
167
168 //! Third body concentrations
169 vector<double> m_concm;
170
171 //! Activity concentrations, as calculated by ThermoPhase::getActivityConcentrations
172 vector<double> m_act_conc;
173
174 //! Physical concentrations, as calculated by ThermoPhase::getConcentrations
175 vector<double> m_phys_conc;
176
177 //! Derivative settings
179 bool m_jac_skip_falloff;
180 double m_jac_rtol_delta;
181
182 bool m_ROP_ok = false;
183
184 //! Buffers for partial rop results with length nReactions()
185 vector<double> m_rbuf0;
186 vector<double> m_rbuf1;
187 vector<double> m_rbuf2;
188 vector<double> m_kf0; //!< Forward rate constants without perturbation
189 vector<double> m_sbuf0;
190 vector<double> m_state;
191 vector<double> m_grt; //!< Standard chemical potentials for each species
192};
193
194}
195
196#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:427
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.
map< string, size_t > m_bulk_types
Mapping of rate handlers.
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...
bool isReversible(size_t i) override
True if reaction i has been declared to be reversible.
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,...
vector< size_t > m_revindex
Indices of reversible reactions.
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.
vector< unique_ptr< MultiRateBase > > m_bulk_rates
Vector of rate handlers.
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()
vector< size_t > m_irrev
Indices of irreversible reactions.
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
ThermoPhase & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism.
Definition Kinetics.h:254
This class handles operations involving the stoichiometric coefficients on one side of a reaction (re...
Base class for a phase with thermodynamic properties.
Calculate and apply third-body effects on reaction rates, including non- unity third-body efficiencie...
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564