This commit is contained in:
Dave Goodwin 2003-11-24 16:39:27 +00:00
parent a13383c057
commit ec71c9dd36
18 changed files with 323 additions and 74 deletions

View file

@ -23,6 +23,7 @@
#include "Storage.h"
#include "Cabinet.h"
#include "InterfaceKinetics.h"
#include "PureFluidPhase.h"
#include "clib_defs.h"
@ -30,9 +31,20 @@ inline XML_Node* _xml(int i) {
return Cabinet<XML_Node>::cabinet(false)->item(i);
}
static PureFluid* purefluid(int n) {
ThermoPhase* tp = th(n);
if (tp->eosType() == cPureFluid) {
return (PureFluid*)tp;
}
else {
throw CanteraError("purefluid","object is not a PureFluid object");
}
}
inline int nThermo() {
return Storage::storage()->nThermo();
}
/**
* Exported functions.
@ -481,7 +493,43 @@ extern "C" {
return 0;
}
//-------------- pure fluids ---------------//
double DLL_EXPORT th_critTemperature(int n) {
return th(n)->critTemperature();
}
double DLL_EXPORT th_critPressure(int n) {
return th(n)->critPressure();
}
double DLL_EXPORT th_critDensity(int n) {
return th(n)->critDensity();
}
double DLL_EXPORT th_vaporFraction(int n) {
return th(n)->vaporFraction();
}
double DLL_EXPORT th_satTemperature(int n, double p) {
return th(n)->satTemperature(p);
}
double DLL_EXPORT th_satPressure(int n, double t) {
return th(n)->satPressure(t);
}
int DLL_EXPORT th_setState_satLiquid(int n) {
th(n)->setState_satLiquid();
return 0;
}
int DLL_EXPORT th_setState_satVapor(int n) {
th(n)->setState_satVapor();
return 0;
}
//-------------- Kinetics ------------------//
int DLL_EXPORT newKineticsFromXML(int mxml, int iphase,

View file

@ -2,6 +2,7 @@
#define CTC_CT_H
#include "clib_defs.h"
#include <cantera/Cantera.h>
extern "C" {
@ -74,7 +75,16 @@ extern "C" {
int DLL_IMPORT th_set_SV(int n, double* vals);
int DLL_IMPORT th_set_SP(int n, double* vals);
int DLL_IMPORT th_equil(int n, int XY);
double DLL_IMPORT th_critTemperature(int n);
double DLL_EXPORT th_critPressure(int n);
double DLL_EXPORT th_critDensity(int n);
double DLL_EXPORT th_vaporFraction(int n);
double DLL_EXPORT th_satTemperature(int n, double p);
double DLL_EXPORT th_satPressure(int n, double t);
int DLL_EXPORT th_setState_satLiquid(int n);
int DLL_EXPORT th_setState_satVapor(int n);
int DLL_IMPORT newKineticsFromXML(int mxml, int iphase,
int neighbor1=-1, int neighbor2=-1, int neighbor3=-1,
int neighbor4=-1);

View file

@ -258,7 +258,28 @@ class ThermoPhase(Phase):
raise 'invalid equilibrium option: '+XY
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_satLiquid(self):
_cantera.thermo_setfp(self._phase_id,7,0.0,0.0)
def setState_satVapor(self):
_cantera.thermo_setfp(self._phase_id,8,0.0,0.0)

View file

@ -959,6 +959,11 @@ class ideal_gas(phase):
self._tr = transport
if self.debug:
print 'Read ideal_gas entry '+self._name
try:
print 'in file '+__name__
except:
pass
def build(self, p):
@ -1008,6 +1013,33 @@ class pure_solid(phase):
k['model'] = 'none'
class pure_fluid(phase):
"""A pure fluid."""
def __init__(self,
name = '',
elements = '',
species = '',
substance_flag = 0,
initial_state = None,
options = []):
phase.__init__(self, name, 3, elements, species, 'none',
initial_state, options)
self._subflag = substance_flag
self._pure = 1
def conc_dim(self):
return (0,0)
def build(self, p):
ph = phase.build(self, p)
e = ph.addChild("thermo")
e['model'] = 'PureFluid'
e['fluid_type'] = `self._subflag`
k = ph.addChild("kinetics")
k['model'] = 'none'
class ideal_interface(phase):
"""An ideal interface."""
def __init__(self,
@ -1208,7 +1240,10 @@ if __name__ == "__main__":
# $Revision$
# $Date$
# $Log$
# Revision 1.24 2003-11-13 12:29:45 dggoodwin
# Revision 1.25 2003-11-24 16:39:33 dggoodwin
# -
#
# Revision 1.24 2003/11/13 12:29:45 dggoodwin
# *** empty log message ***
#
# Revision 1.23 2003/11/12 18:58:15 dggoodwin

View file

@ -14,7 +14,7 @@ if platform == "win32":
else:
libs = ["clib", "zeroD","oneD","converters", "transport",
"cantera","recipes","ctlapack",
"ctblas", "ctmath", "cvode", "stdc++", "g2c", "m"]
"ctblas", "ctmath", "cvode", "tpx", "stdc++", "g2c", "m"]
#if sys.argv[1] == 'install':

View file

@ -8,7 +8,6 @@ ct_newThermoFromXML(PyObject *self, PyObject *args)
return NULL;
int n = newThermoFromXML(mxml);
if (n < 0) return reportCanteraError();
//int p = th_phase(n);
return Py_BuildValue("i",n);
}
@ -50,13 +49,6 @@ thermo_maxtemp(PyObject *self, PyObject *args) {
return Py_BuildValue("d",th_maxTemp(th,k));
}
// static PyObject*
// thermo_geteos(PyObject *self, PyObject *args) {
// char *fname, *id;
// if (!PyArg_ParseTuple(args, "ss:geteos", &fname, &id)) return NULL;
// return Py_BuildValue("i",get_eos(fname, id));
// }
static PyObject*
thermo_import(PyObject *self, PyObject *args) {
int n, mxml;
@ -79,53 +71,68 @@ thermo_getfp(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "ii:thermo_getfp", &th, &job))
return NULL;
// floating-point attributes
switch (job) {
case 1:
vv = th_enthalpy_mole(th); break;
case 2:
vv = th_intEnergy_mole(th); break;
case 3:
vv = th_entropy_mole(th); break;
case 4:
vv = th_gibbs_mole(th); break;
case 5:
vv = th_cp_mole(th); break;
case 6:
vv = th_cv_mole(th); break;
case 7:
vv = th_pressure(th); break;
case 8:
vv = th_enthalpy_mass(th); break;
case 9:
vv = th_intEnergy_mass(th); break;
case 10:
vv = th_entropy_mass(th); break;
case 11:
vv = th_gibbs_mass(th); break;
case 12:
vv = th_cp_mass(th); break;
case 13:
vv = th_cv_mass(th); break;
default:
ok = false;
}
if (ok) {
if (vv == -999.999) {
return reportCanteraError();
try {
// floating-point attributes
switch (job) {
case 1:
vv = th_enthalpy_mole(th); break;
case 2:
vv = th_intEnergy_mole(th); break;
case 3:
vv = th_entropy_mole(th); break;
case 4:
vv = th_gibbs_mole(th); break;
case 5:
vv = th_cp_mole(th); break;
case 6:
vv = th_cv_mole(th); break;
case 7:
vv = th_pressure(th); break;
case 8:
vv = th_enthalpy_mass(th); break;
case 9:
vv = th_intEnergy_mass(th); break;
case 10:
vv = th_entropy_mass(th); break;
case 11:
vv = th_gibbs_mass(th); break;
case 12:
vv = th_cp_mass(th); break;
case 13:
vv = th_cv_mass(th); break;
case 50:
vv = th_critTemperature(th); break;
case 51:
vv = th_critPressure(th); break;
case 52:
vv = th_critDensity(th); break;
case 53:
vv = th_vaporFraction(th); break;
default:
ok = false;
}
if (ok) {
if (vv == -999.999) {
return reportCanteraError();
}
return Py_BuildValue("d",vv);
}
else {
PyErr_SetString(ErrorObject,"Unknown floating-point attribute");
return NULL;
}
return Py_BuildValue("d",vv);
}
else {
PyErr_SetString(ErrorObject,"Unknown floating-point attribute");
return NULL;
}
catch (CanteraError) {
return reportCanteraError();
}
}
static PyObject*
thermo_setfp(PyObject *self, PyObject *args)
{
double v1, v2;
double v1 = -1.0, v2 = -1.0;
int iok = -2;
int th;
int job;
@ -134,7 +141,7 @@ thermo_setfp(PyObject *self, PyObject *args)
return NULL;
//vector_fp v(2);
double* v = new double[2];
double v[2];
v[0] = v1; v[1] = v2;
// set floating-point attributes
@ -151,10 +158,14 @@ thermo_setfp(PyObject *self, PyObject *args)
iok = th_set_SP(th, v); break;
case 6:
iok = th_setElectricPotential(th, v[0]); break;
case 7:
iok = th_setState_satLiquid(th); break;
case 8:
iok = th_setState_satVapor(th); break;
default:
iok = -10;
}
delete v;
//delete v;
if (iok >= 0)
return Py_BuildValue("i",iok);
if (iok == -1) return reportCanteraError();
@ -231,3 +242,4 @@ thermo_equil(PyObject *self, PyObject *args)

View file

@ -194,10 +194,10 @@ namespace Cantera {
/// Set the temperature to value temp (K).
void setTemperature(doublereal temp) {
if (temp != m_temp) {
//if (temp != m_temp) {
m_temp = temp;
//m_T_updater.need_update();
}
//}
}
/**

View file

@ -19,6 +19,7 @@
#include "SpeciesThermoFactory.h"
#include "IdealGasPhase.h"
#include "PureFluidPhase.h"
#include "ConstDensityThermo.h"
#include "SurfPhase.h"
#include "MetalPhase.h"
@ -29,16 +30,19 @@ namespace Cantera {
ThermoFactory* ThermoFactory::__factory = 0;
static int ntypes = 5;
static int ntypes = 6;
static string _types[] = {"IdealGas", "Incompressible",
"Surface", "Metal", "SolidCompound"};
static int _itypes[] = {cIdealGas, cIncompressible,
cSurf, cMetal, cSolidCompound};
"Surface", "Metal", "SolidCompound",
"PureFluid"};
static int _itypes[] = {cIdealGas, cIncompressible,
cSurf, cMetal, cSolidCompound,
cPureFluid};
ThermoPhase* ThermoFactory::newThermoPhase(string model) {
int ieos=-1;
for (int n = 0; n < ntypes; n++) {
if (model == _types[n]) ieos = _itypes[n];
}
@ -67,6 +71,10 @@ namespace Cantera {
th = new SolidCompound;
break;
case cPureFluid:
th = new PureFluid;
break;
default:
throw UnknownThermoPhaseModel("ThermoFactory::newThermoPhase",
model);

View file

@ -590,8 +590,50 @@ namespace Cantera {
* @param c array of \i n coefficients
*/
virtual void setParameters(int n, doublereal* c) {}
//---------------------------------------------------------
/// @name Critical state properties.
//@{
/// Critical temperature (K).
virtual doublereal critTemperature() const {
err("critTemperature"); return -1.0;
}
/// Critical pressure (Pa).
virtual doublereal critPressure() const {
err("critPressure"); return -1.0;
}
/// Critical density (kg/m3).
virtual doublereal critDensity() const {
err("critDensity"); return -1.0;
}
//@}
virtual doublereal satTemperature(doublereal p) const {
err("satTemperature"); return -1.0;
}
virtual doublereal satPressure(doublereal t) const {
err("satPressure"); return -1.0;
}
virtual doublereal vaporFraction() const {
err("vaprFraction"); return -1.0;
}
virtual void setState_satLiquid() {
err("setState_satLiquid");
}
virtual void setState_satVapor() {
err("setState_satVapor");
}
/**
* @internal Install a species thermodynamic property
* manager. The species thermodynamic property manager
@ -625,7 +667,8 @@ namespace Cantera {
doublereal maxTemp(int k = -1) {
return m_spthermo->maxTemp();
}
ThermoPhase() {
m_spthermo = 0;
m_speciesData = 0;

View file

@ -250,6 +250,44 @@ namespace ctml {
}
/**
* Get a floating-point value from a child element. Returns a
* double value for the child named 'name' of element 'parent'. If
* 'type' is supplied and matches a known unit type, unit
* conversion to SI will be done if the child element has an attribute
* 'units'.
*/
int getInteger(const XML_Node& parent, string name) {
if (!parent.hasChild(name))
throw CanteraError("getInteger (called from XML Node \"" +
parent.name() + "\"): ",
"no child XML element named " + name);
const XML_Node& node = parent.child(name);
int x, x0, x1;
string units, vmin, vmax;
x = atoi(node().c_str());
x0 = Undefined;
x1 = Undefined;
vmin = node["min"];
vmax = node["max"];
if (vmin != "") {
x0 = atoi(vmin.c_str());
if (x < x0) {
writelog("\nWarning: value "+node()+" is below lower limit of "
+vmin+".\n");
}
}
if (node["max"] != "") {
x1 = atoi(vmax.c_str());
if (x > x1) {
writelog("\nWarning: value "+node()+" is above upper limit of "
+vmax+".\n");
}
}
return x;
}
void getFloatArray(const XML_Node& node, vector_fp& v, bool convert) {
int icom;
string numstr;

View file

@ -81,6 +81,8 @@ namespace ctml {
void getIntegers(const XML_Node& node, map<string,int>& v);
void getFloats(const XML_Node& node, map<string,double>& v, bool convert=true);
doublereal getFloat(const XML_Node& parent, string name, string type="");
int getInteger(const XML_Node& parent, string name);
void getStrings(const XML_Node& node, map<string,string>& v);
void getFunction(const XML_Node& node, string& type, doublereal& xmin,
doublereal& xmax, vector_fp& coeffs);

View file

@ -769,6 +769,8 @@ namespace Cantera {
*/
bool importPhase(XML_Node& phase, ThermoPhase* th) {
int subflag = -1;
if (phase.name() != "phase")
throw CanteraError("importPhase",
"Current const XML_Node is not a phase element.");
@ -796,7 +798,6 @@ namespace Cantera {
const XML_Node& eos = phase.child("thermo");
if (eos["model"] == "Incompressible") {
if (th->eosType() == cIncompressible) {
//map<string, doublereal> d;
doublereal rho = getFloat(eos, "density", "-");
//doublereal rho = d["density"];
th->setParameters(1, &rho);
@ -829,6 +830,25 @@ namespace Cantera {
"wrong equation of state type");
}
}
else if (eos["model"] == "PureFluid") {
if (th->eosType() == cPureFluid) {
subflag = atoi(eos["fluid_type"].c_str());
//doublereal h0 = getFloat(eos, "h0", "-");
//doublereal s0 = getFloat(eos, "s0", "-");
if (subflag < 0)
throw CanteraError("importCTML",
"missing fluid type flag");
//doublereal c[3];
//c[0] = doublereal(subflag);
//c[1] = h0;
//c[2] = s0;
//th->setParameters(3, c);
}
else {
throw CanteraError("importCTML",
"wrong equation of state type");
}
}
}
@ -963,6 +983,12 @@ namespace Cantera {
setState(phase, th);
th->saveSpeciesData(db);
if (th->eosType() == cPureFluid) {
doublereal dsub = doublereal(subflag);
th->setParameters(1, &dsub);
}
return true;
}

View file

@ -35,6 +35,10 @@ namespace Cantera {
const int cSurf = 3; // SurfPhase in SurfPhase.h
const int cMetal = 4; // MetalPhase in MetalPhase.h
const int cSolidCompound = 5; // SolidCompound in SolidCompound.h
// pure fluids with liquid/vapor eqs of state
const int cPureFluid = 10;
const int cEdge = 6;
// kinetic manager types

View file

@ -697,9 +697,8 @@ namespace Cantera {
*/
void StFlow::updateDiffFluxes(const doublereal* x, int j0, int j1) {
int j, k, m;
doublereal sum, wtm, rho, dz, gradlogT, s;
doublereal fluxsum;
char ch;
doublereal sum, wtm, rho, dz, gradlogT;
switch (m_transport_option) {
case c_Mixav_Transport:

View file

@ -3,9 +3,11 @@
* @file DustyGasTransport.cpp
* Implementation file for class DustyGasTransport
*
* @ingroup transportProps
* @ingroup transportProps
*
* $Author$
*/
/* $Author$
* $Date$
* $Revision$
*

View file

@ -276,8 +276,9 @@ namespace Cantera {
XML_Node::XML_Node(string nm, XML_Node* p, int n)
: m_name(nm), m_parent(p), m_nchildren(0),
m_n(n), m_iscomment(false), m_locked(false) {
: m_name(nm), m_value(""), m_parent(p),
m_locked(false), m_nchildren(0),
m_n(n), m_iscomment(false) {
if (!p) m_root = this;
else m_root = &p->root();
}

2
configure vendored
View file

@ -117,7 +117,7 @@ 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='n'
ENABLE_TPX='y'

View file

@ -6,9 +6,9 @@ namespace tpx {
Substance * GetSub(int isub) {
if (isub == 0)
return new water();
if (isub == 1)
return new nitrogen();
return new water;
else if (isub == 1)
return new nitrogen;
else if (isub == 2)
return new methane;
else if (isub == 3)