zero dimensional reactor

564 views
Skip to first unread message

Dong Wang

unread,
Jan 9, 2015, 1:16:43 AM1/9/15
to canter...@googlegroups.com
Hi Everyone, 

I'm using cantera to evolve a system at constant temperature and pressure. There is a strange behavior that is freaking me out. So here is my code. 

import sys
import numpy as np
import cantera as ct

# initilize the phase
ct.add_directory('/Users/wangdong/Documents/2014_summer/cantera_input_files')
gas1=ct.Solution('test_1.cti')
gas1.TPX = 2200.0,100.0e5,"H2:1.0, He:0.17, CH4:5.38e-4, O2:4.90e-4, N2:6.76e-5"

# chemcial evolution initilzation
r1 = ct.IdealGasConstPressureReactor(contents = gas1, energy = 'off')
network1=ct.ReactorNet([r1])
data = np.zeros((50,5))
t=1.0e-10

for i in range(50):
    t=t*2.0
    network1.advance(t)
    data[i,0]=t
    print t 
    data[i,1:] = r1.thermo['H','C2H6','OH','NH3'].X

There is an error: 
2e-10
4e-10
8e-10
1.6e-09
3.2e-09
6.4e-09
1.28e-08
2.56e-08
5.12e-08
1.024e-07
2.048e-07
4.096e-07
8.192e-07
1.6384e-06
3.2768e-06
6.5536e-06
Traceback (most recent call last):
  File "evolution_0D_not_working.py", line 22, in <module>
    network1.advance(t)
  File "cantera/reactor.pyx", line 760, in cantera._cantera.ReactorNet.advance (interfaces/cython/cantera/_cantera.cpp:40599)
RuntimeError: 
***********************************************************************
CanteraError thrown by CVodesIntegrator:
CVodes error encountered. Error code: -1
At t = 1.05537e-05, mxstep steps taken before reaching tout.

Components with largest weighted error estimates:
26: 1.12675e-08
28: 2.41636e-09
35: 1.3409e-10
34: 9.25656e-11
71: 3.57017e-11
25: -3.29988e-11
13: -2.79367e-11
23: 2.31985e-11
7: -2.10332e-11
12: -2.02191e-11
***********************************************************************

However, if I reinitialize the reactor and reactorNet every time, like this: 
for i in range(50):
    t=t*2.0
    gas1.TPX = 2200.0,100.0e5,"H2:1.0, He:0.17, CH4:5.38e-4, O2:4.90e-4, N2:6.76e-5"
    r1.syncState()
    network1.reinitialize()
    network1.set_initial_time(0.0)
    network1.advance(t)
    data[i,0]=t
    print t
    data[i,1:] = r1.thermo['H','C2H6','OH','NH3'].X

There is no error and the code runs pretty well. So can anyone tell me what is wrong with the first implementation? Thank you very much! 

best,
-Dong

Ray Speth

unread,
Jan 9, 2015, 1:34:39 PM1/9/15
to canter...@googlegroups.com
Hi Dong,

This is caused by the automatic selection of the maximum internal time step which is done the first time you call 'advance' based on the time that you pass to advance. If you know that you are going to be asking for output after longer intervals, you may want to explicitly set a larger maximum step size by calling ReactorNet.set_max_time_step.

Regards,
Ray 

Dong Wang

unread,
Jan 10, 2015, 6:10:21 AM1/10/15
to canter...@googlegroups.com
Thanks, Ray, it works! 
-Dong
Reply all
Reply to author
Forward
0 new messages