From ac9dfa055c7ab3fa8edd9b0dd5b7837801c13aa8 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 12 Nov 2015 12:15:22 -0500 Subject: [PATCH] [Thermo] Synchronize Mixture/Multiphase state before printing report Do not assume that the states of the individual ThermoPhase objects still correspond to the state of the mixture object. See #306. --- include/cantera/equil/MultiPhase.h | 1 + interfaces/cython/cantera/_cantera.pxd | 1 + interfaces/cython/cantera/mixture.pyx | 1 + interfaces/matlab/toolbox/@Mixture/display.m | 1 + src/clib/ctmultiphase.cpp | 10 ++++++++++ src/clib/ctmultiphase.h | 1 + src/matlab/mixturemethods.cpp | 5 ++++- 7 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/cantera/equil/MultiPhase.h b/include/cantera/equil/MultiPhase.h index 227167df6..0c3dad0d9 100644 --- a/include/cantera/equil/MultiPhase.h +++ b/include/cantera/equil/MultiPhase.h @@ -673,6 +673,7 @@ private: */ inline std::ostream& operator<<(std::ostream& s, MultiPhase& x) { + x.updatePhases(); size_t ip; for (ip = 0; ip < x.nPhases(); ip++) { if (x.phase(ip).name() != "") { diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index 404196be9..4fc96a49e 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -417,6 +417,7 @@ cdef extern from "cantera/equil/MultiPhase.h" namespace "Cantera": CxxMultiPhase() void addPhase(CxxThermoPhase*, double) except + void init() except + + void updatePhases() except + void equilibrate(string, string, double, int, int, int, int) except + diff --git a/interfaces/cython/cantera/mixture.pyx b/interfaces/cython/cantera/mixture.pyx index 6df0359de..a63f9d9a3 100644 --- a/interfaces/cython/cantera/mixture.pyx +++ b/interfaces/cython/cantera/mixture.pyx @@ -59,6 +59,7 @@ cdef class Mixture: >>> mix() >>> print(mix.report()) """ + self.mix.updatePhases() s = [] for i,phase in enumerate(self._phases): s.append('************ Phase {0} ************'.format(phase.name)) diff --git a/interfaces/matlab/toolbox/@Mixture/display.m b/interfaces/matlab/toolbox/@Mixture/display.m index ebd235a07..60ae4605b 100644 --- a/interfaces/matlab/toolbox/@Mixture/display.m +++ b/interfaces/matlab/toolbox/@Mixture/display.m @@ -5,6 +5,7 @@ function display(self) % Instance of class :mat:func:`Mixture` % +mixturemethods(9, mix_hndl(self)); [np nc] = size(self.phases); for n = 1:np s = [sprintf('\n******************* Phase %d', n) ... diff --git a/src/clib/ctmultiphase.cpp b/src/clib/ctmultiphase.cpp index 2ed40c12e..ee3bb9891 100644 --- a/src/clib/ctmultiphase.cpp +++ b/src/clib/ctmultiphase.cpp @@ -75,6 +75,16 @@ extern "C" { } } + int mix_updatePhases(int i) + { + try { + mixCabinet::item(i).updatePhases(); + return 0; + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + size_t mix_nElements(int i) { try { diff --git a/src/clib/ctmultiphase.h b/src/clib/ctmultiphase.h index 5698de8bd..34f805cf2 100644 --- a/src/clib/ctmultiphase.h +++ b/src/clib/ctmultiphase.h @@ -13,6 +13,7 @@ extern "C" { CANTERA_CAPI int mix_copy(int i); CANTERA_CAPI int mix_addPhase(int i, int j, double moles); CANTERA_CAPI int mix_init(int i); + CANTERA_CAPI int mix_updatePhases(int i); CANTERA_CAPI size_t mix_nElements(int i); CANTERA_CAPI size_t mix_elementIndex(int i, char* name); CANTERA_CAPI size_t mix_speciesIndex(int i, int k, int p); diff --git a/src/matlab/mixturemethods.cpp b/src/matlab/mixturemethods.cpp index 4d37cd5fc..6654d5f9d 100644 --- a/src/matlab/mixturemethods.cpp +++ b/src/matlab/mixturemethods.cpp @@ -17,7 +17,7 @@ void mixturemethods(int nlhs, mxArray* plhs[], double r = Undef; double v = Undef; - if (nrhs > 3 && job != 8 && job != 22 && job != 23) { + if (nrhs > 3 && job != 8 && job != 9 && job != 22 && job != 23) { v = getDouble(prhs[3]); } @@ -66,6 +66,9 @@ void mixturemethods(int nlhs, mxArray* plhs[], nmstr = getString(prhs[3]); iok = mix_setMolesByName(i, nmstr); break; + case 9: + iok = mix_updatePhases(i); + break; default: mexErrMsgTxt("unknown job parameter"); }