Note
Go to the end to download the full example code.
Sound speeds#
Compute the “equilibrium” and “frozen” sound speeds for a gas
Requires: cantera >= 3.0.0
300 (351.818984966187, 351.8225040320234, 351.82565046978357)
400 (404.3290777629895, 404.6071356805201, 404.6106924541565)
500 (450.60662270383807, 450.53970117382426, 450.5433589227729)
600 (493.2287102125155, 491.47923558550104, 491.48326156110255)
700 (531.9409473063305, 528.5737887206026, 528.5780855920744)
800 (565.7789795359693, 562.6519864465995, 562.6563178453433)
900 (594.7936893580119, 594.3886895722893, 594.3928488252863)
1000 (623.1837977066346, 623.1967284031583, 624.3875562792416)
1100 (652.9331874690085, 653.0237849529088, 653.0280701595478)
1200 (680.2903236712064, 680.3796001114183, 680.3839791558561)
1300 (706.4795780421464, 706.6231821892553, 706.627651807389)
1400 (731.5764993620883, 731.8946234757758, 731.8991757740549)
1500 (755.5871061638995, 756.3126623123195, 756.317281331249)
1600 (778.4548233925482, 779.9838905115625, 779.9885487212903)
1700 (800.0748512541905, 803.0114145357675, 803.0160688399629)
1800 (820.3500644565545, 825.5030087192243, 825.507601064624)
1900 (839.2604317904062, 847.5787658333646, 847.5832274741305)
2000 (856.942478647293, 869.3776016457344, 869.3818629810728)
2100 (873.7271651838738, 891.0618357980982, 891.0658400362184)
2200 (889.9263807926993, 912.8187135683238, 912.82242839223)
2300 (906.6589518714205, 934.8583249816345, 934.8617486982836)
2400 (923.8715376222767, 957.4081129925239, 957.4112711605417)
2500 (942.1089312677743, 980.7060365749328, 980.7089748986756)
2600 (961.7644839679816, 1004.9962731533067, 1004.999044790852)
2700 (982.9835165064522, 1030.531157558223, 1030.5338173647083)
2800 (1005.8548869080112, 1057.579133024057, 1057.5817342152743)
2900 (1030.5547501009894, 1086.4306221855172, 1086.433214339237)
import cantera as ct
import math
import numpy as np
def equilSoundSpeeds(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
equilibrium state at the temperature and pressure of the gas, since
otherwise the equilibrium sound speed is not defined.
"""
# set the gas to equilibrium at its current T and P
gas.equilibrate('TP', rtol=rtol, max_iter=max_iter)
# save properties
s0 = gas.s
p0 = gas.P
r0 = gas.density
# perturb the pressure
p1 = p0*1.0001
# set the gas to a state with the same entropy and composition but
# the perturbed pressure
gas.SP = s0, p1
# frozen sound speed
afrozen = math.sqrt((p1 - p0)/(gas.density - r0))
# now equilibrate the gas holding S and P constant
gas.equilibrate('SP', rtol=rtol, max_iter=max_iter)
# equilibrium sound speed
aequil = math.sqrt((p1 - p0)/(gas.density - r0))
# check against the built-in sound speed function
afrozen2 = gas.sound_speed
return aequil, afrozen, afrozen2
# test program
if __name__ == "__main__":
gas = ct.Solution('gri30.yaml')
gas.X = 'CH4:1.00, O2:2.0, N2:7.52'
T_range = np.arange(300, 2901, 100)
for T in T_range:
gas.TP = T, ct.one_atm
print(T, equilSoundSpeeds(gas))
Total running time of the script: (0 minutes 0.074 seconds)