Skip to content

Commit

Permalink
*** empty log message ***
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Goodwin committed Mar 12, 2004
1 parent 2351fc7 commit d298e3b
Show file tree
Hide file tree
Showing 22 changed files with 236 additions and 108 deletions.
10 changes: 6 additions & 4 deletions Cantera/clib/src/ct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,21 +539,23 @@ extern "C" {
catch (CanteraError) { return DERR; }
}

int DLL_EXPORT th_setState_satLiquid(int n) {
int DLL_EXPORT th_setState_Psat(int n, double p, double x) {
try {
purefluid(n)->setState_satLiquid();
purefluid(n)->setState_Psat(p, x);
return 0;
}
catch (CanteraError) { return -1; }
}

int DLL_EXPORT th_setState_satVapor(int n) {
int DLL_EXPORT th_setState_Tsat(int n, double t, double x) {
try {
purefluid(n)->setState_satVapor();
purefluid(n)->setState_Tsat(t, x);
return 0;
}
catch (CanteraError) { return -1; }
}



//-------------- Kinetics ------------------//

Expand Down
4 changes: 2 additions & 2 deletions Cantera/clib/src/ct.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ extern "C" {
double DLL_IMPORT th_vaporFraction(int n);
double DLL_IMPORT th_satTemperature(int n, double p);
double DLL_IMPORT th_satPressure(int n, double t);
int DLL_IMPORT th_setState_satLiquid(int n);
int DLL_IMPORT th_setState_satVapor(int n);
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,
Expand Down
8 changes: 4 additions & 4 deletions Cantera/matlab/cantera/GRI30.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
%
% GRI-Mech 3.0 is a widely-used reaction mechanism for natural gas
% combustion. It contains 53 species composed of the elements H,
% C, O, N, and/or Ar, and contains 325 reactions, most of which
% are reversible. GRI-Mech 3.0, like most combustion mechanisms,
% is designed for use at pressures where the ideal gas law holds.
% C, O, N, and/or Ar, and 325 reactions, most of which are
% reversible. GRI-Mech 3.0, like most combustion mechanisms, is
% designed for use at pressures where the ideal gas law holds.
%
% Function GRI30 creates the solution according to the
% specifications in file gri30.xml. The ideal gas equation of
% specifications in file gri30.cti. The ideal gas equation of
% state is used. Transport property evaluation is disabled by
% default. To enable transport properties, supply the name of
% the transport model to use.
Expand Down
3 changes: 3 additions & 0 deletions Cantera/matlab/cantera/Hydrogen.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
% equation of state is taken from W. C. Reynolds, "Thermodynamic
% Properties in SI."
%
% For more details, see classes Cantera::PureFluid and tpx::hydrogen in the
% Cantera C++ source code documentation.
%
n = importPhase('purefluids.cti','hydrogen');

2 changes: 1 addition & 1 deletion Cantera/matlab/cantera/MassFlowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
% mass flow controller that maintains a constant mass flow rate
% independent of upstream or downstream conditions. If two reactor
% objects are supplied as arguments, the controller is installed
% between the two reactors.
% between the two reactors.
%
% see also: FlowDevice
%
Expand Down
3 changes: 3 additions & 0 deletions Cantera/matlab/cantera/Water.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
% equation of state is taken from W. C. Reynolds, "Thermodynamic
% Properties in SI."
%
% For more details, see classes Cantera::PureFluid and tpx::water in the
% Cantera C++ source code documentation.
%
w = importPhase('purefluids.cti','water');

7 changes: 4 additions & 3 deletions Cantera/matlab/cantera/private/thermomethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ static void thermoset( int nlhs, mxArray *plhs[],
case 1:
ierr = th_setPressure(th,*ptr); break;
case 2:
ierr = th_setState_satLiquid(th); break;
ierr = th_setState_Psat(th,ptr[0],ptr[1]); break;
case 3:
ierr = th_setState_satVapor(th); break;
ierr = th_setState_Tsat(th,ptr[0],ptr[1]); break;
default:
mexErrMsgTxt("unknown attribute.");
}
Expand Down Expand Up @@ -62,7 +62,8 @@ static void thermoset( int nlhs, mxArray *plhs[],
else if (job == 50) {
int xy = int(*ptr);
ierr = th_equil(th, xy);
}
}
if (ierr < 0) reportError();

plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
double *h = mxGetPr(plhs[0]);
Expand Down
8 changes: 4 additions & 4 deletions Cantera/python/Cantera/ThermoPhase.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ 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_Psat(self, p, vaporFraction):
_cantera.thermo_setfp(self._phase_id,8, p, vaporFraction)

def setState_satVapor(self):
_cantera.thermo_setfp(self._phase_id,8,0.0,0.0)
def setState_Tsat(self, t, vaporFraction):
_cantera.thermo_setfp(self._phase_id,7, t, vaporFraction)


def thermophase(self):
Expand Down
74 changes: 65 additions & 9 deletions Cantera/python/Cantera/ctml_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,9 +1012,15 @@ def build(self, p):

def is_ideal_gas(self):
return 1

class pure_solid(phase):
"""A pure solid."""


class stoichiometric_solid(phase):
"""A solid compound or pure element.Stoichiometric solid phases
contain exactly one species, which always has unit activity. The
solid is assumed to have constant density. Therefore the rates of
reactions involving these phases do not contain any concentration
terms for the (one) species in the phase, since the concentration
is always the same. """
def __init__(self,
name = '',
elements = '',
Expand All @@ -1038,7 +1044,7 @@ def conc_dim(self):
def build(self, p):
ph = phase.build(self, p)
e = ph.addChild("thermo")
e['model'] = 'SolidCompound'
e['model'] = 'StoichCompound'
addFloat(e, 'density', self._dens, defunits = _umass+'/'+_ulen+'3')
if self._tr:
t = ph.addChild('transport')
Expand All @@ -1047,6 +1053,50 @@ def build(self, p):
k['model'] = 'none'


class stoichiometric_liquid(stoichiometric_solid):
"""A stoichiometric liquid. Currently, there is no distinction
between stoichiometric liquids and solids."""
def __init__(self,
name = '',
elements = '',
species = '',
density = -1.0,
transport = 'None',
initial_state = None,
options = []):

stoichiometric_solid.__init__(self, name, 3, elements,
species, 'none',
initial_state, options)
self._dens = density
self._pure = 1
if self._dens < 0.0:
raise 'density must be specified.'
self._tr = transport

class pure_solid(stoichiometric_solid):
"""Deprecated. Use stoichiometric_solid"""
def __init__(self,
name = '',
elements = '',
species = '',
density = -1.0,
transport = 'None',
initial_state = None,
options = []):

stoichiometric_solid.__init__(self, name, 3, elements,
species, 'none',
initial_state, options)
self._dens = density
self._pure = 1
if self._dens < 0.0:
raise 'density must be specified.'
self._tr = transport
print 'WARNING: entry type pure_solid is deprecated.'
print 'Use stoichiometric_solid instead.'


class metal(phase):
"""A metal."""
def __init__(self,
Expand All @@ -1062,8 +1112,6 @@ def __init__(self,
initial_state, options)
self._dens = density
self._pure = 0
#if self._dens < 0.0:
# raise 'density must be specified.'
self._tr = transport

def conc_dim(self):
Expand Down Expand Up @@ -1115,8 +1163,13 @@ def build(self, p):
k['model'] = 'none'


class pure_fluid(phase):
"""A pure fluid."""
class liquid_vapor(phase):
"""A fluid with a complete liquid/vapor equation of state.
This entry type selects one of a set of predefined fluids with
built-in liquid/vapor equations of state. The substance_flag
parameter selects the fluid. See purefluids.py for the usage
of this entry type."""

def __init__(self,
name = '',
elements = '',
Expand Down Expand Up @@ -1310,7 +1363,10 @@ def build(self, p):
# $Revision$
# $Date$
# $Log$
# Revision 1.30 2004-02-08 13:25:21 dggoodwin
# Revision 1.31 2004-03-12 05:59:59 dggoodwin
# *** empty log message ***
#
# Revision 1.30 2004/02/08 13:25:21 dggoodwin
# *** empty log message ***
#
# Revision 1.29 2004/02/08 13:22:31 dggoodwin
Expand Down
17 changes: 8 additions & 9 deletions Cantera/python/examples/diamond.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#
# A CVD example. This example computes the growth rate of a diamond film according to
# a simplified version of a particular published growth mechanism (see file diamond.cti
# for details). Only the surface coverage equations are solved here; the gas composition
# is fixed. (For an example of coupled gas-phase and surface, see catcomb.py.)
#
# Atomic hydrogen plays an important role in diamond CVD, and this
# example computes the growth rate and surface coverages as a function
# of [H] at the surface for fixed temperature and [CH3].
# A CVD example. This example computes the growth rate of a diamond
#film according to a simplified version of a particular published
#growth mechanism (see file diamond.cti for details). Only the surface
#coverage equations are solved here; the gas composition is
#fixed. (For an example of coupled gas-phase and surface, see
#catcomb.py.) Atomic hydrogen plays an important role in diamond CVD,
#and this example computes the growth rate and surface coverages as a
#function of [H] at the surface for fixed temperature and [CH3].

from Cantera import *
import math
Expand Down
92 changes: 69 additions & 23 deletions Cantera/python/examples/rankine.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,83 @@
#
# an ideal Rankine cycle
# an Rankine cycle
#
from Cantera import *
from Cantera.pureFluids import Water
from Cantera.liquidvapor import Water

w = Water()
# parameters
eta_pump = 0.6 # pump isentropic efficiency
et_turbine = 0.8 # turbine isentropic efficiency
pmax = 8.0e5 # maximum pressure

# start with saturated liquid water at 300 K
w.setTemperature(300.0)
w.setState_satLiquid()
h1 = w.enthalpy_mass()
p1 = w.pressure()
########################################################
#
# some useful functions
#

# pump it isentropically to 10 MPa
w.setState_SP(w.entropy_mass(), 1.0e7)
h2 = w.enthalpy_mass()
def pump(fluid, pfinal, eta):
"""Adiabatically pump a fluid to pressure pfinal, using
a pump with isentropic efficiency eta."""
h0 = fluid.enthalpy_mass()
s0 = fluid.entropy_mass()
fluid.setState_SP(s0, pfinal)
h1s = fluid.enthalpy_mass()
isentropic_work = h1s - h0
actual_work = isentropic_work / eta
h1 = h0 + actual_work
fluid.setState_HP(h1, pfinal)
return actual_work

pump_work = h2 - h1
def expand(fluid, pfinal, eta):
"""Adiabatically expand a fluid to pressure pfinal, using
a turbine with isentropic efficiency eta."""
h0 = fluid.enthalpy_mass()
s0 = fluid.entropy_mass()
fluid.setState_SP(s0, pfinal)
h1s = fluid.enthalpy_mass()
isentropic_work = h0 - h1s
actual_work = isentropic_work * eta
h1 = h0 - actual_work
fluid.setState_HP(h1, pfinal)
return actual_work

# heat at constant pressure to 1500 K
w.setState_TP(1500.0, w.pressure())
h3 = w.enthalpy_mass()
###############################################################

heat_in = h3 - h2

# expand isentropically back to 300 K
w.setState_SP(w.entropy_mass(), p1)
h4 = w.enthalpy_mass()
# create an object representing water
w = Water()

# start with saturated liquid water at 300 K
w.setTemperature(300.0)
w.setState_Tsat(0.0)
hf = w.enthalpy_mass()
print w
w.setState_Tsat(1.0)
hv = w.enthalpy_mass()
print hv - hf

print w

work_out = h3 - h4
heat_out = h4 - h1
# pump it adiabatically to pmax
pump_work = pump(w, pmax, eta_pump)
print pump_work

efficiency = (work_out - pump_work)/heat_in
# heat it at constant pressure until it reaches the
# saturated vapor state at this pressure
#w.setState_Psat(1.0)
#print w

print 'efficiency = ',efficiency
w.setTemperature(273.16)
w.setState_Tsat(0.0)
h0 = w.enthalpy_mass()
for t in [300.0, 350.0, 400.0, 450.0, 500.0]:
w.setTemperature(t)
w.setState_Tsat(0.0)
hf = w.enthalpy_mass()
w.setState_Tsat(1.0)
hv = w.enthalpy_mass()
print t, 0.001*(hf - h0), 0.001*(hv - h0), 0.001*(hv - hf)

for t in [750.0, 800.0, 850.0, 1150.0]:
w.setState_TP(t, 2.0e4)
print t, w.enthalpy_mass() - h0

4 changes: 2 additions & 2 deletions Cantera/python/src/ctthermo_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ thermo_setfp(PyObject *self, PyObject *args)
case 6:
iok = th_setElectricPotential(th, v[0]); break;
case 7:
iok = th_setState_satLiquid(th); break;
iok = th_setState_Tsat(th, v1, v2); break;
case 8:
iok = th_setState_satVapor(th); break;
iok = th_setState_Psat(th, v1, v2); break;
default:
iok = -10;
}
Expand Down
2 changes: 1 addition & 1 deletion Cantera/src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ BASE = State.o Elements.o Constituents.o stringUtils.o misc.o importCTML.o
xml.o Phase.o DenseMatrix.o ctml.o funcs.o ctvector.o phasereport.o ct2ctml.o

# thermodynamic properties
THERMO = $(BASE) ThermoPhase.o IdealGasPhase.o ConstDensityThermo.o SolidCompound.o SpeciesThermoFactory.o ThermoFactory.o
THERMO = $(BASE) ThermoPhase.o IdealGasPhase.o ConstDensityThermo.o StoichSubstance.o SpeciesThermoFactory.o ThermoFactory.o

# homogeneous kinetics
KINETICS = GRI_30_Kinetics.o KineticsFactory.o GasKinetics.o FalloffFactory.o \
Expand Down
Loading

0 comments on commit d298e3b

Please sign in to comment.