Cantera  2.5.1
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 
14 namespace Cantera
15 {
16 GasTransportData::GasTransportData()
17  : diameter(0.0)
18  , well_depth(0.0)
19  , dipole(0.0)
20  , polarizability(0.0)
21  , rotational_relaxation(0.0)
22  , acentric_factor(0.0)
23  , dispersion_coefficient(0.0)
24  , quadrupole_polarizability(0.0)
25 {
26 }
27 
28 GasTransportData::GasTransportData(
29  const std::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 std::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& elem : sp.composition) {
66  if (!caseInsensitiveEquals(elem.first, "E")) {
67  nAtoms += elem.second;
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 
130 void setupGasTransportData(GasTransportData& tr, const XML_Node& tr_node)
131 {
132  std::string geometry, dummy;
133  getString(tr_node, "geometry", geometry, dummy);
134 
135  double diam = getFloat(tr_node, "LJ_diameter");
136  double welldepth = getFloat(tr_node, "LJ_welldepth");
137 
138  double dipole = 0.0;
139  getOptionalFloat(tr_node, "dipoleMoment", dipole);
140 
141  double polar = 0.0;
142  getOptionalFloat(tr_node, "polarizability", polar);
143 
144  double rot = 0.0;
145  getOptionalFloat(tr_node, "rotRelax", rot);
146  double acentric = 0.0;
147  getOptionalFloat(tr_node, "acentric_factor", acentric);
148 
149  double dispersion = 0.0;
150  getOptionalFloat(tr_node, "dispersion_coefficient", dispersion);
151 
152  double quad = 0.0;
153  getOptionalFloat(tr_node, "quadrupole_polarizability", quad);
154 
155  tr.setCustomaryUnits(geometry, diam, welldepth, dipole, polar,
156  rot, acentric, dispersion, quad);
157 }
158 
159 void setupGasTransportData(GasTransportData& tr, const AnyMap& node)
160 {
161  std::string geometry = node["geometry"].asString();
162  double welldepth = node["well-depth"].asDouble();
163  double diameter = node["diameter"].asDouble();
164  double dipole = node.getDouble("dipole", 0.0);
165  double polar = node.getDouble("polarizability", 0.0);
166  double rot = node.getDouble("rotational-relaxation", 0.0);
167  double acentric = node.getDouble("acentric-factor", 0.0);
168  double dispersion = node.getDouble("dispersion-coefficient", 0.0);
169  double quad = node.getDouble("quadrupole-polarizability", 0.0);
170 
171  tr.setCustomaryUnits(geometry, diameter, welldepth, dipole, polar,
172  rot, acentric, dispersion, quad);
173 
174  tr.input = node;
175 }
176 
177 shared_ptr<TransportData> newTransportData(const XML_Node& transport_node)
178 {
179  std::string model = transport_node["model"];
180  if (model == "gas_transport") {
181  auto tr = make_shared<GasTransportData>();
182  setupGasTransportData(*tr, transport_node);
183  return tr;
184  } else {
185  // Transport model not handled here
186  return make_shared<TransportData>();
187  }
188 }
189 
190 unique_ptr<TransportData> newTransportData(const AnyMap& node)
191 {
192  if (node.getString("model", "") == "gas") {
193  unique_ptr<GasTransportData> tr(new GasTransportData());
194  setupGasTransportData(*tr, node);
195  return unique_ptr<TransportData>(move(tr));
196  } else {
197  // Transport model not handled here
198  unique_ptr<TransportData> tr(new TransportData());
199  tr->input = node;
200  return tr;
201  }
202 }
203 
204 }
Declaration for class Cantera::Species.
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:360
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:1049
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:34
double polarizability
The polarizability of the molecule [m^3]. Default 0.0.
Definition: TransportData.h:74
std::string geometry
A string specifying the molecular geometry.
Definition: TransportData.h:62
double diameter
The Lennard-Jones collision diameter [m].
Definition: TransportData.h:65
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,...
double acentric_factor
Pitzer's acentric factor [dimensionless]. Default 0.0.
Definition: TransportData.h:82
double quadrupole_polarizability
quadrupole. Default 0.0.
Definition: TransportData.h:88
double rotational_relaxation
The rotational relaxation number (the number of collisions it takes to equilibrate the rotational deg...
Definition: TransportData.h:79
double dispersion_coefficient
dispersion normalized by e^2. [m^5] Default 0.0.
Definition: TransportData.h:85
double dipole
The permanent dipole moment of the molecule [Coulomb-m]. Default 0.0.
Definition: TransportData.h:71
double well_depth
The Lennard-Jones well depth [J].
Definition: TransportData.h:68
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:25
compositionMap composition
The elemental composition of the species.
Definition: Species.h:43
std::string name
The name of the species.
Definition: Species.h:39
Base class for transport data for a single species.
Definition: TransportData.h:20
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:104
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.
const double Boltzmann
Boltzmann constant [J/K].
Definition: ct_defs.h:66
const double lightSpeed
Speed of Light in a vacuum [m/s].
Definition: ct_defs.h:75
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264
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:139
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:164
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:212
bool caseInsensitiveEquals(const std::string &input, const std::string &test)
Case insensitive equality predicate.
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.