CanteraError thrown by OneDim::timeStep:

1,035 views
Skip to first unread message

Maina George

unread,
Nov 26, 2015, 4:34:29 AM11/26/15
to Cantera Users' Group

am getting the above error when i run the code
import sys, argparse, pickle
import exceptions
import csv
import numpy as np
import matplotlib as plt
import cantera as ct
from matplotlib import rc
import matplotlib.pyplot as plt
from collections import deque
from time import clock
t0=clock()

P1 = ct.one_atm
T1 = 330
initial_grid = [0.0, 0.001, 0.5]
tol_ss = [1.0e-5, 1.0e-9]
tol_ts = [1.0e-5, 1.0e-9]
loglevel = 1
refine_grid = False
phi = [(0.+x*0.05) for x in range(18,30)]
airmoles = 3
gas = ct.Solution('gri30.xml','gri30_mix')
#gas()

dry = open("dry.txt","wt") #file for storing dry combustion

for i in range(0,len(phi)): #molefractions definitions #assume 1 mole air
    nCH4 = phi[i]* airmoles/9.54
    nO2 = (1-nCH4)*0.209
    nN2 = (1-nCH4)*0.791
    q= 'CH4:'+str(nCH4)+' O2:'+str(nO2)+' N2:'+str(nN2)+'';
    gas.TPX = T1, P1, q
    #print 'nCH4=%f nO2=%f nN2=%f'  %(nCH4, nO2, nN2)
    print gas['CH4','O2','N2','H2O'].Y
    phidry = phi[i] #pass the value of phi
    f=ct.FreeFlame(gas, initial_grid)
    f.flame.set_steady_tolerances(default=tol_ss)
    f.flame.set_transient_tolerances(default=tol_ts)
    f.inlet.T = T1
    f.inlet.X = q
    f.show_solution
    f.energy_enabled = False
    print '================================'
    print 'the energy equation is turned off'
    print '================================'
    f.set_max_jac_age(5,10)
    f.set_time_step(5.0e-6,[2,5,10,20,50,80,120,150])
    f.solve(loglevel=loglevel, refine_grid=False)
   
    f.energy_enabled = True
    print '================================'
    print 'the energy equation is turned on'
    print '================================'
    f.set_refine_criteria(ratio = 3.0, slope = 1.0, curve = 0.8, prune = 0.05)
    f.solve(loglevel=loglevel, refine_grid=False)
    f.save('freeflame_1_'+str(phi[i])+'_.xml')
    f.show_solution 
   
    z= f.flame.grid
    T=f.T
    V=f.V
    u=f.u
    Sh = 0.0
    Ufs0 = u[0]   
          
    f.show_stats 
    print '========================================================='
    #print 'for mfH2O=', mfH2O
    print 'and phi=',phidry
    print 'flamespeed w/o H2O = ',Ufs0,'m/s'
    dry.write("%.4f %.4f \n" %(phidry,Ufs0))
    #steam.write("%.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\n" %(mfCH4,mfO2,mfN2,mfH2O,phidry,Sh,nfCH4,nfO2,nfN2,nfH2O,Ufs0,Ufs0/Ufs0))
   
dry.close()

maybe someone can help me correct it. thanks
also if anyone could point me where i can find experimental data on methane air premixed flames i would be grateful

am using cantera 2.1.1 python 2.7 windows 7 64 bits




Traceback (most recent call last):
  File "c:\Users\Ja\Desktop\tutorial\mole numbers\molefractions.py", line 55, in <module>
    f.solve(loglevel=loglevel, refine_grid=False)
  File "C:\Python27\Lib\site-packages\cantera\_cantera.pyd", line 662, in cantera._cantera.Sim1D.solve (cantera/_cantera.cpp:43710)
    I‹U I‹ÍÿR0A‹Äë A‹ÄL \$`I‹[0I‹s8 (t$P (|$@I‹ãA_A^A]A\_ÃÌÌÌÌÌÌÌÌÌÌÌÌH‰\$ H‰l$ WHƒì H‹A 3ÛH‹ùL‹€ \000\000\000M
Àt H‹
)R\000AÿÐH‹èë,L‹@@M
Àt H‹ )R\000HƒÂ AÿÐH‹èë H‹ ò(R\000ÿ ll=\000H‹èH‰t$0L‰d$8H
íu H‹=óŸO\000A¼ 0\000\000é, \000\000H‹G L‹€ \000\000\000M
Àt H‹ I,R\000H‹ÏAÿÐH‹ðë2L‹@@M
Àt H‹ .,R\000H‹ÏHƒÂ AÿÐH‹ðë H‹ ,R\000H‹Ïÿ ÷k=\000H‹ðH
öu H‹=ˆŸO\000A¼ 0\000\000é
\000\000\000H‹G L‹€ \000\000\000M
Àt H‹ ®#R\000H‹ÏAÿÐH‹Øë2L‹@@M
Àt H‹ “#R\000H‹ÏHƒÂ AÿÐH‹Øë H‹ }#R\000H‹Ïÿ Œk=\000H‹ØH
Ûu H‹=
ŸO\000A¼ 0\000\000ë
¹ \000\000\000ÿ ’h=\000H
ÀueH‹=þžO\000A¼ 0\000\000HƒE\000ÿu
Exception:
***********************************************************************
CanteraError thrown by OneDim::timeStep:
Time integration failed.

Ray Speth

unread,
Dec 1, 2015, 2:10:45 PM12/1/15
to Cantera Users' Group
Hi,

Fixing issues where "time integration failed" errors occurred is unfortunately a bit of a trial-and-error process. Usually, your best bet is to try adjusting one of a few different things:

(1) Tolerances - your absolute tolerances are possibly too loose. In most cases, An absolute tolerance on the order of 1e-13, as used in some of the examples, may be better.
(2) Initial grid - your initial grid has only 3 points, which are spaced very un-evenly. I would suggest an evenly spaced grid with a few more points and a domain that's closer to the actual flame thickness, i.e. a few centimeters instead of half a meter.

You may also have better luck if you can get a solution for the first equivalence ratio and then use that as the initial guess for subsequent simulations (i.e., only create the FreeFlame object once, rather than starting over for each equivalence ratio).

Regards,
Ray

Maina George

unread,
Dec 3, 2015, 9:39:12 AM12/3/15
to Cantera Users' Group
hi Ray
i have changed it to suit just one equivalence ratio, and now i get a new error!
code


from time import clock
import numpy as np
import cantera as ct
t0=clock()
initial_grid = [0.0, 0.001, 0.02, 0.03, 0.04, 0.05] #grid chosen as a pipe of length 50 cm
tol_ss = [1.0e-13, 1.0e-9]  #abs and rel tolerances for steady state problem
tol_ts = [1.0e-13, 1.0e-9]  #abs and rel tie tolernces for time step function
loglevel = 1  #amount of diagonistic output
refine_grid = False  #true to turn it on
T1 = 300.0
P1 = ct.one_atm
rxn = 'gri30_highT.cti'        #reaction mechanism
mix = 'gri30_mix'  # produces an ideal gas object

################ create the gas object ########################
gas = ct.Solution(rxn,mix)

WMF =  0.0 #[(y*0.01) for y in range(1,14)] #water mass fraction 
phi =  0.55  #[(0.+x*0.05) for x in range(18,27)]

nCH4= phi/(phi+(0.791/0.209+1)*2)   #mole fraction of methane definition
nO2 = (1-nCH4)*0.209   #mole fraction of air then becomes (1-nCH4)
nN2 = (1-nCH4)*0.791   #mole fractions of N O according to 79.1 and 20.9 % by mole in air
q ='CH4:%f,O2:%f,N2:%f' %(nCH4, nO2, nN2)

gas.TPX = T1, P1, q
f=ct.FreeFlame(gas,initial_grid)
f.flame.set_steady_tolerances(default=tol_ss)   #set tolerances
f.flame.set_transient_tolerances(default=tol_ts)
f.inlet.T = T1  # inlet Temperature set
f.inlet.X = q   # inlet composition by mole
f.show_solution
f.energy_enabled = False   #disable energy

print '================================'
print 'the energy equation is turned off'
print '================================'
f.set_max_jac_age(50,50)

f.set_time_step(5.0e-6,[2,5,10,20,50,80,120,150])
f.solve(loglevel=loglevel, refine_grid=False)
   
f.energy_enabled = True  #enable energy
print '================================'
print 'the energy equation is turned on'
print '================================'
f.set_refine_criteria(ratio = 3.0, slope = 1.0, curve = 0.8, prune = 0.05)
f.solve(loglevel=loglevel, refine_grid=False)
f.show_solution
u=f.u
Ufs0= u[0]
f.show_stats
print 'flamespeed w/o H2O = %f' % Ufs0,'m/s'
#print 'old mfCH4 = %f ' % gas["CH4"].Y
#print q
#print 'old nfCH4 = %f ' % nCH4

massfrac = gas["CH4","O2","N2"].Y
mfH2O = WMF
mfCH4 = massfrac[0]*(1-mfH2O)
mfO2 =  massfrac[1]*(1-mfH2O)
mfN2 =  massfrac[2]*(1-mfH2O)
#gas()
q2 ='CH4:%f,O2:%f,N2:%f,H2O:%f' %(mfCH4, mfO2, mfN2,mfH2O)
#print q2
#print 'new mfCH4 = %f new mfO2=%f new mfN2=%f' % (mfCH4 ,mfO2,mfN2)
#print 'total moles %f' %(mfCH4+mfO2+mfN2+mfH2O)
gas.TPY = T1, P1, q2
#gas()  gas defined by mass fractions
molefrac = gas["CH4","O2","N2","H2O"].X
#print molefrac
f2=ct.FreeFlame(gas,initial_grid)
f2.flame.set_steady_tolerances(default=tol_ss)   #set tolerances
f2.flame.set_transient_tolerances(default=tol_ts)
f2.inlet.T = T1  # inlet Temperature set
f2.inlet.X = q   # inlet composition by mole
f2.show_solution
f2.energy_enabled = False   #disable energy

print '================================'
print 'the energy equation is turned off'
print '================================'
f2.set_max_jac_age(50,50)
f2.set_time_step(5.0e-6,[2,5,10,20,50,80,120,150])
f2.solve(loglevel=loglevel, refine_grid=False)
   
f2.energy_enabled = True  #enable energy
print '================================'
print 'the energy equation is turned on'
print '================================'
f2.set_refine_criteria(ratio = 3.0, slope = 1.0, curve = 0.8, prune = 0.05)
f2.solve(loglevel=loglevel, refine_grid=False)
f2.show_solution
u2=f2.u
Ufs2= u2[0]
f2.show_stats
print 'flamespeed w H2O = ',Ufs2,'m/s'


error
Attempt Newton solution of steady-state problem...

the energy equation is turned off
================================

Traceback (most recent call last):
  File "C:\Users\Ja\Desktop\assign.py", line 38, in <module>

    f.solve(loglevel=loglevel, refine_grid=False)
  File "C:\Python27\Lib\site-packages\cantera\_cantera.pyd", line 662, in cantera._cantera.Sim1D.solve (cantera/_cantera.cpp:43710)
    I‹U I‹ÍÿR0A‹Äë A‹ÄL \$`I‹[0I‹s8 (t$P (|$@I‹ãA_A^A]A\_ÃÌÌÌÌÌÌÌÌÌÌÌÌH‰\$ H‰l$ WHƒì H‹A 3ÛH‹ùL‹€ \000\000\000M
Àt H‹
)R\000AÿÐH‹èë,L‹@@M
Àt H‹ )R\000HƒÂ AÿÐH‹èë H‹ ò(R\000ÿ ll=\000H‹èH‰t$0L‰d$8H
íu H‹=óŸO\000A¼ 0\000\000é, \000\000H‹G L‹€ \000\000\000M
Àt H‹ I,R\000H‹ÏAÿÐH‹ðë2L‹@@M
Àt H‹ .,R\000H‹ÏHƒÂ AÿÐH‹ðë H‹ ,R\000H‹Ïÿ ÷k=\000H‹ðH
öu H‹=ˆŸO\000A¼ 0\000\000é
\000\000\000H‹G L‹€ \000\000\000M
Àt H‹ ®#R\000H‹ÏAÿÐH‹Øë2L‹@@M
Àt H‹ “#R\000H‹ÏHƒÂ AÿÐH‹Øë H‹ }#R\000H‹Ïÿ Œk=\000H‹ØH
Ûu H‹=
ŸO\000A¼ 0\000\000ë
¹ \000\000\000ÿ ’h=\000H
ÀueH‹=þžO\000A¼ 0\000\000HƒE\000ÿu
Exception:
***********************************************************************
CanteraError thrown by MultiNewton::step:
Jacobian is singular for domain flame, component V at point 1
(Matrix row 60)
see file bandmatrix.csv
***********************************************************************


'''
for i in range(0,len(phi)):
    nCH4= phi[i]/(phi[i] + (0.791/0.209+1)*2)   #mole fraction of methane definition
    nO2 = (1-nCH4)*0.209   #mole fraction of air then becomes (1-nCH4)
    nN2 = (1-nCH4)*0.791   #mole fractions of N O according to 79.1 and 20.9 % by mole in air
    nH2O = 0.0   #assuming dry combustion so we neglect moles of water and mass as well
    phidry =phi[i]  #store the value of the stoichiometric coefficient

    #q = 'CH4:'+str(nCH4)+' O2:'+str(nO2)+' N2:'+str(nN2)+''; #composition by moles defined above
    #print q
    q ='CH4:%f,O2:%f,N2:%f' %(nCH4, nO2, nN2)
    print q
    gas.TPX = T1, P1, q  #set the gas
    gas()
    mfH2O
'''   

Maina George

unread,
Dec 3, 2015, 9:47:43 AM12/3/15
to Cantera Users' Group
and Ray could you maybe show me an example or direct me to a page with an example on how i would use the speed from one equivalence ratio as the initial guess please


On Thursday, November 26, 2015 at 10:34:29 AM UTC+1, Maina George wrote:

Ray Speth

unread,
Dec 4, 2015, 1:57:11 PM12/4/15
to Cantera Users' Group
Hi,

I found a few changes that help with convergence in this case:

1) Try the following initial grid:

initial_grid = np.array([0.0, 0.3, 0.5, 0.7, 1.0])*0.05

If you want a different width, just change the multiplicative factor. Maintaining this relative spacing within the domain fits with how the initial profiles for temperature and species are generated for the freely propagating flame. This configuration is particularly sensitive to the initial grid because of how the point at which the temperature profile is fixed is defined.

2) I think you have your absolute and relative tolerances backwards. The first number in each is the relative tolerance. Even then 1e-9 is far to tight of a relative tolerance. I would suggest the following tolerances as a starting point in almost all cases (these are taken from the adibatic_flame.py example):

tol_ss = [1.0e-5, 1.0e-13]  # [rtol atol] for steady-state problem
tol_ts
= [1.0e-4, 1.0e-13]  # [rtol atol] for time stepping

3) Don't increase the maximum allowable Jacobian age -- just let the solver use its default value. More frequent Jacobian updates will make it less likely to run into timestepping errors.

4) Set a non-zero initial guess for the mass flux, e.g.:

f.inlet.mdot = 1.0

This doesn't even need to be a decent guess, just some positive value should be fine.

As for an example of reusing a flame object, see the example stagnation_flame.py, where multiple flames are computed while varying the mass flow rate. You can easily adapt this to be a loop over equivalence ratio or some other parameter of your choice.

Regards,
Ray
Reply all
Reply to author
Forward
0 new messages