removed critical and saturation properties from ThermoPhase

This commit is contained in:
Dave Goodwin 2005-12-09 17:49:33 +00:00
parent 3c3f7d47ec
commit 33fbbf0b93
10 changed files with 192 additions and 113 deletions

View file

@ -34,7 +34,7 @@ inline XML_Node* _xml(int i) {
}
#ifdef INCL_PURE_FLUID
#ifdef WITH_PURE_FLUIDS
static PureFluidPhase* purefluid(int n) {
try {
ThermoPhase* tp = th(n);
@ -49,10 +49,34 @@ static PureFluidPhase* purefluid(int n) {
return 0;
}
}
static double pfprop(int n, int i, double v=0.0, double x=0.0) {
PureFluidPhase* p = purefluid(n);
if (p) {
switch(i) {
case 0: return p->critTemperature();
case 1: return p->critPressure();
case 2: return p->critDensity();
case 3: return p->vaporFraction();
case 4: return p->satTemperature(v);
case 5: return p->satPressure(v);
case 6: p->setState_Psat(v, x); return 0.0;
case 7: p->setState_Tsat(v, x); return 0.0;
}
}
else
return DERR;
}
#else
static ThermoPhase* purefluid(int n) {
return th(n);
}
static double pfprop(int n, int i, double v=0.0, double x=0.0) {
return DERR;
}
#endif
inline int nThermo() {
@ -559,9 +583,10 @@ extern "C" {
}
//-------------- pure fluids ---------------//
#ifdef WITH_PURE_FLUIDS
double DLL_EXPORT th_critTemperature(int n) {
return purefluid(n)->critTemperature();
return pfprop(n,0);
}
double DLL_EXPORT th_critPressure(int n) {
@ -605,6 +630,40 @@ extern "C" {
}
catch (CanteraError) { return -1; }
}
#else
double DLL_EXPORT th_critTemperature(int n) {
return DERR;
}
double DLL_EXPORT th_critPressure(int n) {
return DERR;
}
double DLL_EXPORT th_critDensity(int n) {
return DERR;
}
double DLL_EXPORT th_vaporFraction(int n) {
return DERR;
}
double DLL_EXPORT th_satTemperature(int n, double p) {
return DERR;
}
double DLL_EXPORT th_satPressure(int n, double t) {
return DERR;
}
int DLL_EXPORT th_setState_Psat(int n, double p, double x) {
return DERR;
}
int DLL_EXPORT th_setState_Tsat(int n, double t, double x) {
return DERR;
}
#endif

View file

@ -83,7 +83,6 @@ extern "C" {
int DLL_IMPORT th_equil(int n, char* XY, int solver,
double rtol, int maxsteps, int maxiter, int loglevel);
#ifdef INCL_PURE_FLUIDS
double DLL_IMPORT th_critTemperature(int n);
double DLL_IMPORT th_critPressure(int n);
double DLL_IMPORT th_critDensity(int n);
@ -92,7 +91,6 @@ extern "C" {
double DLL_IMPORT th_satPressure(int n, double t);
int DLL_IMPORT th_setState_Psat(int n, double p, double x);
int DLL_IMPORT th_setState_Tsat(int n, double t, double x);
#endif
int DLL_IMPORT newKineticsFromXML(int mxml, int iphase,
int neighbor1=-1, int neighbor2=-1, int neighbor3=-1,

View file

@ -306,33 +306,6 @@ class ThermoPhase(Phase):
rtol, maxsteps, maxiter, loglevel)
def critTemperature(self):
"""Critical temperature [K]."""
return _cantera.thermo_getfp(self._phase_id,50)
def critPressure(self):
"""Critical pressure [Pa]."""
return _cantera.thermo_getfp(self._phase_id,51)
def critDensity(self):
"""Critical density [kg/m3]."""
return _cantera.thermo_getfp(self._phase_id,52)
def vaporFraction(self):
"""Vapor fraction."""
return _cantera.thermo_getfp(self._phase_id,53)
def setState_Psat(self, p, vaporFraction):
"""Set the state of a saturated liquid/vapor mixture by
specifying the pressure and vapor fraction."""
_cantera.thermo_setfp(self._phase_id,8, p, vaporFraction)
def setState_Tsat(self, t, vaporFraction):
"""Set the state of a saturated liquid/vapor mixture by
specifying the temperature and vapor fraction."""
_cantera.thermo_setfp(self._phase_id,7, t, vaporFraction)
def saveState(self):
"""Return an array with state information that can later be
used to restore the state."""

View file

@ -6,27 +6,129 @@ function 'importPhase' to import the phase definition from file
from importFromFile import importPhase
import os
from constants import *
from ThermoPhase import ThermoPhase
from set import setByName
import XML
import _cantera
class PureFluid(ThermoPhase):
"""
A class for chemically-reacting solutions.
Instances can be created to represent any type of solution -- a
mixture of gases, a liquid solution, or a solid solution, for
example.
Class PureFluid derives from classes ThermoPhase, Kinetics, and
Transport. It defines very few methods of its own, and is
provided largely for convenience, so that a single object can be
used to compute thermodynamic, kinetic, and transport properties
of a solution. Functions like IdealGasMix and others defined in
module gases return objects of class PureFluid.
"""
def __init__(self, src="", id=""):
self.ckin = 0
self._owner = 0
self.verbose = 1
fname = os.path.basename(src)
ff = os.path.splitext(fname)
if src:
root = XML.XML_Node(name = 'doc', src = src, preprocess = 1)
if id:
s = root.child(id = id)
else:
s = root.child(name = "phase")
self._name = s['id']
# initialize the equation of state
ThermoPhase.__init__(self, xml_phase=s)
def __del__(self):
ThermoPhase.__del__(self)
def __repr__(self):
return _cantera.phase_report(self._phase_id, self.verbose)
def name(self):
return self._name
def set(self, **options):
"""Set various properties.
T --- temperature [K]
P --- pressure [Pa]
Rho --- density [kg/m3]
V --- specific volume [m3/kg]
H --- specific enthalpy [J/kg]
U --- specific internal energy [J/kg]
S --- specific entropy [J/kg/K]
X --- mole fractions (string or array)
Y --- mass fractions (string or array)
Vapor --- saturated vapor fraction
Liquid --- saturated liquid fraction
"""
setByName(self, options)
def critTemperature(self):
"""Critical temperature [K]."""
return _cantera.thermo_getfp(self._phase_id,50)
def critPressure(self):
"""Critical pressure [Pa]."""
return _cantera.thermo_getfp(self._phase_id,51)
def critDensity(self):
"""Critical density [kg/m3]."""
return _cantera.thermo_getfp(self._phase_id,52)
def vaporFraction(self):
"""Vapor fraction."""
return _cantera.thermo_getfp(self._phase_id,53)
def setState_Psat(self, p, vaporFraction):
"""Set the state of a saturated liquid/vapor mixture by
specifying the pressure and vapor fraction."""
_cantera.thermo_setfp(self._phase_id,8, p, vaporFraction)
def setState_Tsat(self, t, vaporFraction):
"""Set the state of a saturated liquid/vapor mixture by
specifying the temperature and vapor fraction."""
_cantera.thermo_setfp(self._phase_id,7, t, vaporFraction)
def Water():
return importPhase('liquidvapor.cti','water')
return PureFluid('liquidvapor.cti','water')
def Nitrogen():
return importPhase('liquidvapor.cti','nitrogen')
return PureFluid('liquidvapor.cti','nitrogen')
def Methane():
return importPhase('liquidvapor.cti','methane')
return PureFluid('liquidvapor.cti','methane')
def Hydrogen():
return importPhase('liquidvapor.cti','hydrogen')
return PureFluid('liquidvapor.cti','hydrogen')
def Oxygen():
return importPhase('liquidvapor.cti','oxygen')
return PureFluid('liquidvapor.cti','oxygen')
def HFC134a():
return importPhase('liquidvapor.cti','hfc134a')
return PureFluid('liquidvapor.cti','hfc134a')
def CarbonDioxide():
return importPhase('liquidvapor.cti','carbondioxide')
return PureFluid('liquidvapor.cti','carbondioxide')
def Heptane():
return importPhase('liquidvapor.cti','heptane')
return PureFluid('liquidvapor.cti','heptane')

View file

@ -1,6 +1,7 @@
#include "xml.h"
#include "PureFluidPhase.h"
#include "../../ext/tpx/Sub.h"
#include "../../ext/tpx/utils.h"
@ -239,3 +240,6 @@ namespace Cantera {
}
}

View file

@ -16,7 +16,7 @@
#include "ThermoPhase.h"
#ifdef INCL_PURE_FLUIDS
#ifdef WITH_PURE_FLUIDS
#include "mix_defs.h"

View file

@ -757,6 +757,8 @@ namespace Cantera {
}
//@}
/*
//---------------------------------------------------------
/// @name Critical State Properties.
/// These methods are only implemented by some subclasses, and may
@ -805,6 +807,7 @@ namespace Cantera {
virtual void setState_Psat(doublereal p, doublereal x) {
err("setState_sat");
}
*/
//@}

View file

@ -6,7 +6,10 @@
// Copyright 2001 California Institute of Technology
//
// $Log$
// Revision 1.19 2005-07-28 23:02:44 hkmoffa
// Revision 1.20 2005-12-09 17:49:34 dggoodwin
// removed critical and saturation properties from ThermoPhase
//
// Revision 1.19 2005/07/28 23:02:44 hkmoffa
// Got rid of one warning message.
//
// Revision 1.18 2005/07/26 03:56:35 dggoodwin
@ -181,10 +184,6 @@ namespace ckr {
throw CK_SyntaxError(log,
"error reading Tmin, Tmid, or Tmax");
}
//if (tmin > tmid || tmid > tmax) {
// throw CK_SyntaxError(log,
// "condition Tmin <= Tmid <= Tmax violated");
//}
}
static void getSpecies(string s,
@ -242,65 +241,6 @@ namespace ckr {
}
/**
* given a string specifying either the reactant or product side of a
* reaction equation, construct a list of RxnSpecies objects
* containing the species symbols and stoichiometric coefficients.
* @todo allow non-integral stoichiometric coefficients
*/
static void getSpecies_old(string s,
int n, vector<RxnSpecies>& species, bool debug, ostream& log)
{
char* begin = new char[n+1];
copy(s.begin(), s.end(), begin);
begin[n] = '\0';
char* end = begin + n;
char* p = begin;
bool inplus = true;
double m;
species.clear();
vector<string> syms;
vector_fp coeffs;
for (; p != end; p++) {
// if the previous character was a '+' but this one is not,
// then the '+' must be a '+' between species names, not part
// of a name (e.g. O++). Replace it with a space.
if (*p != '+' && inplus) {
if (p > begin) *(p - 1) = ' ';
// if the current character is a number, it must be a
// coefficient.
if (m = atof(p), m > 0) {
*p = ' ';
coeffs.push_back(m);
}
// otherwise, the coefficient is 1.0
else
coeffs.push_back(1.0);
// we're not processing a '+' string
inplus = false;
}
else if (*p == '+')
inplus = true;
}
string str = string(begin);
getTokens(str, n, syms);
RxnSpecies ss;
unsigned int j;
for (j = 0; j < syms.size(); j++) {
ss.name = syms[j];
ss.number = coeffs[j];
species.push_back(ss);
if (debug) {
log << ss.number << " " << ss.name << endl;
}
}
}
/**
* given a string specifying either the reactant or product side of a
* reaction equation, construct a list of Constituent objects

View file

@ -6,6 +6,7 @@
#endif
#include "ThermoPhase.h"
#include "PureFluidPhase.h"
#include <stdio.h>
#include "mix_defs.h"
@ -31,13 +32,16 @@ namespace Cantera {
s += p;
sprintf(p, " mean mol. weight %12.6g amu\n", th.meanMolecularWeight());
s += p;
#ifdef WITH_PURE_FLUIDS
if (th.eosType() == cPureFluid) {
double xx = ((PureFluidPhase*)(&th))->vaporFraction();
// if (th.temperature() < th.critTemperature()) {
sprintf(p, " vapor fraction %12.6g \n",
th.vaporFraction());
sprintf(p, " vapor fraction %12.6g \n",
xx); //th.vaporFraction());
s += p;
//}
}
#endif
doublereal phi = th.electricPotential();
if (phi != 0.0) {
sprintf(p, " potential %12.6g V\n", phi);

10
configure vendored
View file

@ -139,7 +139,7 @@ F90=${F90:="default"}
# these compilers will be added automatically, and you do not need to
# specify them here. Otherwise, add any required compiler-specific
# flags here.
F90FLAGS=${F90FLAGS:='-O3 -g'}
F90FLAGS=${F90FLAGS:='-O0 -g'}
#----------------------------------------------------------------------
@ -186,7 +186,7 @@ WITH_PURE_FLUIDS='y'
# Enable expanded electrochemistry capabilities, include thermo
# models for electrolyte solutions
WITH_ELECTROLYTES='y'
WITH_ELECTROLYTES='n'
######################################################################
# if set to 'y', the ck2cti program that converts Chemkin input files
# to Cantera format will be built. If you don't use Chemkin format
@ -214,10 +214,6 @@ ENABLE_SOLVERS='y'
# reaction path analysis
ENABLE_RXNPATH='y'
# non-ideal pure substance models for a few fluids imported from the
# 'TPX' package. (http://adam.caltech.edu/software/tpx)
ENABLE_TPX='y'
#-----------------------------------------------------------------
# CVODE / CVODES
#-----------------------------------------------------------------
@ -284,7 +280,7 @@ CXX=${CXX:=g++}
CC=${CC:=gcc}
# C++ compiler flags
CXXFLAGS=${CXXFLAGS:="-O3 -Wall"}
CXXFLAGS=${CXXFLAGS:="-O0 -Wall"}
# the C++ flags required for linking. Uncomment if additional flags
# need to be passed to the linker.