[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.
This commit is contained in:
Ray Speth 2015-11-12 12:15:22 -05:00
parent 66a3b5b48a
commit ac9dfa055c
7 changed files with 19 additions and 1 deletions

View file

@ -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() != "") {

View file

@ -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 +

View file

@ -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))

View file

@ -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) ...

View file

@ -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 {

View file

@ -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);

View file

@ -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");
}