Cantera  4.0.0a2
Loading...
Searching...
No Matches
Kinetics.h
Go to the documentation of this file.
1/**
2 * @file Kinetics.h
3 * Base class for kinetics managers and also contains the kineticsmgr
4 * module documentation (see @ref kineticsmgr and class
5 * @link Cantera::Kinetics Kinetics@endlink).
6 */
7
8// This file is part of Cantera. See License.txt in the top-level directory or
9// at https://cantera.org/license.txt for license and copyright information.
10
11#ifndef CT_KINETICS_H
12#define CT_KINETICS_H
13
14#include "StoichManager.h"
16#include "MultiRate.h"
17
18namespace Cantera
19{
20
21class ThermoPhase;
22class Reaction;
23class Solution;
24class AnyMap;
25
26//! @defgroup derivGroup Derivative Calculations
27//! @details Methods for calculating analytical and/or numerical derivatives.
28
29/**
30 * @defgroup chemkinetics Chemical Kinetics
31 */
32
33//! @defgroup reactionGroup Reactions and Reaction Rates
34//! Classes for handling reactions and reaction rates.
35//! @ingroup chemkinetics
36
37//! @defgroup kineticsmgr Kinetics Managers
38//! Classes implementing models for chemical kinetics.
39//! @section kinmodman Models and Managers
40//!
41//! A kinetics manager is a C++ class that implements a kinetics model; a
42//! kinetics model is a set of mathematical equation describing how various
43//! kinetic quantities are to be computed -- reaction rates, species production
44//! rates, etc. Many different kinetics models might be defined to handle
45//! different types of kinetic processes. For example, one kinetics model might
46//! use expressions valid for elementary reactions in ideal gas mixtures. It
47//! might, for example, require the reaction orders to be integral and equal to
48//! the forward stoichiometric coefficients, require that each reaction be
49//! reversible with a reverse rate satisfying detailed balance, include
50//! pressure-dependent unimolecular reactions, etc. Another kinetics model might
51//! be designed for heterogeneous chemistry at interfaces, and might allow
52//! empirical reaction orders, coverage-dependent activation energies,
53//! irreversible reactions, and include effects of potential differences across
54//! the interface on reaction rates.
55//!
56//! A kinetics manager implements a kinetics model. Since the model equations
57//! may be complex and expensive to evaluate, a kinetics manager may adopt
58//! various strategies to 'manage' the computation and evaluate the expressions
59//! efficiently. For example, if there are rate coefficients or other quantities
60//! that depend only on temperature, a manager class may choose to store these
61//! quantities internally, and re-evaluate them only when the temperature has
62//! actually changed. Or a manager designed for use with reaction mechanisms
63//! with a few repeated activation energies might precompute the terms @f$
64//! \exp(-E/RT) @f$, instead of evaluating the exponential repeatedly for each
65//! reaction. There are many other possible 'management styles', each of which
66//! might be better suited to some reaction mechanisms than others.
67//!
68//! But however a manager structures the internal computation, the tasks the
69//! manager class must perform are, for the most part, the same. It must be able
70//! to compute reaction rates, species production rates, equilibrium constants,
71//! etc. Therefore, all kinetics manager classes should have a common set of
72//! public methods, but differ in how they implement these methods.
73//!
74//! A kinetics manager computes reaction rates of progress, species production
75//! rates, equilibrium constants, and similar quantities for a reaction
76//! mechanism. All kinetics manager classes derive from class Kinetics, which
77//! defines a common public interface for all kinetics managers. Each derived
78//! class overloads the virtual methods of Kinetics to implement a particular
79//! kinetics model.
80//!
81//! For example, class BulkKinetics implements reaction rate expressions appropriate for
82//! homogeneous reactions, and class InterfaceKinetics implements expressions
83//! appropriate for heterogeneous mechanisms at interfaces, including how to handle
84//! reactions involving charged species of phases with different electric potentials ---
85//! something that class BulkKinetics doesn't deal with at all.
86//!
87//! Many of the methods of class Kinetics write into arrays the values of some
88//! quantity for each species, for example the net production rate. These
89//! methods always write the results into flat arrays, ordered by phase in the
90//! order the phase was added, and within a phase in the order the species were
91//! added to the phase (which is the same ordering as in the input file).
92//! For example, suppose a heterogeneous mechanism involves three phases -- a surface
93//! phase 's' surrounded by two bulk phases 'a' and 'b'. The surface defines 5 adsorbed
94//! species, phase 'a' contains 12 species, and phase 'b' contains 3. Then methods like
95//! `getNetProductionRates(span<double> net)` will write an output array of length 20,
96//! beginning at the start of the span. The first 5 values will be the net production
97//! rates for all 5 species of phase 's' (even if some do not participate in the
98//! reactions); the next 12 will be for phase 'a', and finally the net production rates
99//! for phase 'b' will occupy the last 3 locations.
100//! @ingroup chemkinetics
101
102//! @defgroup rateEvaluators Rate Evaluators
103//! These classes are used to evaluate the rates of reactions.
104//! @ingroup chemkinetics
105
106
107//! Public interface for kinetics managers.
108/*!
109 * This class serves as a base class to derive 'kinetics managers', which are
110 * classes that manage homogeneous chemistry within one phase, or heterogeneous
111 * chemistry at one interface. The virtual methods of this class are meant to be
112 * overloaded in subclasses. The non-virtual methods perform generic functions
113 * and are implemented in Kinetics. They should not be overloaded. Only those
114 * methods required by a subclass need to be overloaded; the rest will throw
115 * exceptions if called.
116 *
117 * When the nomenclature "kinetics species index" is used below, this means that
118 * the species index ranges over all species in all phases handled by the
119 * kinetics manager.
120 *
121 * @ingroup kineticsmgr
122 */
124{
125public:
126 //! @name Constructors and General Information about Mechanism
127 //! @{
128
129 //! Default constructor.
130 Kinetics() = default;
131
132 virtual ~Kinetics() = default;
133
134 //! Kinetics objects are not copyable or assignable
135 Kinetics(const Kinetics&) = delete;
136 Kinetics& operator=(const Kinetics&)= delete;
137
138 //! Create a new Kinetics object with the same kinetics model and reactions as
139 //! this one.
140 //! @param phases Phases used to specify the state for the newly cloned Kinetics
141 //! object. These can be created from the phases used by this object using the
142 //! ThermoPhase::clone() method.
143 //! @since New in %Cantera 3.2.
144 shared_ptr<Kinetics> clone(const vector<shared_ptr<ThermoPhase>>& phases) const;
145
146 //! Identifies the Kinetics manager type.
147 //! Each class derived from Kinetics should override this method to return
148 //! a meaningful identifier.
149 //! @since Starting in %Cantera 3.0, the name returned by this method corresponds
150 //! to the canonical name used in the YAML input format.
151 virtual string kineticsType() const {
152 return "none";
153 }
154
155 //! Finalize Kinetics object and associated objects
156 virtual void resizeReactions();
157
158 //! Number of reactions in the reaction mechanism.
159 size_t nReactions() const {
160 return m_reactions.size();
161 }
162
163 //! Check that the specified reaction index is in range
164 /*!
165 * @since Starting in %Cantera 3.2, returns the input reaction index, if valid.
166 * @exception Throws an IndexError if m is greater than nReactions()-1
167 */
168 size_t checkReactionIndex(size_t m) const;
169
170 //! Check that the specified species index is in range
171 /*!
172 * @since Starting in %Cantera 3.2, returns the input species index, if valid.
173 * @exception Throws an IndexError if k is greater than nSpecies()-1
174 */
175 size_t checkSpeciesIndex(size_t k) const;
176
177 //! @}
178 //! @name Information/Lookup Functions about Phases and Species
179 //! @{
180
181 /**
182 * The number of phases participating in the reaction mechanism. For a
183 * homogeneous reaction mechanism, this will always return 1, but for a
184 * heterogeneous mechanism it will return the total number of phases in the
185 * mechanism.
186 */
187 size_t nPhases() const {
188 return m_thermo.size();
189 }
190
191 //! Check that the specified phase index is in range
192 /*!
193 * @since Starting in %Cantera 3.2, returns the input phase index, if valid.
194 * @exception Throws an IndexError if m is greater than nPhases()-1
195 */
196 size_t checkPhaseIndex(size_t m) const;
197
198 /**
199 * Return the index of a phase among the phases participating in this kinetic
200 * mechanism.
201 *
202 * @param ph string name of the phase
203 * @param raise If `true`, raise exception if the specified phase is not defined
204 * in the Kinetics object.
205 * @since Added the `raise` argument in %Cantera 3.2. In %Cantera 4.0, changed the
206 * default value of `raise` to `true`.
207 * @exception Throws a CanteraError if the specified phase is not found and
208 * `raise` is `true`.
209 */
210 size_t phaseIndex(const string& ph, bool raise=true) const;
211
212 /**
213 * Return pointer to phase where the reactions occur.
214 * @since New in %Cantera 3.0
215 */
216 shared_ptr<ThermoPhase> reactionPhase() const;
217
218 /**
219 * Return pointer to phase associated with Kinetics by index.
220 * @param n Index of the ThermoPhase being sought.
221 * @since New in %Cantera 3.2.
222 * @see thermo
223 */
224 shared_ptr<ThermoPhase> phase(size_t n=0) const {
225 return m_thermo[n];
226 }
227
228 /**
229 * This method returns a reference to the nth ThermoPhase object defined
230 * in this kinetics mechanism. It is typically used so that member
231 * functions of the ThermoPhase object may be called. For homogeneous
232 * mechanisms, there is only one object, and this method can be called
233 * without an argument to access it.
234 *
235 * @param n Index of the ThermoPhase being sought.
236 */
237 ThermoPhase& thermo(size_t n=0) {
238 return *m_thermo[n];
239 }
240 const ThermoPhase& thermo(size_t n=0) const {
241 return *m_thermo[n];
242 }
243
244 /**
245 * The total number of species in all phases participating in the kinetics
246 * mechanism. This is useful to dimension arrays for use in calls to
247 * methods that return the species production rates, for example.
248 */
249 size_t nTotalSpecies() const {
250 return m_kk;
251 }
252
253 /**
254 * The location of species k of phase n in species arrays. Kinetics manager
255 * classes return species production rates in flat arrays, with the species
256 * of each phases following one another, in the order the phases were added.
257 * This method is useful to find the value for a particular species of a
258 * particular phase in arrays returned from methods like getCreationRates
259 * that return an array of species-specific quantities.
260 *
261 * Example: suppose a heterogeneous mechanism involves three phases. The
262 * first contains 12 species, the second 26, and the third 3. Then species
263 * arrays must have size at least 41, and positions 0 - 11 are the values
264 * for the species in the first phase, positions 12 - 37 are the values for
265 * the species in the second phase, etc. Then kineticsSpeciesIndex(7, 0) =
266 * 7, kineticsSpeciesIndex(4, 1) = 16, and kineticsSpeciesIndex(2, 2) = 40.
267 *
268 * @param k species index
269 * @param n phase index for the species
270 */
271 size_t kineticsSpeciesIndex(size_t k, size_t n) const {
272 return m_start[n] + k;
273 }
274
275 size_t speciesOffset(const ThermoPhase& phase) const;
276
277 //! Return the name of the kth species in the kinetics manager.
278 /*!
279 * k is an integer from 0 to ktot - 1, where ktot is the number of
280 * species in the kinetics manager, which is the sum of the number of
281 * species in all phases participating in the kinetics manager.
282 *
283 * @param k species index
284 * @exception Throws an IndexError if the specified species index is out of bounds
285 * @since Starting in %Cantera 4.0, this method throws an exception if the
286 * species index is out of bounds instead of returning "<unknown>".
287 */
288 string kineticsSpeciesName(size_t k) const;
289
290 /**
291 * Return the index of a species within the phases participating in this kinetic
292 * mechanism.
293 * This routine will look up a species number based on the input string `nm`. The
294 * lookup of species will occur for all phases listed in the Kinetics object.
295 * @param nm Name of the species.
296 * @param raise If `true`, raise exception if the specified species is not defined
297 * in the Kinetics object.
298 * @since Added the `raise` argument in %Cantera 3.2. In %Cantera 4.0, changed the
299 * default value of `raise` to `true`.
300 * @exception Throws a CanteraError if the specified species is not found and
301 * `raise` is `true`.
302 */
303 size_t kineticsSpeciesIndex(const string& nm, bool raise=true) const;
304
305 /**
306 * This function looks up the name of a species and returns a
307 * reference to the ThermoPhase object of the phase where the species
308 * resides. Will throw an error if the species doesn't match.
309 *
310 * @param nm String containing the name of the species.
311 */
312 ThermoPhase& speciesPhase(const string& nm);
313 const ThermoPhase& speciesPhase(const string& nm) const;
314
315 /**
316 * This function takes as an argument the kineticsSpecies index
317 * (that is, the list index in the list of species in the kinetics
318 * manager) and returns the species' owning ThermoPhase object.
319 *
320 * @param k Species index
321 */
323 return thermo(speciesPhaseIndex(k));
324 }
325
326 /**
327 * This function takes as an argument the kineticsSpecies index (that is, the
328 * list index in the list of species in the kinetics manager) and returns
329 * the index of the phase owning the species.
330 *
331 * @param k Species index
332 */
333 size_t speciesPhaseIndex(size_t k) const;
334
335 //! @}
336 //! @name Reaction Rates Of Progress
337 //! @{
338
339 //! Return the forward rates of progress of the reactions
340 /*!
341 * Forward rates of progress. Return the forward rates of
342 * progress in array fwdROP, which must be dimensioned at
343 * least as large as the total number of reactions.
344 *
345 * @param fwdROP Output vector containing forward rates
346 * of progress of the reactions. Length: nReactions().
347 */
348 virtual void getFwdRatesOfProgress(span<double> fwdROP);
349
350 //! Return the Reverse rates of progress of the reactions
351 /*!
352 * Return the reverse rates of progress in array revROP, which must be
353 * dimensioned at least as large as the total number of reactions.
354 *
355 * @param revROP Output vector containing reverse rates
356 * of progress of the reactions. Length: nReactions().
357 */
358 virtual void getRevRatesOfProgress(span<double> revROP);
359
360 /**
361 * Net rates of progress. Return the net (forward - reverse) rates of
362 * progress in array netROP, which must be dimensioned at least as large
363 * as the total number of reactions.
364 *
365 * @param netROP Output vector of the net ROP. Length: nReactions().
366 */
367 virtual void getNetRatesOfProgress(span<double> netROP);
368
369 //! Get the vector of equilibrium constants in concentration units.
370 /*!
371 * The equilibrium constant for reaction *i* is defined as
372 * @f[
373 * K_{c,i} = \exp \left( -\frac{\Delta G^\circ_i}{RT}
374 * + \sum_k \nu_{k,i} \ln C^\circ_k
375 * - \frac{F}{RT} \sum_k \nu_{k,i} z_k \phi_{p(k)} \right)
376 * @f]
377 * where @f$ \Delta G^\circ_i @f$ is the standard state Gibbs free energy change for
378 * reaction *i*, @f$ \nu_{k,i} @f$ is the stoichiometric coefficient of species *k*
379 * in reaction *i*, @f$ C^\circ_k @f$ is the standard concentration for species *k*,
380 * @f$ z_k @f$ is the charge of species *k*, @f$ \phi_{p(k)} @f$ is the electric
381 * potential of the phase containing species *k*, and @f$ F @f$ is the
382 * Faraday constant. The final term is included only for reactions involving species
383 * in multiple phases (InterfaceKinetics), since it is otherwise identically zero.
384 * @param[out] kc Vector of equilibrium constants in concentration units;
385 * length nReactions().
386 */
387 virtual void getEquilibriumConstants(span<double> kc) {
388 throw NotImplementedError("Kinetics::getEquilibriumConstants");
389 }
390
391 /**
392 * Change in species properties. Given an array of molar species property
393 * values @f$ z_k, k = 1, \dots, K @f$, return the array of reaction values
394 * @f[
395 * \Delta Z_i = \sum_k \nu_{k,i} z_k, i = 1, \dots, I.
396 * @f]
397 * For example, if this method is called with the array of standard-state
398 * molar Gibbs free energies for the species, then the values returned in
399 * array @c deltaProperty would be the standard-state Gibbs free energies of
400 * reaction for each reaction.
401 *
402 * @param property Input vector of property value. Length: #m_kk.
403 * @param deltaProperty Output vector of deltaRxn. Length: nReactions().
404 */
405 virtual void getReactionDelta(span<const double> property,
406 span<double> deltaProperty) const;
407
408 /**
409 * Given an array of species properties 'g', return in array 'dg' the
410 * change in this quantity in the reversible reactions. Array 'g' must
411 * have a length at least as great as the number of species, and array
412 * 'dg' must have a length as great as the total number of reactions.
413 * This method only computes 'dg' for the reversible reactions, and the
414 * entries of 'dg' for the irreversible reactions are unaltered. This is
415 * primarily designed for use in calculating reverse rate coefficients
416 * from thermochemistry for reversible reactions.
417 */
418 virtual void getRevReactionDelta(span<const double> g, span<double> dg) const;
419
420 //! Return the vector of values for the reaction Gibbs free energy change.
421 /*!
422 * (virtual from Kinetics.h)
423 * These values depend upon the concentration of the solution.
424 *
425 * units = J kmol-1
426 *
427 * @param deltaG Output vector of deltaG's for reactions Length:
428 * nReactions().
429 */
430 virtual void getDeltaGibbs(span<double> deltaG) {
431 throw NotImplementedError("Kinetics::getDeltaGibbs");
432 }
433
434 //! Return the vector of values for the reaction electrochemical free
435 //! energy change.
436 /*!
437 * These values depend upon the concentration of the solution and the
438 * voltage of the phases
439 *
440 * units = J kmol-1
441 *
442 * @param deltaM Output vector of deltaM's for reactions Length:
443 * nReactions().
444 */
445 virtual void getDeltaElectrochemPotentials(span<double> deltaM) {
446 throw NotImplementedError("Kinetics::getDeltaElectrochemPotentials");
447 }
448
449 /**
450 * Return the vector of values for the reactions change in enthalpy.
451 * These values depend upon the concentration of the solution.
452 *
453 * units = J kmol-1
454 *
455 * @param deltaH Output vector of deltaH's for reactions Length:
456 * nReactions().
457 */
458 virtual void getDeltaEnthalpy(span<double> deltaH) {
459 throw NotImplementedError("Kinetics::getDeltaEnthalpy");
460 }
461
462 /**
463 * Return the vector of values for the reactions change in entropy. These
464 * values depend upon the concentration of the solution.
465 *
466 * units = J kmol-1 Kelvin-1
467 *
468 * @param deltaS Output vector of deltaS's for reactions Length:
469 * nReactions().
470 */
471 virtual void getDeltaEntropy(span<double> deltaS) {
472 throw NotImplementedError("Kinetics::getDeltaEntropy");
473 }
474
475 /**
476 * Return the vector of values for the reaction standard state Gibbs free
477 * energy change. These values don't depend upon the concentration of the
478 * solution.
479 *
480 * units = J kmol-1
481 *
482 * @param deltaG Output vector of ss deltaG's for reactions Length:
483 * nReactions().
484 */
485 virtual void getDeltaSSGibbs(span<double> deltaG) {
486 throw NotImplementedError("Kinetics::getDeltaSSGibbs");
487 }
488
489 /**
490 * Return the vector of values for the change in the standard state
491 * enthalpies of reaction. These values don't depend upon the concentration
492 * of the solution.
493 *
494 * units = J kmol-1
495 *
496 * @param deltaH Output vector of ss deltaH's for reactions Length:
497 * nReactions().
498 */
499 virtual void getDeltaSSEnthalpy(span<double> deltaH) {
500 throw NotImplementedError("Kinetics::getDeltaSSEnthalpy");
501 }
502
503 /**
504 * Return the vector of values for the change in the standard state
505 * entropies for each reaction. These values don't depend upon the
506 * concentration of the solution.
507 *
508 * units = J kmol-1 Kelvin-1
509 *
510 * @param deltaS Output vector of ss deltaS's for reactions Length:
511 * nReactions().
512 */
513 virtual void getDeltaSSEntropy(span<double> deltaS) {
514 throw NotImplementedError("Kinetics::getDeltaSSEntropy");
515 }
516
517 /**
518 * Return a vector of values of effective concentrations of third-body
519 * collision partners of any reaction. Entries for reactions not involving
520 * third-body collision partners are not defined and set to not-a-number.
521 *
522 * @param concm Output vector of effective third-body concentrations.
523 * Length: nReactions().
524 */
525 virtual void getThirdBodyConcentrations(span<double> concm) {
526 throw NotImplementedError("Kinetics::getThirdBodyConcentrations",
527 "Not applicable/implemented for Kinetics object of type '{}'",
528 kineticsType());
529 }
530
531 /**
532 * Provide direct access to current third-body concentration values.
533 * @see getThirdBodyConcentrations.
534 */
535 virtual span<const double> thirdBodyConcentrations() const {
536 throw NotImplementedError("Kinetics::thirdBodyConcentrations",
537 "Not applicable/implemented for Kinetics object of type '{}'",
538 kineticsType());
539 return {};
540 }
541
542 //! @}
543 //! @name Species Production Rates
544 //! @{
545
546 /**
547 * Species creation rates [kmol/m^3/s or kmol/m^2/s]. Return the species
548 * creation rates in array cdot, which must be dimensioned at least as
549 * large as the total number of species in all phases. @see nTotalSpecies.
550 *
551 * @param cdot Output vector of creation rates. Length: #m_kk.
552 */
553 virtual void getCreationRates(span<double> cdot);
554
555 /**
556 * Species destruction rates [kmol/m^3/s or kmol/m^2/s]. Return the species
557 * destruction rates in array ddot, which must be dimensioned at least as
558 * large as the total number of species. @see nTotalSpecies.
559 *
560 * @param ddot Output vector of destruction rates. Length: #m_kk.
561 */
562 virtual void getDestructionRates(span<double> ddot);
563
564 /**
565 * Species net production rates [kmol/m^3/s or kmol/m^2/s]. Return the
566 * species net production rates (creation - destruction) in array wdot,
567 * which must be dimensioned at least as large as the total number of
568 * species. @see nTotalSpecies.
569 *
570 * @param wdot Output vector of net production rates. Length: #m_kk.
571 */
572 virtual void getNetProductionRates(span<double> wdot);
573
574 //! @}
575
576 //! @addtogroup derivGroup
577 //! @{
578
579 /**
580 * @anchor kinDerivs
581 * @par Routines to Calculate Kinetics Derivatives (Jacobians)
582 * @name
583 *
584 * Kinetics derivatives are calculated with respect to temperature, pressure,
585 * molar concentrations and species mole fractions for forward/reverse/net rates
586 * of progress as well as creation/destruction and net production of species.
587 *
588 * The following suffixes are used to indicate derivatives:
589 * - `_ddT`: derivative with respect to temperature (a vector)
590 * - `_ddP`: derivative with respect to pressure (a vector)
591 * - `_ddC`: derivative with respect to molar concentration (a vector)
592 * - `_ddX`: derivative with respect to species mole fractions (a matrix)
593 * - `_ddCi`: derivative with respect to species concentrations (a matrix)
594 *
595 * @since New in Cantera 2.6
596 *
597 * @warning The calculation of kinetics derivatives is an experimental part of the
598 * %Cantera API and may be changed or removed without notice.
599 *
600 * Source term derivatives are based on a generic rate-of-progress expression
601 * for the @f$ i @f$-th reaction @f$ R_i @f$, which is a function of temperature
602 * @f$ T @f$, pressure @f$ P @f$ and molar concentrations @f$ C_j @f$:
603 * @f[
604 * R_i = k_{f,i} C_M^{\nu_{M,i}} \prod_j C_j^{\nu_{ji}^\prime} -
605 * k_{r,i} C_M^{\nu_{M,i}} \prod_j C_j^{\nu_{ji}^{\prime\prime}}
606 * @f]
607 * Forward/reverse rate expressions @f$ k_{f,i} @f$ and @f$ k_{r,i} @f$ are
608 * implemented by ReactionRate specializations; forward/reverse stoichiometric
609 * coefficients are @f$ \nu_{ji}^\prime @f$ and @f$ \nu_{ji}^{\prime\prime} @f$.
610 * Unless the reaction involves third-body colliders, @f$ \nu_{M,i} = 0 @f$.
611 * For three-body reactions, effective ThirdBody collider concentrations @f$ C_M @f$
612 * are considered with @f$ \nu_{M,i} = 1 @f$. For more detailed information on
613 * relevant theory, see, for example, Perini, et al. @cite perini2012 or Niemeyer,
614 * et al. @cite niemeyer2017, although specifics of %Cantera's implementation may
615 * differ.
616 *
617 * Partial derivatives are obtained from the product rule, where resulting terms
618 * consider reaction rate derivatives, derivatives of the concentration product
619 * term, and, if applicable, third-body term derivatives. ReactionRate
620 * specializations may implement exact derivatives (example:
621 * ArrheniusRate::ddTScaledFromStruct) or approximate them numerically (examples:
622 * ReactionData::perturbTemperature, PlogData::perturbPressure,
623 * FalloffData::perturbThirdBodies). Derivatives of concentration and third-body
624 * terms are based on analytic expressions.
625 *
626 * %Species creation and destruction rates are obtained by multiplying
627 * rate-of-progress vectors by stoichiometric coefficient matrices. As this is a
628 * linear operation, it is possible to calculate derivatives the same way.
629 *
630 * All derivatives are calculated for source terms while holding other properties
631 * constant, independent of whether equation of state or @f$ \sum X_k = 1 @f$
632 * constraints are satisfied. Thus, derivatives deviate from Jacobians and
633 * numerical derivatives that implicitly enforce these constraints. Depending
634 * on application and equation of state, derivatives can nevertheless be used to
635 * obtain Jacobians, for example:
636 *
637 * - The Jacobian of net production rates @f$ \dot{\omega}_{k,\mathrm{net}} @f$
638 * with respect to temperature at constant pressure needs to consider changes
639 * of molar density @f$ C @f$ due to temperature
640 * @f[
641 * \left.
642 * \frac{\partial \dot{\omega}_{k,\mathrm{net}}}{\partial T}
643 * \right|_{P=\mathrm{const}} =
644 * \frac{\partial \dot{\omega}_{k,\mathrm{net}}}{\partial T} +
645 * \frac{\partial \dot{\omega}_{k,\mathrm{net}}}{\partial C}
646 * \left. \frac{\partial C}{\partial T} \right|_{P=\mathrm{const}}
647 * @f]
648 * where for an ideal gas @f$ \partial C / \partial T = - C / T @f$. The
649 * remaining partial derivatives are obtained from getNetProductionRates_ddT()
650 * and getNetProductionRates_ddC(), respectively.
651 *
652 * - The Jacobian of @f$ \dot{\omega}_{k,\mathrm{net}} @f$ with respect to
653 * temperature at constant volume needs to consider pressure changes due to
654 * temperature
655 * @f[
656 * \left.
657 * \frac{\partial \dot{\omega}_{k,\mathrm{net}}}{\partial T}
658 * \right|_{V=\mathrm{const}} =
659 * \frac{\partial \dot{\omega}_{k,\mathrm{net}}}{\partial T} +
660 * \frac{\partial \dot{\omega}_{k,\mathrm{net}}}{\partial P}
661 * \left. \frac{\partial P}{\partial T} \right|_{V=\mathrm{const}}
662 * @f]
663 * where for an ideal gas @f$ \partial P / \partial T = P / T @f$. The
664 * remaining partial derivatives are obtained from getNetProductionRates_ddT()
665 * and getNetProductionRates_ddP(), respectively.
666 *
667 * - Similar expressions can be derived for other derivatives and source terms.
668 *
669 * While some applications require exact derivatives, others can tolerate
670 * approximate derivatives that neglect terms to increase computational speed
671 * and/or improve Jacobian sparsity (example: AdaptivePreconditioner).
672 * Derivative evaluations settings are accessible by keyword/value pairs
673 * using the methods getDerivativeSettings() and setDerivativeSettings().
674 *
675 * For BulkKinetics, the following keyword/value pairs are supported:
676 * - `skip-third-bodies` (boolean): if `false` (default), third body
677 * concentrations are considered for the evaluation of Jacobians
678 * - `skip-falloff` (boolean): if `false` (default), third-body effects
679 * on rate constants are considered for the evaluation of derivatives.
680 * - `skip-nonideal` (boolean): if `false` (default), derivatives are only
681 * supported for ideal ThermoPhase models; if `true`, derivatives for
682 * non-ideal phases are evaluated using idealized approximations that
683 * neglect non-ideal contributions.
684 * - `rtol-delta` (double): relative tolerance used to perturb properties
685 * when calculating numerical derivatives. The default value is 1e-8.
686 *
687 * For InterfaceKinetics, the following keyword/value pairs are supported:
688 * - `skip-coverage-dependence` (boolean): if `false` (default), rate constant
689 * coverage dependence is not considered when evaluating derivatives.
690 * - `skip-electrochemistry` (boolean): if `false` (default), electrical charge
691 * is not considered in evaluating the derivatives and these reactions are
692 * treated as normal surface reactions.
693 * - `rtol-delta` (double): relative tolerance used to perturb properties
694 * when calculating numerical derivatives. The default value is 1e-8.
695 *
696 * @{
697 */
698
699 /**
700 * Retrieve derivative settings.
701 *
702 * @param settings AnyMap containing settings determining derivative evaluation.
703 */
704 virtual void getDerivativeSettings(AnyMap& settings) const
705 {
706 throw NotImplementedError("Kinetics::getDerivativeSettings",
707 "Not implemented for kinetics type '{}'.", kineticsType());
708 }
709
710 /**
711 * Set/modify derivative settings.
712 *
713 * @param settings AnyMap containing settings determining derivative evaluation.
714 */
715 virtual void setDerivativeSettings(const AnyMap& settings)
716 {
717 throw NotImplementedError("Kinetics::setDerivativeSettings",
718 "Not implemented for kinetics type '{}'.", kineticsType());
719 }
720
721 /**
722 * Calculate derivatives for forward rate constants with respect to temperature
723 * at constant pressure, molar concentration and mole fractions
724 * @param[out] dkfwd Output vector of derivatives. Length: nReactions().
725 */
726 virtual void getFwdRateConstants_ddT(span<double> dkfwd)
727 {
728 throw NotImplementedError("Kinetics::getFwdRateConstants_ddT",
729 "Not implemented for kinetics type '{}'.", kineticsType());
730 }
731
732 /**
733 * Calculate derivatives for forward rate constants with respect to pressure
734 * at constant temperature, molar concentration and mole fractions.
735 * @param[out] dkfwd Output vector of derivatives. Length: nReactions().
736 */
737 virtual void getFwdRateConstants_ddP(span<double> dkfwd)
738 {
739 throw NotImplementedError("Kinetics::getFwdRateConstants_ddP",
740 "Not implemented for kinetics type '{}'.", kineticsType());
741 }
742
743 /**
744 * Calculate derivatives for forward rate constants with respect to molar
745 * concentration at constant temperature, pressure and mole fractions.
746 * @param[out] dkfwd Output vector of derivatives. Length: nReactions().
747 *
748 * @warning This method is an experimental part of the %Cantera API and
749 * may be changed or removed without notice.
750 */
751 virtual void getFwdRateConstants_ddC(span<double> dkfwd)
752 {
753 throw NotImplementedError("Kinetics::getFwdRateConstants_ddC",
754 "Not implemented for kinetics type '{}'.", kineticsType());
755 }
756
757 /**
758 * Calculate derivatives for forward rates-of-progress with respect to temperature
759 * at constant pressure, molar concentration and mole fractions.
760 * @param[out] drop Output vector of derivatives. Length: nReactions().
761 */
762 virtual void getFwdRatesOfProgress_ddT(span<double> drop)
763 {
764 throw NotImplementedError("Kinetics::getFwdRatesOfProgress_ddT",
765 "Not implemented for kinetics type '{}'.", kineticsType());
766 }
767
768 /**
769 * Calculate derivatives for forward rates-of-progress with respect to pressure
770 * at constant temperature, molar concentration and mole fractions.
771 * @param[out] drop Output vector of derivatives. Length: nReactions().
772 */
773 virtual void getFwdRatesOfProgress_ddP(span<double> drop)
774 {
775 throw NotImplementedError("Kinetics::getFwdRatesOfProgress_ddP",
776 "Not implemented for kinetics type '{}'.", kineticsType());
777 }
778
779 /**
780 * Calculate derivatives for forward rates-of-progress with respect to molar
781 * concentration at constant temperature, pressure and mole fractions.
782 * @param[out] drop Output vector of derivatives. Length: nReactions().
783 *
784 * @warning This method is an experimental part of the %Cantera API and
785 * may be changed or removed without notice.
786 */
787 virtual void getFwdRatesOfProgress_ddC(span<double> drop)
788 {
789 throw NotImplementedError("Kinetics::getFwdRatesOfProgress_ddC",
790 "Not implemented for kinetics type '{}'.", kineticsType());
791 }
792
793 /**
794 * Calculate derivatives for forward rates-of-progress with respect to species
795 * mole fractions at constant temperature, pressure and molar concentration.
796 *
797 * The method returns a matrix with nReactions() rows and nTotalSpecies() columns.
798 * For a derivative with respect to @f$ X_i @f$, all other @f$ X_j @f$ are held
799 * constant, rather than enforcing @f$ \sum X_j = 1 @f$.
800 *
801 * @warning This method is an experimental part of the %Cantera API and
802 * may be changed or removed without notice.
803 */
804 virtual Eigen::SparseMatrix<double> fwdRatesOfProgress_ddX()
805 {
806 throw NotImplementedError("Kinetics::fwdRatesOfProgress_ddX",
807 "Not implemented for kinetics type '{}'.", kineticsType());
808 }
809
810 /**
811 * Calculate derivatives for forward rates-of-progress with respect to species
812 * concentration at constant temperature, pressure and remaining species
813 * concentrations.
814 *
815 * The method returns a matrix with nReactions() rows and nTotalSpecies() columns.
816 * For a derivative with respect to @f$ c_i @f$, all other @f$ c_j @f$ are held
817 * constant.
818 *
819 * @warning This method is an experimental part of the %Cantera API and
820 * may be changed or removed without notice.
821 *
822 * @since New in %Cantera 3.0.
823 */
824 virtual Eigen::SparseMatrix<double> fwdRatesOfProgress_ddCi()
825 {
826 throw NotImplementedError("Kinetics::fwdRatesOfProgress_ddCi",
827 "Not implemented for kinetics type '{}'.", kineticsType());
828 }
829
830 /**
831 * Calculate derivatives for reverse rates-of-progress with respect to temperature
832 * at constant pressure, molar concentration and mole fractions.
833 * @param[out] drop Output vector of derivatives. Length: nReactions().
834 */
835 virtual void getRevRatesOfProgress_ddT(span<double> drop)
836 {
837 throw NotImplementedError("Kinetics::getRevRatesOfProgress_ddT",
838 "Not implemented for kinetics type '{}'.", kineticsType());
839 }
840
841 /**
842 * Calculate derivatives for reverse rates-of-progress with respect to pressure
843 * at constant temperature, molar concentration and mole fractions.
844 * @param[out] drop Output vector of derivatives. Length: nReactions().
845 */
846 virtual void getRevRatesOfProgress_ddP(span<double> drop)
847 {
848 throw NotImplementedError("Kinetics::getRevRatesOfProgress_ddP",
849 "Not implemented for kinetics type '{}'.", kineticsType());
850 }
851
852 /**
853 * Calculate derivatives for reverse rates-of-progress with respect to molar
854 * concentration at constant temperature, pressure and mole fractions.
855 * @param[out] drop Output vector of derivatives. Length: nReactions().
856 *
857 * @warning This method is an experimental part of the %Cantera API and
858 * may be changed or removed without notice.
859 */
860 virtual void getRevRatesOfProgress_ddC(span<double> drop)
861 {
862 throw NotImplementedError("Kinetics::getRevRatesOfProgress_ddC",
863 "Not implemented for kinetics type '{}'.", kineticsType());
864 }
865
866 /**
867 * Calculate derivatives for reverse rates-of-progress with respect to species
868 * mole fractions at constant temperature, pressure and molar concentration.
869 *
870 * The method returns a matrix with nReactions() rows and nTotalSpecies() columns.
871 * For a derivative with respect to @f$ X_i @f$, all other @f$ X_j @f$ are held
872 * constant, rather than enforcing @f$ \sum X_j = 1 @f$.
873 *
874 * @warning This method is an experimental part of the %Cantera API and
875 * may be changed or removed without notice.
876 */
877 virtual Eigen::SparseMatrix<double> revRatesOfProgress_ddX()
878 {
879 throw NotImplementedError("Kinetics::revRatesOfProgress_ddX",
880 "Not implemented for kinetics type '{}'.", kineticsType());
881 }
882
883 /**
884 * Calculate derivatives for forward rates-of-progress with respect to species
885 * concentration at constant temperature, pressure and remaining species
886 * concentrations.
887 *
888 * The method returns a matrix with nReactions() rows and nTotalSpecies() columns.
889 * For a derivative with respect to @f$ c_i @f$, all other @f$ c_j @f$ are held
890 * constant.
891 *
892 * @warning This method is an experimental part of the %Cantera API and
893 * may be changed or removed without notice.
894 *
895 * @since New in %Cantera 3.0.
896 */
897 virtual Eigen::SparseMatrix<double> revRatesOfProgress_ddCi()
898 {
899 throw NotImplementedError("Kinetics::revRatesOfProgress_ddCi",
900 "Not implemented for kinetics type '{}'.", kineticsType());
901 }
902
903 /**
904 * Calculate derivatives for net rates-of-progress with respect to temperature
905 * at constant pressure, molar concentration and mole fractions.
906 * @param[out] drop Output vector of derivatives. Length: nReactions().
907 */
908 virtual void getNetRatesOfProgress_ddT(span<double> drop)
909 {
910 throw NotImplementedError("Kinetics::getNetRatesOfProgress_ddT",
911 "Not implemented for kinetics type '{}'.", kineticsType());
912 }
913
914 /**
915 * Calculate derivatives for net rates-of-progress with respect to pressure
916 * at constant temperature, molar concentration and mole fractions.
917 * @param[out] drop Output vector of derivatives. Length: nReactions().
918 */
919 virtual void getNetRatesOfProgress_ddP(span<double> drop)
920 {
921 throw NotImplementedError("Kinetics::getNetRatesOfProgress_ddP",
922 "Not implemented for kinetics type '{}'.", kineticsType());
923 }
924
925 /**
926 * Calculate derivatives for net rates-of-progress with respect to molar
927 * concentration at constant temperature, pressure and mole fractions.
928 * @param[out] drop Output vector of derivatives. Length: nReactions().
929 *
930 * @warning This method is an experimental part of the %Cantera API and
931 * may be changed or removed without notice.
932 */
933 virtual void getNetRatesOfProgress_ddC(span<double> drop)
934 {
935 throw NotImplementedError("Kinetics::getNetRatesOfProgress_ddC",
936 "Not implemented for kinetics type '{}'.", kineticsType());
937 }
938
939 /**
940 * Calculate derivatives for net rates-of-progress with respect to species
941 * mole fractions at constant temperature, pressure and molar concentration.
942 *
943 * The method returns a matrix with nReactions() rows and nTotalSpecies() columns.
944 * For a derivative with respect to @f$ X_i @f$, all other @f$ X_j @f$ are held
945 * constant, rather than enforcing @f$ \sum X_j = 1 @f$.
946 *
947 * @warning This method is an experimental part of the %Cantera API and
948 * may be changed or removed without notice.
949 */
950 virtual Eigen::SparseMatrix<double> netRatesOfProgress_ddX()
951 {
952 throw NotImplementedError("Kinetics::netRatesOfProgress_ddX",
953 "Not implemented for kinetics type '{}'.", kineticsType());
954 }
955
956 /**
957 * Calculate derivatives for net rates-of-progress with respect to species
958 * concentration at constant temperature, pressure, and remaining species
959 * concentrations.
960 *
961 * The method returns a matrix with nReactions() rows and nTotalSpecies() columns.
962 * For a derivative with respect to @f$ c_i @f$, all other @f$ c_j @f$ are held
963 * constant.
964 *
965 * @warning This method is an experimental part of the %Cantera API and
966 * may be changed or removed without notice.
967 *
968 * @since New in %Cantera 3.0.
969 */
970 virtual Eigen::SparseMatrix<double> netRatesOfProgress_ddCi()
971 {
972 throw NotImplementedError("Kinetics::netRatesOfProgress_ddCi",
973 "Not implemented for kinetics type '{}'.", kineticsType());
974 }
975
976 /**
977 * Calculate derivatives for species creation rates with respect to temperature
978 * at constant pressure, molar concentration and mole fractions.
979 * @param[out] dwdot Output vector of derivatives. Length: #m_kk.
980 */
981 void getCreationRates_ddT(span<double> dwdot);
982
983 /**
984 * Calculate derivatives for species creation rates with respect to pressure
985 * at constant temperature, molar concentration and mole fractions.
986 * @param[out] dwdot Output vector of derivatives. Length: #m_kk.
987 */
988 void getCreationRates_ddP(span<double> dwdot);
989
990 /**
991 * Calculate derivatives for species creation rates with respect to molar
992 * concentration at constant temperature, pressure and mole fractions.
993 * @param[out] dwdot Output vector of derivatives. Length: #m_kk.
994 *
995 * @warning This method is an experimental part of the %Cantera API and
996 * may be changed or removed without notice.
997 */
998 void getCreationRates_ddC(span<double> dwdot);
999
1000 /**
1001 * Calculate derivatives for species creation rates with respect to species
1002 * mole fractions at constant temperature, pressure and molar concentration.
1003 *
1004 * The method returns a square matrix with nTotalSpecies() rows and columns.
1005 * For a derivative with respect to @f$ X_i @f$, all other @f$ X_j @f$ are held
1006 * constant, rather than enforcing @f$ \sum X_j = 1 @f$.
1007 *
1008 * @warning This method is an experimental part of the %Cantera API and
1009 * may be changed or removed without notice.
1010 */
1011 Eigen::SparseMatrix<double> creationRates_ddX();
1012
1013 /**
1014 * Calculate derivatives for species creation rates with respect to species
1015 * concentration at constant temperature, pressure, and concentration of all other
1016 * species.
1017 *
1018 * The method returns a square matrix with nTotalSpecies() rows and columns.
1019 * For a derivative with respect to @f$ c_i @f$, all other @f$ c_j @f$ are held
1020 * constant.
1021 *
1022 * @warning This method is an experimental part of the %Cantera API and
1023 * may be changed or removed without notice.
1024 *
1025 * @since New in %Cantera 3.0.
1026 */
1027 Eigen::SparseMatrix<double> creationRates_ddCi();
1028
1029 /**
1030 * Calculate derivatives for species destruction rates with respect to temperature
1031 * at constant pressure, molar concentration and mole fractions.
1032 * @param[out] dwdot Output vector of derivatives. Length: #m_kk.
1033 */
1034 void getDestructionRates_ddT(span<double> dwdot);
1035
1036 /**
1037 * Calculate derivatives for species destruction rates with respect to pressure
1038 * at constant temperature, molar concentration and mole fractions.
1039 * @param[out] dwdot Output vector of derivatives. Length: #m_kk.
1040 */
1041 void getDestructionRates_ddP(span<double> dwdot);
1042
1043 /**
1044 * Calculate derivatives for species destruction rates with respect to molar
1045 * concentration at constant temperature, pressure and mole fractions.
1046 * @param[out] dwdot Output vector of derivatives. Length: #m_kk.
1047 *
1048 * @warning This method is an experimental part of the %Cantera API and
1049 * may be changed or removed without notice.
1050 */
1051 void getDestructionRates_ddC(span<double> dwdot);
1052
1053 /**
1054 * Calculate derivatives for species destruction rates with respect to species
1055 * mole fractions at constant temperature, pressure and molar concentration.
1056 *
1057 * The method returns a square matrix with nTotalSpecies() rows and columns.
1058 * For a derivative with respect to @f$ X_i @f$, all other @f$ X_j @f$ are held
1059 * constant, rather than enforcing @f$ \sum X_j = 1 @f$.
1060 *
1061 * @warning This method is an experimental part of the %Cantera API and
1062 * may be changed or removed without notice.
1063 */
1064 Eigen::SparseMatrix<double> destructionRates_ddX();
1065
1066 /**
1067 * Calculate derivatives for species destruction rates with respect to species
1068 * concentration at constant temperature, pressure, and concentration of all other
1069 * species.
1070 *
1071 * The method returns a square matrix with nTotalSpecies() rows and columns.
1072 * For a derivative with respect to @f$ c_i @f$, all other @f$ c_j @f$ are held
1073 * constant.
1074 *
1075 * @warning This method is an experimental part of the %Cantera API and
1076 * may be changed or removed without notice.
1077 *
1078 * @since New in %Cantera 3.0.
1079 */
1080 Eigen::SparseMatrix<double> destructionRates_ddCi();
1081
1082 /**
1083 * Calculate derivatives for species net production rates with respect to
1084 * temperature at constant pressure, molar concentration and mole fractions.
1085 * @param[out] dwdot Output vector of derivatives. Length: #m_kk.
1086 */
1087 void getNetProductionRates_ddT(span<double> dwdot);
1088
1089 /**
1090 * Calculate derivatives for species net production rates with respect to pressure
1091 * at constant temperature, molar concentration and mole fractions.
1092 * @param[out] dwdot Output vector of derivatives. Length: #m_kk.
1093 */
1094 void getNetProductionRates_ddP(span<double> dwdot);
1095
1096 /**
1097 * Calculate derivatives for species net production rates with respect to molar
1098 * concentration at constant temperature, pressure and mole fractions.
1099 * @param[out] dwdot Output vector of derivatives. Length: #m_kk.
1100 *
1101 * @warning This method is an experimental part of the %Cantera API and
1102 * may be changed or removed without notice.
1103 */
1104 void getNetProductionRates_ddC(span<double> dwdot);
1105
1106 /**
1107 * Calculate derivatives for species net production rates with respect to species
1108 * mole fractions at constant temperature, pressure and molar concentration.
1109 *
1110 * The method returns a square matrix with nTotalSpecies() rows and columns.
1111 * For a derivative with respect to @f$ X_i @f$, all other @f$ X_j @f$ are held
1112 * constant, rather than enforcing @f$ \sum X_j = 1 @f$.
1113 *
1114 * @warning This method is an experimental part of the %Cantera API and
1115 * may be changed or removed without notice.
1116 */
1117 Eigen::SparseMatrix<double> netProductionRates_ddX();
1118
1119 /**
1120 * Calculate derivatives for species net production rates with respect to species
1121 * concentration at constant temperature, pressure, and concentration of all other
1122 * species.
1123 *
1124 * The method returns a square matrix with nTotalSpecies() rows and columns.
1125 * For a derivative with respect to @f$ c_i @f$, all other @f$ c_j @f$ are held
1126 * constant.
1127 *
1128 * @warning This method is an experimental part of the %Cantera API and
1129 * may be changed or removed without notice.
1130 *
1131 * @since New in %Cantera 3.0.
1132 */
1133 Eigen::SparseMatrix<double> netProductionRates_ddCi();
1134
1135 /** @} End of Kinetics Derivatives */
1136 //! @} End of addtogroup derivGroup
1137
1138 //! @name Reaction Mechanism Informational Query Routines
1139 //! @{
1140
1141 /**
1142 * Stoichiometric coefficient of species k as a reactant in reaction i.
1143 *
1144 * @param k kinetic species index
1145 * @param i reaction index
1146 */
1147 virtual double reactantStoichCoeff(size_t k, size_t i) const;
1148
1149 /**
1150 * Stoichiometric coefficient matrix for reactants.
1151 */
1152 Eigen::SparseMatrix<double> reactantStoichCoeffs() const {
1154 }
1155
1156 /**
1157 * Stoichiometric coefficient of species k as a product in reaction i.
1158 *
1159 * @param k kinetic species index
1160 * @param i reaction index
1161 */
1162 virtual double productStoichCoeff(size_t k, size_t i) const;
1163
1164 /**
1165 * Stoichiometric coefficient matrix for products.
1166 */
1167 Eigen::SparseMatrix<double> productStoichCoeffs() const {
1169 }
1170
1171 /**
1172 * Stoichiometric coefficient matrix for products of reversible reactions.
1173 */
1174 Eigen::SparseMatrix<double> revProductStoichCoeffs() const {
1176 }
1177
1178 //! Reactant order of species k in reaction i.
1179 /*!
1180 * This is the nominal order of the activity concentration in
1181 * determining the forward rate of progress of the reaction
1182 *
1183 * @param k kinetic species index
1184 * @param i reaction index
1185 */
1186 virtual double reactantOrder(size_t k, size_t i) const {
1187 throw NotImplementedError("Kinetics::reactantOrder");
1188 }
1189
1190 //! product Order of species k in reaction i.
1191 /*!
1192 * This is the nominal order of the activity concentration of species k in
1193 * determining the reverse rate of progress of the reaction i
1194 *
1195 * For irreversible reactions, this will all be zero.
1196 *
1197 * @param k kinetic species index
1198 * @param i reaction index
1199 */
1200 virtual double productOrder(int k, int i) const {
1201 throw NotImplementedError("Kinetics::productOrder");
1202 }
1203
1204 /**
1205 * True if reaction i has been declared to be reversible. If isReversible(i)
1206 * is false, then the reverse rate of progress for reaction i is always
1207 * zero.
1208 *
1209 * @param i reaction index
1210 */
1211 bool isReversible(size_t i) const {
1212 return std::find(m_revindex.begin(), m_revindex.end(), i) < m_revindex.end();
1213 }
1214
1215 /**
1216 * Return the forward rate constants
1217 *
1218 * The computed values include all temperature-dependent and pressure-dependent
1219 * contributions. By default, third-body concentrations are only considered if
1220 * they are part of the reaction rate definition; for a legacy implementation that
1221 * includes third-body concentrations see Cantera::use_legacy_rate_constants().
1222 * Length is the number of reactions. Units are a combination of kmol, m^3 and s,
1223 * that depend on the rate expression for the reaction.
1224 *
1225 * @param kfwd Output vector containing the forward reaction rate
1226 * constants. Length: nReactions().
1227 */
1228 virtual void getFwdRateConstants(span<double> kfwd) {
1229 throw NotImplementedError("Kinetics::getFwdRateConstants");
1230 }
1231
1232 /**
1233 * Return the reverse rate constants.
1234 *
1235 * The computed values include all temperature-dependent and pressure-dependent
1236 * contributions. By default, third-body concentrations are only considered if
1237 * they are part of the reaction rate definition; for a legacy implementation that
1238 * includes third-body concentrations see Cantera::use_legacy_rate_constants().
1239 * Length is the number of reactions. Units are a combination of kmol, m^3 and s,
1240 * that depend on the rate expression for the reaction. Note, this routine will
1241 * return rate constants for irreversible reactions if the default for
1242 * `doIrreversible` is overridden.
1243 *
1244 * @param krev Output vector of reverse rate constants
1245 * @param doIrreversible boolean indicating whether irreversible reactions
1246 * should be included.
1247 */
1248 virtual void getRevRateConstants(span<double> krev, bool doIrreversible = false) {
1249 throw NotImplementedError("Kinetics::getRevRateConstants");
1250 }
1251
1252 //! @}
1253 //! @name Reaction Mechanism Construction
1254 //! @{
1255
1256 //! Add a phase to the kinetics manager object.
1257 /*!
1258 * This must be done before the function init() is called or before any
1259 * reactions are input. The following fields are updated:
1260 *
1261 * - #m_start -> vector of integers, containing the starting position of
1262 * the species for each phase in the kinetics mechanism.
1263 * - #m_thermo -> vector of pointers to ThermoPhase phases that
1264 * participate in the kinetics mechanism.
1265 * - #m_phaseindex -> map containing the string id of each
1266 * ThermoPhase phase as a key and the index of the phase within the
1267 * kinetics manager object as the value.
1268 *
1269 * @param thermo Reference to the ThermoPhase to be added.
1270 * @since New in %Cantera 3.0. Replaces addPhase.
1271 */
1272 virtual void addThermo(shared_ptr<ThermoPhase> thermo);
1273
1274 /**
1275 * Prepare the class for the addition of reactions, after all phases have
1276 * been added. This method is called automatically when the first reaction
1277 * is added. It needs to be called directly only in the degenerate case
1278 * where there are no reactions. The base class method does nothing, but
1279 * derived classes may use this to perform any initialization (allocating
1280 * arrays, etc.) that requires knowing the phases.
1281 */
1282 virtual void init() {}
1283
1284 //! Set kinetics-related parameters from an AnyMap phase description.
1285 //! @since New in %Cantera 3.2.
1286 virtual void setParameters(const AnyMap& phaseNode);
1287
1288 //! Return the parameters for a phase definition which are needed to
1289 //! reconstruct an identical object using the newKinetics function. This
1290 //! excludes the reaction definitions, which are handled separately.
1291 AnyMap parameters() const;
1292
1293 /**
1294 * Resize arrays with sizes that depend on the total number of species.
1295 * Automatically called before adding each Reaction and Phase.
1296 */
1297 virtual void resizeSpecies();
1298
1299 /**
1300 * Add a single reaction to the mechanism. Derived classes should call the
1301 * base class method in addition to handling their own specialized behavior.
1302 *
1303 * @param r Pointer to the Reaction object to be added.
1304 * @param resize If `true`, resizeReactions is called after reaction is added.
1305 * @return `true` if the reaction is added or `false` if it was skipped
1306 */
1307 virtual bool addReaction(shared_ptr<Reaction> r, bool resize=true);
1308
1309 /**
1310 * Modify the rate expression associated with a reaction. The
1311 * stoichiometric equation, type of the reaction, reaction orders, third
1312 * body efficiencies, reversibility, etc. must be unchanged.
1313 *
1314 * @param i Index of the reaction to be modified
1315 * @param rNew Reaction with the new rate expressions
1316 */
1317 virtual void modifyReaction(size_t i, shared_ptr<Reaction> rNew);
1318
1319 /**
1320 * Return the Reaction object for reaction *i*. Changes to this object do
1321 * not affect the Kinetics object until the #modifyReaction function is
1322 * called.
1323 */
1324 shared_ptr<Reaction> reaction(size_t i);
1325
1326 shared_ptr<const Reaction> reaction(size_t i) const;
1327
1328 //! Determine behavior when adding a new reaction that contains species not
1329 //! defined in any of the phases associated with this kinetics manager. If
1330 //! set to true, the reaction will silently be ignored. If false, (the
1331 //! default) an exception will be raised.
1332 void skipUndeclaredSpecies(bool skip) {
1334 }
1335 bool skipUndeclaredSpecies() const {
1337 }
1338
1339 //! Determine behavior when adding a new reaction that contains third-body
1340 //! efficiencies for species not defined in any of the phases associated
1341 //! with this kinetics manager. If set to true, the given third-body
1342 //! efficiency will be ignored. If false, (the default) an exception will be
1343 //! raised.
1346 }
1347 bool skipUndeclaredThirdBodies() const {
1349 }
1350
1351 //! Specify how to handle duplicate third body reactions where one reaction
1352 //! has an explicit third body and the other has the generic third body with a
1353 //! non-zero efficiency for the former third body. Options are "warn" (default),
1354 //! "error", "mark-duplicate", and "modify-efficiency".
1355 void setExplicitThirdBodyDuplicateHandling(const string& flag);
1356 string explicitThirdBodyDuplicateHandling() const {
1357 return m_explicit_third_body_duplicates;
1358 }
1359
1360 //! @}
1361 //! @name Altering Reaction Rates
1362 //!
1363 //! These methods alter reaction rates. They are designed primarily for
1364 //! carrying out sensitivity analysis, but may be used for any purpose
1365 //! requiring dynamic alteration of rate constants. For each reaction, a
1366 //! real-valued multiplier may be defined that multiplies the reaction rate
1367 //! coefficient. The multiplier may be set to zero to completely remove a
1368 //! reaction from the mechanism.
1369 //! @{
1370
1371 //! The current value of the multiplier for reaction i.
1372 /*!
1373 * @param i index of the reaction
1374 */
1375 double multiplier(size_t i) const {
1376 return m_perturb[i];
1377 }
1378
1379 //! Set the multiplier for reaction i to f.
1380 /*!
1381 * @param i index of the reaction
1382 * @param f value of the multiplier.
1383 */
1384 virtual void setMultiplier(size_t i, double f) {
1385 m_perturb[i] = f;
1386 }
1387
1388 virtual void invalidateCache() {
1389 m_cache.clear();
1390 };
1391
1392 //! @}
1393 //! Check for unmarked duplicate reactions and unmatched marked duplicates
1394 //!
1395 //! @param throw_err If `true`, raise an exception that identifies any unmarked
1396 //! duplicate reactions and any reactions marked as duplicate that do not
1397 //! actually have a matching reaction.
1398 //! @param fix If `true` (and if `throw_err` is false), update the `duplicate`
1399 //! flag on all reactions to correctly indicate whether or not they are
1400 //! duplicates.
1401 //! @return If `throw_err` and `fix` are `false`, the indices of the first pair
1402 //! of duplicate reactions or the index of an unmatched duplicate as both
1403 //! elements of the `pair`. Otherwise, `(npos, npos)` if no errors were detected
1404 //! or if the errors were fixed.
1405 //! @since The `fix` argument was added in %Cantera 3.2.
1406 virtual pair<size_t, size_t> checkDuplicates(bool throw_err=true, bool fix=false);
1407
1408 //! Set root Solution holding all phase information
1409 virtual void setRoot(shared_ptr<Solution> root) {
1410 m_root = root;
1411 }
1412
1413 //! Get the Solution object containing this Kinetics object and associated
1414 //! ThermoPhase objects
1415 shared_ptr<Solution> root() const {
1416 return m_root.lock();
1417 }
1418
1419 //! Register a function to be called if reaction is added.
1420 //! @param id A unique ID corresponding to the object affected by the callback.
1421 //! Typically, this is a pointer to an object that also holds a reference to the
1422 //! Kinetics object.
1423 //! @param callback The callback function to be called after any reaction is added.
1424 //! When the callback becomes invalid (for example, the corresponding object is
1425 //! being deleted, the removeReactionAddedCallback() method must be invoked.
1426 //! @since New in %Cantera 3.1
1427 void registerReactionAddedCallback(void* id, const function<void()>& callback)
1428 {
1429 m_reactionAddedCallbacks[id] = callback;
1430 }
1431
1432 //! Remove the reaction-changed callback function associated with the specified object.
1433 //! @since New in %Cantera 3.1
1435 {
1436 m_reactionAddedCallbacks.erase(id);
1437 }
1438
1439protected:
1440 //! Cache for saved calculations within each Kinetics object.
1442
1443 // Update internal rate-of-progress variables #m_ropf and #m_ropr.
1444 virtual void updateROP() {
1445 throw NotImplementedError("Kinetics::updateROP");
1446 }
1447
1448 //! Check whether `r1` and `r2` represent duplicate stoichiometries
1449 //! This function returns a ratio if two reactions are duplicates of
1450 //! one another, and 0.0 otherwise.
1451 /*!
1452 * `r1` and `r2` are maps of species key to stoichiometric coefficient, one
1453 * for each reaction, where the species key is `1+k` for reactants and
1454 * `-1-k` for products and `k` is the species index.
1455 *
1456 * @return 0.0 if the stoichiometries are not multiples of one another
1457 * Otherwise, it returns the ratio of the stoichiometric coefficients.
1458 */
1459 double checkDuplicateStoich(map<int, double>& r1, map<int, double>& r2) const;
1460
1461 //! Vector of rate handlers
1462 vector<unique_ptr<MultiRateBase>> m_rateHandlers;
1463 map<string, size_t> m_rateTypes; //!< Mapping of rate handlers
1464
1465 //! @name Stoichiometry management
1466 //!
1467 //! These objects and functions handle turning reaction extents into species
1468 //! production rates and also handle turning thermo properties into reaction
1469 //! thermo properties.
1470 //! @{
1471
1472 //! Stoichiometry manager for the reactants for each reaction
1474
1475 //! Stoichiometry manager for the products for each reaction
1477
1478 //! Stoichiometry manager for the products of reversible reactions
1480
1481 //! Net stoichiometry (products - reactants)
1482 Eigen::SparseMatrix<double> m_stoichMatrix;
1483 //! @}
1484
1485 //! The number of species in all of the phases
1486 //! that participate in this kinetics mechanism.
1487 size_t m_kk = 0;
1488
1489 //! Vector of perturbation factors for each reaction's rate of
1490 //! progress vector. It is initialized to one.
1491 vector<double> m_perturb;
1492
1493 //! Default values for perturbations defined in the phase definition's
1494 //! `rate-multipliers` field. Key -1 contains the default multiplier.
1495 map<size_t, double> m_defaultPerturb = {{-1, 1.0}};
1496
1497 //! Vector of Reaction objects represented by this Kinetics manager
1498 vector<shared_ptr<Reaction>> m_reactions;
1499
1500 //! m_thermo is a vector of pointers to ThermoPhase objects that are
1501 //! involved with this kinetics operator
1502 /*!
1503 * For homogeneous kinetics applications, this vector will only have one
1504 * entry. For interfacial reactions, this vector will consist of multiple
1505 * entries; some of them will be surface phases, and the other ones will be
1506 * bulk phases. The order that the objects are listed determines the order
1507 * in which the species comprising each phase are listed in the source term
1508 * vector, originating from the reaction mechanism.
1509 */
1510 vector<shared_ptr<ThermoPhase>> m_thermo;
1511
1512 /**
1513 * m_start is a vector of integers specifying the beginning position for the
1514 * species vector for the n'th phase in the kinetics class.
1515 */
1516 vector<size_t> m_start;
1517
1518 /**
1519 * Mapping of the phase name to the position of the phase within the
1520 * kinetics object. Positions start with the value of 1. The member
1521 * function, phaseIndex() decrements by one before returning the index
1522 * value, so that missing phases return -1.
1523 */
1524 map<string, size_t> m_phaseindex;
1525
1526 //! number of spatial dimensions of lowest-dimensional phase.
1527 size_t m_mindim = 4;
1528
1529 //! Forward rate constant for each reaction
1530 vector<double> m_rfn;
1531
1532 //! Delta G^0 for all reactions
1533 vector<double> m_delta_gibbs0;
1534
1535 //! Reciprocal of the equilibrium constant in concentration units
1536 vector<double> m_rkcn;
1537
1538 //! Forward rate-of-progress for each reaction
1539 vector<double> m_ropf;
1540
1541 //! Reverse rate-of-progress for each reaction
1542 vector<double> m_ropr;
1543
1544 //! Net rate-of-progress for each reaction
1545 vector<double> m_ropnet;
1546
1547 vector<size_t> m_revindex; //!< Indices of reversible reactions
1548 vector<size_t> m_irrev; //!< Indices of irreversible reactions
1549
1550 //! The enthalpy change for each reaction to calculate Blowers-Masel rates
1551 vector<double> m_dH;
1552
1553 //! Buffer used for storage of intermediate reaction-specific results
1554 vector<double> m_rbuf;
1555
1556 //! See skipUndeclaredSpecies()
1558
1559 //! See skipUndeclaredThirdBodies()
1561
1562 //! Flag indicating whether reactions include undeclared third bodies
1564
1565
1566 string m_explicit_third_body_duplicates = "warn";
1567
1568 //! reference to Solution
1569 std::weak_ptr<Solution> m_root;
1570
1571 //! Callback functions that are invoked when the reaction is added.
1572 map<void*, function<void()>> m_reactionAddedCallbacks;
1573};
1574
1575}
1576
1577#endif
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:431
Public interface for kinetics managers.
Definition Kinetics.h:124
shared_ptr< ThermoPhase > phase(size_t n=0) const
Return pointer to phase associated with Kinetics by index.
Definition Kinetics.h:224
virtual void resizeReactions()
Finalize Kinetics object and associated objects.
Definition Kinetics.cpp:50
virtual void getRevRatesOfProgress(span< double > revROP)
Return the Reverse rates of progress of the reactions.
Definition Kinetics.cpp:382
Eigen::SparseMatrix< double > reactantStoichCoeffs() const
Stoichiometric coefficient matrix for reactants.
Definition Kinetics.h:1152
virtual void getNetRatesOfProgress(span< double > netROP)
Net rates of progress.
Definition Kinetics.cpp:389
double multiplier(size_t i) const
The current value of the multiplier for reaction i.
Definition Kinetics.h:1375
virtual void setParameters(const AnyMap &phaseNode)
Set kinetics-related parameters from an AnyMap phase description.
Definition Kinetics.cpp:631
virtual void getDeltaSSEnthalpy(span< double > deltaH)
Return the vector of values for the change in the standard state enthalpies of reaction.
Definition Kinetics.h:499
size_t checkPhaseIndex(size_t m) const
Check that the specified phase index is in range.
Definition Kinetics.cpp:67
Kinetics(const Kinetics &)=delete
Kinetics objects are not copyable or assignable.
ThermoPhase & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism.
Definition Kinetics.h:237
vector< shared_ptr< Reaction > > m_reactions
Vector of Reaction objects represented by this Kinetics manager.
Definition Kinetics.h:1498
double checkDuplicateStoich(map< int, double > &r1, map< int, double > &r2) const
Check whether r1 and r2 represent duplicate stoichiometries This function returns a ratio if two reac...
Definition Kinetics.cpp:253
ValueCache m_cache
Cache for saved calculations within each Kinetics object.
Definition Kinetics.h:1441
vector< double > m_perturb
Vector of perturbation factors for each reaction's rate of progress vector.
Definition Kinetics.h:1491
vector< double > m_ropf
Forward rate-of-progress for each reaction.
Definition Kinetics.h:1539
virtual void getDeltaEntropy(span< double > deltaS)
Return the vector of values for the reactions change in entropy.
Definition Kinetics.h:471
void setExplicitThirdBodyDuplicateHandling(const string &flag)
Specify how to handle duplicate third body reactions where one reaction has an explicit third body an...
Definition Kinetics.cpp:100
vector< unique_ptr< MultiRateBase > > m_rateHandlers
Vector of rate handlers.
Definition Kinetics.h:1462
vector< size_t > m_start
m_start is a vector of integers specifying the beginning position for the species vector for the n'th...
Definition Kinetics.h:1516
virtual string kineticsType() const
Identifies the Kinetics manager type.
Definition Kinetics.h:151
virtual void getDeltaEnthalpy(span< double > deltaH)
Return the vector of values for the reactions change in enthalpy.
Definition Kinetics.h:458
vector< double > m_rkcn
Reciprocal of the equilibrium constant in concentration units.
Definition Kinetics.h:1536
shared_ptr< ThermoPhase > reactionPhase() const
Return pointer to phase where the reactions occur.
Definition Kinetics.cpp:87
virtual void getDeltaSSEntropy(span< double > deltaS)
Return the vector of values for the change in the standard state entropies for each reaction.
Definition Kinetics.h:513
size_t m_kk
The number of species in all of the phases that participate in this kinetics mechanism.
Definition Kinetics.h:1487
virtual pair< size_t, size_t > checkDuplicates(bool throw_err=true, bool fix=false)
Check for unmarked duplicate reactions and unmatched marked duplicates.
Definition Kinetics.cpp:112
virtual void getFwdRateConstants(span< double > kfwd)
Return the forward rate constants.
Definition Kinetics.h:1228
vector< double > m_dH
The enthalpy change for each reaction to calculate Blowers-Masel rates.
Definition Kinetics.h:1551
vector< double > m_ropr
Reverse rate-of-progress for each reaction.
Definition Kinetics.h:1542
virtual span< const double > thirdBodyConcentrations() const
Provide direct access to current third-body concentration values.
Definition Kinetics.h:535
size_t nPhases() const
The number of phases participating in the reaction mechanism.
Definition Kinetics.h:187
vector< shared_ptr< ThermoPhase > > m_thermo
m_thermo is a vector of pointers to ThermoPhase objects that are involved with this kinetics operator
Definition Kinetics.h:1510
map< void *, function< void()> > m_reactionAddedCallbacks
Callback functions that are invoked when the reaction is added.
Definition Kinetics.h:1572
AnyMap parameters() const
Return the parameters for a phase definition which are needed to reconstruct an identical object usin...
Definition Kinetics.cpp:648
size_t phaseIndex(const string &ph, bool raise=true) const
Return the index of a phase among the phases participating in this kinetic mechanism.
Definition Kinetics.cpp:75
virtual bool addReaction(shared_ptr< Reaction > r, bool resize=true)
Add a single reaction to the mechanism.
Definition Kinetics.cpp:704
vector< size_t > m_revindex
Indices of reversible reactions.
Definition Kinetics.h:1547
virtual void getThirdBodyConcentrations(span< double > concm)
Return a vector of values of effective concentrations of third-body collision partners of any reactio...
Definition Kinetics.h:525
void skipUndeclaredSpecies(bool skip)
Determine behavior when adding a new reaction that contains species not defined in any of the phases ...
Definition Kinetics.h:1332
string kineticsSpeciesName(size_t k) const
Return the name of the kth species in the kinetics manager.
Definition Kinetics.cpp:296
virtual void getEquilibriumConstants(span< double > kc)
Get the vector of equilibrium constants in concentration units.
Definition Kinetics.h:387
bool isReversible(size_t i) const
True if reaction i has been declared to be reversible.
Definition Kinetics.h:1211
virtual void getRevRateConstants(span< double > krev, bool doIrreversible=false)
Return the reverse rate constants.
Definition Kinetics.h:1248
virtual void getDeltaElectrochemPotentials(span< double > deltaM)
Return the vector of values for the reaction electrochemical free energy change.
Definition Kinetics.h:445
Kinetics()=default
Default constructor.
virtual void getDeltaSSGibbs(span< double > deltaG)
Return the vector of values for the reaction standard state Gibbs free energy change.
Definition Kinetics.h:485
virtual void init()
Prepare the class for the addition of reactions, after all phases have been added.
Definition Kinetics.h:1282
shared_ptr< Solution > root() const
Get the Solution object containing this Kinetics object and associated ThermoPhase objects.
Definition Kinetics.h:1415
bool m_skipUndeclaredThirdBodies
See skipUndeclaredThirdBodies()
Definition Kinetics.h:1560
virtual double reactantOrder(size_t k, size_t i) const
Reactant order of species k in reaction i.
Definition Kinetics.h:1186
virtual void modifyReaction(size_t i, shared_ptr< Reaction > rNew)
Modify the rate expression associated with a reaction.
Definition Kinetics.cpp:797
map< string, size_t > m_rateTypes
Mapping of rate handlers.
Definition Kinetics.h:1463
vector< double > m_ropnet
Net rate-of-progress for each reaction.
Definition Kinetics.h:1545
void skipUndeclaredThirdBodies(bool skip)
Determine behavior when adding a new reaction that contains third-body efficiencies for species not d...
Definition Kinetics.h:1344
virtual double productStoichCoeff(size_t k, size_t i) const
Stoichiometric coefficient of species k as a product in reaction i.
Definition Kinetics.cpp:370
virtual void addThermo(shared_ptr< ThermoPhase > thermo)
Add a phase to the kinetics manager object.
Definition Kinetics.cpp:614
virtual void getRevReactionDelta(span< const double > g, span< double > dg) const
Given an array of species properties 'g', return in array 'dg' the change in this quantity in the rev...
Definition Kinetics.cpp:408
Eigen::SparseMatrix< double > productStoichCoeffs() const
Stoichiometric coefficient matrix for products.
Definition Kinetics.h:1167
vector< double > m_rbuf
Buffer used for storage of intermediate reaction-specific results.
Definition Kinetics.h:1554
Eigen::SparseMatrix< double > m_stoichMatrix
Net stoichiometry (products - reactants)
Definition Kinetics.h:1482
bool m_skipUndeclaredSpecies
See skipUndeclaredSpecies()
Definition Kinetics.h:1557
map< string, size_t > m_phaseindex
Mapping of the phase name to the position of the phase within the kinetics object.
Definition Kinetics.h:1524
size_t m_mindim
number of spatial dimensions of lowest-dimensional phase.
Definition Kinetics.h:1527
StoichManagerN m_productStoich
Stoichiometry manager for the products for each reaction.
Definition Kinetics.h:1476
std::weak_ptr< Solution > m_root
reference to Solution
Definition Kinetics.h:1569
StoichManagerN m_revProductStoich
Stoichiometry manager for the products of reversible reactions.
Definition Kinetics.h:1479
shared_ptr< Kinetics > clone(const vector< shared_ptr< ThermoPhase > > &phases) const
Create a new Kinetics object with the same kinetics model and reactions as this one.
Definition Kinetics.cpp:27
Eigen::SparseMatrix< double > revProductStoichCoeffs() const
Stoichiometric coefficient matrix for products of reversible reactions.
Definition Kinetics.h:1174
size_t nReactions() const
Number of reactions in the reaction mechanism.
Definition Kinetics.h:159
map< size_t, double > m_defaultPerturb
Default values for perturbations defined in the phase definition's rate-multipliers field.
Definition Kinetics.h:1495
void removeReactionAddedCallback(void *id)
Remove the reaction-changed callback function associated with the specified object.
Definition Kinetics.h:1434
vector< size_t > m_irrev
Indices of irreversible reactions.
Definition Kinetics.h:1548
virtual void getNetProductionRates(span< double > wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
Definition Kinetics.cpp:447
virtual void getFwdRatesOfProgress(span< double > fwdROP)
Return the forward rates of progress of the reactions.
Definition Kinetics.cpp:375
virtual void setRoot(shared_ptr< Solution > root)
Set root Solution holding all phase information.
Definition Kinetics.h:1409
void registerReactionAddedCallback(void *id, const function< void()> &callback)
Register a function to be called if reaction is added.
Definition Kinetics.h:1427
bool m_hasUndeclaredThirdBodies
Flag indicating whether reactions include undeclared third bodies.
Definition Kinetics.h:1563
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
Definition Kinetics.h:271
virtual void getReactionDelta(span< const double > property, span< double > deltaProperty) const
Change in species properties.
Definition Kinetics.cpp:396
virtual double productOrder(int k, int i) const
product Order of species k in reaction i.
Definition Kinetics.h:1200
virtual void setMultiplier(size_t i, double f)
Set the multiplier for reaction i to f.
Definition Kinetics.h:1384
vector< double > m_rfn
Forward rate constant for each reaction.
Definition Kinetics.h:1530
size_t checkSpeciesIndex(size_t k) const
Check that the specified species index is in range.
Definition Kinetics.cpp:92
virtual void getDestructionRates(span< double > ddot)
Species destruction rates [kmol/m^3/s or kmol/m^2/s].
Definition Kinetics.cpp:435
virtual void getCreationRates(span< double > cdot)
Species creation rates [kmol/m^3/s or kmol/m^2/s].
Definition Kinetics.cpp:420
StoichManagerN m_reactantStoich
Stoichiometry manager for the reactants for each reaction.
Definition Kinetics.h:1473
virtual void getDeltaGibbs(span< double > deltaG)
Return the vector of values for the reaction Gibbs free energy change.
Definition Kinetics.h:430
virtual void resizeSpecies()
Resize arrays with sizes that depend on the total number of species.
Definition Kinetics.cpp:692
size_t nTotalSpecies() const
The total number of species in all phases participating in the kinetics mechanism.
Definition Kinetics.h:249
virtual double reactantStoichCoeff(size_t k, size_t i) const
Stoichiometric coefficient of species k as a reactant in reaction i.
Definition Kinetics.cpp:365
ThermoPhase & speciesPhase(const string &nm)
This function looks up the name of a species and returns a reference to the ThermoPhase object of the...
Definition Kinetics.cpp:333
vector< double > m_delta_gibbs0
Delta G^0 for all reactions.
Definition Kinetics.h:1533
size_t checkReactionIndex(size_t m) const
Check that the specified reaction index is in range.
Definition Kinetics.cpp:42
ThermoPhase & speciesPhase(size_t k)
This function takes as an argument the kineticsSpecies index (that is, the list index in the list of ...
Definition Kinetics.h:322
size_t speciesPhaseIndex(size_t k) const
This function takes as an argument the kineticsSpecies index (that is, the list index in the list of ...
Definition Kinetics.cpp:354
An error indicating that an unimplemented function has been called.
This class handles operations involving the stoichiometric coefficients on one side of a reaction (re...
const Eigen::SparseMatrix< double > & stoichCoeffs() const
Return matrix containing stoichiometric coefficients.
Base class for a phase with thermodynamic properties.
Storage for cached values.
Definition ValueCache.h:153
void clear()
Clear all cached values.
void getNetProductionRates_ddT(span< double > dwdot)
Calculate derivatives for species net production rates with respect to temperature at constant pressu...
Definition Kinetics.cpp:577
virtual void setDerivativeSettings(const AnyMap &settings)
Set/modify derivative settings.
Definition Kinetics.h:715
virtual void getFwdRatesOfProgress_ddC(span< double > drop)
Calculate derivatives for forward rates-of-progress with respect to molar concentration at constant t...
Definition Kinetics.h:787
virtual void getRevRatesOfProgress_ddT(span< double > drop)
Calculate derivatives for reverse rates-of-progress with respect to temperature at constant pressure,...
Definition Kinetics.h:835
virtual Eigen::SparseMatrix< double > fwdRatesOfProgress_ddCi()
Calculate derivatives for forward rates-of-progress with respect to species concentration at constant...
Definition Kinetics.h:824
virtual void getFwdRateConstants_ddP(span< double > dkfwd)
Calculate derivatives for forward rate constants with respect to pressure at constant temperature,...
Definition Kinetics.h:737
void getCreationRates_ddT(span< double > dwdot)
Calculate derivatives for species creation rates with respect to temperature at constant pressure,...
Definition Kinetics.cpp:459
Eigen::SparseMatrix< double > creationRates_ddCi()
Calculate derivatives for species creation rates with respect to species concentration at constant te...
Definition Kinetics.cpp:508
void getDestructionRates_ddT(span< double > dwdot)
Calculate derivatives for species destruction rates with respect to temperature at constant pressure,...
Definition Kinetics.cpp:518
virtual Eigen::SparseMatrix< double > netRatesOfProgress_ddCi()
Calculate derivatives for net rates-of-progress with respect to species concentration at constant tem...
Definition Kinetics.h:970
virtual Eigen::SparseMatrix< double > netRatesOfProgress_ddX()
Calculate derivatives for net rates-of-progress with respect to species mole fractions at constant te...
Definition Kinetics.h:950
void getCreationRates_ddP(span< double > dwdot)
Calculate derivatives for species creation rates with respect to pressure at constant temperature,...
Definition Kinetics.cpp:472
Eigen::SparseMatrix< double > destructionRates_ddX()
Calculate derivatives for species destruction rates with respect to species mole fractions at constan...
Definition Kinetics.cpp:557
void getNetProductionRates_ddC(span< double > dwdot)
Calculate derivatives for species net production rates with respect to molar concentration at constan...
Definition Kinetics.cpp:595
void getDestructionRates_ddC(span< double > dwdot)
Calculate derivatives for species destruction rates with respect to molar concentration at constant t...
Definition Kinetics.cpp:544
virtual void getRevRatesOfProgress_ddC(span< double > drop)
Calculate derivatives for reverse rates-of-progress with respect to molar concentration at constant t...
Definition Kinetics.h:860
Eigen::SparseMatrix< double > netProductionRates_ddX()
Calculate derivatives for species net production rates with respect to species mole fractions at cons...
Definition Kinetics.cpp:604
Eigen::SparseMatrix< double > creationRates_ddX()
Calculate derivatives for species creation rates with respect to species mole fractions at constant t...
Definition Kinetics.cpp:498
Eigen::SparseMatrix< double > destructionRates_ddCi()
Calculate derivatives for species destruction rates with respect to species concentration at constant...
Definition Kinetics.cpp:567
virtual Eigen::SparseMatrix< double > fwdRatesOfProgress_ddX()
Calculate derivatives for forward rates-of-progress with respect to species mole fractions at constan...
Definition Kinetics.h:804
virtual void getNetRatesOfProgress_ddT(span< double > drop)
Calculate derivatives for net rates-of-progress with respect to temperature at constant pressure,...
Definition Kinetics.h:908
virtual void getRevRatesOfProgress_ddP(span< double > drop)
Calculate derivatives for reverse rates-of-progress with respect to pressure at constant temperature,...
Definition Kinetics.h:846
virtual void getFwdRatesOfProgress_ddT(span< double > drop)
Calculate derivatives for forward rates-of-progress with respect to temperature at constant pressure,...
Definition Kinetics.h:762
virtual void getFwdRatesOfProgress_ddP(span< double > drop)
Calculate derivatives for forward rates-of-progress with respect to pressure at constant temperature,...
Definition Kinetics.h:773
virtual void getNetRatesOfProgress_ddC(span< double > drop)
Calculate derivatives for net rates-of-progress with respect to molar concentration at constant tempe...
Definition Kinetics.h:933
void getNetProductionRates_ddP(span< double > dwdot)
Calculate derivatives for species net production rates with respect to pressure at constant temperatu...
Definition Kinetics.cpp:586
Eigen::SparseMatrix< double > netProductionRates_ddCi()
Calculate derivatives for species net production rates with respect to species concentration at const...
Definition Kinetics.cpp:609
virtual void getDerivativeSettings(AnyMap &settings) const
Retrieve derivative settings.
Definition Kinetics.h:704
void getCreationRates_ddC(span< double > dwdot)
Calculate derivatives for species creation rates with respect to molar concentration at constant temp...
Definition Kinetics.cpp:485
virtual void getNetRatesOfProgress_ddP(span< double > drop)
Calculate derivatives for net rates-of-progress with respect to pressure at constant temperature,...
Definition Kinetics.h:919
virtual void getFwdRateConstants_ddC(span< double > dkfwd)
Calculate derivatives for forward rate constants with respect to molar concentration at constant temp...
Definition Kinetics.h:751
virtual Eigen::SparseMatrix< double > revRatesOfProgress_ddCi()
Calculate derivatives for forward rates-of-progress with respect to species concentration at constant...
Definition Kinetics.h:897
void getDestructionRates_ddP(span< double > dwdot)
Calculate derivatives for species destruction rates with respect to pressure at constant temperature,...
Definition Kinetics.cpp:531
virtual Eigen::SparseMatrix< double > revRatesOfProgress_ddX()
Calculate derivatives for reverse rates-of-progress with respect to species mole fractions at constan...
Definition Kinetics.h:877
virtual void getFwdRateConstants_ddT(span< double > dkfwd)
Calculate derivatives for forward rate constants with respect to temperature at constant pressure,...
Definition Kinetics.h:726
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595