[Examples] Add example keywords for units

This commit is contained in:
Bryan Weber 2022-09-24 17:44:26 -04:00 committed by Ray Speth
parent 08997ddd53
commit 82a24baa73
5 changed files with 21 additions and 15 deletions

View File

@ -41,5 +41,6 @@ thermodynamic cycle
thermodynamics
transport
tutorial
units
user-defined model
well-stirred reactor

View File

@ -106,7 +106,7 @@ else:
localenv.Depends(ext, localenv['cantera_shlib'])
for f in (multi_glob(localenv, 'cantera', 'py') +
multi_glob(localenv, 'cantera/*', 'py')):
multi_glob(localenv, 'cantera/*', 'py', 'in')):
localenv.Depends(mod, f)
UNITS = {

View File

@ -1,10 +1,11 @@
"""
Isentropic, adiabatic flow example - calculate area ratio vs. Mach number curve
Requires: cantera >= 2.6.0
Requires: cantera >= 3.0.0
Keywords: thermodynamics, compressible flow, units
"""
import cantera.units as ct
import cantera.with_units as ct
import numpy as np
ct.units.default_format = ".2F~P"
label_string = "area ratio\tMach number\ttemperature\tpressure ratio"

View File

@ -1,15 +1,17 @@
"""
A Rankine vapor power cycle
Calculate the efficiency of a Rankine vapor power cycle using a pure fluid model
for water. Includes the units of quantities in the calculations.
Requires: Cantera >= 2.6.0
Keywords: thermodynamics, thermodynamic cycle, non-ideal fluid, units
"""
import cantera.units as ct
import cantera.with_units as ct
# parameters
eta_pump = 0.6 * ct.units.dimensionless # pump isentropic efficiency
eta_pump = 0.6 * ct.units.dimensionless # pump isentropic efficiency
eta_turbine = 0.8 * ct.units.dimensionless # turbine isentropic efficiency
p_max = 116.03 * ct.units.psi # maximum pressure
p_max = 116.03 * ct.units.psi # maximum pressure
def pump(fluid, p_final, eta):
@ -40,7 +42,7 @@ def expand(fluid, p_final, eta):
return actual_work
def printState(n, fluid):
def print_state(n, fluid):
print('\n***************** State {0} ******************'.format(n))
print(fluid.report())
@ -53,23 +55,23 @@ if __name__ == '__main__':
w.TQ = 540 * ct.units.degR, 0.0 * ct.units.dimensionless
h1 = w.h
p1 = w.P
printState(1, w)
print_state(1, w)
# pump it adiabatically to p_max
pump_work = pump(w, p_max, eta_pump)
h2 = w.h
printState(2, w)
print_state(2, w)
# heat it at constant pressure until it reaches the saturated vapor state
# at this pressure
w.PQ = p_max, 1.0 * ct.units.dimensionless
h3 = w.h
heat_added = h3 - h2
printState(3, w)
print_state(3, w)
# expand back to p1
turbine_work = expand(w, p1, eta_turbine)
printState(4, w)
print_state(4, w)
# efficiency
eff = (turbine_work - pump_work)/heat_added

View File

@ -2,14 +2,15 @@
Compute the "equilibrium" and "frozen" sound speeds for a gas
Requires: cantera >= 2.6.0
Keywords: thermodynamics, equilibrium
"""
import cantera.units as ct
import cantera.with_units as ct
import numpy as np
ct.units.default_format = ".2F~P"
def equilSoundSpeeds(gas, rtol=1.0e-6, max_iter=5000):
def equilibrium_sound_speeds(gas, rtol=1.0e-6, max_iter=5000):
"""
Returns a tuple containing the equilibrium and frozen sound speeds for a
gas with an equilibrium composition. The gas is first set to an
@ -43,6 +44,7 @@ def equilSoundSpeeds(gas, rtol=1.0e-6, max_iter=5000):
# compute the frozen sound speed using the ideal gas expression as a check
gamma = gas.cp/gas.cv
gamma * ct.units.molar_gas_constant
afrozen2 = np.sqrt(gamma * ct.units.molar_gas_constant * gas.T /
gas.mean_molecular_weight).to("ft/s")
@ -56,4 +58,4 @@ if __name__ == "__main__":
print("Temperature Equilibrium Sound Speed Frozen Sound Speed Frozen Sound Speed Check")
for T in T_range:
gas.TP = T, 1.0 * ct.units.atm
print(T, *equilSoundSpeeds(gas), sep = " ")
print(T, *equilibrium_sound_speeds(gas), sep = " ")