Cantera  2.4.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 http://www.cantera.org/license.txt for license and copyright information.
5 
10 #include "cantera/base/ctml.h"
11 
12 namespace Cantera
13 {
14 GasTransportData::GasTransportData()
15  : diameter(0.0)
16  , well_depth(0.0)
17  , dipole(0.0)
18  , polarizability(0.0)
19  , rotational_relaxation(0.0)
20  , acentric_factor(0.0)
21  , dispersion_coefficient(0.0)
22  , quadrupole_polarizability(0.0)
23 {
24 }
25 
26 GasTransportData::GasTransportData(
27  const std::string& geometry_,
28  double diameter_, double well_depth_, double dipole_,
29  double polarizability_, double rot_relax, double acentric,
30  double dispersion, double quad_polar)
31  : geometry(geometry_)
32  , diameter(diameter_)
33  , well_depth(well_depth_)
34  , dipole(dipole_)
35  , polarizability(polarizability_)
36  , rotational_relaxation(rot_relax)
37  , acentric_factor(acentric)
38  , dispersion_coefficient(dispersion)
39  , quadrupole_polarizability(quad_polar)
40 {
41 }
42 
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 {
49  geometry = geometry_;
50  diameter = 1e-10 * diameter_; // convert from Angstroms to m
51  well_depth = Boltzmann * well_depth_; // convert from K to J
52  dipole = 1e-21 / lightSpeed * dipole_; // convert from Debye to Coulomb-m
53  polarizability = 1e-30 * polarizability_; // convert from Angstroms^3 to m^3
54  rotational_relaxation = rot_relax; // pure number
55  acentric_factor = acentric; // dimensionless
56  dispersion_coefficient = 1e-50 * dispersion; // convert from Angstroms^5 to m^5
57  quadrupole_polarizability = 1e-50 * quad_polar; // convert from Angstroms^5 to m^5
58 }
59 
61 {
62  double nAtoms = 0;
63  for (const auto& elem : sp.composition) {
64  if (!caseInsensitiveEquals(elem.first, "E")) {
65  nAtoms += elem.second;
66  }
67  }
68 
69  if (geometry == "atom") {
70  if (nAtoms > 1) {
71  throw CanteraError("GasTransportData::validate",
72  "invalid geometry for species '{}'. 'atom' specified, but "
73  "species contains multiple atoms.", sp.name);
74  }
75  } else if (geometry == "linear") {
76  if (nAtoms < 2) {
77  throw CanteraError("GasTransportData::validate",
78  "invalid geometry for species '{}'. 'linear' specified, but "
79  "species does not contain multiple atoms.", sp.name);
80  }
81  } else if (geometry == "nonlinear") {
82  if (nAtoms < 3) {
83  throw CanteraError("GasTransportData::validate",
84  "invalid geometry for species '{}'. 'nonlinear' specified, but "
85  "species only contains {} atoms.", sp.name, nAtoms);
86  }
87  } else {
88  throw CanteraError("GasTransportData::validate",
89  "invalid geometry for species '{}': '{}'.", sp.name, geometry);
90  }
91 
92  if (well_depth < 0.0) {
93  throw CanteraError("GasTransportData::validate",
94  "negative well depth for species '{}'.", sp.name);
95  }
96 
97  if (diameter <= 0.0) {
98  throw CanteraError("GasTransportData::validate",
99  "negative or zero diameter for species '{}'.", sp.name);
100  }
101 
102  if (dipole < 0.0) {
103  throw CanteraError("GasTransportData::validate",
104  "negative dipole moment for species '{}'.", sp.name);
105  }
106 
107  if (polarizability < 0.0) {
108  throw CanteraError("GasTransportData::validate",
109  "negative polarizability for species '{}'.", sp.name);
110  }
111 
112  if (rotational_relaxation < 0.0) {
113  throw CanteraError("GasTransportData::validate",
114  "negative rotation relaxation number for species '{}'.", sp.name);
115  }
116 
117  if (dispersion_coefficient < 0.0) {
118  throw CanteraError("GasTransportData::validate",
119  "negative dispersion coefficient for species '{}'.", sp.name);
120  }
121 
122  if (quadrupole_polarizability < 0.0) {
123  throw CanteraError("GasTransportData::validate",
124  "negative quadrupole polarizability for species '{}'.", sp.name);
125  }
126 }
127 
128 void setupGasTransportData(GasTransportData& tr, const XML_Node& tr_node)
129 {
130  std::string geometry, dummy;
131  getString(tr_node, "geometry", geometry, dummy);
132 
133  double diam = getFloat(tr_node, "LJ_diameter");
134  double welldepth = getFloat(tr_node, "LJ_welldepth");
135 
136  double dipole = 0.0;
137  getOptionalFloat(tr_node, "dipoleMoment", dipole);
138 
139  double polar = 0.0;
140  getOptionalFloat(tr_node, "polarizability", polar);
141 
142  double rot = 0.0;
143  getOptionalFloat(tr_node, "rotRelax", rot);
144  double acentric = 0.0;
145  getOptionalFloat(tr_node, "acentric_factor", acentric);
146 
147  double dispersion = 0.0;
148  getOptionalFloat(tr_node, "dispersion_coefficient", dispersion);
149 
150  double quad = 0.0;
151  getOptionalFloat(tr_node, "quadrupole_polarizability", quad);
152 
153  tr.setCustomaryUnits(geometry, diam, welldepth, dipole, polar,
154  rot, acentric, dispersion, quad);
155 }
156 
157 shared_ptr<TransportData> newTransportData(const XML_Node& transport_node)
158 {
159  std::string model = transport_node["model"];
160  if (model == "gas_transport") {
161  auto tr = make_shared<GasTransportData>();
162  setupGasTransportData(*tr, transport_node);
163  return tr;
164  } else {
165  // Transport model not handled here
166  return make_shared<TransportData>();
167  }
168 }
169 
170 }
Transport data for a single gas-phase species which can be used in mixture-averaged or multicomponent...
Definition: TransportData.h:29
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
double quadrupole_polarizability
quadrupole. Default 0.0.
Definition: TransportData.h:84
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, dipole in Debye, and polarizability in Angstroms^3.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
double rotational_relaxation
The rotational relaxation number (the number of collisions it takes to equilibrate the rotational deg...
Definition: TransportData.h:75
double well_depth
The Lennard-Jones well depth [J].
Definition: TransportData.h:64
virtual void validate(const Species &species)
Check transport data for invalid parameters such as a geometry inconsistent with the atomic compositi...
std::string name
The name of the species.
Definition: Species.h:39
double diameter
The Lennard-Jones collision diameter [m].
Definition: TransportData.h:61
double dispersion_coefficient
dispersion normalized by e^2. [m^5] Default 0.0.
Definition: TransportData.h:81
bool caseInsensitiveEquals(const std::string &input, const std::string &test)
Case insensitive equality predicate.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
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
double dipole
The permanent dipole moment of the molecule [Coulomb-m]. Default 0.0.
Definition: TransportData.h:67
compositionMap composition
The elemental composition of the species.
Definition: Species.h:43
Contains declarations for string manipulation functions within Cantera.
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
std::string geometry
A string specifying the molecular geometry.
Definition: TransportData.h:58
Contains data about a single chemical species.
Definition: Species.h:24
double polarizability
The polarizability of the molecule [m^3]. Default 0.0.
Definition: TransportData.h:70
double acentric_factor
Pitzer&#39;s acentric factor [dimensionless]. Default 0.0.
Definition: TransportData.h:78
Declaration for class Cantera::Species.
const doublereal lightSpeed
Speed of Light (m/s).
Definition: ct_defs.h:100
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
const doublereal Boltzmann
Boltzmann&#39;s constant [J/K].
Definition: ct_defs.h:76
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
shared_ptr< TransportData > newTransportData(const XML_Node &transport_node)
Create a new TransportData object from a &#39;transport&#39; XML_Node.
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