Python Cantera MassFlowController无法从中提取质量

2024-04-27 18:20:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试建立一个氢气罐模型(液体蒸汽),包括通过罐壁随时间增加的热量,一个在给定压力下激活的排气阀,以及在休眠时间后激活的恒定燃料电池供应。在

H2 tank

所有这些都是用适当的坎特拉反应堆和水库来模拟的。此外,壁和质量流量控制器分别用于热量添加和燃料电池供应。在

当我运行时间积分时,在一段时间后(在下面的代码中是18000秒),质量流会自动改变,但是它不会从容器中输出任何质量。坎特拉在那之后不久就抛出了一个错误。在

以下是示例代码:

import cantera as ct

""" Variables """
Tint = 20.24 #K
Tamb = 293.0 #K
Rho = 44.623  #kg/m3
TankVolume = 7.04 #m3
TankArea = 20.0 # m2
TankU = 0.36
Pvent = 7.0 #bar
Psupply = 2.0 #bar
msupply = 0.005 #kg/s
DormTime = 5.0 #hrs
TotTime = 10.0 #hrs

""" Tank Reactor """
LH2 = ct.Hydrogen()
LH2.TD = Tint, Rho
LR = ct.Reactor(contents=LH2)
LR.volume = TankVolume

""" Air as the ambient medium """
air = ct.Solution('air.cti')
air.TP = Tamb, ct.one_atm
Rin = ct.Reservoir(air)

""" Air as the medium for extraction. Set the outlet pressure to Pvent """
extr = ct.Solution('air.cti')
extr.TP = Tamb, Pvent * ct.one_atm
Rout = ct.Reservoir(extr)

""" Fuel cell reactor. Does not operate as FC """
FCH2 = ct.Hydrogen()
FCH2.TP = Tamb, Psupply * ct.one_atm
Rextr = ct.Reservoir(FCH2)

""" Tank wall for the heat addition """
TW1 = ct.Wall(LR, Rin, A=TankArea, U=0.36)

""" Initiate the supply if there is no dormancy time """
if DormTime != 0.0:
    FCVLV = ct.MassFlowController(LR,Rextr,mdot=0.0)
    MassOn = False
else:
    FCVLV = ct.MassFlowController(LR,Rextr,mdot=msupply)
    MassOn = True

""" Valve for venting the H2 to the atmosphere if the pressure reached Pvent """
VVLV = ct.Valve(LR, Rout, K=1.0)

""" Reactor network for the tank """
network = ct.ReactorNet([LR])

""" Time integartion """
t = 0.0
dt = 60.0

print('{:>6s} {:>12s} {:>6s} {:>5s} {:>9s} {:>7s} {:>7s} {:>8s} {:>8s}'.format(
        'Time', 'Press', 'Temp', 'VapFr', 'Mass', 'Vol', 'Dens', 'H2FC', 'H2Vent'))

print('{:6.0f} {:12.2f} {:6.2f} {:5.3f} {:9.3f} {:7.2f} {:7.3f} {:8.6f} {:8.6f}'.format(
          t, LR.thermo.P, LR.thermo.T, LR.thermo.X, LR.get_state()[0], 
          LR.get_state()[1], LR.thermo.density_mass, FCVLV.mdot(t), VVLV.mdot(t)))

while t < 60.0*60*TotTime:
    if LR.thermo.density_mass < 0.1: #Safety
        break

    t += dt

    """ Initiate the FC mass flow after the dormancy time """
    if t>= 60.0*60.0*DormTime and not MassOn:
        if LR.thermo.P < Psupply:
            print('WARNING: Pressure in tank lower than FC supply pressure. Supply will stay closed')
        else:
            FCVLV.set_mass_flow_rate(msupply)
            MassOn = True

    network.advance(t)

    print('{:6.0f} {:12.2f} {:6.2f} {:5.3f} {:9.3f} {:7.2f} {:7.3f} {:8.6f} {:8.6f}'.format(
          t, LR.thermo.P, LR.thermo.T, LR.thermo.X, LR.get_state()[0], 
          LR.get_state()[1], LR.thermo.density_mass, FCVLV.mdot(t), VVLV.mdot(t)))

这给了我下面的行为,直到错误的点,我认为这就是坎特拉试图从坦克里取出质量的点(见下面的原因)。请注意,“质量流”处于启用状态,但H2的质量没有减少。在

H2Time

如果我减少休眠时间,模型不会抛出错误,但在开始减少储罐中的H2质量之前,它仍然显示出相同的行为(这可能是上面的错误原因)。我怀疑这和氢物理无关,因为在不同的压强下,我得到了相同的误差(如下)。在

CanteraError thrown by CVodesIntegrator::integrate: CVodes error encountered. Error code: -3 At t = 18483.3 and h = 0.00100341, the error test failed repeatedly or with |h| = hmin. Exceptions caught during RHS evaluation: density must be positive Components with largest weighted error estimates: 0: -15.9704 2: 15.9166 1: 0 3: 0

当休眠时间为零时,MassFlowController按预期工作,导致它在开始时间步之前启动。在

这是Cantera的缺陷还是我遗漏了什么?在


Tags: thethermoifas错误时间质量air