ReactionMechanismGenerator / RMG-Py

Python version of the amazing Reaction Mechanism Generator (RMG).
http://reactionmechanismgenerator.github.io/RMG-Py/
Other
396 stars 228 forks source link

ZeroDivisionError in solver computeRateDerivative() #1420

Closed alongd closed 1 year ago

alongd commented 6 years ago

Running the long nitrogen test (unmerged) crashes with:

Conducting sensitivity analysis of reaction system 1...
initializing surface ...
surface initialization complete
Traceback (most recent call last):
  File "rmgpy/kinetics/arrhenius.pyx", line 768, in rmgpy.kinetics.arrhenius.MultiPDepArrhenius.getRateCoefficient
AssertionError
Exception AssertionError in 'rmgpy.reaction.Reaction.getRateCoefficient' ignored
Traceback (most recent call last):
  File "/home/alongd/Code/RMG-Py//rmg.py", line 173, in <module>
    main()
  File "/home/alongd/Code/RMG-Py//rmg.py", line 167, in main
    rmg.execute(**kwargs)
  File "/home/alongd/Code/RMG-Py/rmgpy/rmg/main.py", line 896, in execute
    conditions = reactionSystem.sensConditions,
  File "rmgpy/solver/base.pyx", line 563, in rmgpy.solver.base.ReactionSystem.simulate
  File "rmgpy/solver/base.pyx", line 654, in rmgpy.solver.base.ReactionSystem.simulate
  File "rmgpy/solver/simple.pyx", line 194, in rmgpy.solver.simple.SimpleReactor.initializeModel
  File "rmgpy/solver/base.pyx", line 468, in rmgpy.solver.base.ReactionSystem.set_initial_derivative
  File "rmgpy/solver/simple.pyx", line 516, in rmgpy.solver.simple.SimpleReactor.residual
  File "rmgpy/solver/base.pyx", line 1227, in rmgpy.solver.base.ReactionSystem.computeRateDerivative
ZeroDivisionError: float division

Adding debug prints gave zero values in some kr, kf, C entries:

C[ip[j,0]]:  0.0
C[ip[j,1]]:  0.0
kr[j]:  4.16435446471e-12
kf[j]:  1632443.00606
C[ip[j,0]]:  0.0
C[ip[j,1]]:  0.0
kr[j]:  11249.7233143
kf[j]:  14615140.5227
C[ip[j,0]]:  0.0
C[ip[j,1]]:  0.0
kr[j]:  24705.4468994
kf[j]:  150000000.0
C[ip[j,0]]:  0.0
C[ip[j,1]]:  0.0
kr[j]:  9.58832144071e-09
kf[j]:  5575644.98708
C[ip[j,0]]:  0.0
C[ip[j,1]]:  0.0
kr[j]:  0.0
kf[j]:  0.0
C[ip[j,0]]:  0.0
C[ip[j,1]]:  0.0
shenghuiqin commented 5 years ago

I think I met the same problem when I try to use the simulate module in RMG-Py/scripts (Simulation and Sensitivity/Uncertainty Analysis):

Conducting simulation and sensitivity analysis of reaction system 1...

Traceback (most recent call last):
  File "simulate.py", line 74, in <module>
    main()
  File "simulate.py", line 69, in main
    run_simulation(inputFile, chemkinFile, dictFile, diffusionLimited=dflag, checkDuplicates=checkDuplicates)
  File "/home/shenghuiqin/Code/RMG-Py/rmgpy/tools/simulate.py", line 128, in run_simulation
    simulate(rmg,diffusionLimited)
  File "/home/shenghuiqin/Code/RMG-Py/rmgpy/tools/simulate.py", line 105, in simulate
    simulatorSettings=simulatorSettings,
  File "rmgpy/solver/base.pyx", line 570, in rmgpy.solver.base.ReactionSystem.simulate
  File "rmgpy/solver/base.pyx", line 669, in rmgpy.solver.base.ReactionSystem.simulate
  File "rmgpy/solver/simple.pyx", line 202, in rmgpy.solver.simple.SimpleReactor.initializeModel
  File "rmgpy/solver/base.pyx", line 475, in rmgpy.solver.base.ReactionSystem.set_initial_derivative
  File "rmgpy/solver/simple.pyx", line 524, in rmgpy.solver.simple.SimpleReactor.residual
  File "rmgpy/solver/base.pyx", line 1325, in rmgpy.solver.base.ReactionSystem.computeRateDerivative
ZeroDivisionError: float division
AH9316 commented 5 years ago

@alongd Hello, Alon. I meet the same issue as below:

Traceback (most recent call last): File "rmg.py", line 173, in main() File "rmg.py", line 167, in main rmg.execute(**kwargs) File "/home/rcf-40/anguohu/.conda/envs/rmg_env/lib/python2.7/site-packages/rmgpy/rmg/main.py", line 662, in execute conditions = self.rmg_memories[index].get_cond(), File "rmgpy/solver/simple.pyx", line 166, in rmgpy.solver.simple.SimpleReactor.initializeModel File "rmgpy/solver/simple.pyx", line 202, in rmgpy.solver.simple.SimpleReactor.initializeModel File "rmgpy/solver/base.pyx", line 475, in rmgpy.solver.base.ReactionSystem.set_initial_derivative File "rmgpy/solver/simple.pyx", line 371, in rmgpy.solver.simple.SimpleReactor.residual ZeroDivisionError: float division

Did you find a way to solve this problem? Thanks!

alongd commented 4 years ago

Hi @AH9316, it's been a while since I reported this, I think that the status is still of an open issue, I don't recall we resolved this. Could you prepare a minimal input file that reproduces this error?

AH9316 commented 4 years ago

Hi @alongd, below is the input file I used. Because I used imported mechanism as seed mechanism and thermolibrary, I attach the imported kinetic files(dictionary.txt and reaction.py) and thermo file(test3.py) too. Thanks.

test3.zip

AH9316 commented 4 years ago

Hi, @alongd. We find the reason cause this error in my case. In order to make you understand, let me recall what we have done.

Purpose: To import a gasoline mechanism into RMG database and use it as a ‘seedmechanism’ to run RMG simulation with addition of other fuel components. The objective is to obtain a final mechanism with cross reactions between gasoline and other fuel components.

Problem: The gasoline mechanism has the keyword ‘REV’ which expresses reversible reactions. Upon importing this into the database, RMG doesn’t recognize the ‘REV’ keyword, which means, the imported mechanism only has forward reactions.

Solution to this problem: In order to solve this problem, we change the original gasoline mechanism by manually separating reversible reactions into forward and backward reactions, thus avoiding the ‘REV’ keyword. Subsequently, we import this modified gasoline mechanism into the RMG database with both forward and backward reactions in the imported mechanism.

New problem: When we run RMG simulation with this modified imported gasoline mechanism, we meet this error: ZeroDivisionError: float division.

By checking each reaction, we narrowed down this problem to the following set of reactions shown below: !5, 5 in original mech H2+M<=>H+H+M 4.577E+19 -1.400 1.044E+05 REV/ 1.145E+20 -1.676 8.200E+02 / H2/2.5/ H2O/12/ CO/1.9/ CO2/3.8/ !6, 6 in original mech O2+M<=>O+O+M 4.420E+17 -0.634 1.189E+05 REV/ 6.165E+15 -0.500 0.000E+00 / H2/2.5/ H2O/12/ CO/1.9/ CO2/3.8/ CH4/2/ C2H6/3/ !7, 7 in original mech OH+M<=>O+H+M 9.780E+17 -0.743 1.021E+05 REV/ 4.714E+18 -1.000 0.000E+00 / H2/2.5/ H2O/12/ CO/1.5/ CO2/2/ CH4/2/ C2H6/3/ !8, 8 in original mech H2O+M<=>H+OH+M 1.907E+23 -1.830 1.185E+05 REV/ 4.500E+22 -2.000 0.000E+00 / H2/.73/ H2O/12/ CH4/2/ C2H6/3/ !26, 26 in original mech HCO+M<=>H+CO+M 4.750E+11 0.660 1.487E+04 REV/ 3.582E+10 1.041 -4.573E+02 / H2/2/ H2O/12/ CO/1.5/ CO2/2/ CH4/2/ C2H6/3/

To illustrate how we separate a reaction into forward and backward reactions: For reaction #5: H2+M=>H+H+M 4.577E+19 -1.400 1.044E+05 H2/2.5/ H2O/12/ CO/1.9/ CO2/3.8/ H+H+M=> H2+M 1.145E+20 -1.676 8.200E+02 H2/2.5/ H2O/12/ CO/1.9/ CO2/3.8/

Solution for new Problem: Due to the ‘ZeroDivision’ error we obtained when we separate the above set of reactions, we decided to maintain it as the same in the original gasoline mechanism and rather separate other reversible reactions into forward and backward reactions before importing this new modified mechanism into the database. With this new modified imported mechanism, we can run RMG simulation successfully without any ‘ZeroDivison’ error. Upon obtaining the final ‘chem.inp’ from RMG, we append the reversible Arrhenius parameters for the above reactions.

Other problem: 1) RMG still cannot handle reactions with more than 3 products, so when we run RMG simulation with the new modified imported mechanism, we comment out any such reaction in the reaction.py file located in the kinetic/library directory; for example “C14H14+O<=>C6H5CH2J+C6H6+CO+H”. 2) Since RMG produced an error when Tmin> 298K, we also change all Tmin which aren’t 298K to 298K of the corresponding imported thermodynamic file in thermo/library directory.

I attach the original gasoline mechanism below: Original_gasoline_mechanism.zip

I hope this is helpful to improve RMG software. Thanks!

JacksonBurns commented 1 year ago

This is in Python 2.7 and we stand no chance of reproducing it. Closing as stale.