From 717a2367b1b785a154ffb8935deb25365947e068 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Fri, 23 Aug 2013 17:43:55 +0000 Subject: [PATCH] [Transport] Add electricalConductivity method to all language interfaces Thanks to user 'hencken' for the patch. Resolves Issue 171. --- interfaces/cython/cantera/_cantera.pxd | 1 + interfaces/cython/cantera/transport.pyx | 5 +++++ .../toolbox/@Transport/electricalConductivity.m | 8 ++++++++ interfaces/python/Cantera/Transport.py | 4 ++++ src/clib/ct.cpp | 9 +++++++++ src/clib/ct.h | 1 + src/fortran/cantera.f90 | 4 ++++ src/fortran/cantera_transport.f90 | 7 +++++++ src/fortran/fct.cpp | 9 +++++++++ src/fortran/fct_interface.f90 | 4 ++++ src/matlab/transportmethods.cpp | 2 ++ src/python/cttransport_methods.cpp | 14 ++++++++++++++ src/python/methods.h | 1 + 13 files changed, 69 insertions(+) create mode 100644 interfaces/matlab/toolbox/@Transport/electricalConductivity.m diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index 7bdb29906..0595f08fb 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -180,6 +180,7 @@ cdef extern from "cantera/transport/TransportBase.h" namespace "Cantera": int model() double viscosity() except + double thermalConductivity() except + + double electricalConductivity() except + cdef extern from "cantera/transport/DustyGasTransport.h" namespace "Cantera": diff --git a/interfaces/cython/cantera/transport.pyx b/interfaces/cython/cantera/transport.pyx index 6d858144c..dc4ad7160 100644 --- a/interfaces/cython/cantera/transport.pyx +++ b/interfaces/cython/cantera/transport.pyx @@ -50,6 +50,11 @@ cdef class Transport(_SolutionBase): def __get__(self): return self.transport.viscosity() + property electrical_conductivity: + """Electrical conductivity. [S/m].""" + def __get__(self): + return self.transport.electricalConductivity() + property thermal_conductivity: """Thermal conductivity. [W/m/K].""" def __get__(self): diff --git a/interfaces/matlab/toolbox/@Transport/electricalConductivity.m b/interfaces/matlab/toolbox/@Transport/electricalConductivity.m new file mode 100644 index 000000000..8dd0234df --- /dev/null +++ b/interfaces/matlab/toolbox/@Transport/electricalConductivity.m @@ -0,0 +1,8 @@ +function v = electricalConductivity(a) +% ELECTRICALCONDUCTIVITY Electrical conductivity in S/m. +v = trans_get(a.id, 3); +if v == -1.0 + error(geterr); +elseif v < 0.0 + error('exception raised'); +end diff --git a/interfaces/python/Cantera/Transport.py b/interfaces/python/Cantera/Transport.py index 54d6a91b8..d00128099 100755 --- a/interfaces/python/Cantera/Transport.py +++ b/interfaces/python/Cantera/Transport.py @@ -126,6 +126,10 @@ class Transport: "Viscosity [Pa-s].""" return _cantera.tran_viscosity(self.__tr_id) + def electricalConductivity(self): + """electrical conductivity. [S/m].""" + return _cantera.tran_electricalConductivity(self.__tr_id) + def thermalConductivity(self): """Thermal conductivity. [W/m/K].""" return _cantera.tran_thermalConductivity(self.__tr_id) diff --git a/src/clib/ct.cpp b/src/clib/ct.cpp index e1aaf220c..178223fea 100644 --- a/src/clib/ct.cpp +++ b/src/clib/ct.cpp @@ -1190,6 +1190,15 @@ extern "C" { } } + double trans_electricalConductivity(int n) + { + try { + return TransportCabinet::item(n).electricalConductivity(); + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + double trans_thermalConductivity(int n) { try { diff --git a/src/clib/ct.h b/src/clib/ct.h index 324ff21fd..17a549a73 100644 --- a/src/clib/ct.h +++ b/src/clib/ct.h @@ -127,6 +127,7 @@ extern "C" { CANTERA_CAPI size_t newTransport(char* model, int th, int loglevel); CANTERA_CAPI double trans_viscosity(int n); + CANTERA_CAPI double trans_electricalConductivity(int n); CANTERA_CAPI double trans_thermalConductivity(int n); CANTERA_CAPI int trans_getThermalDiffCoeffs(int n, int ldt, double* dt); CANTERA_CAPI int trans_getMixDiffCoeffs(int n, int ld, double* d); diff --git a/src/fortran/cantera.f90 b/src/fortran/cantera.f90 index fbfc79fad..d2bb1c2cd 100644 --- a/src/fortran/cantera.f90 +++ b/src/fortran/cantera.f90 @@ -395,6 +395,10 @@ MODULE CANTERA MODULE PROCEDURE ctthermo_temperature END INTERFACE temperature + INTERFACE electricalConductivity + MODULE PROCEDURE ctrans_electricalConductivity + END INTERFACE electricalConductivity + INTERFACE thermalConductivity MODULE PROCEDURE ctrans_thermalConductivity END INTERFACE thermalConductivity diff --git a/src/fortran/cantera_transport.f90 b/src/fortran/cantera_transport.f90 index 26d427a61..b1845f5dc 100644 --- a/src/fortran/cantera_transport.f90 +++ b/src/fortran/cantera_transport.f90 @@ -25,6 +25,13 @@ contains self%err = 0 end function ctrans_viscosity + double precision function ctrans_electricalConductivity(self) + implicit none + type(phase_t), intent(inout) :: self + ctrans_electricalConductivity = trans_electricalConductivity(self%tran_id) + self%err = 0 + end function ctrans_electricalConductivity + double precision function ctrans_thermalConductivity(self) implicit none type(phase_t), intent(inout) :: self diff --git a/src/fortran/fct.cpp b/src/fortran/fct.cpp index 1061d11c7..b447a66dc 100644 --- a/src/fortran/fct.cpp +++ b/src/fortran/fct.cpp @@ -925,6 +925,15 @@ extern "C" { } } + doublereal trans_electricalconductivity_(const integer* n) + { + try { + return _ftrans(n)->electricalConductivity(); + } catch (...) { + return handleAllExceptions(DERR, DERR); + } + } + doublereal trans_thermalconductivity_(const integer* n) { try { diff --git a/src/fortran/fct_interface.f90 b/src/fortran/fct_interface.f90 index 25d3da11a..e3650f17c 100644 --- a/src/fortran/fct_interface.f90 +++ b/src/fortran/fct_interface.f90 @@ -379,6 +379,10 @@ interface integer, intent(in) :: n end function trans_viscosity + double precision function trans_electricalConductivity(n) + integer, intent(in) :: n + end function trans_electricalConductivity + double precision function trans_thermalConductivity(n) integer, intent(in) :: n end function trans_thermalConductivity diff --git a/src/matlab/transportmethods.cpp b/src/matlab/transportmethods.cpp index 1aeaf797c..25bdc4802 100644 --- a/src/matlab/transportmethods.cpp +++ b/src/matlab/transportmethods.cpp @@ -43,6 +43,8 @@ void transportmethods(int nlhs, mxArray* plhs[], break; case 2: vv = trans_thermalConductivity(n); + case 3: + vv = trans_electricalConductivity(n); break; default: mexErrMsgTxt("unknown Transport method"); diff --git a/src/python/cttransport_methods.cpp b/src/python/cttransport_methods.cpp index f701925c7..c4bc67df1 100644 --- a/src/python/cttransport_methods.cpp +++ b/src/python/cttransport_methods.cpp @@ -71,6 +71,20 @@ py_viscosity(PyObject* self, PyObject* args) return Py_BuildValue("d",mu); } +static PyObject* +py_electricalConductivity(PyObject* self, PyObject* args) +{ + int n; + if (!PyArg_ParseTuple(args, "i:py_electricalConductivity", &n)) { + return NULL; + } + double sigma = trans_electricalConductivity(n); + if (sigma < 0.0) { + return reportError(int(sigma)); + } + return Py_BuildValue("d",sigma); +} + static PyObject* py_thermalConductivity(PyObject* self, PyObject* args) { diff --git a/src/python/methods.h b/src/python/methods.h index 42da26e20..7a96cd9db 100644 --- a/src/python/methods.h +++ b/src/python/methods.h @@ -76,6 +76,7 @@ static PyMethodDef ct_methods[] = { {"Transport", py_transport_new, METH_VARARGS}, {"tran_delete", py_transport_delete, METH_VARARGS}, {"tran_viscosity", py_viscosity, METH_VARARGS}, + {"tran_electricalConductivity", py_electricalConductivity, METH_VARARGS}, {"tran_thermalConductivity", py_thermalConductivity, METH_VARARGS}, {"tran_thermalDiffCoeffs", py_thermalDiffCoeffs, METH_VARARGS}, {"tran_binaryDiffCoeffs", py_binaryDiffCoeffs, METH_VARARGS},