Cantera
Loading...
Searching...
No Matches
VibrationalRelaxationRate.cpp
Go to the documentation of this file.
1//! @file VibrationalRelaxationRate.cpp
2//! @since New in %Cantera 4.0
3
4// This file is part of Cantera. See License.txt in the top-level directory or
5// at https://cantera.org/license.txt for license and copyright information.
6
8
9namespace Cantera
10{
11
12namespace
13{
14
15const string WhereSetContext =
16 "VibrationalRelaxationRate::setContext";
17
18} // namespace
19
21{
23 recipT13 = std::cbrt(recipT);
24}
25
27{
28 const double T = phase.temperature();
29
30 if (T == temperature) {
31 return false;
32 }
33
34 update(T);
35 return true;
36}
37
38// Default constructor
40
42 double A, double b, double C0, double C13,
43 double Cm, double m, double Cn, double n)
44 : m_A(A), m_b(b) , m_C0(C0), m_C13(C13), m_Cm(Cm),
45 m_m(m), m_Cn(Cn), m_n(n)
46{
47 m_valid = true;
48}
49
51 const UnitStack& rate_units)
52{
53 // m_valid is set back to true by the derived class's setParameters() function.
54 m_valid = false;
55
56 ReactionRate::setParameters(node, rate_units);
57
58 m_negativeA_ok = node.getBool("negative-A", false);
59}
60
62{
63 if (!valid()) {
64 return;
65 }
66
67 if (m_negativeA_ok) {
68 node["negative-A"] = true;
69 }
70
71 AnyMap rateNode;
72 getRateParameters(rateNode);
73 rateNode.setFlowStyle();
74 node["rate-constant"] = std::move(rateNode);
75}
76
77void VibrationalRelaxationRate::getPreExponentialFactor(
78 AnyMap& rateNode) const
79{
80 if (conversionUnits().factor() != 0.0) {
81 rateNode["A"].setQuantity(m_A, conversionUnits());
82 } else {
83 rateNode["A"] = m_A;
84 rateNode["__unconvertible__"] = true;
85 }
86}
87
89 const VibrationalRelaxationData& shared_data) const
90{
91
92 return m_b * shared_data.recipT
93 - (m_C13 / 3.0) * shared_data.recipT13 * shared_data.recipT
94 - m_m * m_Cm * std::pow(shared_data.recipT, m_m) * shared_data.recipT
95 - m_n * m_Cn * std::pow(shared_data.recipT, m_n) * shared_data.recipT;
96}
97
99{
100 if (rxn.reversible) {
101 throw InputFileError(WhereSetContext, rxn.input,
102 "Vibrational relaxation rates do not support reversible "
103 "reactions.");
104 }
105}
106
107void VibrationalRelaxationRate::check(const string& equation)
108{
109 if (!m_negativeA_ok && m_A < 0.0) {
110 if (equation.empty()) {
111 throw CanteraError(
112 "VibrationalRelaxationRate::check",
113 "Detected negative pre-exponential constant A={}. "
114 "Set 'negative-A: true' to allow it.",
115 m_A);
116 }
117
118 throw InputFileError(
119 "VibrationalRelaxationRate::check", m_input,
120 "Undeclared negative leading pre-exponential constant found "
121 "in reaction '{}'.",
122 equation);
123 }
124}
125
127 const string& equation, const Kinetics& kin)
128{
129 if (!valid()) {
130 throw InputFileError(
131 "VibrationalRelaxationRate::validate", m_input,
132 "Rate object for reaction '{}' is not configured.",
133 equation);
134 }
135}
136
137void VibrationalRelaxationRate::requireKeys(const AnyMap& node,
138 const string& rateType, const string& where,
139 std::initializer_list<string> keys)
140{
141 for (const auto& key : keys) {
142 if (!node.hasKey(key)) {
143 throw InputFileError(
144 where,
145 node,
146 "Missing required key '{}' for reaction rate type '{}'.",
147 key,
148 rateType);
149 }
150 }
151}
152
153
154void VibrationalRelaxationRate::forbidKeys(const AnyMap& node,
155 const string& rateType, const string& where,
156 std::initializer_list<string> keys)
157{
158 for (const auto& key : keys) {
159 if (node.hasKey(key)) {
160 throw InputFileError(
161 where,
162 node,
163 "Key '{}' is not allowed for reaction rate type '{}'.",
164 key,
165 rateType);
166 }
167 }
168}
169
170} // namespace Cantera
Header for vibrational relaxation reaction rates in plasma kinetics.
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:431
bool hasKey(const string &key) const
Returns true if the map contains an item named key.
Definition AnyMap.cpp:1477
void setFlowStyle(bool flow=true)
Use "flow" style when outputting this AnyMap to YAML.
Definition AnyMap.cpp:1794
bool getBool(const string &key, bool default_) const
If key exists, return it as a bool, otherwise return default_.
Definition AnyMap.cpp:1575
Base class for exceptions thrown by Cantera classes.
Error thrown for problems processing information contained in an AnyMap or AnyValue.
Definition AnyMap.h:749
Public interface for kinetics managers.
Definition Kinetics.h:124
double temperature() const
Temperature (K).
Definition Phase.h:586
virtual void setParameters(const AnyMap &node, const UnitStack &units)
Set parameters.
const Units & conversionUnits() const
Get the units for converting the leading term in the reaction rate expression.
bool valid() const
Get flag indicating whether reaction rate is set up correctly.
bool m_valid
Flag indicating whether reaction rate is set up correctly.
AnyMap m_input
Input data used for specific models.
Abstract base class which stores data about a reaction and its rate parameterization so that it can b...
Definition Reaction.h:25
bool reversible
True if the current reaction is reversible. False otherwise.
Definition Reaction.h:126
AnyMap input
Input data used for specific models.
Definition Reaction.h:139
Base class for a phase with thermodynamic properties.
void setContext(const Reaction &rxn, const Kinetics &kin) override
Set context of reaction rate evaluation.
virtual void getRateParameters(AnyMap &rateNode) const =0
Store the model-specific coefficients in the rate-constant node.
double m_n
Temperature exponent used by the Cn term.
void setParameters(const AnyMap &node, const UnitStack &rate_units) override
Set parameters.
void validate(const string &equation, const Kinetics &kin) override
Validate the reaction rate expression.
void getParameters(AnyMap &node) const override
Write the fields shared by all vibrational relaxation rates, then delegate the model-specific rate-co...
double m_A
Pre-exponential constant for the reaction rate.
VibrationalRelaxationRate()
Default constructor.
double ddTScaledFromStruct(const VibrationalRelaxationData &shared_data) const
Evaluate the scaled temperature derivative.
bool m_negativeA_ok
Whether a negative leading coefficient is explicitly allowed.
double m_C13
Coefficient multiplying .
double m_b
Temperature exponent for the reaction rate.
void check(const string &equation) override
Check basic syntax and settings of reaction rate expression.
double m_m
Temperature exponent used by the Cm term.
double m_C0
Dimensionless constant in the exponential.
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
double recipT
inverse of temperature
virtual void update(double T)
Update data container based on temperature T.
double temperature
temperature
Unit aggregation utility.
Definition Units.h:105
Shared temperature data for vibrational relaxation rates.
void update(double T) override
Update cached temperature-dependent data directly from temperature.