You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.6KB

  1. """
  2. Constant-pressure, adiabatic kinetics simulation with sensitivity analysis
  3. """
  4. import sys
  5. import time
  6. import numpy as np
  7. start = time.time()
  8. import cantera as ct
  9. gas = ct.Solution('./mech-FFCM1.cti')
  10. temp = 900.0
  11. pres = 10.0*ct.one_atm
  12. gas.TPX = temp, pres, 'CH4:0.0499002,O2:0.199601,N2:0.750499'
  13. r = ct.IdealGasConstPressureReactor(gas, name='R1')
  14. sim = ct.ReactorNet([r])
  15. # enable sensitivity with respect to all reactions
  16. for i in range(0,gas.n_reactions):
  17. r.add_sensitivity_reaction(i)
  18. # set the tolerances for the solution and for the sensitivity coefficients
  19. sim.rtol = 1.0e-6
  20. sim.atol = 1.0e-12
  21. sim.rtol_sensitivity = 1.0e-6
  22. sim.atol_sensitivity = 1.0e-12
  23. #states = ct.SolutionArray(gas, extra=['t','s2'])
  24. ignitionStateFound=False
  25. Told=temp
  26. TIgn=1.115367e+03 #K
  27. tEnd=1.0 #s
  28. tauIgn=0.0
  29. nPts=1000
  30. dt=tEnd/(float(nPts)-1.0)
  31. sens=np.zeros(gas.n_reactions)
  32. out=open("ignitionSensitivities.dat","w")
  33. for t in np.arange(0, tEnd, dt):
  34. TOld=r.T
  35. sim.advance(t)
  36. TCurrent=r.T
  37. for i in range(0,gas.n_reactions):
  38. sens[i] = sim.sensitivity('temperature', i)
  39. if(ignitionStateFound==False):
  40. if(r.T>=TIgn):
  41. print("Ignition state found!\n")
  42. print("T=%15.6e K\n"%(TCurrent))
  43. print("tau=%15.6e s\n"%(t))
  44. ignitionStateFound=True
  45. tauIgn=t
  46. dTdtau=(TCurrent-TOld)/dt
  47. for i in range(0,gas.n_reactions):
  48. sens[i]=sens[i]*(-1.0e0/dTdtau)*(TCurrent/tauIgn)
  49. out.write("%15d\t%15.6e\n"%(i,sens[i]))
  50. break
  51. out.close()
  52. end = time.time()
  53. print("Elapsed time: %15.6e s\n"%(end-start))