Cvode error RCM

281 views
Skip to first unread message

davè chavwuko

unread,
Oct 17, 2013, 12:57:19 PM10/17/13
to canter...@googlegroups.com
Hi everyone 

Please can any one tell me how to handle this integrator error posted below. I am simulating  the compression period of a rapid compression machine. My code seems technically okay but when I run it,  it seems my volume gets so small and a Cvode error emerges. I have increased my tolerances but it does'nt solve it. If I use the dimensions in cm, the code runs through but the volume becomes excessively large and compression is lost. Thanks 


 stroke = 25.4e-2    # 25.4 cm
cl = 1.615e-2      # 1.615 cm
dia = 5.0e-2     #5.0cm
vol_add = 45.0e-6     # 4.5e1 ms

vol_start = (math.pi/4.0 *(dia**2.0)*(stroke+cl)) + vadd


************************************************
                Cantera Error!                  
************************************************


Procedure: CVodesIntegrator
Error:    CVodes error encountered. Error code: -3

Nick Curtis

unread,
Oct 17, 2013, 9:38:14 PM10/17/13
to canter...@googlegroups.com
From the CVodes documentation code #3:

CV ERR FAILURE

Error test failures occurred too many times during one internal time step or minimum step size was reached

Basically I find the best strategy is to put a try/catch around your integration call, if you reach an error just recall the integrator.  You may get the "Error test failure" error a couple times, but it'll complete the integration step after a few tries

Also, if you're not using version 2.1.x, apparently this has a number of upgrades to the numerics of the Reactor class which should help with things like this

Nick

davè chavwuko

unread,
Oct 18, 2013, 7:04:41 AM10/18/13
to canter...@googlegroups.com
Hi Nick 
Thanks for the response. I had tried to use the try/catch stuff but I am not sure I am doing it right. Please, if you dont mind can you just iilustrate it with the small code i have added to my post. Thanks

from Cantera import *
from Cantera.Reactor import *
from Cantera.Func import *

gas 
= GRI30()
gas
.set(T=600.0, P=0.2*OneAtm, X='CH4:1.1, O2:2, N2:7.52')

dia 
= 0.1
stroke 
= 0.18
cl 
= 0.02
= math.pi/4 *(dia**2)
vcom 
= 0.001
vmax 
= 3

vol_start 
= (math.pi/4 *(dia**2)*(stroke+cl)) + vcom
taccel = 5e-3
t_end 
= 20e-3

r1 
= Reactor(gas, volume=vol_start)
env 
= Reservoir(Air())

= Wall(left = env, right = r1)

sim 
= ReactorNet([r1])


f_accel 
= Polynomial([0.0, vmax / taccel]) # f(t) = vmax * t / taccel
w
.setVelocity(f_accel)

= 0.0
while t <= taccel:
    t 
+= 1.0e-6
    sim
.advance(t)
    
print sim.time(), r1.temperature(), r1.volume()

sim
.setInitialTime(taccel)
f_const 
= Polynomial([vmax])
w
.setVelocity(f_const)
while t < t_end:
    t 
+= 1.0e-5
    sim
.advance(t)
    
print sim.time(), r1.temperature(), r1.volume()

Nick Curtis

unread,
Oct 19, 2013, 10:28:39 AM10/19/13
to canter...@googlegroups.com
from Cantera import *
from Cantera.Reactor import *
from Cantera.Func import *

gas 
= GRI30()
gas
.set(T=600.0, P=0.2*OneAtm, X='CH4:1.1, O2:2, N2:7.52')

dia 
= 0.1
stroke 
= 0.18
cl 
= 0.02
= math.pi/4 *(dia**2)
vcom 
= 0.001
vmax 
= 3

vol_start 
= (math.pi/4 *(dia**2)*(stroke+cl)) + vcom
taccel = 5e-3
t_end 
= 20e-3

r1 
= Reactor(gas, volume=vol_start)
env 
= Reservoir(Air())

= Wall(left = env, right = r1)

sim 
= ReactorNet([r1])


f_accel 
= Polynomial([0.0, vmax / taccel]) # f(t) = vmax * t / taccel
w
.setVelocity(f_accel)

= 0.0
while t <= taccel:
    try
        sim
.advance(t + 1e-06)
        t += 1.0e-6
        print sim.time(), r1.temperature(), r1.volume()
    catch err
        %nothing to do
    end
sim
.setInitialTime(taccel)

f_const 
= Polynomial([vmax])
w
.setVelocity(f_const)
while t < t_end
:
    try

        sim
.advance(t + 1e-05)
       
+= 1.0e-5
        print sim.time(), r1.temperature(), r1.volume()
    catch err
        %nothing to do
    end

So functionally how this works is as follows:
1.  Try to advance to the next timestep.
     if error, retry
2.  Once next time step has been reached, add delta_t to t, and output

davè chavwuko

unread,
Oct 19, 2013, 1:06:20 PM10/19/13
to canter...@googlegroups.com
Hi Nick
Thanks for the contribution. Really sorry to bother you again. I got the explanation of how it works but t not the  syntax . I am I suppose to use "catch err" directly in my code like you have in yours  or I am missing how to implement  it. Please I am a bit new to python. if you dont mind, please make it a bit clearer because I tried it out but got an invalid synatax error in return. Thanks

Dave  

Nick Curtis

unread,
Oct 21, 2013, 9:48:15 AM10/21/13
to canter...@googlegroups.com
Ah, crap, thought you were doing Matlab for whatever reason.
In python it would be

 try:
code here
except:
#nothin to do

davè chavwuko

unread,
Oct 23, 2013, 6:52:51 AM10/23/13
to canter...@googlegroups.com
Nick,

Thanks. I am okay now.
Reply all
Reply to author
Forward
0 new messages