I am trying to build a hydrogen tank model (liquid-vapour) that includes heat addition over time through the tank walls, a venting valve that is activated at a given pressure and a constant fuel cell supply that is activated after a dormancy time.
All these are modelled with appropiate cantera reactors and reservoirs. Also a Wall and a MassFlowController are used for the heat addition and the fuel cell supply respectively.
When I run the time integration, after some time (18000 sec in the code below), the MassFlowController mass flow is changed automatically, but it won't export any mass from the tank. Cantera is throwing an error shortly after that.
This is a sample code:
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)))
Which gives me the below behaviour, up to the point of the error, which I think is the point that cantera tries to actually take mass out of the tank (see below why). Notice that the mass flow is on, but the mass of H2 is not reducing.
The model won't throw an error if I reduce the dormancy time, but it still shows the same behaviour before it starts reducing the H2 mass in the tank (that's possibly the error cause above). I suspect that it doesn't have to do with the H2 physics, because I get the same error (below) at different pressures.
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
The MassFlowController functions as expected when the dormancy time is zero causing it to be initiated before starting the time steps.
Is this a bug of the Cantera MassFlowController
or am I missing anything here?