Cantera  3.0.0
Loading...
Searching...
No Matches
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
11namespace Cantera
12{
13
14AnyMap TransportData::parameters(bool withInput) const
15{
16 AnyMap out;
17 getParameters(out);
18 if (withInput) {
19 out.update(input);
20 }
21 return out;
22}
23
24void TransportData::getParameters(AnyMap &transportNode) const
25{
26}
27
28GasTransportData::GasTransportData(
29 const string& geometry_,
30 double diameter_, double well_depth_, double dipole_,
31 double polarizability_, double rot_relax, double acentric,
32 double dispersion, double quad_polar)
33 : geometry(geometry_)
34 , diameter(diameter_)
35 , well_depth(well_depth_)
36 , dipole(dipole_)
37 , polarizability(polarizability_)
38 , rotational_relaxation(rot_relax)
39 , acentric_factor(acentric)
40 , dispersion_coefficient(dispersion)
41 , quadrupole_polarizability(quad_polar)
42{
43}
44
46 const string& geometry_,
47 double diameter_, double well_depth_, double dipole_,
48 double polarizability_, double rot_relax, double acentric,
49 double dispersion, double quad_polar)
50{
51 geometry = geometry_;
52 diameter = 1e-10 * diameter_; // convert from Angstroms to m
53 well_depth = Boltzmann * well_depth_; // convert from K to J
54 dipole = 1e-21 / lightSpeed * dipole_; // convert from Debye to Coulomb-m
55 polarizability = 1e-30 * polarizability_; // convert from Angstroms^3 to m^3
56 rotational_relaxation = rot_relax; // pure number
57 acentric_factor = acentric; // dimensionless
58 dispersion_coefficient = 1e-50 * dispersion; // convert from Angstroms^5 to m^5
59 quadrupole_polarizability = 1e-50 * quad_polar; // convert from Angstroms^5 to m^5
60}
61
63{
64 double nAtoms = 0;
65 for (const auto& [eName, stoich] : sp.composition) {
66 if (!caseInsensitiveEquals(eName, "E")) {
67 nAtoms += stoich;
68 }
69 }
70
71 if (geometry == "atom") {
72 if (nAtoms > 1) {
73 throw CanteraError("GasTransportData::validate",
74 "invalid geometry for species '{}'. 'atom' specified, but "
75 "species contains multiple atoms.", sp.name);
76 }
77 } else if (geometry == "linear") {
78 if (nAtoms < 2) {
79 throw CanteraError("GasTransportData::validate",
80 "invalid geometry for species '{}'. 'linear' specified, but "
81 "species does not contain multiple atoms.", sp.name);
82 }
83 } else if (geometry == "nonlinear") {
84 if (nAtoms < 3) {
85 throw CanteraError("GasTransportData::validate",
86 "invalid geometry for species '{}'. 'nonlinear' specified, but "
87 "species only contains {} atoms.", sp.name, nAtoms);
88 }
89 } else {
90 throw CanteraError("GasTransportData::validate",
91 "invalid geometry for species '{}': '{}'.", sp.name, geometry);
92 }
93
94 if (well_depth < 0.0) {
95 throw CanteraError("GasTransportData::validate",
96 "negative well depth for species '{}'.", sp.name);
97 }
98
99 if (diameter <= 0.0) {
100 throw CanteraError("GasTransportData::validate",
101 "negative or zero diameter for species '{}'.", sp.name);
102 }
103
104 if (dipole < 0.0) {
105 throw CanteraError("GasTransportData::validate",
106 "negative dipole moment for species '{}'.", sp.name);
107 }
108
109 if (polarizability < 0.0) {
110 throw CanteraError("GasTransportData::validate",
111 "negative polarizability for species '{}'.", sp.name);
112 }
113
114 if (rotational_relaxation < 0.0) {
115 throw CanteraError("GasTransportData::validate",
116 "negative rotation relaxation number for species '{}'.", sp.name);
117 }
118
119 if (dispersion_coefficient < 0.0) {
120 throw CanteraError("GasTransportData::validate",
121 "negative dispersion coefficient for species '{}'.", sp.name);
122 }
123
124 if (quadrupole_polarizability < 0.0) {
125 throw CanteraError("GasTransportData::validate",
126 "negative quadrupole polarizability for species '{}'.", sp.name);
127 }
128}
129
130void GasTransportData::getParameters(AnyMap& transportNode) const
131{
132 TransportData::getParameters(transportNode);
133 transportNode["model"] = "gas";
134 transportNode["geometry"] = geometry;
135 transportNode["diameter"] = diameter * 1e10; // convert from m to Angstroms
136 transportNode["well-depth"] = well_depth / Boltzmann; // convert from J to K
137 if (dipole != 0) {
138 // convert from Debye to Coulomb-m
139 transportNode["dipole"] = dipole * 1e21 * lightSpeed;
140 }
141 if (polarizability != 0) {
142 // convert from m^3 to Angstroms^3
143 transportNode["polarizability"] = 1e30 * polarizability;
144 }
145 if (rotational_relaxation != 0) {
146 transportNode["rotational-relaxation"] = rotational_relaxation;
147 }
148 if (acentric_factor != 0) {
149 transportNode["acentric-factor"] = acentric_factor;
150 }
151 if (dispersion_coefficient != 0) {
152 // convert from m^5 to Angstroms^5
153 transportNode["dispersion-coefficient"] = dispersion_coefficient * 1e50;
154 }
156 // convert from m^5 to Angstroms^5
157 transportNode["quadrupole-polarizability"] = quadrupole_polarizability * 1e50;
158 }
159}
160
161void setupGasTransportData(GasTransportData& tr, const AnyMap& node)
162{
163 string geometry = node["geometry"].asString();
164 double welldepth = node["well-depth"].asDouble();
165 double diameter = node["diameter"].asDouble();
166 double dipole = node.getDouble("dipole", 0.0);
167 double polar = node.getDouble("polarizability", 0.0);
168 double rot = node.getDouble("rotational-relaxation", 0.0);
169 double acentric = node.getDouble("acentric-factor", 0.0);
170 double dispersion = node.getDouble("dispersion-coefficient", 0.0);
171 double quad = node.getDouble("quadrupole-polarizability", 0.0);
172
173 tr.setCustomaryUnits(geometry, diameter, welldepth, dipole, polar,
174 rot, acentric, dispersion, quad);
175
176 tr.input = node;
177}
178
179unique_ptr<TransportData> newTransportData(const AnyMap& node)
180{
181 if (node.getString("model", "") == "gas") {
182 auto tr = make_unique<GasTransportData>();
183 setupGasTransportData(*tr, node);
184 return tr;
185 } else {
186 // Transport model not handled here
187 auto tr = make_unique<TransportData>();
188 tr->input = node;
189 return tr;
190 }
191}
192
193}
Declaration for class Cantera::Species.
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:427
double getDouble(const string &key, double default_) const
If key exists, return it as a double, otherwise return default_.
Definition AnyMap.cpp:1520
const string & getString(const string &key, const string &default_) const
If key exists, return it as a string, otherwise return default_.
Definition AnyMap.cpp:1530
void update(const AnyMap &other, bool keepExisting=true)
Add items from other to this AnyMap.
Definition AnyMap.cpp:1438
Base class for exceptions thrown by Cantera classes.
Transport data for a single gas-phase species which can be used in mixture-averaged or multicomponent...
double polarizability
The polarizability of the molecule [m^3]. Default 0.0.
double diameter
The Lennard-Jones collision diameter [m].
double acentric_factor
Pitzer's acentric factor [dimensionless]. Default 0.0.
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...
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.
void getParameters(AnyMap &transportNode) const override
Store the parameters needed to reconstruct a TransportData object.
double well_depth
The Lennard-Jones well depth [J].
void setCustomaryUnits(const 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,...
void validate(const Species &species) override
Check transport data for invalid parameters such as a geometry inconsistent with the atomic compositi...
string geometry
A string specifying the molecular geometry.
Contains data about a single chemical species.
Definition Species.h:25
Composition composition
The elemental composition of the species.
Definition Species.h:45
string name
The name of the species.
Definition Species.h:41
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.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
bool caseInsensitiveEquals(const string &input, const string &test)
Case insensitive equality predicate.
const double Boltzmann
Boltzmann constant [J/K].
Definition ct_defs.h:84
const double lightSpeed
Speed of Light in a vacuum [m/s].
Definition ct_defs.h:93
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
unique_ptr< TransportData > newTransportData(const AnyMap &node)
Create a new TransportData object from an AnyMap specification.
Contains declarations for string manipulation functions within Cantera.