BioSTEAMDevelopmentGroup / biosteam

The Biorefinery Simulation and Techno-Economic Analysis Modules; Life Cycle Assessment; Chemical Process Simulation Under Uncertainty
Other
177 stars 35 forks source link

Flash not working when V=1 #102

Closed BenPortner closed 2 years ago

BenPortner commented 2 years ago

Dear @yoelcortes,

units._flash.Flash can currently not handle complete vaporization (V=1):

Minimum error example

import biosteam as bst

bst.settings.set_thermo(["H2O"])
feed = bst.Stream(H2O=1, T=100+273.15, P=101325, phase='l')
F = bst.units._flash.Flash(ins=feed, outs=('steam', 'liquid'), V=1.0, P=feed.P)

Error message:

C:\Users\user\programs\miniconda\envs\biosteam\python.exe "C:\Users\user\programs\PyCharm\PyCharm Community Edition 2020.3.2\plugins\python-ce\helpers\pydev\pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 62201 --file C:/Users/user/PycharmProjects/biosteam/flasher.py
Connected to pydev debugger (build 212.4746.96)
Traceback (most recent call last):
  File "C:\Users\user\programs\PyCharm\PyCharm Community Edition 2020.3.2\plugins\python-ce\helpers\pydev\pydevd.py", line 1483, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Users\user\programs\PyCharm\PyCharm Community Edition 2020.3.2\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/user/PycharmProjects/biosteam/flasher.py", line 6, in <module>
    F.simulate()
  File "c:\users\user\pycharmprojects\biosteam_dev\biosteam\_unit.py", line 1012, in simulate
    self._summary()
  File "c:\users\user\pycharmprojects\biosteam_dev\biosteam\_unit.py", line 913, in _summary
    self._design()
  File "c:\users\user\pycharmprojects\biosteam_dev\biosteam\units\_flash.py", line 257, in _design
    vessel_type = self.vessel_type
  File "c:\users\user\pycharmprojects\biosteam_dev\biosteam\units\design_tools\pressure_vessel.py", line 44, in vessel_type
    self._vessel_type = vessel_type = self._default_vessel_type()
  File "c:\users\user\pycharmprojects\biosteam_dev\biosteam\units\_flash.py", line 245, in _default_vessel_type
    assert F_mass_liq, "no liquid effluent; flash vessel must have liquid to default vessel type"
AssertionError: no liquid effluent; flash vessel must have liquid to default vessel type

Things I've tried

The error is thrown because F_mass_liq = 0.0 in this line. It can be fixed by removing the assertion and making vertical drums the default for flashers without a liquid phase:

        F_mass_liq = liq.F_mass # 0.0
        #assert F_mass_liq, "no liquid effluent; flash vessel must have liquid to default vessel type"
        return 'Vertical' if not F_mass_liq or F_mass_vap / F_mass_liq > 0.1 else 'Horizontal'

However, the trouble continues. After making above change, a ZeroDivisionError is thrown in this line because the density of the liquid phase cannot be determined. One could set rhol = 0 but then Ut and Uv in the same function will turn into imaginary numbers (square root of negative value) . Without knowing the specific vessel design procedure, I expect this will lead to further problems downstream. Hence, instead of hacking our way through units._flash._vertical_vessel_pressure_diameter_and_length with many, many if-statements it might be better to have a separate design function for "single-phase-outs" to begin with. What do you think?

yoelcortes commented 2 years ago

Dear @BenPortner,

My understanding of a flash vessel (and I might be wrong), is that it allows the separation of gas bubbles and liquid droplets in phase equilibrium (so that the vapor phase is free of liquid droplets and the liquid phase is free of gas bubbles). If there is only one phase, I don't think there is a need to have a flash vessel nor can we design one. If we just want to vaporize a liquid, we can use a heat exchanger. In BioSTEAM, we can set V for heat exchangers too https://biosteam.readthedocs.io/en/latest/API/units/heat_exchange.html#biosteam.units.heat_exchange.HXutility.

Thanks,

yoelcortes commented 2 years ago

I'll go ahead and make the assertion error a RuntimeError and make it more clear that a flash vessel cannot be designed without two phases.

BenPortner commented 2 years ago

You're aboslutely right, @yoelcortes. This was a confusion about the terminology on my side. Feel free to close this issue at your convenience.

yoelcortes commented 2 years ago

No worries, thanks for submitting the issue!