Skip to content

Commit

Permalink
[Thermo] Adds getPhase function
Browse files Browse the repository at this point in the history
getPhase returns the phase (liquid, vapor, etc.) of the phase. Not
implemented in the base ThermoPhase, must be overridden in derived
classes because it only makes sense for phases that can have multiple
phases.
  • Loading branch information
bryanwweber committed Oct 6, 2019
1 parent fe7be79 commit 86216ef
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions include/cantera/thermo/PureFluidPhase.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ class PureFluidPhase : public ThermoPhase
return "PureFluid";
}

virtual std::string getPhase() const {
if (temperature() >= critTemperature() || pressure() >= critPressure()) {
return "supercritical";
} else if (m_sub->TwoPhase() == 1) {
return "twophase";
} else {
if (temperature() > satTemperature(pressure())) {
return "vapor";
} else {
return "liquid";
}
}
}

//! Set the name of the TPX substance to use for the equation of state. This
//! function should be called before initThermo().
void setSubstance(const std::string& name) {
Expand Down
5 changes: 5 additions & 0 deletions include/cantera/thermo/ThermoPhase.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ class ThermoPhase : public Phase
return "ThermoPhase";
}

//! String indicating the phase (liquid, vapor, etc.) of the phase
virtual std::string getPhase() const {
throw NotImplementedError("ThermoPhase::getPhase");
}

/**
* Returns the reference pressure in Pa. This function is a wrapper
* that calls the species thermo refPressure function.
Expand Down
1 change: 1 addition & 0 deletions interfaces/cython/cantera/_cantera.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ cdef extern from "cantera/thermo/ThermoPhase.h" namespace "Cantera":

# miscellaneous
string type()
string getPhase()
string report(cbool, double) except +translate_exception
string name()
void setName(string)
Expand Down
7 changes: 7 additions & 0 deletions interfaces/cython/cantera/thermo.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,13 @@ cdef class PureFluid(ThermoPhase):
def __get__(self):
return self.s, self.v, self.X

property phase:
"""
Get the phase (vapor, liquid, etc.) at the current conditions.
"""
def __get__(self):
return pystr(self.thermo.getPhase())


class Element:
"""
Expand Down

0 comments on commit 86216ef

Please sign in to comment.