Address review line comments

This commit is contained in:
Bryan Weber 2022-10-23 13:13:12 -04:00 committed by Ray Speth
parent 82c323f3f8
commit 2d07de24f5
5 changed files with 37 additions and 31 deletions

1
.gitignore vendored
View File

@ -52,4 +52,3 @@ coverage.info
.coverage
doc/sphinx/matlab/*.rst
!doc/sphinx/matlab/index.rst
interfaces/cython/cantera/units/solution.py

View File

@ -1,22 +1,24 @@
"""
Isentropic, adiabatic flow example - calculate area ratio vs. Mach number curve
Requires: cantera >= 3.0.0
Requires: Cantera >= 3.0.0, pint
Keywords: thermodynamics, compressible flow, units
"""
import cantera.with_units as ct
import cantera.with_units as ctu
import numpy as np
ct.units.default_format = ".2F~P"
label_string = "area ratio\tMach number\ttemperature\tpressure ratio"
output_string = "{0:.2E~P}\t{1} {2}\t{3:.2E~P}"
# This sets the default output format of the units to have 2 significant digits
# and the units are printed with a Unicode font. See:
# https://pint.readthedocs.io/en/stable/formatting.html#unit-format-types
ctu.units.default_format = ".2F~P"
def soundspeed(gas):
"""The speed of sound. Assumes an ideal gas."""
gamma = gas.cp / gas.cv
return np.sqrt(gamma * ct.units.molar_gas_constant
return np.sqrt(gamma * ctu.units.molar_gas_constant
* gas.T / gas.mean_molecular_weight).to("m/s")
@ -29,16 +31,16 @@ def isentropic(gas=None):
degrees Fahrenheit, P0 = 10 atm.
"""
if gas is None:
gas = ct.Solution('gri30.yaml')
gas.TPX = 2160 * ct.units.degR, 10.0 * ct.units.atm, 'H2:1,N2:0.1'
gas = ctu.Solution('gri30.yaml')
gas.TPX = 2160 * ctu.units.degR, 10.0 * ctu.units.atm, 'H2:1,N2:0.1'
# get the stagnation state parameters
s0 = gas.s
h0 = gas.h
p0 = gas.P
mdot = 1 * ct.units.kg / ct.units.s # arbitrary
amin = 1.e14 * ct.units.m**2
mdot = 1 * ctu.units.kg / ctu.units.s # arbitrary
amin = 1.e14 * ctu.units.m**2
data = []
@ -60,6 +62,8 @@ def isentropic(gas=None):
if __name__ == "__main__":
print(__doc__)
data, amin = isentropic()
label_string = "area ratio\tMach number\ttemperature\tpressure ratio"
output_string = "{0:.2E~P}\t{1} {2}\t{3:.2E~P}"
print(label_string)
for row in data:
print(output_string.format(row[0] / amin, row[1], row[2], row[3]))

View File

@ -2,16 +2,16 @@
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
Requires: Cantera >= 3.0.0, pint
Keywords: thermodynamics, thermodynamic cycle, non-ideal fluid, units
"""
import cantera.with_units as ct
import cantera.with_units as ctu
# parameters
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
eta_pump = 0.6 * ctu.units.dimensionless # pump isentropic efficiency
eta_turbine = 0.8 * ctu.units.dimensionless # turbine isentropic efficiency
p_max = 116.03 * ctu.units.psi # maximum pressure
def pump(fluid, p_final, eta):
@ -49,10 +49,10 @@ def print_state(n, fluid):
if __name__ == '__main__':
# create an object representing water
w = ct.Water()
w = ctu.Water()
# start with saturated liquid water at 80.33 degrees Rankine
w.TQ = 540 * ct.units.degR, 0.0 * ct.units.dimensionless
# start with saturated liquid water at 80.33 degrees Fahrenheit
w.TQ = ctu.Q_(80.33, "degF"), 0.0 * ctu.units.dimensionless
h1 = w.h
p1 = w.P
print_state(1, w)
@ -64,7 +64,7 @@ if __name__ == '__main__':
# heat it at constant pressure until it reaches the saturated vapor state
# at this pressure
w.PQ = p_max, 1.0 * ct.units.dimensionless
w.PQ = p_max, 1.0 * ctu.units.dimensionless
h3 = w.h
heat_added = h3 - h2
print_state(3, w)

View File

@ -54,7 +54,7 @@ def equilSoundSpeeds(gas, rtol=1.0e-6, max_iter=5000):
if __name__ == "__main__":
gas = ct.Solution('gri30.yaml')
gas.X = 'CH4:1.00, O2:2.0, N2:7.52'
T_range = np.linspace(300, 2900, 27)
T_range = np.arange(300, 2901, 100)
for T in T_range:
gas.TP = T, ct.one_atm
print(T, equilSoundSpeeds(gas))

View File

@ -1,14 +1,17 @@
"""
Compute the "equilibrium" and "frozen" sound speeds for a gas
Requires: cantera >= 2.6.0
Keywords: thermodynamics, equilibrium
Requires: Cantera >= 3.0.0, pint
Keywords: thermodynamics, equilibrium, units
"""
import cantera.with_units as ct
import cantera.with_units as ctu
import numpy as np
ct.units.default_format = ".2F~P"
# This sets the default output format of the units to have 2 significant digits
# and the units are printed with a Unicode font. See:
# https://pint.readthedocs.io/en/stable/formatting.html#unit-format-types
ctu.units.default_format = ".2F~P"
def equilibrium_sound_speeds(gas, rtol=1.0e-6, max_iter=5000):
"""
@ -44,18 +47,18 @@ def equilibrium_sound_speeds(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 /
gamma * ctu.units.molar_gas_constant
afrozen2 = np.sqrt(gamma * ctu.units.molar_gas_constant * gas.T /
gas.mean_molecular_weight).to("ft/s")
return aequil, afrozen, afrozen2
# test program
if __name__ == "__main__":
gas = ct.Solution('gri30.yaml')
gas = ctu.Solution('gri30.yaml')
gas.X = 'CH4:1.00, O2:2.0, N2:7.52'
T_range = np.linspace(80.33, 4760.33, 50) * ct.units.degF
T_range = np.linspace(80.33, 4760.33, 50) * ctu.units.degF
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, *equilibrium_sound_speeds(gas), sep = " ")
gas.TP = T, 1.0 * ctu.units.atm
print(T.to("degF"), *equilibrium_sound_speeds(gas), sep = " ")