| 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
15 namespace Cantera
16{
17
18//! Specialization of Kinetics for chemistry in a single bulk phase
19//! @ingroup kineticsmgr
20 class BulkKinetics : public Kinetics
21{
22 public:
23 //! @name Constructors and General Information
24 //! @{
25 BulkKinetics();
26
27 //! @deprecated To be removed after %Cantera 3.0; code base only uses default.
28 BulkKinetics(ThermoPhase* thermo);
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
99 protected:
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
178 bool m_jac_skip_third_bodies;
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
Kinetics.h
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
MultiRate.h
ThirdBodyCalc.h
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:427
Cantera::BulkKinetics
Specialization of Kinetics for chemistry in a single bulk phase.
Definition BulkKinetics.h:21
Cantera::BulkKinetics::addReaction
bool addReaction(shared_ptr< Reaction > r, bool resize=true) override
Add a single reaction to the mechanism.
Definition BulkKinetics.cpp:26
Cantera::BulkKinetics::getNetRatesOfProgress_ddC
void getNetRatesOfProgress_ddC(double *drop) override
Calculate derivatives for net rates-of-progress with respect to molar concentration at constant tempe...
Definition BulkKinetics.cpp:382
Cantera::BulkKinetics::netRatesOfProgress_ddX
Eigen::SparseMatrix< double > netRatesOfProgress_ddX() override
Calculate derivatives for net rates-of-progress with respect to species mole fractions at constant te...
Definition BulkKinetics.cpp:415
Cantera::BulkKinetics::getNetRatesOfProgress_ddP
void getNetRatesOfProgress_ddP(double *drop) override
Calculate derivatives for net rates-of-progress with respect to pressure at constant temperature,...
Definition BulkKinetics.cpp:354
Cantera::BulkKinetics::kineticsType
string kineticsType() const override
Identifies the Kinetics manager type.
Definition BulkKinetics.h:30
Cantera::BulkKinetics::revRatesOfProgress_ddCi
Eigen::SparseMatrix< double > revRatesOfProgress_ddCi() override
Calculate derivatives for forward rates-of-progress with respect to species concentration at constant...
Definition BulkKinetics.cpp:439
Cantera::BulkKinetics::getFwdRateConstants
void getFwdRateConstants(double *kfwd) override
Return the forward rate constants.
Definition BulkKinetics.cpp:166
Cantera::BulkKinetics::getDeltaSSGibbs
void getDeltaSSGibbs(double *deltaG) override
Return the vector of values for the reaction standard state Gibbs free energy change.
Definition BulkKinetics.cpp:235
Cantera::BulkKinetics::m_bulk_types
map< string, size_t > m_bulk_types
Mapping of rate handlers.
Definition BulkKinetics.h:156
Cantera::BulkKinetics::fwdRatesOfProgress_ddX
Eigen::SparseMatrix< double > fwdRatesOfProgress_ddX() override
Calculate derivatives for forward rates-of-progress with respect to species mole fractions at constan...
Definition BulkKinetics.cpp:394
Cantera::BulkKinetics::thirdBodyConcentrations
const vector< double > & thirdBodyConcentrations() const override
Provide direct access to current third-body concentration values.
Definition BulkKinetics.h:93
Cantera::BulkKinetics::getDeltaGibbs
void getDeltaGibbs(double *deltaG) override
Return the vector of values for the reaction Gibbs free energy change.
Definition BulkKinetics.cpp:211
Cantera::BulkKinetics::m_phys_conc
vector< double > m_phys_conc
Physical concentrations, as calculated by ThermoPhase::getConcentrations.
Definition BulkKinetics.h:175
Cantera::BulkKinetics::revRatesOfProgress_ddX
Eigen::SparseMatrix< double > revRatesOfProgress_ddX() override
Calculate derivatives for reverse rates-of-progress with respect to species mole fractions at constan...
Definition BulkKinetics.cpp:404
Cantera::BulkKinetics::isReversible
bool isReversible(size_t i) override
True if reaction i has been declared to be reversible.
Definition BulkKinetics.cpp:22
Cantera::BulkKinetics::getFwdRatesOfProgress_ddT
void getFwdRatesOfProgress_ddT(double *drop) override
Calculate derivatives for forward rates-of-progress with respect to temperature at constant pressure,...
Definition BulkKinetics.cpp:298
Cantera::BulkKinetics::assertDerivativesValid
void assertDerivativesValid(const string &name)
Helper function ensuring that all rate derivatives can be calculated.
Definition BulkKinetics.cpp:701
Cantera::BulkKinetics::getFwdRatesOfProgress_ddP
void getFwdRatesOfProgress_ddP(double *drop) override
Calculate derivatives for forward rates-of-progress with respect to pressure at constant temperature,...
Definition BulkKinetics.cpp:340
Cantera::BulkKinetics::getFwdRateConstants_ddT
void getFwdRateConstants_ddT(double *dkfwd) override
Calculate derivatives for forward rate constants with respect to temperature at constant pressure,...
Definition BulkKinetics.cpp:291
Cantera::BulkKinetics::setMultiplier
void setMultiplier(size_t i, double f) override
Set the multiplier for reaction i to f.
Definition BulkKinetics.cpp:154
Cantera::BulkKinetics::getDeltaSSEntropy
void getDeltaSSEntropy(double *deltaS) override
Return the vector of values for the change in the standard state entropies for each reaction.
Definition BulkKinetics.cpp:257
Cantera::BulkKinetics::m_dn
vector< double > m_dn
Difference between the global reactants order and the global products order.
Definition BulkKinetics.h:164
Cantera::BulkKinetics::m_jac_skip_third_bodies
bool m_jac_skip_third_bodies
Derivative settings.
Definition BulkKinetics.h:178
Cantera::BulkKinetics::getDeltaSSEnthalpy
void getDeltaSSEnthalpy(double *deltaH) override
Return the vector of values for the change in the standard state enthalpies of reaction.
Definition BulkKinetics.cpp:246
Cantera::BulkKinetics::calculateCompositionDerivatives
Eigen::SparseMatrix< double > calculateCompositionDerivatives(StoichManagerN &stoich, const vector< double > &in, bool ddX=true)
Process derivatives.
Definition BulkKinetics.cpp:659
Cantera::BulkKinetics::resizeSpecies
void resizeSpecies() override
Resize arrays with sizes that depend on the total number of species.
Definition BulkKinetics.cpp:125
Cantera::BulkKinetics::m_grt
vector< double > m_grt
Standard chemical potentials for each species.
Definition BulkKinetics.h:191
Cantera::BulkKinetics::m_act_conc
vector< double > m_act_conc
Activity concentrations, as calculated by ThermoPhase::getActivityConcentrations.
Definition BulkKinetics.h:172
Cantera::BulkKinetics::getRevRateConstants
void getRevRateConstants(double *krev, bool doIrreversible=false) override
Return the reverse rate constants.
Definition BulkKinetics.cpp:192
Cantera::BulkKinetics::getEquilibriumConstants
void getEquilibriumConstants(double *kc) override
Return a vector of Equilibrium constants.
Definition BulkKinetics.cpp:175
Cantera::BulkKinetics::getNetRatesOfProgress_ddT
void getNetRatesOfProgress_ddT(double *drop) override
Calculate derivatives for net rates-of-progress with respect to temperature at constant pressure,...
Definition BulkKinetics.cpp:319
Cantera::BulkKinetics::m_revindex
vector< size_t > m_revindex
Indices of reversible reactions.
Definition BulkKinetics.h:158
Cantera::BulkKinetics::processThirdBodies
void processThirdBodies(double *rop)
Multiply rate with third-body collider concentrations.
Definition BulkKinetics.cpp:554
Cantera::BulkKinetics::applyEquilibriumConstants
void applyEquilibriumConstants(double *rop)
Multiply rate with inverse equilibrium constant.
Definition BulkKinetics.cpp:562
Cantera::BulkKinetics::getDerivativeSettings
void getDerivativeSettings(AnyMap &settings) const override
Retrieve derivative settings.
Definition BulkKinetics.cpp:270
Cantera::BulkKinetics::process_ddT
void process_ddT(const vector< double > &in, double *drop)
Process temperature derivative.
Definition BulkKinetics.cpp:606
Cantera::BulkKinetics::getDeltaEnthalpy
void getDeltaEnthalpy(double *deltaH) override
Return the vector of values for the reactions change in enthalpy.
Definition BulkKinetics.cpp:219
Cantera::BulkKinetics::m_bulk_rates
vector< unique_ptr< MultiRateBase > > m_bulk_rates
Vector of rate handlers.
Definition BulkKinetics.h:155
Cantera::BulkKinetics::getRevRatesOfProgress_ddT
void getRevRatesOfProgress_ddT(double *drop) override
Calculate derivatives for reverse rates-of-progress with respect to temperature at constant pressure,...
Definition BulkKinetics.cpp:305
Cantera::BulkKinetics::fwdRatesOfProgress_ddCi
Eigen::SparseMatrix< double > fwdRatesOfProgress_ddCi() override
Calculate derivatives for forward rates-of-progress with respect to species concentration at constant...
Definition BulkKinetics.cpp:429
Cantera::BulkKinetics::modifyReaction
void modifyReaction(size_t i, shared_ptr< Reaction > rNew) override
Modify the rate expression associated with a reaction.
Definition BulkKinetics.cpp:100
Cantera::BulkKinetics::getFwdRatesOfProgress_ddC
void getFwdRatesOfProgress_ddC(double *drop) override
Calculate derivatives for forward rates-of-progress with respect to molar concentration at constant t...
Definition BulkKinetics.cpp:368
Cantera::BulkKinetics::process_ddC
void process_ddC(StoichManagerN &stoich, const vector< double > &in, double *drop, bool mass_action=true)
Process concentration (molar density) derivative.
Definition BulkKinetics.cpp:624
Cantera::BulkKinetics::process_ddP
void process_ddP(const vector< double > &in, double *drop)
Process pressure derivative.
Definition BulkKinetics.cpp:615
Cantera::BulkKinetics::getFwdRateConstants_ddP
void getFwdRateConstants_ddP(double *dkfwd) override
Calculate derivatives for forward rate constants with respect to pressure at constant temperature,...
Definition BulkKinetics.cpp:333
Cantera::BulkKinetics::getRevRatesOfProgress_ddP
void getRevRatesOfProgress_ddP(double *drop) override
Calculate derivatives for reverse rates-of-progress with respect to pressure at constant temperature,...
Definition BulkKinetics.cpp:347
Cantera::BulkKinetics::getRevRatesOfProgress_ddC
void getRevRatesOfProgress_ddC(double *drop) override
Calculate derivatives for reverse rates-of-progress with respect to molar concentration at constant t...
Definition BulkKinetics.cpp:375
Cantera::BulkKinetics::m_rbuf0
vector< double > m_rbuf0
Buffers for partial rop results with length nReactions()
Definition BulkKinetics.h:185
Cantera::BulkKinetics::m_irrev
vector< size_t > m_irrev
Indices of irreversible reactions.
Definition BulkKinetics.h:159
Cantera::BulkKinetics::m_multi_concm
ThirdBodyCalc m_multi_concm
used with MultiRate evaluator
Definition BulkKinetics.h:166
Cantera::BulkKinetics::applyEquilibriumConstants_ddT
void applyEquilibriumConstants_ddT(double *drkcn)
Multiply rate with scaled temperature derivatives of the inverse equilibrium constant.
Definition BulkKinetics.cpp:571
Cantera::BulkKinetics::resizeReactions
void resizeReactions() override
Finalize Kinetics object and associated objects.
Definition BulkKinetics.cpp:136
Cantera::BulkKinetics::netRatesOfProgress_ddCi
Eigen::SparseMatrix< double > netRatesOfProgress_ddCi() override
Calculate derivatives for net rates-of-progress with respect to species concentration at constant tem...
Definition BulkKinetics.cpp:450
Cantera::BulkKinetics::getThirdBodyConcentrations
void getThirdBodyConcentrations(double *concm) override
Return a vector of values of effective concentrations of third-body collision partners of any reactio...
Definition BulkKinetics.cpp:548
Cantera::BulkKinetics::getDeltaEntropy
void getDeltaEntropy(double *deltaS) override
Return the vector of values for the reactions change in entropy.
Definition BulkKinetics.cpp:227
Cantera::BulkKinetics::m_concm
vector< double > m_concm
Third body concentrations.
Definition BulkKinetics.h:169
Cantera::BulkKinetics::m_kf0
vector< double > m_kf0
Forward rate constants without perturbation.
Definition BulkKinetics.h:188
Cantera::BulkKinetics::setDerivativeSettings
void setDerivativeSettings(const AnyMap &settings) override
Set/modify derivative settings.
Definition BulkKinetics.cpp:277
Cantera::BulkKinetics::getFwdRateConstants_ddC
void getFwdRateConstants_ddC(double *dkfwd) override
Calculate derivatives for forward rate constants with respect to molar concentration at constant temp...
Definition BulkKinetics.cpp:361
Cantera::Kinetics
Public interface for kinetics managers.
Definition Kinetics.h:126
Cantera::Kinetics::thermo
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
Cantera::StoichManagerN
This class handles operations involving the stoichiometric coefficients on one side of a reaction (re...
Definition StoichManager.h:589
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition ThermoPhase.h:390
Cantera::ThirdBodyCalc
Calculate and apply third-body effects on reaction rates, including non- unity third-body efficiencie...
Definition ThirdBodyCalc.h:20
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564