From 4a9173fa9e72f38ab6a7bcb6f0886063c1b3118f Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Tue, 24 Mar 2009 14:18:14 +0000 Subject: [PATCH] Added dir --- .../examples/reactors/mix1_sim/.cvsignore | 8 ++ .../examples/reactors/mix1_sim/Makefile.in | 15 +++ .../python/examples/reactors/mix1_sim/cleanup | 5 + .../python/examples/reactors/mix1_sim/mix1.py | 84 ++++++++++++++ .../reactors/mix1_sim/output_blessed_0.txt | 108 ++++++++++++++++++ .../examples/reactors/mix1_sim/runtest.in | 44 +++++++ 6 files changed, 264 insertions(+) create mode 100644 Cantera/python/examples/reactors/mix1_sim/.cvsignore create mode 100644 Cantera/python/examples/reactors/mix1_sim/Makefile.in create mode 100755 Cantera/python/examples/reactors/mix1_sim/cleanup create mode 100644 Cantera/python/examples/reactors/mix1_sim/mix1.py create mode 100644 Cantera/python/examples/reactors/mix1_sim/output_blessed_0.txt create mode 100755 Cantera/python/examples/reactors/mix1_sim/runtest.in diff --git a/Cantera/python/examples/reactors/mix1_sim/.cvsignore b/Cantera/python/examples/reactors/mix1_sim/.cvsignore new file mode 100644 index 000000000..6dace8b8f --- /dev/null +++ b/Cantera/python/examples/reactors/mix1_sim/.cvsignore @@ -0,0 +1,8 @@ +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/mix1_sim/Makefile.in b/Cantera/python/examples/reactors/mix1_sim/Makefile.in new file mode 100644 index 000000000..b38d56f0e --- /dev/null +++ b/Cantera/python/examples/reactors/mix1_sim/Makefile.in @@ -0,0 +1,15 @@ +#!/bin/sh + +PYTHON_CMD = @PYTHON_CMD@ + +run: + $(PYTHON_CMD) mix1.py + +test: + ./runtest +clean: + rm -f *.log *.csv *.xml + ./cleanup + +# end of file + diff --git a/Cantera/python/examples/reactors/mix1_sim/cleanup b/Cantera/python/examples/reactors/mix1_sim/cleanup new file mode 100755 index 000000000..40e1dbd9e --- /dev/null +++ b/Cantera/python/examples/reactors/mix1_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/mix1_sim/mix1.py b/Cantera/python/examples/reactors/mix1_sim/mix1.py new file mode 100644 index 000000000..f43d2df34 --- /dev/null +++ b/Cantera/python/examples/reactors/mix1_sim/mix1.py @@ -0,0 +1,84 @@ +# Mixing two streams. + +# Since reactors can have multiple inlets and outlets, they can be +# used to implement mixers, splitters, etc. In this example, air and +# methane are mixed in stoichiometric proportions. Due to the low +# temperature, no reactions occur. Note that the air stream and the +# methane stream use *different* reaction mechanisms, with different +# numbers of species and reactions. When gas flows from one reactor or +# reservoir to another one with a different reaction mechanism, +# species are matched by name. If the upstream reactor contains a +# species that is not present in the downstream reaction mechanism, it +# will be ignored. In general, reaction mechanisms for downstream +# reactors should contain all species that might be present in any +# upstream reactor. +# +#----------------------------------------------------------------------- + +from Cantera import * +from Cantera.Reactor import * + + +# Use air for stream a. Note that the Air() function does not set the +# composition correctly; thus, we need to explicitly set the +# composition to that of air. +gas_a = Air() +gas_a.set(T = 300.0, P = OneAtm, X = 'O2:0.21, N2:0.78, AR:0.01') +rho_a = gas_a.density() + + +# Use GRI-Mech 3.0 for stream b (methane) and for the mixer. If it is +# desired to have a pure mixer, with no chemistry, use instead a +# reaction mechanism for gas_b that has no reactions. +gas_b = GRI30() +gas_b.set(T = 300.0, P = OneAtm, X = 'CH4:1') +rho_b = gas_b.density() + + +# Create reservoirs for the two inlet streams and for the outlet +# stream. The upsteam reservoirs could be replaced by reactors, which +# might themselves be connected to reactors further upstream. The +# outlet reservoir could be replaced with a reactor with no outlet, if +# it is desired to integrate the composition leaving the mixer in +# time, or by an arbitrary network of downstream reactors. +res_a = Reservoir(gas_a) +res_b = Reservoir(gas_b) +downstream = Reservoir(gas_b) + + +# Create a reactor for the mixer. A reactor is required instead of a +# reservoir, since the state will change with time if the inlet mass +# flow rates change or if there is chemistry occurring. +mixer = Reactor(gas_b) + + +# create two mass flow controllers connecting the upstream reservoirs +# to the mixer, and set their mass flow rates to values corresponding +# to stoichiometric combustion. +mfc1 = MassFlowController(upstream = res_a, downstream = mixer, + mdot = rho_a*2.5/0.21) + +mfc2 = MassFlowController(upstream = res_b, downstream = mixer, + mdot = rho_b*1.0) + + +# connect the mixer to the downstream reservoir with a valve. +outlet = Valve(upstream = mixer, downstream = downstream, Kv = 1.0) + +sim = ReactorNet([mixer]) + +# Since the mixer is a reactor, we need to integrate in time to reach +# steady state. A few residence times should be enough. +t = 0.0 +for n in range(30): + tres = mixer.mass()/(mfc1.massFlowRate() + mfc2.massFlowRate()) + t += 0.5*tres + sim.advance(t) + print '%14.5g %14.5g %14.5g %14.5g %14.5g' % (t, mixer.temperature(), + mixer.enthalpy_mass(), + mixer.pressure(), + mixer.massFraction('CH4')) + +# view the state of the gas in the mixer +print mixer.contents() + diff --git a/Cantera/python/examples/reactors/mix1_sim/output_blessed_0.txt b/Cantera/python/examples/reactors/mix1_sim/output_blessed_0.txt new file mode 100644 index 000000000..28aa8a238 --- /dev/null +++ b/Cantera/python/examples/reactors/mix1_sim/output_blessed_0.txt @@ -0,0 +1,108 @@ + Adding reactor (none) +Initializing reactor network. +Reactor 0: 55 variables. + 0 sensitivity params. +Number of equations: 55 +Maximum time step: 0.0222248 + 0.022225 300.01 -3.0173e+06 1.0133e+05 0.6496 + 0.048571 300 -1.9676e+06 1.0134e+05 0.42374 + 0.078491 300 -1.2995e+06 1.0134e+05 0.28 + 0.11124 300 -8.7956e+05 1.0134e+05 0.18965 + 0.14606 300 -6.1842e+05 1.0134e+05 0.13346 + 0.1823 300 -4.5736e+05 1.0134e+05 0.09881 + 0.21948 300 -3.586e+05 1.0134e+05 0.077563 + 0.25725 300 -2.983e+05 1.0134e+05 0.064588 + 0.29541 300 -2.6156e+05 1.0134e+05 0.056684 + 0.33379 300 -2.3922e+05 1.0134e+05 0.051878 + 0.37232 300 -2.2565e+05 1.0134e+05 0.048958 + 0.41094 300 -2.1741e+05 1.0134e+05 0.047185 + 0.44961 300 -2.1241e+05 1.0134e+05 0.046109 + 0.48831 300 -2.0938e+05 1.0134e+05 0.045456 + 0.52703 300 -2.0754e+05 1.0134e+05 0.04506 + 0.56576 300 -2.0642e+05 1.0134e+05 0.04482 + 0.6045 300 -2.0574e+05 1.0134e+05 0.044674 + 0.64324 300 -2.0533e+05 1.0134e+05 0.044586 + 0.68199 300 -2.0508e+05 1.0134e+05 0.044532 + 0.72074 300 -2.0493e+05 1.0134e+05 0.0445 + 0.75949 300 -2.0484e+05 1.0134e+05 0.04448 + 0.79824 300 -2.0479e+05 1.0134e+05 0.044468 + 0.83699 300 -2.0475e+05 1.0134e+05 0.044461 + 0.87574 300 -2.0473e+05 1.0134e+05 0.044456 + 0.91449 300 -2.0472e+05 1.0134e+05 0.044454 + 0.95324 300 -2.0471e+05 1.0134e+05 0.044452 + 0.99199 300 -2.0471e+05 1.0134e+05 0.044451 + 1.0307 300 -2.047e+05 1.0134e+05 0.04445 + 1.0695 300 -2.047e+05 1.0134e+05 0.04445 + 1.1082 300 -2.047e+05 1.0134e+05 0.04445 + + gri30: + + temperature 300 K + pressure 101340 Pa + density 1.13628 kg/m^3 + mean mol. weight 27.968 amu + + 1 kg 1 kmol + ----------- ------------ + enthalpy -204701 -5.725e+06 J + internal energy -293887 -8.219e+06 J + entropy 7158.82 2.002e+05 J/K + Gibbs function -2.35235e+06 -6.579e+07 J + heat capacity c_p 1057.55 2.958e+04 J/K + heat capacity c_v 760.267 2.126e+04 J/K + + X Y Chem. Pot. / RT + ------------- ------------ ------------ + H2 -1.39247e-26 -1.00367e-27 + H 6.99708e-36 2.52168e-37 -7.348 + O 6.27033e-26 3.58701e-26 22.4934 + O2 0.193727 0.221647 -26.3149 + OH 4.03747e-28 2.45519e-28 -69.4009 + H2O -1.31058e-25 -8.44198e-26 + HO2 -7.38828e-26 -8.71936e-26 + H2O2 1.47055e-26 1.78848e-26 -142.164 + C 9.7717e-51 4.1965e-51 153.154 + CH 5.49579e-57 2.55826e-57 87.9186 + CH2 5.47598e-40 2.74639e-40 43.5033 + CH2(S) 2.8441e-41 1.42641e-41 56.2277 + CH3 -2.53586e-25 -1.36321e-25 + CH4 0.0774913 0.0444499 -54.8803 + CO -5.06019e-25 -5.06786e-25 + CO2 -1.19731e-26 -1.88405e-26 + HCO -3.21166e-46 -3.33227e-46 + CH2O -1.93659e-26 -2.07911e-26 + CH2OH 2.49106e-44 2.76416e-44 -135.602 + CH3O 6.23777e-41 6.92163e-41 -113.519 + CH3OH -3.00319e-25 -3.44067e-25 + C2H -2.05809e-60 -1.84188e-60 + C2H2 1.92734e-27 1.79433e-27 5.80845 + C2H3 -1.03178e-56 -9.97759e-57 + C2H4 1.09158e-33 1.09493e-33 -81.2284 + C2H5 2.10344e-43 2.18569e-43 -80.4182 + C2H6 1.26434e-25 1.35935e-25 -118.515 + HCCO 5.01827e-53 7.36185e-53 -78.9701 + CH2CO 6.85692e-40 1.03063e-39 -138.394 + HCCOH 1.529e-46 2.29816e-46 -102.429 + N 1.48958e-62 7.45998e-63 28.7005 + NH -1.18909e-61 -6.38363e-62 + NH2 7.00357e-65 4.01228e-65 -94.18 + NH3 6.52586e-75 3.97379e-75 -212.404 + NNH 1.55782e-45 1.6165e-45 -30.1419 + NO 1.55384e-47 1.66707e-47 -96.5388 + NO2 1.58296e-59 2.60387e-59 -150.571 + N2O 4.16806e-32 6.55922e-32 -66.0023 + HNO 1.02925e-51 1.14134e-51 -101.373 + CN -2.16929e-76 -2.01802e-76 + HCN -2.28397e-57 -2.20701e-57 + H2CN 5.97323e-58 5.98724e-58 -59.5761 + HCNN 2.00387e-57 2.93992e-57 24.6336 + HCNO 2.71425e-67 4.17552e-67 -113.895 + HOCN 2.80322e-77 4.31237e-77 -210.119 + HNCO -2.67855e-58 -4.12059e-58 + NCO 3.49931e-51 5.25711e-51 -91.2905 + N2 0.719557 0.720727 -23.3621 + AR 0.00922509 0.0131766 -23.2957 + C3H7 -4.67463e-49 -7.20191e-49 + C3H8 4.59173e-43 7.23968e-43 -171.618 + CH2CHO -3.82399e-55 -5.88546e-55 + CH3CHO -2.03875e-42 -3.21128e-42 diff --git a/Cantera/python/examples/reactors/mix1_sim/runtest.in b/Cantera/python/examples/reactors/mix1_sim/runtest.in new file mode 100755 index 000000000..e4392d987 --- /dev/null +++ b/Cantera/python/examples/reactors/mix1_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=mix1.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 +