Added ability to switch between transport models in the Cython module

This commit is contained in:
Ray Speth 2012-09-06 19:59:45 +00:00
parent a9132d1fc3
commit 5f2ec1f11d
4 changed files with 37 additions and 1 deletions

View file

@ -80,6 +80,9 @@ public:
*/
virtual ~TransportFactory() {}
//! Get the name of the transport model corresponding to the specified constant.
static std::string modelName(int model);
//! Make one of several transport models, and return a base class pointer to it.
/*!
* This method operates at the level of a single transport property as a function of temperature
@ -161,7 +164,6 @@ public:
*/
virtual void initLiquidTransport(Transport* tr, thermo_t* thermo, int log_level=0);
private:
//! Static instance of the factor -> This is the only instance of this
@ -362,6 +364,9 @@ private:
//! for a transport model and the integer name.
std::map<std::string, int> m_models;
//! Inverse mapping of transport models, from integer constant to string
std::map<int, std::string> m_modelNames;
//! Mapping between between the string name
//! for a transport property and the integer name.
std::map<std::string, TransportPropertyType> m_tranPropMap;

View file

@ -153,9 +153,15 @@ cdef extern from "cantera/kinetics/InterfaceKinetics.h":
cdef cppclass CxxInterfaceKinetics "Cantera::InterfaceKinetics":
void advanceCoverages(double) except +
cdef extern from "cantera/transport/TransportFactory.h":
cdef string transportModelName "Cantera::TransportFactory::modelName" (int)
cdef extern from "cantera/transport/TransportBase.h" namespace "Cantera":
cdef cppclass CxxTransport "Cantera::Transport":
CxxTransport(CxxThermoPhase*)
int model()
double viscosity() except +
double thermalConductivity() except +

View file

@ -25,6 +25,15 @@ cdef class Transport(_SolutionBase):
self.transport = newDefaultTransportMgr(self.thermo)
super().__init__(*args, **kwargs)
property transportModel:
def __get__(self):
return pystr(transportModelName(self.transport.model()))
def __set__(self, model):
cdef CxxTransport* old = self.transport
self.transport = newTransportMgr(stringify(model), self.thermo)
del old # only if the new transport manager was successfully created
property viscosity:
def __get__(self):
return self.transport.viscosity()

View file

@ -206,6 +206,11 @@ TransportFactory::TransportFactory() :
m_models["Pecos"] = cPecosTransport;
m_models["None"] = None;
//m_models["Radiative"] = cRadiative;
for (map<string, int>::iterator iter = m_models.begin();
iter != m_models.end();
iter++) {
m_modelNames[iter->second] = iter->first;
}
m_tranPropMap["viscosity"] = TP_VISCOSITY;
m_tranPropMap["ionConductivity"] = TP_IONCONDUCTIVITY;
@ -244,6 +249,17 @@ void TransportFactory::deleteFactory()
}
}
std::string TransportFactory::modelName(int model)
{
TransportFactory& f = *factory();
map<int, string>::iterator iter = f.m_modelNames.find(model);
if (iter != f.m_modelNames.end()) {
return iter->second;
} else {
return "";
}
}
/*
make one of several transport models, and return a base class
pointer to it. This method operates at the level of a