Reactors with walls and heat transfer#

Two reactors connected with a piston, with heat loss to the environment

This script simulates the following situation. A closed cylinder with volume 2 m^3 is divided into two equal parts by a massless piston that moves with speed proportional to the pressure difference between the two sides. It is initially held in place in the middle. One side is filled with 1000 K argon at 20 atm, and the other with a combustible 500 K methane/air mixture at 0.1 atm (\(\phi = 1.1\)). At \(t = 0\), the piston is released and begins to move due to the large pressure difference, compressing and heating the methane/air mixture, which eventually explodes. At the same time, the argon cools as it expands. The piston allows heat transfer between the reactors and some heat is lost through the outer cylinder walls to the environment.

Note that this simulation, being zero-dimensional, takes no account of shock wave propagation. It is somewhat artificial, but nevertheless instructive.

Requires: cantera >= 2.5.0, matplotlib >= 2.0

Tags: combustion reactor network plotting

reactor2
finished setup, begin solution...
0 0.0004 500.0
1 0.0008 506.90424519562805
2 0.0012000000000000001 513.6996289344828
3 0.0016 520.4177565777707
4 0.002 527.0847257436435
5 0.0024000000000000002 533.7226597018097
6 0.0028000000000000004 540.3507678488163
7 0.0032000000000000006 546.9860943041527
8 0.0036000000000000008 553.6440683989028
9 0.004000000000000001 560.3389171973483
10 0.004400000000000001 567.0839831588196
11 0.004800000000000001 573.8919751737893
12 0.0052000000000000015 580.7751699610216
13 0.005600000000000002 587.7455793825313
14 0.006000000000000002 594.8150917356442
15 0.006400000000000002 601.9955937316422
16 0.006800000000000002 609.2990784862708
17 0.007200000000000002 616.7377428859597
18 0.007600000000000003 624.3240765945801
19 0.008000000000000002 632.0709450732944
20 0.008400000000000001 639.9916683639017
21 0.0088 648.100094633534
22 0.0092 656.410669804042
23 0.0096 664.9385030638515
24 0.009999999999999998 673.6994252326798
25 0.010399999999999998 682.7100400758626
26 0.010799999999999997 691.9877648833748
27 0.011199999999999996 701.5508520732766
28 0.011599999999999996 711.4183914613903
29 0.011999999999999995 721.6102820668305
30 0.012399999999999994 732.147158602927
31 0.012799999999999994 743.0502595173352
32 0.013199999999999993 754.3412143398891
33 0.013599999999999992 766.0417230051311
34 0.013999999999999992 778.1730874478769
35 0.014399999999999991 790.7555524603905
36 0.01479999999999999 803.807394536763
37 0.01519999999999999 817.3436872943021
38 0.015599999999999989 831.3746584644714
39 0.01599999999999999 845.9035474547672
40 0.01639999999999999 860.923871361137
41 0.016799999999999992 876.4160358539526
42 0.017199999999999993 892.3432831123088
43 0.017599999999999994 908.6470720702195
44 0.017999999999999995 925.2422423350381
45 0.018399999999999996 942.012514299255
46 0.018799999999999997 958.8073453689059
47 0.0192 975.4414577878887
48 0.0196 991.698640375053
49 0.02 1007.3419354907595
50 0.0204 1022.1320630654427
51 0.020800000000000003 1035.8389779419465
52 0.021200000000000004 1048.26853416929
53 0.021600000000000005 1059.283492788295
54 0.022000000000000006 1068.8161546269055
55 0.022400000000000007 1076.870547630061
56 0.022800000000000008 1083.5141250866777
57 0.02320000000000001 1088.8622193135313
58 0.02360000000000001 1093.0599236022008
59 0.02400000000000001 1096.265075276298
60 0.024400000000000012 1098.6344637492796
61 0.024800000000000013 1100.3142114146237
62 0.025200000000000014 1101.4342498043754
63 0.025600000000000015 1102.1061086642778
64 0.026000000000000016 1102.4229903314315
65 0.026400000000000017 1102.4612018469877
66 0.026800000000000018 1102.282243144616
67 0.02720000000000002 1101.9350847840524
68 0.02760000000000002 1101.458359583
69 0.02800000000000002 1100.882327932714
70 0.028400000000000022 1100.2305626892187
71 0.028800000000000023 1099.5213506387854
72 0.029200000000000025 1098.7688332900834
73 0.029600000000000026 1097.9839212490983
74 0.030000000000000027 1097.1750174613517
75 0.030400000000000028 1096.3485891759296
76 0.03080000000000003 1095.5096062953837
77 0.03120000000000003 1094.6618934664946
78 0.03160000000000003 1093.8083948266294
79 0.03200000000000003 1092.9513772176547
80 0.032400000000000026 1092.0925917163108
81 0.032800000000000024 1091.233394330887
82 0.03320000000000002 1090.3748403658997
83 0.03360000000000002 1089.5177559645965
84 0.034000000000000016 1088.662793349377
85 0.034400000000000014 1087.8104730187772
86 0.03480000000000001 1086.9612161563882
87 0.03520000000000001 1086.1153694714003
88 0.03560000000000001 1085.273224233643
89 0.036000000000000004 1084.4350309857302
90 0.0364 1083.601011049741
91 0.0368 1082.7713649288448
92 0.0372 1081.9462792320005
93 0.037599999999999995 1081.1259321087493
94 0.03799999999999999 1080.3104974500163
95 0.03839999999999999 1079.500148244557
96 0.03879999999999999 1078.6950593621266
97 0.039199999999999985 1077.8954099069367
98 0.03959999999999998 1077.1013851841005
99 0.03999999999999998 1076.3131784770935
100 0.04039999999999998 1075.5309926807795
101 0.040799999999999975 1074.7550418389417
102 0.04119999999999997 1073.9855526594965
103 0.04159999999999997 1073.2227660450199
104 0.04199999999999997 1072.4669386862943
105 0.042399999999999965 1071.7183447164743
106 0.04279999999999996 1070.9772775165334
107 0.04319999999999996 1070.2440516540103
108 0.04359999999999996 1069.5190050309373
109 0.043999999999999956 1068.8025012415417
110 0.04439999999999995 1068.0949322019435
111 0.04479999999999995 1067.396721079331
112 0.04519999999999995 1066.7083255971368
113 0.045599999999999946 1066.0302417297964
114 0.045999999999999944 1065.3630079499112
115 0.04639999999999994 1064.707209955327
116 0.04679999999999994 1064.0634861112933
117 0.047199999999999936 1063.4325336658999
118 0.047599999999999934 1062.8151158717774
119 0.04799999999999993 1062.2120701693668
120 0.04839999999999993 1061.6243176401135
121 0.04879999999999993 1061.052874023075
122 0.049199999999999924 1060.4988624644584
123 0.04959999999999992 1059.963528465117
124 0.04999999999999992 1059.4482574441906
125 0.05039999999999992 1058.9545954586722
126 0.050799999999999915 1058.4842737872088
127 0.05119999999999991 1058.039238248448
128 0.05159999999999991 1057.621684381245
129 0.05199999999999991 1057.234099892561
130 0.052399999999999905 1056.8793162329594
131 0.0527999999999999 1056.5605716901182
132 0.0531999999999999 1056.2815891536036
133 0.0535999999999999 1056.0466727581013
134 0.053999999999999895 1055.8608290468726
135 0.05439999999999989 1055.7299202846339
136 0.05479999999999989 1055.6608605405831
137 0.05519999999999989 1055.6618692676693
138 0.055599999999999886 1055.7428033318058
139 0.05599999999999988 1055.915597876334
140 0.05639999999999988 1056.1948604943063
141 0.05679999999999988 1056.5986858261415
142 0.057199999999999876 1057.149793772775
143 0.057599999999999874 1057.8771548212374
144 0.05799999999999987 1058.8183685314257
145 0.05839999999999987 1060.0232448233598
146 0.058799999999999866 1061.5593786427671
147 0.059199999999999864 1063.5211763872792
148 0.05959999999999986 1066.0451814617727
149 0.05999999999999986 1069.3376597375795
150 0.06039999999999986 1073.7280536330527
151 0.060799999999999854 1079.7830428129275
152 0.06119999999999985 1088.5842446849256
153 0.06159999999999985 1102.5488162741733
154 0.06199999999999985 1128.768857089804
155 0.062399999999999844 1206.0932436845274
156 0.06279999999999984 2864.3789407245145
157 0.06319999999999984 2781.3469143898387
158 0.06359999999999984 2733.1192416714143
159 0.06399999999999983 2699.441408028897
160 0.06439999999999983 2674.0981597630166
161 0.06479999999999983 2654.1514804276603
162 0.06519999999999983 2637.961248915433
163 0.06559999999999983 2624.516800166751
164 0.06599999999999982 2613.151492637569
165 0.06639999999999982 2603.4029290929752
166 0.06679999999999982 2594.937704194201
167 0.06719999999999982 2587.507919754854
168 0.06759999999999981 2580.9245940775195
169 0.06799999999999981 2575.0406960762302
170 0.06839999999999981 2569.739851222434
171 0.0687999999999998 2564.928619979552
172 0.0691999999999998 2560.531058818281
173 0.0695999999999998 2556.4848025358338
174 0.0699999999999998 2552.738175481502
175 0.0703999999999998 2549.248032067459
176 0.0707999999999998 2545.9781092968215
177 0.07119999999999979 2542.897755046549
178 0.07159999999999979 2539.9809299966682
179 0.07199999999999979 2537.20541832851
180 0.07239999999999978 2534.5521952686936
181 0.07279999999999978 2532.0049144001914
182 0.07319999999999978 2529.549491839324
183 0.07359999999999978 2527.173761382109
184 0.07399999999999977 2524.867193436239
185 0.07439999999999977 2522.6206557286923
186 0.07479999999999977 2520.426212693925
187 0.07519999999999977 2518.2769625722717
188 0.07559999999999976 2516.1668930783844
189 0.07599999999999976 2514.0907620584744
190 0.07639999999999976 2512.043993715852
191 0.07679999999999976 2510.022591526701
192 0.07719999999999975 2508.023061752519
193 0.07759999999999975 2506.0423487760045
194 0.07799999999999975 2504.0777785321247
195 0.07839999999999975 2502.1270101170917
196 0.07879999999999975 2500.187993602602
197 0.07919999999999974 2498.2589327171804
198 0.07959999999999974 2496.338254303093
199 0.07999999999999974 2494.424579423909
200 0.08039999999999974 2492.5166990131092
201 0.08079999999999973 2490.613553624268
202 0.08119999999999973 2488.7142147378518
203 0.08159999999999973 2486.8178683858555
204 0.08199999999999973 2484.9238012938445
205 0.08239999999999972 2483.03138845045
206 0.08279999999999972 2481.1400822765563
207 0.08319999999999972 2479.249403311084
208 0.08359999999999972 2477.3589316587327
209 0.08399999999999971 2475.468299892038
210 0.08439999999999971 2473.5771867421777
211 0.08479999999999971 2471.685311405567
212 0.0851999999999997 2469.7924285971194
213 0.0855999999999997 2467.898324318425
214 0.0859999999999997 2466.0028120559837
215 0.0863999999999997 2464.1057294979773
216 0.0867999999999997 2462.2069357013625
217 0.0871999999999997 2460.3063083648503
218 0.08759999999999969 2458.403741647826
219 0.08799999999999969 2456.4991442030355
220 0.08839999999999969 2454.592437516264
221 0.08879999999999968 2452.6835545090357
222 0.08919999999999968 2450.772437948036
223 0.08959999999999968 2448.8590393336804
224 0.08999999999999968 2446.9433179899042
225 0.09039999999999968 2445.0252398940174
226 0.09079999999999967 2443.1047770960154
227 0.09119999999999967 2441.181907669705
228 0.09159999999999967 2439.2566143469494
229 0.09199999999999967 2437.328882893348
230 0.09239999999999966 2435.398703509647
231 0.09279999999999966 2433.4660711556185
232 0.09319999999999966 2431.5309815772953
233 0.09359999999999966 2429.5934348451797
234 0.09399999999999965 2427.653432436895
235 0.09439999999999965 2425.7109790286395
236 0.09479999999999965 2423.766080198291
237 0.09519999999999965 2421.818743877022
238 0.09559999999999964 2419.868979438025
239 0.09599999999999964 2417.9167976879944
240 0.09639999999999964 2415.9622108757953
241 0.09679999999999964 2414.005232288032
242 0.09719999999999963 2412.0458765981534
243 0.09759999999999963 2410.0841592292604
244 0.09799999999999963 2408.1200967297705
245 0.09839999999999963 2406.153706475359
246 0.09879999999999962 2404.1850066680913
247 0.09919999999999962 2402.2140162710416
248 0.09959999999999962 2400.2407549737877
249 0.09999999999999962 2398.2652431219994
250 0.10039999999999961 2396.287501742228
251 0.10079999999999961 2394.3075524501082
252 0.10119999999999961 2392.325417432341
253 0.10159999999999961 2390.3411194383075
254 0.1019999999999996 2388.3546816880516
255 0.1023999999999996 2386.3661279139847
256 0.1027999999999996 2384.3754823430254
257 0.1031999999999996 2382.382769668043
258 0.1035999999999996 2380.3880149817924
259 0.10399999999999959 2378.391243776016
260 0.10439999999999959 2376.392481942961
261 0.10479999999999959 2374.391755793438
262 0.10519999999999959 2372.3890920286904
263 0.10559999999999958 2370.384517683917
264 0.10599999999999958 2368.3780601075277
265 0.10639999999999958 2366.3697469447743
266 0.10679999999999958 2364.359606170148
267 0.10719999999999957 2362.347666095318
268 0.10759999999999957 2360.3339553949836
269 0.10799999999999957 2358.3185031065573
270 0.10839999999999957 2356.3013381697942
271 0.10879999999999956 2354.282489808665
272 0.10919999999999956 2352.261987683602
273 0.10959999999999956 2350.239861723587
274 0.10999999999999956 2348.216142031608
275 0.11039999999999955 2346.1908589010222
276 0.11079999999999955 2344.164042781796
277 0.11119999999999955 2342.135724321046
278 0.11159999999999955 2340.1059343638594
279 0.11199999999999954 2338.074703889638
280 0.11239999999999954 2336.0420640259704
281 0.11279999999999954 2334.0080460798645
282 0.11319999999999954 2331.9726814559126
283 0.11359999999999953 2329.936001637097
284 0.11399999999999953 2327.8980382905393
285 0.11439999999999953 2325.858823179082
286 0.11479999999999953 2323.818388027757
287 0.11519999999999953 2321.77676470799
288 0.11559999999999952 2319.7339853313224
289 0.11599999999999952 2317.690081860994
290 0.11639999999999952 2315.645086143049
291 0.11679999999999952 2313.5990304429315
292 0.11719999999999951 2311.5519469526644
293 0.11759999999999951 2309.5038673956183
294 0.11799999999999951 2307.454824117844
295 0.1183999999999995 2305.404849374827
296 0.1187999999999995 2303.3539747730983
297 0.1191999999999995 2301.3022327113886
298 0.1195999999999995 2299.249655514061
299 0.1199999999999995 2297.196274524631
Output written to file piston.csv
Directory: /Users/speth/src/cantera/build/doc/samples/python/reactors

import sys
import os
import csv

import cantera as ct

# First create each gas needed, and a reactor or reservoir for each one.

# create an argon gas object and set its state
ar = ct.Solution('air.yaml')
ar.TPX = 1000.0, 20.0 * ct.one_atm, "AR:1"

# create a reactor to represent the side of the cylinder filled with argon
r1 = ct.IdealGasReactor(ar)

# create a reservoir for the environment, and fill it with air.
env = ct.Reservoir(ct.Solution('air.yaml'))

# use GRI-Mech 3.0 for the methane/air mixture, and set its initial state
gas = ct.Solution('gri30.yaml')
gas.TP = 500.0, 0.2 * ct.one_atm
gas.set_equivalence_ratio(1.1, 'CH4:1.0', 'O2:2, N2:7.52')

# create a reactor for the methane/air side
r2 = ct.IdealGasReactor(gas)

# Now couple the reactors by defining common walls that may move (a piston) or
# conduct heat

# add a flexible wall (a piston) between r2 and r1
w = ct.Wall(r2, r1, A=1.0, K=0.5e-4, U=100.0)

# heat loss to the environment. Heat loss always occur through walls, so we
# create a wall separating r2 from the environment, give it a non-zero area,
# and specify the overall heat transfer coefficient through the wall.
w2 = ct.Wall(r2, env, A=1.0, U=500.0)

sim = ct.ReactorNet([r1, r2])

# Now the problem is set up, and we're ready to solve it.
print('finished setup, begin solution...')

time = 0.0
n_steps = 300
output_data = []
states1 = ct.SolutionArray(ar, extra=['t', 'V'])
states2 = ct.SolutionArray(gas, extra=['t', 'V'])

for n in range(n_steps):
    time += 4.e-4
    print(n, time, r2.T)
    sim.advance(time)
    states1.append(r1.thermo.state, t=time, V=r1.volume)
    states2.append(r2.thermo.state, t=time, V=r2.volume)
    output_data.append(
        [time, r1.thermo.T, r1.thermo.P, r1.volume, r2.thermo.T,
         r2.thermo.P, r2.volume]
    )

with open('piston.csv', 'w', newline="") as outfile:
    csvfile = csv.writer(outfile)
    csvfile.writerow(
        ['time (s)', 'T1 (K)', 'P1 (Bar)', 'V1 (m3)', 'T2 (K)',
         'P2 (Bar)', 'V2 (m3)']
    )
    csvfile.writerows(output_data)

print('Output written to file piston.csv')
print('Directory: '+os.getcwd())

if '--plot' in sys.argv:
    import matplotlib.pyplot as plt
    plt.clf()
    plt.subplot(2, 2, 1)
    h = plt.plot(states1.t, states1.T, 'g-', states2.t, states2.T, 'b-')
    # plt.legend(['Reactor 1','Reactor 2'], 2)
    plt.xlabel('Time (s)')
    plt.ylabel('Temperature (K)')

    plt.subplot(2, 2, 2)
    plt.plot(states1.t, states1.P / 1e5, 'g-', states2.t, states2.P / 1e5, 'b-')
    # plt.legend(['Reactor 1','Reactor 2'], 2)
    plt.xlabel('Time (s)')
    plt.ylabel('Pressure (Bar)')

    plt.subplot(2, 2, 3)
    plt.plot(states1.t, states1.V, 'g-', states2.t, states2.V, 'b-')
    # plt.legend(['Reactor 1','Reactor 2'], 2)
    plt.xlabel('Time (s)')
    plt.ylabel('Volume (m$^3$)')

    plt.figlegend(h, ['Reactor 1', 'Reactor 2'], loc='lower right')
    plt.tight_layout()
    plt.show()
else:
    print("To view a plot of these results, run this script with the option --plot")

Total running time of the script: (0 minutes 0.335 seconds)

Gallery generated by Sphinx-Gallery