*** empty log message ***

This commit is contained in:
Dave Goodwin 2004-03-12 11:44:04 +00:00
parent d298e3b4b0
commit 52ea110888
5 changed files with 132 additions and 77 deletions

View file

@ -0,0 +1,18 @@
"""Fluids with complete liquid/vapor equations of state."""
from importFromFile import importPhase
def Water():
return importPhase('liquidvapor.cti','water')
def Nitrogen():
return importPhase('liquidvapor.cti','nitrogen')
def Methane():
return importPhase('liquidvapor.cti','methane')
def Hydrogen():
return importPhase('liquidvapor.cti','hydrogen')
def Oxygen():
return importPhase('liquidvapor.cti','oxygen')

View file

@ -1,16 +0,0 @@
from importFromFile import importPhase
def Water():
return importPhase('purefluids.cti','water')
def Nitrogen():
return importPhase('purefluids.cti','nitrogen')
def Methane():
return importPhase('purefluids.cti','methane')
def Hydrogen():
return importPhase('purefluids.cti','hydrogen')
def Oxygen():
return importPhase('purefluids.cti','oxygen')

View file

@ -1,58 +1,98 @@
from exceptions import CanteraError from exceptions import CanteraError
def setByName(a, options): def setByName(a, options):
tval = None
pval = None pval = None
hval = None hval = None
uval = None uval = None
sval = None sval = None
vval = None vval = None
qval = None
np = 0 np = 0
nt = 0
nv = 0
nx = 0
ny = 0
ns = 0
nh = 0
nu = 0
nq = 0
for o in options.keys(): for o in options.keys():
val = options[o] val = options[o]
if o == 'Temperature' or o == 'T': if o == 'Temperature' or o == 'T':
a.setTemperature(val) nt += 1
tval = val
elif o == 'Density' or o == 'Rho': elif o == 'Density' or o == 'Rho':
a.setDensity(val) nv += 1
vval = 1.0/val vval = 1.0/val
elif o == 'V': elif o == 'Volume' or o == 'V':
a.setDensity(1.0/val) nv += 1
vval = val vval = val
elif o == 'MoleFractions' or o == 'X': elif o == 'MoleFractions' or o == 'X':
nx += 1
a.setMoleFractions(val) a.setMoleFractions(val)
elif o == 'MassFractions' or o == 'Y': elif o == 'MassFractions' or o == 'Y':
ny += 1
a.setMassFractions(val) a.setMassFractions(val)
elif o == 'Pressure' or o == 'P': elif o == 'Pressure' or o == 'P':
pval = val pval = val
np = np + 1 np += 1
elif o == 'Enthalpy' or o == 'H': elif o == 'Enthalpy' or o == 'H':
hval = val hval = val
np = np + 1 nh += 1
elif o == 'IntEnergy' or o == 'U': elif o == 'IntEnergy' or o == 'U':
uval = val uval = val
np = np + 1 nu += 1
elif o == 'Entropy' or o == 'S': elif o == 'Entropy' or o == 'S':
sval = val sval = val
np = np + 1 ns += 1
elif o == 'Sat' or o == 'Vapor' or o == 'Vap':
nq += 1
qval = val
else: else:
raise CanteraError('unknown property: '+o) raise CanteraError('unknown property: '+o)
if np == 1: if nx + ny > 1:
if pval: raise CanteraError('composition specified multiple times')
a.setPressure(pval)
if np >= 2: ntot = nt + np + nv + ns + nh + nu + nq
if pval and hval:
a.setState_HP(hval,pval) if ntot == 1:
elif uval and vval: if nt == 1:
a.setState_UV(uval,vval) a.setTemperature(tval)
elif sval and pval: elif nv == 1:
a.setState_SP(sval,pval) a.setDensity(1.0/vval)
elif sval and vval: elif np == 1:
a.setState_SV(sval,vval) a.seetPressure(pval)
else:
props = options.keys()
raise CanteraError('property '+props[0]+
' can only be set in combination with '
+'another property')
elif ntot == 2:
if np == 1 and nh == 1:
a.setState_HP(hval, pval)
elif nu == 1 and nv == 1:
a.setState_UV(uval, vval)
elif ns == 1 and np == 1:
a.setState_SP(sval, pval)
elif ns == 1 and nv == 1:
a.setState_SV(sval, vval)
elif nt == 1 and np == 1:
a.setState_TP(tval, pval)
elif nt == 1 and nv == 1:
a.setState_TR(tval, 1.0/vval)
elif nt == 1 and nq == 1:
a.setState_Tsat(tval, qval)
elif np == 1 and nq == 1:
a.setState_Psat(pval, qval)
else: else:
raise CanteraError('unimplemented property pair') raise CanteraError('unimplemented property pair')
def set(a, **options): def set(a, **options):
setByName(a, options) setByName(a, options)

View file

@ -1,14 +1,21 @@
# #
# an Rankine cycle # A Rankine vapor power cycle
# #
from Cantera import * from Cantera import *
from Cantera.liquidvapor import Water from Cantera.liquidvapor import Water
########################################################
#
# parameters # parameters
#
eta_pump = 0.6 # pump isentropic efficiency eta_pump = 0.6 # pump isentropic efficiency
et_turbine = 0.8 # turbine isentropic efficiency eta_turbine = 0.8 # turbine isentropic efficiency
pmax = 8.0e5 # maximum pressure pmax = 8.0e5 # maximum pressure
######################################################## ########################################################
# #
# some useful functions # some useful functions
@ -19,27 +26,33 @@ def pump(fluid, pfinal, eta):
a pump with isentropic efficiency eta.""" a pump with isentropic efficiency eta."""
h0 = fluid.enthalpy_mass() h0 = fluid.enthalpy_mass()
s0 = fluid.entropy_mass() s0 = fluid.entropy_mass()
fluid.setState_SP(s0, pfinal) fluid.set(S = s0, P = pfinal)
h1s = fluid.enthalpy_mass() h1s = fluid.enthalpy_mass()
isentropic_work = h1s - h0 isentropic_work = h1s - h0
actual_work = isentropic_work / eta actual_work = isentropic_work / eta
h1 = h0 + actual_work h1 = h0 + actual_work
fluid.setState_HP(h1, pfinal) fluid.set(H = h1, P = pfinal)
return actual_work return actual_work
def expand(fluid, pfinal, eta): def expand(fluid, pfinal, eta):
"""Adiabatically expand a fluid to pressure pfinal, using """Adiabatically expand a fluid to pressure pfinal, using
a turbine with isentropic efficiency eta.""" a turbine with isentropic efficiency eta."""
h0 = fluid.enthalpy_mass() h0 = fluid.enthalpy_mass()
s0 = fluid.entropy_mass() s0 = fluid.entropy_mass()
fluid.setState_SP(s0, pfinal) fluid.set(S = s0, P = pfinal)
h1s = fluid.enthalpy_mass() h1s = fluid.enthalpy_mass()
isentropic_work = h0 - h1s isentropic_work = h0 - h1s
actual_work = isentropic_work * eta actual_work = isentropic_work * eta
h1 = h0 - actual_work h1 = h0 - actual_work
fluid.setState_HP(h1, pfinal) fluid.set(H = h1, P = pfinal)
return actual_work return actual_work
def printState(n, fluid):
print '\n\n***************** State '+`n`+' ******************\n', fluid
############################################################### ###############################################################
@ -47,37 +60,35 @@ def expand(fluid, pfinal, eta):
w = Water() w = Water()
# start with saturated liquid water at 300 K # start with saturated liquid water at 300 K
w.setTemperature(300.0) w.set(T = 300.0, Vapor = 0.0)
w.setState_Tsat(0.0) h1 = w.enthalpy_mass()
hf = w.enthalpy_mass() p1 = w.pressure()
print w printState(1,w)
w.setState_Tsat(1.0)
hv = w.enthalpy_mass()
print hv - hf
print w
# pump it adiabatically to pmax # pump it adiabatically to pmax
pump_work = pump(w, pmax, eta_pump) pump_work = pump(w, pmax, eta_pump)
print pump_work h2 = w.enthalpy_mass()
printState(2,w)
# heat it at constant pressure until it reaches the # heat it at constant pressure until it reaches the
# saturated vapor state at this pressure # saturated vapor state at this pressure
#w.setState_Psat(1.0) w.set(P = pmax, Vapor = 1.0)
#print w h3 = w.enthalpy_mass()
heat_added = h3 - h2
printState(3,w)
# expand back to p1
turbine_work = expand(w, p1, eta_turbine)
printState(4,w)
# efficiency
eff = (turbine_work - pump_work)/heat_added
print 'efficiency = ',eff
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

View file

@ -1,38 +1,40 @@
# These phase definitions actually represent multiphase fluids. They # These phase definitions represent fluids with complete liquid/vapor
# use equations of state in the 'TPX' package, which in turn take most # equations of state. Depending on conditions, they may represent a
# of the equations of state from the compilation 'Thermodynamic # single-phase fluid, either liquid or vapor, or a saturated
# Properties in SI', by W. C. Reynolds. # liquid/vapor mixture. They use equations of state in the 'TPX'
# package, which in turn take most of the equations of state from the
# compilation 'Thermodynamic Properties in SI', by W. C. Reynolds.
pure_fluid(name = "water", liquid_vapor(name = "water",
elements = " O H ", elements = " O H ",
species = "H2O", species = "H2O",
substance_flag = 0, substance_flag = 0,
initial_state = state(temperature = 300.0, initial_state = state(temperature = 300.0,
pressure = OneAtm) ) pressure = OneAtm) )
pure_fluid(name = "nitrogen", liquid_vapor(name = "nitrogen",
elements = " N ", elements = " N ",
species = "N2", species = "N2",
substance_flag = 1, substance_flag = 1,
initial_state = state(temperature = 300.0, initial_state = state(temperature = 300.0,
pressure = OneAtm) ) pressure = OneAtm) )
pure_fluid(name = "methane", liquid_vapor(name = "methane",
elements = " C H ", elements = " C H ",
species = "CH4", species = "CH4",
substance_flag = 2, substance_flag = 2,
initial_state = state(temperature = 300.0, initial_state = state(temperature = 300.0,
pressure = OneAtm) ) pressure = OneAtm) )
pure_fluid(name = "hydrogen", liquid_vapor(name = "hydrogen",
elements = " H ", elements = " H ",
species = "H2", species = "H2",
substance_flag = 3, substance_flag = 3,
initial_state = state(temperature = 300.0, initial_state = state(temperature = 300.0,
pressure = OneAtm) ) pressure = OneAtm) )
pure_fluid(name = "oxygen", liquid_vapor(name = "oxygen",
elements = " O ", elements = " O ",
species = "O2", species = "O2",
substance_flag = 4, substance_flag = 4,