diff --git a/Cantera/python/examples/gasdynamics/soundSpeed/.cvsignore b/Cantera/python/examples/gasdynamics/soundSpeed/.cvsignore new file mode 100644 index 000000000..50bf3042f --- /dev/null +++ b/Cantera/python/examples/gasdynamics/soundSpeed/.cvsignore @@ -0,0 +1,9 @@ +Makefile +runtest +ct2ctml.log +diff_out_0.txt +gri30.xml +h2o2.xml +liquidvapor.xml +output_0.txt +transport_log.xml diff --git a/Cantera/python/examples/gasdynamics/soundSpeed/Makefile.in b/Cantera/python/examples/gasdynamics/soundSpeed/Makefile.in new file mode 100644 index 000000000..7c1fd3c14 --- /dev/null +++ b/Cantera/python/examples/gasdynamics/soundSpeed/Makefile.in @@ -0,0 +1,15 @@ +#!/bin/sh + +PYTHON_CMD = @PYTHON_CMD@ + +run: + $(PYTHON_CMD) soundSpeed.py + +test: + ./runtest +clean: + rm -f *.log *.csv *.xml + ./cleanup + +# end of file + diff --git a/Cantera/python/examples/gasdynamics/soundSpeed/cleanup b/Cantera/python/examples/gasdynamics/soundSpeed/cleanup new file mode 100755 index 000000000..40e1dbd9e --- /dev/null +++ b/Cantera/python/examples/gasdynamics/soundSpeed/cleanup @@ -0,0 +1,5 @@ +#!/bin/sh +# +/bin/rm -rf equilibrate_log*.html +/bin/rm -rf .cttmp* ct2ctml.log transport_log.xml vcs_equilibrate_res*.csv \ + catcomb.csv output_0.txt diff* diff --git a/Cantera/python/examples/gasdynamics/soundSpeed/output_blessed_0.txt b/Cantera/python/examples/gasdynamics/soundSpeed/output_blessed_0.txt new file mode 100644 index 000000000..ddf42786b --- /dev/null +++ b/Cantera/python/examples/gasdynamics/soundSpeed/output_blessed_0.txt @@ -0,0 +1,27 @@ +300.0 (351.8253431032507, 351.82507355528588, 351.82739542290631) +400.0 (408.99770840823857, 404.61002809345359, 404.61285091294371) +500.0 (450.54302619825074, 450.54285937555824, 450.54565509925817) +600.0 (491.48780257355469, 491.4825370038858, 491.48548219951857) +700.0 (527.48987657090606, 528.57720573041479, 528.58025708728178) +800.0 (562.86514830983003, 562.65546776816757, 562.65862683547061) +900.0 (594.67376495368228, 594.39229774412308, 594.39567427125155) +1000.0 (623.17416605630262, 623.19965168989324, 624.39048433713253) +1100.0 (652.9369222305852, 653.02769201149727, 653.03113456251015) +1200.0 (680.29435014296382, 680.38364158810828, 680.38717309322192) +1300.0 (706.48452611858829, 706.62735514685153, 706.63097030129904) +1400.0 (731.5808296184332, 731.89893594969146, 731.90262480084903) +1500.0 (755.59155534306024, 756.31710177592834, 756.32084667529398) +1600.0 (778.45870616284765, 779.98846087343429, 779.99223241247921) +1700.0 (800.07940727859886, 803.01610907406564, 803.01986287218335) +1800.0 (820.35486912478905, 825.50782639603528, 825.51150274583313) +1900.0 (839.26522886850455, 847.58370670756392, 847.5872348799702) +2000.0 (856.94734148296527, 869.3826755379506, 869.38598378152176) +2100.0 (873.73203929088027, 891.0670366816438, 891.07006552686937) +2200.0 (889.93129596650954, 912.8240458097107, 912.82675962077701) +2300.0 (906.66389430405366, 934.86379554886662, 934.8661884578828) +2400.0 (923.87652400866909, 957.41372871164208, 957.41582112412163) +2500.0 (942.11398411476648, 980.71180764818382, 980.71363895431205) +2600.0 (961.76960984153754, 1005.0022117319121, 1005.003827580195) +2700.0 (982.98872554210232, 1030.537277736008, 1030.5387240276229) +2800.0 (1005.8602014954711, 1057.5854507511394, 1057.5867700914928) +2900.0 (1030.5601847154323, 1086.4371555287519, 1086.4383848570014) diff --git a/Cantera/python/examples/gasdynamics/soundSpeed/runtest.in b/Cantera/python/examples/gasdynamics/soundSpeed/runtest.in new file mode 100755 index 000000000..d76205bfc --- /dev/null +++ b/Cantera/python/examples/gasdynamics/soundSpeed/runtest.in @@ -0,0 +1,47 @@ +#!/bin/sh +# +# +temp_success="1" +/bin/rm -f output_0.txt diff_csv.txt diff_out_0.txt + +########################################################################## +PYTHON_CMD=@PYTHON_CMD@ +prog=soundSpeed.py +if test ! -f $prog ; then + echo $prog ' does not exist' + exit -1 +fi +################################################################# +# +CANTERA_DATA=${CANTERA_DATA:=../../../data/inputs}; export CANTERA_DATA +CANTERA_BIN=${CANTERA_BIN:=../../../bin} + +################################################################# + +$PYTHON_CMD $prog > output_0.txt <<+ +1.0 ++ +retnStat=$? +if [ $retnStat != "0" ] +then + temp_success="0" + echo "$prog returned with bad status, $retnStat, check output" +fi + +diff -w output_blessed_0.txt output_0.txt > diff_out_0.txt +retnStat_0=$? + +retnTotal=1 +if test $retnStat_0 = "0" +then + retnTotal=0 +fi + +if test $retnTotal = "0" +then + echo "Successful test comparison on "`pwd` +else + echo "Unsuccessful test comparison of txt files on "`pwd` " test" + echo " see diff_outi_0.txt " +fi + diff --git a/Cantera/python/examples/gasdynamics/soundSpeed/soundSpeed.py b/Cantera/python/examples/gasdynamics/soundSpeed/soundSpeed.py new file mode 100644 index 000000000..7e2dfaa6b --- /dev/null +++ b/Cantera/python/examples/gasdynamics/soundSpeed/soundSpeed.py @@ -0,0 +1,63 @@ +from Cantera import * +import math + +def equilSoundSpeeds(gas, rtol = 1.0e-6, maxiter = 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, maxiter = maxiter) + + # save properties + s0 = gas.entropy_mass() + p0 = gas.pressure() + 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.set(S = s0, P = p1) + + # save the density for this case for the frozen sound speed + rho_frozen = gas.density() + + # now equilibrate the gas holding S and P constant + gas.equilibrate("SP", loglevel=0, rtol = rtol, maxiter = maxiter) # , rtol = 1.0e-3, maxsteps=10000) + + r1 = gas.density() + + # equilibrium sound speed + aequil = math.sqrt((p1 - p0)/(r1 - r0)); + + # frozen sound speed + afrozen = math.sqrt((p1 - p0)/(rho_frozen - r0)); + + # compute the frozen sound speed using the ideal gas + # expression as a check + cp = gas.cp_mass() + cv = gas.cv_mass() + gamma = cp/cv + afrozen2 = math.sqrt(gamma*GasConstant*gas.temperature() + /gas.meanMolecularWeight()) + return (aequil, afrozen, afrozen2) + + +# test program +if __name__ == "__main__": + + gas = GRI30() + gas.set(X = 'CH4:1.00, O2:2.0, N2:7.52') + for n in range(27): + temp = 300.0 + n*100.0 + gas.set(T = temp, P = OneAtm) + print temp, equilSoundSpeeds(gas) + +