Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TransportData.cpp
Go to the documentation of this file.
1 //! @file TransportData.cpp
2 
7 #include "cantera/base/ctml.h"
8 
9 namespace Cantera
10 {
11 GasTransportData::GasTransportData()
12  : diameter(0.0)
13  , well_depth(0.0)
14  , dipole(0.0)
15  , polarizability(0.0)
16  , rotational_relaxation(0.0)
17  , acentric_factor(0.0)
18 {
19 }
20 
21 GasTransportData::GasTransportData(
22  const std::string& geometry_,
23  double diameter_, double well_depth_, double dipole_,
24  double polarizability_, double rot_relax, double acentric)
25  : geometry(geometry_)
26  , diameter(diameter_)
27  , well_depth(well_depth_)
28  , dipole(dipole_)
29  , polarizability(polarizability_)
30  , rotational_relaxation(rot_relax)
31  , acentric_factor(acentric)
32 {
33 }
34 
36  const std::string& geometry_,
37  double diameter_, double well_depth_, double dipole_,
38  double polarizability_, double rot_relax, double acentric)
39 {
40  geometry = geometry_;
41  diameter = 1e-10 * diameter_; // convert from Angstroms to m
42  well_depth = Boltzmann * well_depth_; // convert from K to J
43  dipole = 1e-21 / lightSpeed * dipole_; // convert from Debye to Coulomb-m
44  polarizability = 1e-30 * polarizability_; // convert from Angstroms^3 to m^3
45  rotational_relaxation = rot_relax; // pure number
46  acentric_factor = acentric; // dimensionless
47 }
48 
50 {
51  double nAtoms = 0;
52  for (compositionMap::const_iterator iter = sp.composition.begin();
53  iter != sp.composition.end();
54  ++iter) {
55  nAtoms += iter->second;
56  }
57 
58  if (geometry == "atom") {
59  if (nAtoms != 1) {
60  throw CanteraError("GasTransportData::validate",
61  "invalid geometry for species '" + sp.name + "'. 'atom' "
62  "specified, but species contains multiple atoms.");
63  }
64  } else if (geometry == "linear") {
65  if (nAtoms == 1) {
66  throw CanteraError("GasTransportData::validate",
67  "invalid geometry for species '" + sp.name + "'. 'linear'"
68  " specified, but species only contains one atom.");
69  }
70  } else if (geometry == "nonlinear") {
71  if (nAtoms < 3) {
72  throw CanteraError("GasTransportData::validate",
73  "invalid geometry for species '" + sp.name + "'. 'nonlinear'"
74  " specified, but species only contains " + fp2str(nAtoms) +
75  " atoms.");
76  }
77  } else {
78  throw CanteraError("GasTransportData::validate",
79  "invalid geometry for species '" + sp.name + "': '" +
80  geometry + "'.");
81  }
82 
83  if (well_depth < 0.0) {
84  throw CanteraError("GasTransportData::validate",
85  "negative well depth for species '" + sp.name + "'.");
86  }
87 
88  if (diameter <= 0.0) {
89  throw CanteraError("GasTransportData::validate",
90  "negative or zero diameter for species '" + sp.name + "'.");
91  }
92 
93  if (dipole < 0.0) {
94  throw CanteraError("GasTransportData::validate",
95  "negative dipole moment for species '" + sp.name + "'.");
96  }
97 
98  if (polarizability < 0.0) {
99  throw CanteraError("GasTransportData::validate",
100  "negative polarizability for species '" + sp.name + "'.");
101  }
102 
103  if (rotational_relaxation < 0.0) {
104  throw CanteraError("GasTransportData::validate",
105  "negative rotation relaxation number for species '" + sp.name + "'");
106  }
107 }
108 
109 void setupGasTransportData(GasTransportData& tr, const XML_Node& tr_node)
110 {
111  std::string geometry, dummy;
112  getString(tr_node, "geometry", geometry, dummy);
113 
114  double diam = getFloat(tr_node, "LJ_diameter");
115  double welldepth = getFloat(tr_node, "LJ_welldepth");
116 
117  double dipole = 0.0;
118  getOptionalFloat(tr_node, "dipoleMoment", dipole);
119 
120  double polar = 0.0;
121  getOptionalFloat(tr_node, "polarizability", polar);
122 
123  double rot = 0.0;
124  getOptionalFloat(tr_node, "rotRelax", rot);
125  double acentric = 0.0;
126  getOptionalFloat(tr_node, "acentric_factor", acentric);
127 
128  tr.setCustomaryUnits(geometry, diam, welldepth, dipole, polar,
129  rot, acentric);
130 }
131 
132 shared_ptr<TransportData> newTransportData(const XML_Node& transport_node)
133 {
134  std::string model = transport_node["model"];
135  if (model == "gas_transport") {
136  shared_ptr<GasTransportData> tr(new GasTransportData());
137  setupGasTransportData(*tr, transport_node);
138  return tr;
139  } else {
140  // Transport model not handled here
141  return shared_ptr<TransportData>(new TransportData());
142  }
143 }
144 
145 }
Transport data for a single gas-phase species which can be used in mixture-averaged or multicomponent...
Definition: TransportData.h:27
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
double rotational_relaxation
The rotational relaxation number (the number of collisions it takes to equilibrate the rotational deg...
Definition: TransportData.h:71
double well_depth
The Lennard-Jones well depth [J].
Definition: TransportData.h:60
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:35
double diameter
The Lennard-Jones collision diameter [m].
Definition: TransportData.h:57
Base class for transport data for a single species.
Definition: TransportData.h:16
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
Definition: stringUtils.cpp:28
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
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:150
double dipole
The permanent dipole moment of the molecule [Coulomb-m]. Default 0.0.
Definition: TransportData.h:63
compositionMap composition
The elemental composition of the species.
Definition: Species.h:39
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)
Set the parameters using "customary" units: diameter in Angstroms, well depth in Kelvin, dipole in Debye, and polarizability in Angstroms^3.
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:194
std::string geometry
A string specifying the molecular geometry.
Definition: TransportData.h:54
Contains data about a single chemical species.
Definition: Species.h:21
double polarizability
The polarizability of the molecule [m^3]. Default 0.0.
Definition: TransportData.h:66
double acentric_factor
Pitzer's acentric factor [dimensionless]. Default 0.0.
Definition: TransportData.h:74
Declaration for class Cantera::Species.
const doublereal lightSpeed
Speed of Light (m/s).
Definition: ct_defs.h:100
const doublereal Boltzmann
Boltzmann'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 'transport' 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:252