diff --git a/include/cantera/transport/TransportData.h b/include/cantera/transport/TransportData.h index 74210cfe2..a52b73b47 100644 --- a/include/cantera/transport/TransportData.h +++ b/include/cantera/transport/TransportData.h @@ -4,11 +4,13 @@ #define CT_TRANSPORTDATA_H #include "cantera/base/ct_defs.h" +#include "cantera/base/smart_ptr.h" namespace Cantera { class Species; +class XML_Node; //! Base class for transport data for a single species class TransportData @@ -67,6 +69,9 @@ public: double acentric_factor; }; +//! Create a new TransportData object from a 'transport' XML_Node. +shared_ptr newTransportData(const XML_Node& transport_node); + } #endif diff --git a/src/thermo/ThermoFactory.cpp b/src/thermo/ThermoFactory.cpp index 6cb7c3953..237c60ff3 100644 --- a/src/thermo/ThermoFactory.cpp +++ b/src/thermo/ThermoFactory.cpp @@ -624,32 +624,9 @@ bool installSpecies(size_t k, const XML_Node& s, thermo_t& th, sp->thermo.reset(newSpeciesThermoInterpType(s.child("thermo"))); // Read gas-phase transport data, if provided - if (s.hasChild("transport") && - s.child("transport")["model"] == "gas_transport") { - XML_Node& tr = s.child("transport"); - - string geometry, dummy; - getString(tr, "geometry", geometry, dummy); - - double diam = getFloat(tr, "LJ_diameter"); - double welldepth = getFloat(tr, "LJ_welldepth"); - - double dipole = 0.0; - getOptionalFloat(tr, "dipoleMoment", dipole); - - double polar = 0.0; - getOptionalFloat(tr, "polarizability", polar); - - double rot = 0.0; - getOptionalFloat(tr, "rotRelax", rot); - double acentric = 0.0; - getOptionalFloat(tr, "acentric_factor", acentric); - - GasTransportData* gastran = new GasTransportData; - gastran->setCustomaryUnits(geometry, diam, welldepth, - dipole, polar, rot, acentric); - sp->transport.reset(gastran); - gastran->validate(*sp); + if (s.hasChild("transport")) { + sp->transport = newTransportData(s.child("transport")); + sp->transport->validate(*sp); } th.addSpecies(sp); } diff --git a/src/transport/TransportData.cpp b/src/transport/TransportData.cpp index 3d8bf4d30..7fb6a6bb5 100644 --- a/src/transport/TransportData.cpp +++ b/src/transport/TransportData.cpp @@ -4,6 +4,9 @@ #include "cantera/thermo/Species.h" #include "cantera/base/ctexceptions.h" #include "cantera/base/stringUtils.h" +#include "cantera/base/ctml.h" + +using namespace ctml; namespace Cantera { @@ -106,4 +109,40 @@ void GasTransportData::validate(const Species& sp) } } +void setupGasTransportData(GasTransportData& tr, const XML_Node& tr_node) +{ + std::string geometry, dummy; + getString(tr_node, "geometry", geometry, dummy); + + double diam = getFloat(tr_node, "LJ_diameter"); + double welldepth = getFloat(tr_node, "LJ_welldepth"); + + double dipole = 0.0; + getOptionalFloat(tr_node, "dipoleMoment", dipole); + + double polar = 0.0; + getOptionalFloat(tr_node, "polarizability", polar); + + double rot = 0.0; + getOptionalFloat(tr_node, "rotRelax", rot); + double acentric = 0.0; + getOptionalFloat(tr_node, "acentric_factor", acentric); + + tr.setCustomaryUnits(geometry, diam, welldepth, dipole, polar, + rot, acentric); +} + +shared_ptr newTransportData(const XML_Node& transport_node) +{ + std::string model = transport_node["model"]; + if (model == "gas_transport") { + shared_ptr tr(new GasTransportData()); + setupGasTransportData(*tr, transport_node); + return tr; + } else { + // Transport model not handled here + return shared_ptr(new TransportData()); + } +} + }