Cantera 2.6.0

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