1+ # HydDown hydrogen/other gas depressurisation
2+ # Copyright (c) 2021 Anders Andreasen
3+ # Published under an MIT license
4+
5+ import streamlit as st
6+ import matplotlib
7+ import matplotlib .pyplot as plt
8+ import numpy as np
9+ import pandas as pd
10+ from hyddown import HydDown
11+
12+ if __name__ == "__main__" :
13+ #matplotlib.use('TkAgg')
14+
15+ sideb = st .sidebar
16+ length = sideb .text_input ('Vessel length (m):' ,10 )
17+ diam = sideb .text_input ('Vessel diam (m):' ,3 )
18+ orifice_diam = sideb .text_input ('Orifice diam (mm):' ,100 )
19+ orifice_diam = float (orifice_diam )/ 1000
20+ pres = sideb .text_input ('Initial pressure (bar):' ,100 )
21+ pres = float (pres )* 1e5
22+ temp = sideb .text_input ('Initial temperature (C):' ,25 )
23+ temp = float (temp )+ 273.15
24+ fluid = sideb .selectbox (
25+ 'Select fluid' ,
26+ ('N2' , 'He' , 'H2' , 'air' , 'CH4' ))
27+ option = sideb .selectbox (
28+ 'Select calculation type' ,
29+ ('isothermal' , 'isenthalpic' , 'isentropic' ))
30+
31+ tstep = sideb .text_input ('Calculation time step (s):' ,0.5 )
32+ end_time = sideb .text_input ('Calculation end time (s):' ,100 )
33+
34+ input = {}
35+ input ['calculation' ] = {}
36+ input ['vessel' ] = {}
37+ input ['initial' ] = {}
38+ input ['valve' ] = {}
39+
40+ input ['calculation' ]['type' ] = option
41+ input ['calculation' ]['time_step' ] = float (tstep )
42+ input ['calculation' ]['end_time' ] = float (end_time )
43+ input ['vessel' ]['length' ] = float (length )
44+ input ['vessel' ]['diameter' ] = float (diam )
45+ input ['initial' ]['pressure' ] = pres
46+ input ['initial' ]['temperature' ] = temp
47+ input ['initial' ]['fluid' ] = fluid
48+ input ['valve' ]['flow' ] = 'discharge'
49+ input ['valve' ]['type' ] = 'orifice'
50+ input ['valve' ]['diameter' ] = float (orifice_diam )
51+ input ['valve' ]['discharge_coef' ] = 0.84
52+ input ['valve' ]['back_pressure' ] = 1e5
53+
54+ col = st .beta_columns (1 )
55+ st .title ('HydDown adiabatic demo' )
56+ st .subheader (r'https://github.com/andr1976/HydDown' )
57+ my_expander = st .beta_expander ("Description" )
58+ my_expander .write ('Real gas vessel depressurisation for pure and pseudo-pure components. No heat transfer is enabled in this demo version.' )
59+
60+ col1 , col2 = st .beta_columns (2 )
61+ hdown = HydDown (input )
62+ hdown .run ()
63+
64+ temp_data = pd .DataFrame ({'Time (s)' : hdown .time_array , 'Temperature (C)' : hdown .T_fluid - 273.15 })
65+ pres_data = pd .DataFrame ({'Time (s)' : hdown .time_array , 'Pressure (bar)' : hdown .P / 1e5 })
66+
67+ col1 .line_chart (pres_data .rename (columns = {'Time (s)' :'index' }).set_index ('index' ))
68+ col1 .text ('Time (s)' )
69+ col2 .line_chart (temp_data .rename (columns = {'Time (s)' :'index' }).set_index ('index' ))
70+ col2 .text ('Time (s)' )
71+
72+
73+ mdot_data = pd .DataFrame ({'Time (s)' : hdown .time_array , 'Mass rate (kg/s)' : hdown .mass_rate })
74+ mass_data = pd .DataFrame ({'Time (s)' : hdown .time_array , 'Fluid inventory (kg)' : hdown .mass_fluid })
75+ col1 .line_chart (mdot_data .rename (columns = {'Time (s)' :'index' }).set_index ('index' ))
76+ col1 .text ('Time (s)' )
77+ col2 .line_chart (mass_data .rename (columns = {'Time (s)' :'index' }).set_index ('index' ))
78+ col2 .text ('Time (s)' )
79+
0 commit comments