我正在尝试构建一个氢气罐模型(液体-蒸汽),其中包括随着时间的推移通过罐壁添加热量、在给定压力下激活的排气阀和在休眠时间后激活的恒定燃料电池供应。
所有这些都是用适当的 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 的质量并未减少。
如果我减少休眠时间,模型不会抛出错误,但它在开始减少水箱中的 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
还是我在这里遗漏了什么?