Cantera 2.6.0
TransportData.cpp
Go to the documentation of this file.
1//! @file TransportData.cpp
2
3// This file is part of Cantera. See License.txt in the top-level directory or
4// at https://cantera.org/license.txt for license and copyright information.
5
10#include "cantera/base/ctml.h"
11
12#include <set>
13
14namespace Cantera
15{
16
17AnyMap TransportData::parameters(bool withInput) const
18{
19 AnyMap out;
20 getParameters(out);
21 if (withInput) {
22 out.update(input);
23 }
24 return out;
25}
26
27void TransportData::getParameters(AnyMap &transportNode) const
28{
29}
30
31GasTransportData::GasTransportData()
32 : diameter(0.0)
33 , well_depth(0.0)
34 , dipole(0.0)
35 , polarizability(0.0)
36 , rotational_relaxation(0.0)
37 , acentric_factor(0.0)
38 , dispersion_coefficient(0.0)
39 , quadrupole_polarizability(0.0)
40{
41}
42
43GasTransportData::GasTransportData(
44 const std::string& geometry_,
45 double diameter_, double well_depth_, double dipole_,
46 double polarizability_, double rot_relax, double acentric,
47 double dispersion, double quad_polar)
48 : geometry(geometry_)
49 , diameter(diameter_)
50 , well_depth(well_depth_)
51 , dipole(dipole_)
52 , polarizability(polarizability_)
53 , rotational_relaxation(rot_relax)
54 , acentric_factor(acentric)
55 , dispersion_coefficient(dispersion)
56 , quadrupole_polarizability(quad_polar)
57{
58}
59
61 const std::string& geometry_,
62 double diameter_, double well_depth_, double dipole_,
63 double polarizability_, double rot_relax, double acentric,
64 double dispersion, double quad_polar)
65{
66 geometry = geometry_;
67 diameter = 1e-10 * diameter_; // convert from Angstroms to m
68 well_depth = Boltzmann * well_depth_; // convert from K to J
69 dipole = 1e-21 / lightSpeed * dipole_; // convert from Debye to Coulomb-m
70 polarizability = 1e-30 * polarizability_; // convert from Angstroms^3 to m^3
71 rotational_relaxation = rot_relax; // pure number
72 acentric_factor = acentric; // dimensionless
73 dispersion_coefficient = 1e-50 * dispersion; // convert from Angstroms^5 to m^5
74 quadrupole_polarizability = 1e-50 * quad_polar; // convert from Angstroms^5 to m^5
75}
76
78{
79 double nAtoms = 0;
80 for (const auto& elem : sp.composition) {
81 if (!caseInsensitiveEquals(elem.first, "E")) {
82 nAtoms += elem.second;
83 }
84 }
85
86 if (geometry == "atom") {
87 if (nAtoms > 1) {
88 throw CanteraError("GasTransportData::validate",
89 "invalid geometry for species '{}'. 'atom' specified, but "
90 "species contains multiple atoms.", sp.name);
91 }
92 } else if (geometry == "linear") {
93 if (nAtoms < 2) {
94 throw CanteraError("GasTransportData::validate",
95 "invalid geometry for species '{}'. 'linear' specified, but "
96 "species does not contain multiple atoms.", sp.name);
97 }
98 } else if (geometry == "nonlinear") {
99 if (nAtoms < 3) {
100 throw CanteraError("GasTransportData::validate",
101 "invalid geometry for species '{}'. 'nonlinear' specified, but "
102 "species only contains {} atoms.", sp.name, nAtoms);
103 }
104 } else {
105 throw CanteraError("GasTransportData::validate",
106 "invalid geometry for species '{}': '{}'.", sp.name, geometry);
107 }
108
109 if (well_depth < 0.0) {
110 throw CanteraError("GasTransportData::validate",
111 "negative well depth for species '{}'.", sp.name);
112 }
113
114 if (diameter <= 0.0) {
115 throw CanteraError("GasTransportData::validate",
116 "negative or zero diameter for species '{}'.", sp.name);
117 }
118
119 if (dipole < 0.0) {
120 throw CanteraError("GasTransportData::validate",
121 "negative dipole moment for species '{}'.", sp.name);
122 }
123
124 if (polarizability < 0.0) {
125 throw CanteraError("GasTransportData::validate",
126 "negative polarizability for species '{}'.", sp.name);
127 }
128
129 if (rotational_relaxation < 0.0) {
130 throw CanteraError("GasTransportData::validate",
131 "negative rotation relaxation number for species '{}'.", sp.name);
132 }
133
134 if (dispersion_coefficient < 0.0) {
135 throw CanteraError("GasTransportData::validate",
136 "negative dispersion coefficient for species '{}'.", sp.name);
137 }
138
139 if (quadrupole_polarizability < 0.0) {
140 throw CanteraError("GasTransportData::validate",
141 "negative quadrupole polarizability for species '{}'.", sp.name);
142 }
143}
144
145void GasTransportData::getParameters(AnyMap& transportNode) const
146{
147 TransportData::getParameters(transportNode);
148 transportNode["model"] = "gas";
149 transportNode["geometry"] = geometry;
150 transportNode["diameter"] = diameter * 1e10; // convert from m to Angstroms
151 transportNode["well-depth"] = well_depth / Boltzmann; // convert from J to K
152 if (dipole != 0) {
153 // convert from Debye to Coulomb-m
154 transportNode["dipole"] = dipole * 1e21 * lightSpeed;
155 }
156 if (polarizability != 0) {
157 // convert from m^3 to Angstroms^3
158 transportNode["polarizability"] = 1e30 * polarizability;
159 }
160 if (rotational_relaxation != 0) {
161 transportNode["rotational-relaxation"] = rotational_relaxation;
162 }
163 if (acentric_factor != 0) {
164 transportNode["acentric-factor"] = acentric_factor;
165 }
166 if (dispersion_coefficient != 0) {
167 // convert from m^5 to Angstroms^5
168 transportNode["dispersion-coefficient"] = dispersion_coefficient * 1e50;
169 }
171 // convert from m^5 to Angstroms^5
172 transportNode["quadrupole-polarizability"] = quadrupole_polarizability * 1e50;
173 }
174}
175
176void setupGasTransportData(GasTransportData& tr, const XML_Node& tr_node)
177{
178 std::string geometry, dummy;
179 getString(tr_node, "geometry", geometry, dummy);
180
181 double diam = getFloat(tr_node, "LJ_diameter");
182 double welldepth = getFloat(tr_node, "LJ_welldepth");
183
184 double dipole = 0.0;
185 getOptionalFloat(tr_node, "dipoleMoment", dipole);
186
187 double polar = 0.0;
188 getOptionalFloat(tr_node, "polarizability", polar);
189
190 double rot = 0.0;
191 getOptionalFloat(tr_node, "rotRelax", rot);
192 double acentric = 0.0;
193 getOptionalFloat(tr_node, "acentric_factor", acentric);
194
195 double dispersion = 0.0;
196 getOptionalFloat(tr_node, "dispersion_coefficient", dispersion);
197
198 double quad = 0.0;
199 getOptionalFloat(tr_node, "quadrupole_polarizability", quad);
200
201 tr.setCustomaryUnits(geometry, diam, welldepth, dipole, polar,
202 rot, acentric, dispersion, quad);
203}
204
205void setupGasTransportData(GasTransportData& tr, const AnyMap& node)
206{
207 std::string geometry = node["geometry"].asString();
208 double welldepth = node["well-depth"].asDouble();
209 double diameter = node["diameter"].asDouble();
210 double dipole = node.getDouble("dipole", 0.0);
211 double polar = node.getDouble("polarizability", 0.0);
212 double rot = node.getDouble("rotational-relaxation", 0.0);
213 double acentric = node.getDouble("acentric-factor", 0.0);
214 double dispersion = node.getDouble("dispersion-coefficient", 0.0);
215 double quad = node.getDouble("quadrupole-polarizability", 0.0);
216
217 tr.setCustomaryUnits(geometry, diameter, welldepth, dipole, polar,
218 rot, acentric, dispersion, quad);
219
220 tr.input = node;
221}
222
223shared_ptr<TransportData> newTransportData(const XML_Node& transport_node)
224{
225 std::string model = transport_node["model"];
226 if (model == "gas_transport") {
227 auto tr = make_shared<GasTransportData>();
228 setupGasTransportData(*tr, transport_node);
229 return tr;
230 } else {
231 // Transport model not handled here
232 return make_shared<TransportData>();
233 }
234}
235
236unique_ptr<TransportData> newTransportData(const AnyMap& node)
237{
238 if (node.getString("model", "") == "gas") {
239 unique_ptr<GasTransportData> tr(new GasTransportData());
240 setupGasTransportData(*tr, node);
241 return unique_ptr<TransportData>(move(tr));
242 } else {
243 // Transport model not handled here
244 unique_ptr<TransportData> tr(new TransportData());
245 tr->input = node;
246 return tr;
247 }
248}
249
250}
Declaration for class Cantera::Species.
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
const std::string & getString(const std::string &key, const std::string &default_) const
If key exists, return it as a string, otherwise return default_.
Definition: AnyMap.cpp:1502
void update(const AnyMap &other, bool keepExisting=true)
Add items from other to this AnyMap.
Definition: AnyMap.cpp:1421
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Transport data for a single gas-phase species which can be used in mixture-averaged or multicomponent...
Definition: TransportData.h:47
double polarizability
The polarizability of the molecule [m^3]. Default 0.0.
Definition: TransportData.h:89
std::string geometry
A string specifying the molecular geometry.
Definition: TransportData.h:77
double diameter
The Lennard-Jones collision diameter [m].
Definition: TransportData.h:80
void setCustomaryUnits(const std::string &geometry, double diameter, double well_depth, double dipole=0.0, double polarizability=0.0, double rot_relax=0.0, double acentric=0.0, double dispersion=0.0, double quad_polar=0.0)
Set the parameters using "customary" units: diameter in Angstroms, well depth in Kelvin,...
virtual void getParameters(AnyMap &transportNode) const
Store the parameters needed to reconstruct a TransportData object.
double acentric_factor
Pitzer's acentric factor [dimensionless]. Default 0.0.
Definition: TransportData.h:97
double quadrupole_polarizability
quadrupole. Default 0.0.
double rotational_relaxation
The rotational relaxation number (the number of collisions it takes to equilibrate the rotational deg...
Definition: TransportData.h:94
double dispersion_coefficient
dispersion normalized by e^2. [m^5] Default 0.0.
double dipole
The permanent dipole moment of the molecule [Coulomb-m]. Default 0.0.
Definition: TransportData.h:86
double well_depth
The Lennard-Jones well depth [J].
Definition: TransportData.h:83
virtual void validate(const Species &species)
Check transport data for invalid parameters such as a geometry inconsistent with the atomic compositi...
Contains data about a single chemical species.
Definition: Species.h:26
compositionMap composition
The elemental composition of the species.
Definition: Species.h:46
std::string name
The name of the species.
Definition: Species.h:42
Base class for transport data for a single species.
Definition: TransportData.h:20
AnyMap parameters(bool withInput) const
Return the parameters such that an identical species transport object could be reconstructed using th...
virtual void getParameters(AnyMap &transportNode) const
Store the parameters needed to reconstruct a TransportData object.
AnyMap input
Input data used for specific models.
Definition: TransportData.h:36
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
void getString(const XML_Node &node, const std::string &titleString, std::string &valueString, std::string &typeString)
This function reads a child node with the name string with a specific title attribute named titleStri...
Definition: ctml.cpp:141
const double Boltzmann
Boltzmann constant [J/K].
Definition: ct_defs.h:69
doublereal getFloat(const XML_Node &parent, const std::string &name, const std::string &type="")
Get a floating-point value from a child element.
Definition: ctml.cpp:166
bool getOptionalFloat(const XML_Node &parent, const std::string &name, doublereal &fltRtn, const std::string &type="")
Get an optional floating-point value from a child element.
Definition: ctml.cpp:214
bool caseInsensitiveEquals(const std::string &input, const std::string &test)
Case insensitive equality predicate.
const double lightSpeed
Speed of Light in a vacuum [m/s].
Definition: ct_defs.h:78
shared_ptr< TransportData > newTransportData(const XML_Node &transport_node)
Create a new TransportData object from a 'transport' XML_Node.
Contains declarations for string manipulation functions within Cantera.