diff --git a/Cantera/python/examples/reactors/reactor1_sim/.cvsignore b/Cantera/python/examples/reactors/reactor1_sim/.cvsignore new file mode 100644 index 000000000..5ca6ef77f --- /dev/null +++ b/Cantera/python/examples/reactors/reactor1_sim/.cvsignore @@ -0,0 +1,9 @@ +Makefile +runtest +air.xml +ct2ctml.log +diff_out_0.txt +gri30.xml +output_0.txt +transport_log.xml + diff --git a/Cantera/python/examples/reactors/reactor1_sim/Makefile.in b/Cantera/python/examples/reactors/reactor1_sim/Makefile.in new file mode 100644 index 000000000..239473432 --- /dev/null +++ b/Cantera/python/examples/reactors/reactor1_sim/Makefile.in @@ -0,0 +1,15 @@ +#!/bin/sh + +PYTHON_CMD = @PYTHON_CMD@ + +run: + $(PYTHON_CMD) reactor1.py + +test: + ./runtest +clean: + rm -f *.log *.csv *.xml + ./cleanup + +# end of file + diff --git a/Cantera/python/examples/reactors/reactor1_sim/cleanup b/Cantera/python/examples/reactors/reactor1_sim/cleanup new file mode 100755 index 000000000..40e1dbd9e --- /dev/null +++ b/Cantera/python/examples/reactors/reactor1_sim/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/reactors/reactor1_sim/output_blessed_0.txt b/Cantera/python/examples/reactors/reactor1_sim/output_blessed_0.txt new file mode 100644 index 000000000..0963f8c2d --- /dev/null +++ b/Cantera/python/examples/reactors/reactor1_sim/output_blessed_0.txt @@ -0,0 +1,107 @@ + Adding reactor (none) +Initializing reactor network. +Reactor 0: 55 variables. + 0 sensitivity params. +Number of equations: 55 +Maximum time step: 1e-05 + 1.000e-05 1001.000 101325.000 6.207690e+05 + 2.000e-05 1001.000 101325.000 6.207690e+05 + 3.000e-05 1001.000 101325.000 6.207690e+05 + 4.000e-05 1001.000 101325.000 6.207690e+05 + 5.000e-05 1001.000 101325.000 6.207690e+05 + 6.000e-05 1001.000 101325.000 6.207690e+05 + 7.000e-05 1001.000 101325.000 6.207690e+05 + 8.000e-05 1001.000 101325.000 6.207689e+05 + 9.000e-05 1001.001 101325.000 6.207689e+05 + 1.000e-04 1001.001 101325.000 6.207687e+05 + 1.100e-04 1001.001 101325.000 6.207686e+05 + 1.200e-04 1001.002 101325.000 6.207683e+05 + 1.300e-04 1001.003 101325.000 6.207679e+05 + 1.400e-04 1001.005 101325.000 6.207673e+05 + 1.500e-04 1001.008 101325.000 6.207663e+05 + 1.600e-04 1001.012 101325.000 6.207648e+05 + 1.700e-04 1001.019 101325.000 6.207625e+05 + 1.800e-04 1001.030 101325.000 6.207588e+05 + 1.900e-04 1001.047 101325.000 6.207528e+05 + 2.000e-04 1001.075 101325.000 6.207432e+05 + 2.100e-04 1001.121 101325.000 6.207272e+05 + 2.200e-04 1001.200 101325.000 6.206998e+05 + 2.300e-04 1001.340 101325.000 6.206504e+05 + 2.400e-04 1001.605 101325.000 6.205558e+05 + 2.500e-04 1002.143 101325.000 6.203619e+05 + 2.600e-04 1003.307 101325.000 6.199378e+05 + 2.700e-04 1005.923 101325.000 6.189783e+05 + 2.800e-04 1011.832 101325.001 6.168061e+05 + 2.900e-04 1025.565 101325.002 6.117616e+05 + 3.000e-04 1061.254 101325.005 5.986875e+05 + 3.100e-04 1190.878 101325.025 5.516319e+05 + 3.200e-04 1697.346 101325.031 3.765609e+05 + 3.300e-04 1941.729 101325.013 2.989367e+05 + 3.400e-04 2076.014 101325.008 2.577823e+05 + 3.500e-04 2167.614 101325.006 2.303060e+05 + 3.600e-04 2236.254 101325.005 2.100293e+05 + 3.700e-04 2290.521 101325.004 1.941860e+05 + 3.800e-04 2334.939 101325.003 1.813403e+05 + 3.900e-04 2372.182 101325.002 1.706537e+05 + 4.000e-04 2403.962 101325.002 1.615951e+05 + 4.100e-04 2431.439 101325.002 1.538073e+05 + 4.200e-04 2455.437 101325.002 1.470392e+05 + 4.300e-04 2476.561 101325.001 1.411075e+05 + 4.400e-04 2495.271 101325.001 1.358740e+05 + 4.500e-04 2511.922 101325.001 1.312321e+05 + 4.600e-04 2526.798 101325.001 1.270977e+05 + 4.700e-04 2540.129 101325.001 1.234029e+05 + 4.800e-04 2552.105 101325.001 1.200920e+05 + 4.900e-04 2562.883 101325.001 1.171187e+05 + 5.000e-04 2572.599 101325.001 1.144441e+05 + 5.100e-04 2581.367 101325.001 1.120348e+05 + 5.200e-04 2589.287 101325.001 1.098621e+05 + 5.300e-04 2596.447 101325.000 1.079011e+05 + 5.400e-04 2602.923 101325.000 1.061300e+05 + 5.500e-04 2608.782 101325.000 1.045295e+05 + 5.600e-04 2614.086 101325.000 1.030826e+05 + 5.700e-04 2618.887 101325.000 1.017741e+05 + 5.800e-04 2623.235 101325.000 1.005906e+05 + 5.900e-04 2627.172 101325.000 9.951996e+04 + 6.000e-04 2630.738 101325.000 9.855127e+04 + 6.100e-04 2633.967 101325.000 9.767481e+04 + 6.200e-04 2636.891 101325.000 9.688179e+04 + 6.300e-04 2639.539 101325.000 9.616426e+04 + 6.400e-04 2641.936 101325.000 9.551510e+04 + 6.500e-04 2644.107 101325.000 9.492782e+04 + 6.600e-04 2646.073 101325.000 9.439660e+04 + 6.700e-04 2647.852 101325.000 9.391615e+04 + 6.800e-04 2649.462 101325.000 9.348169e+04 + 6.900e-04 2650.919 101325.000 9.308889e+04 + 7.000e-04 2652.237 101325.000 9.273384e+04 + 7.100e-04 2653.429 101325.000 9.241300e+04 + 7.200e-04 2654.507 101325.000 9.212314e+04 + 7.300e-04 2655.482 101325.000 9.186136e+04 + 7.400e-04 2656.363 101325.000 9.162503e+04 + 7.500e-04 2657.159 101325.000 9.141176e+04 + 7.600e-04 2657.878 101325.000 9.121938e+04 + 7.700e-04 2658.528 101325.000 9.104594e+04 + 7.800e-04 2659.114 101325.000 9.088965e+04 + 7.900e-04 2659.642 101325.000 9.074891e+04 + 8.000e-04 2660.119 101325.000 9.062226e+04 + 8.100e-04 2660.549 101325.000 9.050838e+04 + 8.200e-04 2660.935 101325.000 9.040607e+04 + 8.300e-04 2661.283 101325.000 9.031424e+04 + 8.400e-04 2661.596 101325.000 9.023191e+04 + 8.500e-04 2661.878 101325.000 9.015819e+04 + 8.600e-04 2662.130 101325.000 9.009228e+04 + 8.700e-04 2662.356 101325.000 9.003343e+04 + 8.800e-04 2662.559 101325.000 8.998099e+04 + 8.900e-04 2662.740 101325.000 8.993435e+04 + 9.000e-04 2662.902 101325.000 8.989297e+04 + 9.100e-04 2663.046 101325.000 8.985636e+04 + 9.200e-04 2663.174 101325.000 8.982407e+04 + 9.300e-04 2663.287 101325.000 8.979569e+04 + 9.400e-04 2663.388 101325.000 8.977085e+04 + 9.500e-04 2663.476 101325.000 8.974923e+04 + 9.600e-04 2663.554 101325.000 8.973051e+04 + 9.700e-04 2663.622 101325.000 8.971443e+04 + 9.800e-04 2663.682 101325.000 8.970074e+04 + 9.900e-04 2663.733 101325.000 8.968921e+04 + 1.000e-03 2663.777 101325.000 8.967964e+04 +To view a plot of these results, run this script with the option -plot diff --git a/Cantera/python/examples/reactors/reactor1_sim/reactor1.py b/Cantera/python/examples/reactors/reactor1_sim/reactor1.py new file mode 100644 index 000000000..b6b60fedf --- /dev/null +++ b/Cantera/python/examples/reactors/reactor1_sim/reactor1.py @@ -0,0 +1,71 @@ +""" + + Constant-pressure, adiabatic kinetics simulation. + +""" +import sys + +from Cantera import * +from Cantera.Reactor import * +from Cantera.Func import * +from Cantera import rxnpath + +gri3 = GRI30() + +gri3.set(T = 1001.0, P = OneAtm, X = 'H2:2,O2:1,N2:4') +r = Reactor(gri3) + +env = Reservoir(Air()) + +# Define a wall between the reactor and the environment, and +# make it flexible, so that the pressure in the reactor is held +# at the environment pressure. +w = Wall(r,env) +w.set(K = 1.0e6) # set expansion parameter. dV/dt = KA(P_1 - P_2) +w.set(A = 1.0) + +sim = ReactorNet([r]) +time = 0.0 +tim = zeros(100,'d') +data = zeros([100,5],'d') + +for n in range(100): + time += 1.e-5 + sim.advance(time) + tim[n] = time + data[n,0] = r.temperature() + data[n,1] = r.moleFraction('OH') + data[n,2] = r.moleFraction('H') + data[n,3] = r.moleFraction('H2') + print '%10.3e %10.3f %10.3f %14.6e' % (sim.time(), r.temperature(), + r.pressure(), r.intEnergy_mass()) + + +# plot the results if matplotlib is installed. +# see http://matplotlib.sourceforge.net to get it +args = sys.argv +if len(args) > 1 and args[1] == '-plot': + try: + from matplotlib.pylab import * + clf + subplot(2,2,1) + plot(tim,data[:,0]) + xlabel('Time (s)'); + ylabel('Temperature (K)'); + subplot(2,2,2) + plot(tim,data[:,1]) + xlabel('Time (s)'); + ylabel('OH Mole Fraction'); + subplot(2,2,3) + plot(tim,data[:,2]); + xlabel('Time (s)'); + ylabel('H Mole Fraction'); + subplot(2,2,4) + plot(tim,data[:,3]); + xlabel('Time (s)'); + ylabel('H2 Mole Fraction'); + show() + except: + pass +else: + print """To view a plot of these results, run this script with the option -plot""" diff --git a/Cantera/python/examples/reactors/reactor1_sim/runtest.in b/Cantera/python/examples/reactors/reactor1_sim/runtest.in new file mode 100755 index 000000000..4387166e4 --- /dev/null +++ b/Cantera/python/examples/reactors/reactor1_sim/runtest.in @@ -0,0 +1,44 @@ +#!/bin/sh +# +# +temp_success="1" +/bin/rm -f output_0.txt diff_csv.txt diff_out_0.txt + +########################################################################## +PYTHON_CMD=@PYTHON_CMD@ +prog=reactor1.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 +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 csv files on "`pwd` " test" +fi +