| Cantera 3.0.0

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
11#include "cantera/base/ct_defs.h"
12#include "cantera/base/ctexceptions.h"
13
14 namespace Cantera
15{
16
17 class ThermoPhase;
18 class 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 */
26 struct ReactionData
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 }
85 m_temperature_buf = temperature;
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 }
95 ReactionData::update(m_temperature_buf);
96 m_temperature_buf = -1.;
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
114 protected:
115 double m_temperature_buf = -1.0; //!< buffered temperature
116};
117
118}
119
120#endif
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition ctexceptions.h:66
Cantera::Kinetics
Public interface for kinetics managers.
Definition Kinetics.h:126
Cantera::NotImplementedError
An error indicating that an unimplemented function has been called.
Definition ctexceptions.h:195
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition ThermoPhase.h:390
ct_defs.h
This file contains definitions of constants, types and terms that are used in internal routines and a...
ctexceptions.h
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
Cantera::ReactionData
Data container holding shared data used for ReactionRate calculation.
Definition ReactionData.h:27
Cantera::ReactionData::recipT
double recipT
inverse of temperature
Definition ReactionData.h:112
Cantera::ReactionData::m_temperature_buf
double m_temperature_buf
buffered temperature
Definition ReactionData.h:115
Cantera::ReactionData::update
virtual void update(double T, double extra)
Update data container based on temperature T and an extra parameter.
Definition ReactionData.h:48
Cantera::ReactionData::update
virtual bool update(const ThermoPhase &phase, const Kinetics &kin)=0
Update data container based on thermodynamic phase state.
Cantera::ReactionData::perturbTemperature
void perturbTemperature(double deltaT)
Perturb temperature of data container.
Definition ReactionData.h:80
Cantera::ReactionData::update
virtual void update(double T)
Update data container based on temperature T
Definition ReactionData.h:36
Cantera::ReactionData::temperature
double temperature
temperature
Definition ReactionData.h:110
Cantera::ReactionData::logT
double logT
logarithm of temperature
Definition ReactionData.h:111
Cantera::ReactionData::restore
virtual void restore()
Restore data container after a perturbation.
Definition ReactionData.h:90
Cantera::ReactionData::resize
virtual void resize(size_t nSpecies, size_t nReactions, size_t nPhases)
Update number of species, reactions and phases.
Definition ReactionData.h:100
Cantera::ReactionData::invalidateCache
virtual void invalidateCache()
Force shared data and reaction rates to be updated next time.
Definition ReactionData.h:106
Cantera::ReactionData::update
virtual void update(double T, const vector< double > &extra)
Update data container based on temperature T and a vector parameter extra
Definition ReactionData.h:62