From 45be8d192448d223e65ae40d27c955665bcf84df Mon Sep 17 00:00:00 2001 From: Dave Goodwin Date: Wed, 25 Apr 2007 20:41:45 +0000 Subject: [PATCH] added ability to enable Soret effect in flame calculations --- Cantera/clib/src/ctonedim.cpp | 16 ++++++++++++++-- Cantera/clib/src/ctonedim.h | 3 ++- Cantera/python/Cantera/OneD/onedim.py | 10 ++++++++-- Cantera/python/examples/flames/flame2.py | 4 ++++ Cantera/python/src/ctonedim_methods.cpp | 19 ++++++++++++++++--- Cantera/python/src/methods.h | 1 + Cantera/src/ThermoFactory.cpp | 4 ++-- Cantera/src/oneD/StFlow.cpp | 10 ++++++++++ Cantera/src/oneD/StFlow.h | 2 ++ 9 files changed, 59 insertions(+), 10 deletions(-) diff --git a/Cantera/clib/src/ctonedim.cpp b/Cantera/clib/src/ctonedim.cpp index 5a4ef20e6..dacef08a2 100644 --- a/Cantera/clib/src/ctonedim.cpp +++ b/Cantera/clib/src/ctonedim.cpp @@ -355,9 +355,21 @@ extern "C" { } - int DLL_EXPORT stflow_setTransport(int i, int itr) { + int DLL_EXPORT stflow_setTransport(int i, int itr, int iSoret) { + bool withSoret = false; + if (iSoret > 0) withSoret = true; try { - _stflow(i)->setTransport(*_transport(itr)); + _stflow(i)->setTransport(*_transport(itr), withSoret); + return 0; + } + catch (CanteraError) { return -1; } + } + + int DLL_EXPORT stflow_enableSoret(int i, int iSoret) { + bool withSoret = false; + if (iSoret > 0) withSoret = true; + try { + _stflow(i)->enableSoret(withSoret); return 0; } catch (CanteraError) { return -1; } diff --git a/Cantera/clib/src/ctonedim.h b/Cantera/clib/src/ctonedim.h index 9ae2ed638..946cba662 100644 --- a/Cantera/clib/src/ctonedim.h +++ b/Cantera/clib/src/ctonedim.h @@ -47,7 +47,8 @@ extern "C" { int DLL_IMPORT inlet_setSpreadRate(int i, double v); int DLL_IMPORT stflow_new(int iph, int ikin, int itr, int itype=1); - int DLL_IMPORT stflow_setTransport(int i, int itr); + int DLL_IMPORT stflow_setTransport(int i, int itr, int iSoret); + int DLL_IMPORT stflow_enableSoret(int i, int iSoret); int DLL_IMPORT stflow_setPressure(int i, double p); int DLL_IMPORT stflow_setFixedTempProfile(int i, int n, double* pos, int m, double* temp); diff --git a/Cantera/python/Cantera/OneD/onedim.py b/Cantera/python/Cantera/OneD/onedim.py index dfee04a7d..34c932798 100644 --- a/Cantera/python/Cantera/OneD/onedim.py +++ b/Cantera/python/Cantera/OneD/onedim.py @@ -389,11 +389,17 @@ class AxisymmetricFlow(Domain1D): _cantera.stflow_setPressure(self._hndl, p) self._p = p - def setTransportModel(self, transp): + def setTransportModel(self, transp, withSoret = 0): """Set the transport model. The argument must be a transport manager for the 'gas' object.""" itr = transp.transport_hndl() - _cantera.stflow_setTransport(self._hndl, itr) + _cantera.stflow_setTransport(self._hndl, itr, withSoret) + + def enableSoret(self, withSoret = 1): + """Include or exclude thermal diffusion (Soret effect) when computing + diffusion velocities. If withSoret is not supplied or is positive, + thermal diffusion is enabled; otherwise it is disabled.""" + _cantera.stflow_enableSoret(self._hndl, withSoret) def pressure(self): """Pressure [Pa].""" diff --git a/Cantera/python/examples/flames/flame2.py b/Cantera/python/examples/flames/flame2.py index a3bf9ebf1..ae1466483 100755 --- a/Cantera/python/examples/flames/flame2.py +++ b/Cantera/python/examples/flames/flame2.py @@ -72,6 +72,10 @@ f.flame.setTransportModel(gas) f.solve(loglevel, refine_grid) f.save('ch4_flame1.xml','energy_multi', 'solution with the energy equation enabled and multicomponent transport') +f.flame.enableSoret() +f.solve(loglevel, refine_grid) +f.save('ch4_flame1.xml','energy_multi_soret', + 'solution with the energy equation enabled and multicomponent transport with thermal diffusion') # write the velocity, temperature, density, and mole fractions to a CSV file z = f.flame.grid() diff --git a/Cantera/python/src/ctonedim_methods.cpp b/Cantera/python/src/ctonedim_methods.cpp index 42ffb0b49..4416a3254 100644 --- a/Cantera/python/src/ctonedim_methods.cpp +++ b/Cantera/python/src/ctonedim_methods.cpp @@ -489,11 +489,24 @@ static PyObject * py_stflow_setTransport(PyObject *self, PyObject *args) { int _val; - int i, itr; - if (!PyArg_ParseTuple(args, "ii:stflow_setTransport", &i, &itr)) + int i, itr, isoret; + if (!PyArg_ParseTuple(args, "iii:stflow_setTransport", &i, &itr, &isoret)) return NULL; - _val = stflow_setTransport(i,itr); + _val = stflow_setTransport(i,itr, isoret); + if (int(_val) == -1) return reportCanteraError(); + return Py_BuildValue("i",_val); +} + +static PyObject * +py_stflow_enableSoret(PyObject *self, PyObject *args) +{ + int _val; + int i, isoret; + if (!PyArg_ParseTuple(args, "ii:stflow_enableSoret", &i, &isoret)) + return NULL; + + _val = stflow_enableSoret(i,isoret); if (int(_val) == -1) return reportCanteraError(); return Py_BuildValue("i",_val); } diff --git a/Cantera/python/src/methods.h b/Cantera/python/src/methods.h index 1aaa25819..1bc0b795d 100644 --- a/Cantera/python/src/methods.h +++ b/Cantera/python/src/methods.h @@ -127,6 +127,7 @@ static PyMethodDef ct_methods[] = { {"stflow_new", py_stflow_new, METH_VARARGS}, {"stflow_setPressure", py_stflow_setPressure, METH_VARARGS}, {"stflow_setTransport", py_stflow_setTransport, METH_VARARGS}, + {"stflow_enableSoret", py_stflow_enableSoret, METH_VARARGS}, {"stflow_setFixedTempProfile", py_stflow_setFixedTempProfile, METH_VARARGS}, {"stflow_solveSpeciesEqs", py_stflow_solveSpeciesEqs, METH_VARARGS}, {"stflow_solveEnergyEqn", py_stflow_solveEnergyEqn, METH_VARARGS}, diff --git a/Cantera/src/ThermoFactory.cpp b/Cantera/src/ThermoFactory.cpp index 8b42119bb..c37290919 100644 --- a/Cantera/src/ThermoFactory.cpp +++ b/Cantera/src/ThermoFactory.cpp @@ -130,8 +130,8 @@ namespace Cantera { break; #endif - default: - throw UnknownThermoPhaseModel("ThermoFactory::newThermoPhase", + default: + throw UnknownThermoPhaseModel("ThermoFactory::newThermoPhase", model); } return th; diff --git a/Cantera/src/oneD/StFlow.cpp b/Cantera/src/oneD/StFlow.cpp index c8f1a3e18..1e0b28d43 100644 --- a/Cantera/src/oneD/StFlow.cpp +++ b/Cantera/src/oneD/StFlow.cpp @@ -267,6 +267,16 @@ namespace Cantera { throw CanteraError("setTransport","unknown transport model."); } + void StFlow::enableSoret(bool withSoret) { + if (m_transport_option == c_Multi_Transport) + m_do_soret = withSoret; + else { + throw CanteraError("setTransport", + "Thermal diffusion (the Soret effect) " + "requires using a multicomponent transport model."); + } + } + /** * Set the gas object state to be consistent with the solution at diff --git a/Cantera/src/oneD/StFlow.h b/Cantera/src/oneD/StFlow.h index 151fd9aad..0a59e05cb 100644 --- a/Cantera/src/oneD/StFlow.h +++ b/Cantera/src/oneD/StFlow.h @@ -100,6 +100,8 @@ namespace Cantera { /// set the transport manager void setTransport(Transport& trans, bool withSoret = false); + void enableSoret(bool withSoret); + bool withSoret() const { return m_do_soret; } /// Set the pressure. Since the flow equations are for the limit of /// small Mach number, the pressure is very nearly constant