From bd8a5d0bc97fbe8b68f0d0ed5e36a90b8bd0953a Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 7 Jul 2016 22:25:05 -0400 Subject: [PATCH] [Transport] Replace numerical constants for Transport types with strings --- include/cantera/oneD/StFlow.h | 7 +- include/cantera/transport/DustyGasTransport.h | 6 ++ .../transport/HighPressureGasTransport.h | 6 ++ include/cantera/transport/LiquidTransport.h | 6 ++ include/cantera/transport/MixTransport.h | 6 ++ include/cantera/transport/MultiTransport.h | 6 ++ include/cantera/transport/SimpleTransport.h | 6 ++ include/cantera/transport/SolidTransport.h | 6 ++ include/cantera/transport/TransportBase.h | 10 +++ include/cantera/transport/TransportFactory.h | 3 + include/cantera/transport/WaterTransport.h | 6 ++ interfaces/cython/cantera/_cantera.pxd | 6 +- interfaces/cython/cantera/transport.pyx | 2 +- src/oneD/StFlow.cpp | 78 ++++++++----------- src/transport/TransportFactory.cpp | 24 +++--- 15 files changed, 105 insertions(+), 73 deletions(-) diff --git a/include/cantera/oneD/StFlow.h b/include/cantera/oneD/StFlow.h index b2eb66da9..b8b579f17 100644 --- a/include/cantera/oneD/StFlow.h +++ b/include/cantera/oneD/StFlow.h @@ -24,11 +24,6 @@ const size_t c_offset_T = 2; // temperature const size_t c_offset_L = 3; // (1/r)dP/dr const size_t c_offset_Y = 4; // mass fractions -// Transport option flags -const int c_Mixav_Transport = 0; -const int c_Multi_Transport = 1; -const int c_Soret = 2; - class Transport; /** @@ -394,7 +389,7 @@ protected: std::vector m_do_energy; bool m_do_soret; std::vector m_do_species; - int m_transport_option; + bool m_do_multicomponent; //! flag for the radiative heat loss bool m_do_radiation; diff --git a/include/cantera/transport/DustyGasTransport.h b/include/cantera/transport/DustyGasTransport.h index 64d4e66e0..8abb7a6b7 100644 --- a/include/cantera/transport/DustyGasTransport.h +++ b/include/cantera/transport/DustyGasTransport.h @@ -89,9 +89,15 @@ public: virtual void setThermo(thermo_t& thermo); virtual int model() const { + warn_deprecated("DustyGasTransport::model", + "To be removed after Cantera 2.3."); return cDustyGasTransport; } + virtual std::string transportType() const { + return "DustyGas"; + } + virtual void getMultiDiffCoeffs(const size_t ld, doublereal* const d); //! Get the molar fluxes [kmol/m^2/s], given the thermodynamic state at two nearby points. diff --git a/include/cantera/transport/HighPressureGasTransport.h b/include/cantera/transport/HighPressureGasTransport.h index b76959ed1..e78586a6f 100644 --- a/include/cantera/transport/HighPressureGasTransport.h +++ b/include/cantera/transport/HighPressureGasTransport.h @@ -35,6 +35,8 @@ protected: public: virtual int model() const { + warn_deprecated("HighPressureGasTransport::model", + "To be removed after Cantera 2.3."); if (m_mode == CK_Mode) { throw CanteraError("HighPressureGasTransport::model", "CK_Mode not accepted"); @@ -43,6 +45,10 @@ public: } } + virtual std::string transportType() const { + return "HighPressureGas"; + } + //! Return the thermal diffusion coefficients (kg/m/s) /*! * Currently not implemented for this model diff --git a/include/cantera/transport/LiquidTransport.h b/include/cantera/transport/LiquidTransport.h index 46f5bdbbd..474bd6d6d 100644 --- a/include/cantera/transport/LiquidTransport.h +++ b/include/cantera/transport/LiquidTransport.h @@ -95,9 +95,15 @@ public: friend class TransportFactory; virtual int model() const { + warn_deprecated("LiquidTransport::model", + "To be removed after Cantera 2.3."); return cLiquidTransport; } + virtual std::string transportType() const { + return "Liquid"; + } + //! Returns the viscosity of the solution /*! * The viscosity calculation is handled by subclasses of diff --git a/include/cantera/transport/MixTransport.h b/include/cantera/transport/MixTransport.h index 078413317..df9985f8d 100644 --- a/include/cantera/transport/MixTransport.h +++ b/include/cantera/transport/MixTransport.h @@ -67,9 +67,15 @@ public: * @return cMixtureAverage */ virtual int model() const { + warn_deprecated("MixTransport::model", + "To be removed after Cantera 2.3."); return cMixtureAveraged; } + virtual std::string transportType() const { + return "Mix"; + } + //! Return the thermal diffusion coefficients /*! * For this approximation, these are all zero. diff --git a/include/cantera/transport/MultiTransport.h b/include/cantera/transport/MultiTransport.h index dc6caed96..dceb187fd 100644 --- a/include/cantera/transport/MultiTransport.h +++ b/include/cantera/transport/MultiTransport.h @@ -32,6 +32,8 @@ public: MultiTransport(thermo_t* thermo=0); virtual int model() const { + warn_deprecated("MultiTransport::model", + "To be removed after Cantera 2.3."); if (m_mode == CK_Mode) { return CK_Multicomponent; } else { @@ -39,6 +41,10 @@ public: } } + virtual std::string transportType() const { + return "Multi"; + } + //! Return the thermal diffusion coefficients (kg/m/s) /*! * Eqn. (12.126) displays how they are calculated. The reference work is diff --git a/include/cantera/transport/SimpleTransport.h b/include/cantera/transport/SimpleTransport.h index 4054a793d..89c3b03ca 100644 --- a/include/cantera/transport/SimpleTransport.h +++ b/include/cantera/transport/SimpleTransport.h @@ -207,9 +207,15 @@ public: virtual bool initLiquid(LiquidTransportParams& tr); virtual int model() const { + warn_deprecated("SimpleTransport::model", + "To be removed after Cantera 2.3."); return cSimpleTransport; } + virtual std::string transportType() const { + return "Simple"; + } + //! Returns the mixture viscosity of the solution /*! * The viscosity is computed using the general mixture rules diff --git a/include/cantera/transport/SolidTransport.h b/include/cantera/transport/SolidTransport.h index d7f231d1c..f30ea3af2 100644 --- a/include/cantera/transport/SolidTransport.h +++ b/include/cantera/transport/SolidTransport.h @@ -26,9 +26,15 @@ public: virtual Transport* duplMyselfAsTransport() const; virtual int model() const { + warn_deprecated("SolidTransport::model", + "To be removed after Cantera 2.3."); return cSolidTransport; } + virtual std::string transportType() const { + return "Solid"; + } + //! Returns the ionic conductivity of the phase /*! * The thermo phase needs to be updated (temperature) prior to calling this. diff --git a/include/cantera/transport/TransportBase.h b/include/cantera/transport/TransportBase.h index d7fe22242..a33dafbcf 100644 --- a/include/cantera/transport/TransportBase.h +++ b/include/cantera/transport/TransportBase.h @@ -33,6 +33,7 @@ class SolidTransportData; const int CK_Mode = 10; // types of transport models that can be constructed +// @deprecated To be removed after Cantera 2.3. const int None = 199; const int cMulticomponent = 200; const int CK_Multicomponent = 202; @@ -181,11 +182,20 @@ public: * The transport model is the set of equations used to compute the transport * properties. This method returns an integer flag that identifies the * transport model implemented. The base class returns 0. + * @deprecated Use `transportType()` instead. To be removed after Cantera + * 2.3. */ virtual int model() const { + warn_deprecated("Transport::model", "To be removed after Cantera 2.3."); return 0; } + //! Identifies the Transport object type. Each derived class should override + //! this method to return a meaningful identifier. + virtual std::string transportType() const { + return "Transport"; + } + /*! * Phase object. Every transport manager is designed to compute properties * for a specific phase of a mixture, which might be a liquid solution, a diff --git a/include/cantera/transport/TransportFactory.h b/include/cantera/transport/TransportFactory.h index 2fc7902c3..4a79ffc12 100644 --- a/include/cantera/transport/TransportFactory.h +++ b/include/cantera/transport/TransportFactory.h @@ -55,6 +55,7 @@ public: //! Get the name of the transport model corresponding to the specified constant. /*! * @param model Integer representing the model name + * @deprecated To be removed after Cantera 2.3. */ static std::string modelName(int model); @@ -225,9 +226,11 @@ private: //! Mapping between between the string name for a transport model and the //! integer name. + //! @deprecated To be removed after Cantera 2.3. std::map m_models; //! Inverse mapping of transport models, from integer constant to string + //! @deprecated To be removed after Cantera 2.3. std::map m_modelNames; //! Mapping between between the string name diff --git a/include/cantera/transport/WaterTransport.h b/include/cantera/transport/WaterTransport.h index 6c83b0f66..1214069f3 100644 --- a/include/cantera/transport/WaterTransport.h +++ b/include/cantera/transport/WaterTransport.h @@ -41,9 +41,15 @@ public: virtual Transport* duplMyselfAsTransport() const; virtual int model() const { + warn_deprecated("WaterTransport::model", + "To be removed after Cantera 2.3."); return cWaterTransport; } + virtual std::string transportType() const { + return "Water"; + } + //! Returns the viscosity of water at the current conditions (kg/m/s) /*! * This function calculates the value of the viscosity of pure water at the diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index d9424a414..a6748e6d6 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -372,14 +372,10 @@ cdef extern from "cantera/kinetics/InterfaceKinetics.h": 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() + string transportType() double viscosity() except + double thermalConductivity() except + double electricalConductivity() except + diff --git a/interfaces/cython/cantera/transport.pyx b/interfaces/cython/cantera/transport.pyx index 4e110af02..82e67f53e 100644 --- a/interfaces/cython/cantera/transport.pyx +++ b/interfaces/cython/cantera/transport.pyx @@ -132,7 +132,7 @@ cdef class Transport(_SolutionBase): object and replaces it with a new one implementing the specified model. """ def __get__(self): - return pystr(transportModelName(self.transport.model())) + return pystr(self.transport.transportType()) def __set__(self, model): cdef CxxTransport* old = self.transport diff --git a/src/oneD/StFlow.cpp b/src/oneD/StFlow.cpp index 7ca6bec46..c68e85bf4 100644 --- a/src/oneD/StFlow.cpp +++ b/src/oneD/StFlow.cpp @@ -22,7 +22,7 @@ StFlow::StFlow(IdealGasPhase* ph, size_t nsp, size_t points) : m_epsilon_left(0.0), m_epsilon_right(0.0), m_do_soret(false), - m_transport_option(-1), + m_do_multicomponent(false), m_do_radiation(false), m_kExcessLeft(0), m_kExcessRight(0) @@ -103,11 +103,9 @@ void StFlow::resize(size_t ncomponents, size_t points) m_visc.resize(m_points, 0.0); m_tcon.resize(m_points, 0.0); - if (m_transport_option == c_Mixav_Transport) { - m_diff.resize(m_nsp*m_points); - } else { + m_diff.resize(m_nsp*m_points); + if (m_do_multicomponent) { m_multidiff.resize(m_nsp*m_nsp*m_points); - m_diff.resize(m_nsp*m_points); m_dthermal.resize(m_nsp, m_points, 0.0); } m_flux.resize(m_nsp,m_points); @@ -149,29 +147,22 @@ void StFlow::setTransport(Transport& trans, bool withSoret) { m_trans = &trans; m_do_soret = withSoret; + m_do_multicomponent = (m_trans->transportType() == "Multi"); - int model = m_trans->model(); - if (model == cMulticomponent || model == CK_Multicomponent) { - m_transport_option = c_Multi_Transport; + m_diff.resize(m_nsp*m_points); + if (m_do_multicomponent) { m_multidiff.resize(m_nsp*m_nsp*m_points); - m_diff.resize(m_nsp*m_points); m_dthermal.resize(m_nsp, m_points, 0.0); - } else if (model == cMixtureAveraged || model == CK_MixtureAveraged) { - m_transport_option = c_Mixav_Transport; - m_diff.resize(m_nsp*m_points); - if (withSoret) { - throw CanteraError("setTransport", - "Thermal diffusion (the Soret effect) " - "requires using a multicomponent transport model."); - } - } else { - throw CanteraError("setTransport","unknown transport model."); + } else if (withSoret) { + throw CanteraError("setTransport", + "Thermal diffusion (the Soret effect) " + "requires using a multicomponent transport model."); } } void StFlow::enableSoret(bool withSoret) { - if (m_transport_option == c_Multi_Transport) { + if (m_do_multicomponent) { m_do_soret = withSoret; } else { throw CanteraError("setTransport", @@ -458,14 +449,7 @@ void StFlow::eval(size_t jg, doublereal* xg, void StFlow::updateTransport(doublereal* x, size_t j0, size_t j1) { - if (m_transport_option == c_Mixav_Transport) { - for (size_t j = j0; j < j1; j++) { - setGasAtMidpoint(x,j); - m_visc[j] = (m_dovisc ? m_trans->viscosity() : 0.0); - m_trans->getMixDiffCoeffs(&m_diff[j*m_nsp]); - m_tcon[j] = m_trans->thermalConductivity(); - } - } else if (m_transport_option == c_Multi_Transport) { + if (m_do_multicomponent) { for (size_t j = j0; j < j1; j++) { setGasAtMidpoint(x,j); doublereal wtm = m_thermo->meanMolecularWeight(); @@ -483,6 +467,13 @@ void StFlow::updateTransport(doublereal* x, size_t j0, size_t j1) m_trans->getThermalDiffCoeffs(m_dthermal.ptrColumn(0) + j*m_nsp); } } + } else { // mixture averaged transport + for (size_t j = j0; j < j1; j++) { + setGasAtMidpoint(x,j); + m_visc[j] = (m_dovisc ? m_trans->viscosity() : 0.0); + m_trans->getMixDiffCoeffs(&m_diff[j*m_nsp]); + m_tcon[j] = m_trans->thermalConductivity(); + } } } @@ -505,8 +496,18 @@ void StFlow::showSolution(const doublereal* x) void StFlow::updateDiffFluxes(const doublereal* x, size_t j0, size_t j1) { - switch (m_transport_option) { - case c_Mixav_Transport: + if (m_do_multicomponent) { + for (size_t j = j0; j < j1; j++) { + double dz = z(j+1) - z(j); + for (double k = 0; k < m_nsp; k++) { + doublereal sum = 0.0; + for (size_t m = 0; m < m_nsp; m++) { + sum += m_wt[m] * m_multidiff[mindex(k,m,j)] * (X(x,m,j+1)-X(x,m,j)); + } + m_flux(k,j) = sum * m_diff[k+j*m_nsp] / dz; + } + } + } else { for (size_t j = j0; j < j1; j++) { double sum = 0.0; double wtm = m_wtm[j]; @@ -522,23 +523,6 @@ void StFlow::updateDiffFluxes(const doublereal* x, size_t j0, size_t j1) m_flux(k,j) += sum*Y(x,k,j); } } - break; - - case c_Multi_Transport: - for (size_t j = j0; j < j1; j++) { - double dz = z(j+1) - z(j); - for (double k = 0; k < m_nsp; k++) { - doublereal sum = 0.0; - for (size_t m = 0; m < m_nsp; m++) { - sum += m_wt[m] * m_multidiff[mindex(k,m,j)] * (X(x,m,j+1)-X(x,m,j)); - } - m_flux(k,j) = sum * m_diff[k+j*m_nsp] / dz; - } - } - break; - - default: - throw CanteraError("updateDiffFluxes","unknown transport model"); } if (m_do_soret) { diff --git a/src/transport/TransportFactory.cpp b/src/transport/TransportFactory.cpp index 8af521307..0175a3936 100644 --- a/src/transport/TransportFactory.cpp +++ b/src/transport/TransportFactory.cpp @@ -104,6 +104,8 @@ void TransportFactory::deleteFactory() std::string TransportFactory::modelName(int model) { + warn_deprecated("TransportFactory::modelName", + "To be removed after Cantera 2.3."); return getValue(factory()->m_modelNames, model, ""); } @@ -184,34 +186,28 @@ Transport* TransportFactory::newTransport(const std::string& transportModel, thermo_t* phase, int log_level, int ndim) { vector_fp state; - Transport* tr = 0, *gastr = 0; - DustyGasTransport* dtr = 0; + Transport* tr = 0; phase->saveState(state); - switch (m_models[transportModel]) { - case cSolidTransport: + if (transportModel == "Solid") { tr = new SolidTransport; initSolidTransport(tr, phase, log_level); tr->setThermo(*phase); - break; - case cDustyGasTransport: + } else if (transportModel == "DustyGas") { tr = new DustyGasTransport; - gastr = new MultiTransport; + Transport* gastr = new MultiTransport; gastr->init(phase, 0, log_level); - dtr = (DustyGasTransport*)tr; + DustyGasTransport* dtr = (DustyGasTransport*)tr; dtr->initialize(phase, gastr); - break; - case cSimpleTransport: + } else if (transportModel == "Simple") { tr = new SimpleTransport(); initLiquidTransport(tr, phase, log_level); tr->setThermo(*phase); - break; - case cLiquidTransport: + } else if (transportModel == "Liquid") { tr = new LiquidTransport(phase, ndim); initLiquidTransport(tr, phase, log_level); tr->setThermo(*phase); - break; - default: + } else { tr = create(transportModel); tr->init(phase, m_CK_mode[transportModel], log_level); }