Cantera  3.1.0b1
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 virtual ~ReactionData() = default;
31
32 //! Update data container based on temperature *T*
33 /**
34 * Only used in conjunction with MultiRateBase::evalSingle / ReactionRate::eval.
35 * This method allows for testing of a reaction rate expression outside of
36 * Kinetics reaction rate evaluators.
37 */
38 virtual void update(double T) {
39 temperature = T;
40 logT = std::log(T);
41 recipT = 1./T;
42 }
43
44 //! Update data container based on temperature *T* and an *extra* parameter
45 /**
46 * Only used in conjunction with MultiRateBase::evalSingle / ReactionRate::eval.
47 * This method allows for testing of a reaction rate expression outside of
48 * Kinetics reaction rate evaluators.
49 */
50 virtual void update(double T, double extra) {
51 throw NotImplementedError("ReactionData::update",
52 "ReactionData type does not use extra scalar argument.");
53 }
54
55 //! Update data container based on temperature *T* and a vector parameter *extra*
56 /**
57 * Only used in conjunction with MultiRateBase::evalSingle / ReactionRate::eval.
58 * This method allows for testing of a reaction rate expression outside of
59 * Kinetics reaction rate evaluators.
60 *
61 * @warning This method is an experimental part of the %Cantera API and
62 * may be changed or removed without notice.
63 */
64 virtual void update(double T, const vector<double>& extra) {
65 throw NotImplementedError("ReactionData::update",
66 "ReactionData type does not use extra vector argument.");
67 }
68
69 //! Update data container based on thermodynamic phase state
70 /**
71 * This update mechanism is used by Kinetics reaction rate evaluators.
72 * @returns A boolean element indicating whether the `evalFromStruct` method
73 * needs to be called (assuming previously-calculated values were cached)
74 */
75 virtual bool update(const ThermoPhase& phase, const Kinetics& kin) = 0;
76
77 //! Perturb temperature of data container
78 /**
79 * The method is used for the evaluation of numerical derivatives.
80 * @param deltaT relative temperature perturbation
81 */
82 void perturbTemperature(double deltaT) {
83 if (m_temperature_buf > 0.) {
84 throw CanteraError("ReactionData::perturbTemperature",
85 "Cannot apply another perturbation as state is already perturbed.");
86 }
88 ReactionData::update(temperature * (1. + deltaT));
89 }
90
91 //! Restore data container after a perturbation
92 virtual void restore() {
93 // only restore if there is a valid buffered value
94 if (m_temperature_buf < 0.) {
95 return;
96 }
99 }
100
101 //! Update number of species, reactions and phases
102 virtual void resize(size_t nSpecies, size_t nReactions, size_t nPhases) {}
103
104 //! Force shared data and reaction rates to be updated next time. This is called by
105 //! functions that change quantities affecting rate calculations that are normally
106 //! assumed to be constant, like the reaction rate parameters or the number of
107 //! reactions.
108 virtual void invalidateCache() {
109 temperature = NAN;
110 }
111
112 double temperature = 1.0; //!< temperature
113 double logT = 0.0; //!< logarithm of temperature
114 double recipT = 1.0; //!< inverse of temperature
115
116protected:
117 double m_temperature_buf = -1.0; //!< buffered temperature
118};
119
120}
121
122#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:595
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