Cantera自定义脚本计算时长异常:设t_end=40却仅计算至20s求助
Cantera计算自燃延迟时间提前终止问题
我在Linux环境下使用Python调用Cantera计算自燃延迟时间,仅修改了官方custom.py示例中的三个参数:
- 将
t_end设为40 - 将
dt设为1 - 初始工况改为
gas.TPX = 801, P, 'H2:0.1667,O2:0.0833,N2:0.75'
但计算结果只到19.45388009s左右就终止了,完整代码如下:
import cantera as ct import numpy as np import scipy.integrate class ReactorOde: def __init__(self, gas): # Parameters of the ODE system and auxiliary data are stored in the # ReactorOde object. self.gas = gas self.P = gas.P def __call__(self, t, y): """the ODE function, y' = f(t,y) """ # State vector is [T, Y_1, Y_2, ... Y_K] self.gas.set_unnormalized_mass_fractions(y[1:]) self.gas.TP = y[0], self.P rho = self.gas.density wdot = self.gas.net_production_rates dTdt = - (np.dot(self.gas.partial_molar_enthalpies, wdot) / (rho * self.gas.cp)) dYdt = wdot * self.gas.molecular_weights / rho return np.hstack((dTdt, dYdt)) gas = ct.Solution('h2o2.yaml') P = ct.one_atm gas.TPX = 801, P, 'H2:0.1667,O2:0.0833,N2:0.75' y0 = np.hstack((gas.T, gas.Y)) ode = ReactorOde(gas) solver = scipy.integrate.ode(ode) solver.set_integrator('vode', method='bdf', with_jacobian=True) solver.set_initial_value(y0, 0.0) t_end = 40 states = ct.SolutionArray(gas, 1, extra={'t': [0.0]}) dt = 1 while solver.successful() and solver.t < t_end: solver.integrate(solver.t + dt) gas.TPY = solver.y[0], P, solver.y[1:] states.append(gas.state, t=solver.t) print(states.t)
程序输出结果:
[ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 19.45388009]
附OH组分与温度变化曲线:
请问这是什么原因?
内容的提问来源于stack exchange,提问作者YOU
相关产品推荐
相关产品推荐

