Skip to content

Vapor Fraction / Quality should return NaN outside of vapor dome #916

@ischoegl

Description

@ischoegl

Problem description

The quality of a saturated mixture is only defined under the vapor dome below the critical point (as the ratio of vapor mass to total mass); the definition could be used for compressed liquid or superheated vapor, but breaks down for supercritical mixtures.

Steps to reproduce / Behavior

In [1]: import cantera as ct
   ...: w = ct.Water()

In [2]: w.TQ = 300, 0
   ...: w.TV = 300, w.v*.9 # compressed liquid

In [3]: w.Q # should be NaN
Out[3]: 0.0

In [4]: w.TQ = 300, 1
   ...: w.TV = 300, w.v * 1.1 # superheated vapor

In [5]: w.Q # should be NaN
Out[5]: 1.0

In [6]: w.TP = w.critical_temperature + 1, w.critical_pressure # supercritical

In [7]: w.Q # should be NaN
Out[7]: 1.0

C's SNAN or C++'s std::numeric_limits<double>::quiet_NaN() could be used instead in the C++ layer, e.g.

double Substance::x()
{
    if (T >= Tcrit()) {
        return SNAN; //(1.0/Rho < Vcrit() ? 0.0 : 1.0);
    } else {
        update_sat();
        if (Rho <= Rhv) {
  	    return (Rho == Rhv ? 1.0 : SNAN); //1.0;
        } else if (Rho >= Rhf) {
            return (Rho == Rhf ? 0.0 : SNAN); //0.0;
        } else {
            double vv = 1.0/Rhv;
            double vl = 1.0/Rhf;
            return (1.0/Rho - vl)/(vv - vl);
        }
    }
}

The change will make it necessary to update logic for exception handling in some places; correct behavior also needs to be checked for MATLAB as well as various file IO formats for SolutionArrays - i.e. CSV/HDF (and pandas DataFrames).

System information

  • Cantera version: all
  • OS: any
  • Python/MATLAB/other software versions: any

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions