From 2d2004da7e9b54ef4c8102fc9f609959e1877070 Mon Sep 17 00:00:00 2001 From: Steven DeCaluwe Date: Tue, 25 Jun 2019 06:45:33 -0600 Subject: [PATCH] Exposing getDeltaEnthalpies to Matlab interface. The general intent here was to enable calculating reaction enthalpies in the Matlab toolbox, as part of the li-ion battery simulations in PR #563. This required several changes: - Create getDeltaEnthalpies.m in Matlab toolbox/@Kinetics, as well as similar methods for Gibbs free energy and entropy of reaction - Add kin_getDelta to kineticsmethods.cpp. - Add getPartialMolarEnthalpies to metalPhase class (it returns all zeros). Note that similar methods are not enabled for the corresponding 'Standard State' methods, for the time being. Mainly because it is difficult for me to envision a significant use case, but also because of some lingering confusion between 'standard' and 'reference' states in Cantera's codebase. --- include/cantera/thermo/MetalPhase.h | 5 +++++ .../matlab/toolbox/@Kinetics/getDeltaEnthalpies.m | 14 ++++++++++++++ .../matlab/toolbox/@Kinetics/getDeltaEntropies.m | 14 ++++++++++++++ .../matlab/toolbox/@Kinetics/getDeltaGibbs.m | 14 ++++++++++++++ src/matlab/kineticsmethods.cpp | 3 +++ 5 files changed, 50 insertions(+) create mode 100644 interfaces/matlab/toolbox/@Kinetics/getDeltaEnthalpies.m create mode 100644 interfaces/matlab/toolbox/@Kinetics/getDeltaEntropies.m create mode 100644 interfaces/matlab/toolbox/@Kinetics/getDeltaGibbs.m diff --git a/include/cantera/thermo/MetalPhase.h b/include/cantera/thermo/MetalPhase.h index a527927e2..4ae2644b1 100644 --- a/include/cantera/thermo/MetalPhase.h +++ b/include/cantera/thermo/MetalPhase.h @@ -85,6 +85,11 @@ public: c[n] = 1.0; } } + virtual void getPartialMolarEnthalpies(doublereal *h) const { + for (size_t n = 0; n < nSpecies(); n++) { + h[n] = 0.0; + } + } virtual Units standardConcentrationUnits() const { return Units(1.0); diff --git a/interfaces/matlab/toolbox/@Kinetics/getDeltaEnthalpies.m b/interfaces/matlab/toolbox/@Kinetics/getDeltaEnthalpies.m new file mode 100644 index 000000000..3f678d0a3 --- /dev/null +++ b/interfaces/matlab/toolbox/@Kinetics/getDeltaEnthalpies.m @@ -0,0 +1,14 @@ +function dH = getDeltaEnthalpies(a) +% GETDELTAENTHALPIES Get the enthalpy of reaction for each reaction. +% dH = getDeltaEnthalpies(a) +% +% :param a: +% Instance of class :mat:func:`Kinetics` (or another +% object deriving from Kinetics) for which the enthalpies of +% reaction are desired. +% :return: +% Returns a vector of the enthalpy of reaction for each +% reaction. Units: J/kmol +% + +dH = kinetics_get(a.id, 17, 0); diff --git a/interfaces/matlab/toolbox/@Kinetics/getDeltaEntropies.m b/interfaces/matlab/toolbox/@Kinetics/getDeltaEntropies.m new file mode 100644 index 000000000..0db6945a1 --- /dev/null +++ b/interfaces/matlab/toolbox/@Kinetics/getDeltaEntropies.m @@ -0,0 +1,14 @@ +function dS = getDeltaEntropies(a) +% GETDELTAENTROPIES Get the entropy of reaction for each reaction. +% dS = getDeltaEntropies(a) +% +% :param a: +% Instance of class :mat:func:`Kinetics` (or another +% object deriving from Kinetics) for which the entropies of +% reaction are desired. +% :return: +% Returns a vector of the entropy of reaction for each +% reaction. Units: J/kmol-K +% + +dS = kinetics_get(a.id, 17, 2); diff --git a/interfaces/matlab/toolbox/@Kinetics/getDeltaGibbs.m b/interfaces/matlab/toolbox/@Kinetics/getDeltaGibbs.m new file mode 100644 index 000000000..e77925a97 --- /dev/null +++ b/interfaces/matlab/toolbox/@Kinetics/getDeltaGibbs.m @@ -0,0 +1,14 @@ +function dG = getDeltaGibbs(a) +% GETDELTAGIBBS Get the Gibbs free energy of reaction for each reaction. +% dG = getDeltaGibbs(a) +% +% :param a: +% Instance of class :mat:func:`Kinetics` (or another +% object deriving from Kinetics) for which the Gibbs free +% energies of reaction are desired. +% :return: +% Returns a vector of the Gibbs free energy of reaction +% for each reaction. Units: J/kmol +% + +dG = kinetics_get(a.id, 17, 1); diff --git a/src/matlab/kineticsmethods.cpp b/src/matlab/kineticsmethods.cpp index 9a9870467..bcca70ed8 100644 --- a/src/matlab/kineticsmethods.cpp +++ b/src/matlab/kineticsmethods.cpp @@ -103,6 +103,9 @@ void kineticsmethods(int nlhs, mxArray* plhs[], case 16: ok = kin_getRevRateConstants(kin,1,nr,h); break; + case 17: + ok = kin_getDelta(kin,getInt(prhs[3]),nr,h); + break; default: ; }