You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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组分与温度变化曲线:
OH与温度变化曲线

请问这是什么原因?


内容的提问来源于stack exchange,提问作者YOU

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 08:15:54