Cantera  2.3.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 {
22 }
23 
24 GasTransportData::GasTransportData(
25  const std::string& geometry_,
26  double diameter_, double well_depth_, double dipole_,
27  double polarizability_, double rot_relax, double acentric)
28  : geometry(geometry_)
29  , diameter(diameter_)
30  , well_depth(well_depth_)
31  , dipole(dipole_)
32  , polarizability(polarizability_)
33  , rotational_relaxation(rot_relax)
34  , acentric_factor(acentric)
35 {
36 }
37 
39  const std::string& geometry_,
40  double diameter_, double well_depth_, double dipole_,
41  double polarizability_, double rot_relax, double acentric)
42 {
43  geometry = geometry_;
44  diameter = 1e-10 * diameter_; // convert from Angstroms to m
45  well_depth = Boltzmann * well_depth_; // convert from K to J
46  dipole = 1e-21 / lightSpeed * dipole_; // convert from Debye to Coulomb-m
47  polarizability = 1e-30 * polarizability_; // convert from Angstroms^3 to m^3
48  rotational_relaxation = rot_relax; // pure number
49  acentric_factor = acentric; // dimensionless
50 }
51 
53 {
54  double nAtoms = 0;
55  for (const auto& elem : sp.composition) {
56  if (!ba::iequals(elem.first, "E")) {
57  nAtoms += elem.second;
58  }
59  }
60 
61  if (geometry == "atom") {
62  if (nAtoms > 1) {
63  throw CanteraError("GasTransportData::validate",
64  "invalid geometry for species '{}'. 'atom' specified, but "
65  "species contains multiple atoms.", sp.name);
66  }
67  } else if (geometry == "linear") {
68  if (nAtoms < 2) {
69  throw CanteraError("GasTransportData::validate",
70  "invalid geometry for species '{}'. 'linear' specified, but "
71  "species does not contain multiple atoms.", sp.name);
72  }
73  } else if (geometry == "nonlinear") {
74  if (nAtoms < 3) {
75  throw CanteraError("GasTransportData::validate",
76  "invalid geometry for species '{}'. 'nonlinear' specified, but "
77  "species only contains {} atoms.", sp.name, nAtoms);
78  }
79  } else {
80  throw CanteraError("GasTransportData::validate",
81  "invalid geometry for species '{}': '{}'.", sp.name, geometry);
82  }
83 
84  if (well_depth < 0.0) {
85  throw CanteraError("GasTransportData::validate",
86  "negative well depth for species '{}'.", sp.name);
87  }
88 
89  if (diameter <= 0.0) {
90  throw CanteraError("GasTransportData::validate",
91  "negative or zero diameter for species '{}'.", sp.name);
92  }
93 
94  if (dipole < 0.0) {
95  throw CanteraError("GasTransportData::validate",
96  "negative dipole moment for species '{}'.", sp.name);
97  }
98 
99  if (polarizability < 0.0) {
100  throw CanteraError("GasTransportData::validate",
101  "negative polarizability for species '{}'.", sp.name);
102  }
103 
104  if (rotational_relaxation < 0.0) {
105  throw CanteraError("GasTransportData::validate",
106  "negative rotation relaxation number for species '{}'.", sp.name);
107  }
108 }
109 
110 void setupGasTransportData(GasTransportData& tr, const XML_Node& tr_node)
111 {
112  std::string geometry, dummy;
113  getString(tr_node, "geometry", geometry, dummy);
114 
115  double diam = getFloat(tr_node, "LJ_diameter");
116  double welldepth = getFloat(tr_node, "LJ_welldepth");
117 
118  double dipole = 0.0;
119  getOptionalFloat(tr_node, "dipoleMoment", dipole);
120 
121  double polar = 0.0;
122  getOptionalFloat(tr_node, "polarizability", polar);
123 
124  double rot = 0.0;
125  getOptionalFloat(tr_node, "rotRelax", rot);
126  double acentric = 0.0;
127  getOptionalFloat(tr_node, "acentric_factor", acentric);
128 
129  tr.setCustomaryUnits(geometry, diam, welldepth, dipole, polar,
130  rot, acentric);
131 }
132 
133 shared_ptr<TransportData> newTransportData(const XML_Node& transport_node)
134 {
135  std::string model = transport_node["model"];
136  if (model == "gas_transport") {
137  auto tr = make_shared<GasTransportData>();
138  setupGasTransportData(*tr, transport_node);
139  return tr;
140  } else {
141  // Transport model not handled here
142  return make_shared<TransportData>();
143  }
144 }
145 
146 }
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...
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:73
double well_depth
The Lennard-Jones well depth [J].
Definition: TransportData.h:62
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:59
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:153
double dipole
The permanent dipole moment of the molecule [Coulomb-m]. Default 0.0.
Definition: TransportData.h:65
compositionMap composition
The elemental composition of the species.
Definition: Species.h:43
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:178
std::string geometry
A string specifying the molecular geometry.
Definition: TransportData.h:56
Contains data about a single chemical species.
Definition: Species.h:23
double polarizability
The polarizability of the molecule [m^3]. Default 0.0.
Definition: TransportData.h:68
double acentric_factor
Pitzer&#39;s acentric factor [dimensionless]. Default 0.0.
Definition: TransportData.h:76
Declaration for class Cantera::Species.
const doublereal lightSpeed
Speed of Light (m/s).
Definition: ct_defs.h:100
Namespace for the Cantera kernel.
Definition: application.cpp:29
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:226