[Thermo] Add compatibility check for phases added to MultiPhase

PureFluidPhase and WaterSSTP are not compatible with MultiPhase since they are
already multi-phase mixtures.

Resolves #306
This commit is contained in:
Ray Speth 2016-04-18 00:27:23 -04:00
parent 32b3543cbe
commit a026c6ad8b
5 changed files with 25 additions and 0 deletions

View file

@ -161,6 +161,10 @@ public:
virtual std::string report(bool show_thermo=true,
doublereal threshold=1e-14) const;
virtual bool compatibleWithMultiPhase() const {
return false;
}
protected:
//! Main call to the tpx level to set the state of the system
/*!

View file

@ -1290,6 +1290,13 @@ public:
*/
bool getElementPotentials(doublereal* lambda) const;
//! Indicates whether this phase type can be used with class MultiPhase for
//! equilibrium calculations. Returns `false` for special phase types which
//! already represent multi-phase mixtures, namely PureFluidPhase.
virtual bool compatibleWithMultiPhase() const {
return true;
}
//@}
/// @name Critical State Properties.
/// These methods are only implemented by subclasses that implement

View file

@ -192,6 +192,10 @@ public:
virtual doublereal satPressure(doublereal t);
virtual bool compatibleWithMultiPhase() const {
return false;
}
//! Return the fraction of vapor at the current conditions
/*!
* Below Tcrit, this routine will always return 0, by definition of the

View file

@ -187,3 +187,8 @@ class TestMixture(utilities.CanteraTest):
x.foobar = 300
with self.assertRaises(AttributeError):
x.foobar
def test_invalid_phase_type(self):
water = ct.Water()
with self.assertRaises(Exception):
self.mix = ct.Mixture([(self.phase1, 1.0), (water, 2.0)])

View file

@ -89,6 +89,11 @@ void MultiPhase::addPhase(ThermoPhase* p, doublereal moles)
"phases cannot be added after init() has been called.");
}
if (!p->compatibleWithMultiPhase()) {
throw CanteraError("MultiPhase::addPhase", "Phase '{}'' is not "
"compatible with MultiPhase equilibrium solver", p->name());
}
// save the pointer to the phase object
m_phase.push_back(p);