diff --git a/include/cantera/transport/TransportFactory.h b/include/cantera/transport/TransportFactory.h index 2998aaba6..1283d8df7 100644 --- a/include/cantera/transport/TransportFactory.h +++ b/include/cantera/transport/TransportFactory.h @@ -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 m_models; + //! Inverse mapping of transport models, from integer constant to string + std::map m_modelNames; + //! Mapping between between the string name //! for a transport property and the integer name. std::map m_tranPropMap; diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index b5209ca09..76644c632 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -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 + diff --git a/interfaces/cython/cantera/transport.pyx b/interfaces/cython/cantera/transport.pyx index bfff53dd6..fe8ecc82c 100644 --- a/interfaces/cython/cantera/transport.pyx +++ b/interfaces/cython/cantera/transport.pyx @@ -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() diff --git a/src/transport/TransportFactory.cpp b/src/transport/TransportFactory.cpp index 82712cf5e..f33963929 100644 --- a/src/transport/TransportFactory.cpp +++ b/src/transport/TransportFactory.cpp @@ -206,6 +206,11 @@ TransportFactory::TransportFactory() : m_models["Pecos"] = cPecosTransport; m_models["None"] = None; //m_models["Radiative"] = cRadiative; + for (map::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::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