Python Cantera MassFlowController不会从反应堆中提取质量

时间:2018-07-27 11:49:33

标签: python cantera

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

H2 tank

所有这些均以合适的cantera反应器和储层进行建模。 Wall和MassFlowController分别用于热量添加和燃料电池供应。

当我运行时间积分时,经过一段时间(下面的代码中为18000秒),MassFlowController质量流量会自动更改,但不会从水箱中输出任何质量。此后不久,Cantera引发了错误。

这是示例代码:

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)))

这会给我以下行为,直到错误为止,我认为这是cantera试图从罐中实际取出质量的原因(请参阅下面的原因)。请注意,质量流在打开,但是H2的质量并没有减少。

H2Time

如果我减少休眠时间,该模型不会抛出错误,但是在开始减少水箱中的H2质量之前,它仍然显示相同的行为(这可能是上面的错误原因)。我怀疑这与H2物理学无关,因为在不同的压力下会出现相同的错误(如下)。

  

CVodesIntegrator :: integrate抛出的CanteraError:   遇到CVodes错误。错误代码:-3   在t = 18483.3和h = 0.00100341时,错误测试反复失败或| h |失败。 =小时   RHS评估中捕获到的异常:   密度必须为正   加权误差估计值最大的组件:   0:-15.9704   2:15.9166   1:0   3:0

MassFlowController在休眠时间为零时会按预期运行,导致它在开始时间步之前启动。

这是Cantera MassFlowController的错误,还是我在这里错过了任何东西?

0 个答案:

没有答案