Cantera  3.1.0a2
Loading...
Searching...
No Matches
ReactionData.h
Go to the documentation of this file.
1/**
2 * @file ReactionData.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_REACTIONDATA_H
9#define CT_REACTIONDATA_H
10
13
14namespace Cantera
15{
16
17class ThermoPhase;
18class Kinetics;
19
20
21//! Data container holding shared data used for ReactionRate calculation
22/**
23 * The base class defines variables and methods used by all specializations.
24 * @ingroup reactionGroup
25 */
27{
28 ReactionData() = default;
29
30 //! Update data container based on temperature *T*
31 /**
32 * Only used in conjunction with MultiRateBase::evalSingle / ReactionRate::eval.
33 * This method allows for testing of a reaction rate expression outside of
34 * Kinetics reaction rate evaluators.
35 */
36 virtual void update(double T) {
37 temperature = T;
38 logT = std::log(T);
39 recipT = 1./T;
40 }
41
42 //! Update data container based on temperature *T* and an *extra* parameter
43 /**
44 * Only used in conjunction with MultiRateBase::evalSingle / ReactionRate::eval.
45 * This method allows for testing of a reaction rate expression outside of
46 * Kinetics reaction rate evaluators.
47 */
48 virtual void update(double T, double extra) {
49 throw NotImplementedError("ReactionData::update",
50 "ReactionData type does not use extra scalar argument.");
51 }
52
53 //! Update data container based on temperature *T* and a vector parameter *extra*
54 /**
55 * Only used in conjunction with MultiRateBase::evalSingle / ReactionRate::eval.
56 * This method allows for testing of a reaction rate expression outside of
57 * Kinetics reaction rate evaluators.
58 *
59 * @warning This method is an experimental part of the %Cantera API and
60 * may be changed or removed without notice.
61 */
62 virtual void update(double T, const vector<double>& extra) {
63 throw NotImplementedError("ReactionData::update",
64 "ReactionData type does not use extra vector argument.");
65 }
66
67 //! Update data container based on thermodynamic phase state
68 /**
69 * This update mechanism is used by Kinetics reaction rate evaluators.
70 * @returns A boolean element indicating whether the `evalFromStruct` method
71 * needs to be called (assuming previously-calculated values were cached)
72 */
73 virtual bool update(const ThermoPhase& phase, const Kinetics& kin) = 0;
74
75 //! Perturb temperature of data container
76 /**
77 * The method is used for the evaluation of numerical derivatives.
78 * @param deltaT relative temperature perturbation
79 */
80 void perturbTemperature(double deltaT) {
81 if (m_temperature_buf > 0.) {
82 throw CanteraError("ReactionData::perturbTemperature",
83 "Cannot apply another perturbation as state is already perturbed.");
84 }
86 ReactionData::update(temperature * (1. + deltaT));
87 }
88
89 //! Restore data container after a perturbation
90 virtual void restore() {
91 // only restore if there is a valid buffered value
92 if (m_temperature_buf < 0.) {
93 return;
94 }
97 }
98
99 //! Update number of species, reactions and phases
100 virtual void resize(size_t nSpecies, size_t nReactions, size_t nPhases) {}
101
102 //! Force shared data and reaction rates to be updated next time. This is called by
103 //! functions that change quantities affecting rate calculations that are normally
104 //! assumed to be constant, like the reaction rate parameters or the number of
105 //! reactions.
106 virtual void invalidateCache() {
107 temperature = NAN;
108 }
109
110 double temperature = 1.0; //!< temperature
111 double logT = 0.0; //!< logarithm of temperature
112 double recipT = 1.0; //!< inverse of temperature
113
114protected:
115 double m_temperature_buf = -1.0; //!< buffered temperature
116};
117
118}
119
120#endif
Base class for exceptions thrown by Cantera classes.
Public interface for kinetics managers.
Definition Kinetics.h:125
An error indicating that an unimplemented function has been called.
Base class for a phase with thermodynamic properties.
This file contains definitions of constants, types and terms that are used in internal routines and a...
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
Data container holding shared data used for ReactionRate calculation.
double recipT
inverse of temperature
double m_temperature_buf
buffered temperature
virtual void update(double T, double extra)
Update data container based on temperature T and an extra parameter.
virtual bool update(const ThermoPhase &phase, const Kinetics &kin)=0
Update data container based on thermodynamic phase state.
void perturbTemperature(double deltaT)
Perturb temperature of data container.
virtual void update(double T)
Update data container based on temperature T
double temperature
temperature
double logT
logarithm of temperature
virtual void restore()
Restore data container after a perturbation.
virtual void resize(size_t nSpecies, size_t nReactions, size_t nPhases)
Update number of species, reactions and phases.
virtual void invalidateCache()
Force shared data and reaction rates to be updated next time.
virtual void update(double T, const vector< double > &extra)
Update data container based on temperature T and a vector parameter extra