[Transport] Refactor TransportData initialization

This commit is contained in:
Ray Speth 2015-04-17 22:38:06 -04:00
parent d6f7fd855a
commit a63874e4b4
3 changed files with 47 additions and 26 deletions

View file

@ -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<TransportData> newTransportData(const XML_Node& transport_node);
}
#endif

View file

@ -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);
}

View file

@ -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<TransportData> newTransportData(const XML_Node& transport_node)
{
std::string model = transport_node["model"];
if (model == "gas_transport") {
shared_ptr<GasTransportData> tr(new GasTransportData());
setupGasTransportData(*tr, transport_node);
return tr;
} else {
// Transport model not handled here
return shared_ptr<TransportData>(new TransportData());
}
}
}