Skip to content

Commit

Permalink
Merge pull request #82 from andr1976/controlvalve-characteristics
Browse files Browse the repository at this point in the history
mdot bug fix and fixing graphs in webapp
  • Loading branch information
andr1976 authored Dec 21, 2024
2 parents c414b63 + bcb8aaa commit 3b3d2da
Show file tree
Hide file tree
Showing 8 changed files with 952 additions and 611 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ src/hyddown/__pycache__/hdclass.cpython-38.pyc
.gitignore
src/hyddown/__pycache__/test_all.cpython-38-pytest-6.2.3.pyc
src/hyddown/__pycache__/hdclass.cpython-38.pyc
src/HydDown.egg-info/PKG-INFO
src/hyddown/__pycache__/validator.cpython-38.pyc
src/hyddown/__pycache__/transport.cpython-38.pyc
src/hyddown/__pycache__/hdclass.cpython-38.pyc
238 changes: 157 additions & 81 deletions scripts/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import pandas as pd
from PIL import Image
import base64
import matplotlib.pyplot as plt

try:
from hyddown import HydDown
except:
import sys
import os

hyddown_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "src")
sys.path.append(os.path.abspath(hyddown_path))
from hyddown import HydDown
Expand All @@ -24,8 +26,10 @@ def get_table_download_link(df, filename):
out: href string
"""
csv = df.to_csv(index=False)
b64 = base64.b64encode(csv.encode()).decode() # some strings <-> bytes conversions necessary here
filename = filename+'.csv'
b64 = base64.b64encode(
csv.encode()
).decode() # some strings <-> bytes conversions necessary here
filename = filename + ".csv"
return f'<a href="data:application/octet-stream;base64,{b64}" download={filename}>Download csv file</a>'


Expand All @@ -34,127 +38,199 @@ def read_input():

with sideb:
try:
image_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "docs", "img", "Sketch.png")
image_path = os.path.join(
os.path.abspath(os.path.dirname(__file__)),
"..",
"docs",
"img",
"Sketch.png",
)
icon = Image.open(image_path)
st.image(icon, use_column_width=True, caption="HydDown")
except:
pass

with st.form(key='my_form'):
submit_button = st.form_submit_button(label='Run calculation')
with st.form(key="my_form"):
submit_button = st.form_submit_button(label="Run calculation")
heattran = st.checkbox("Include heat transfer", value=True)
c1,c2 = st.columns(2)
c1, c2 = st.columns(2)

with c2:
length = st.text_input('Vessel length (m):', 0.463)
diam = st.text_input('Vessel diam (m):', 0.254)
thk = st.text_input('Vessel thichness (m):', 0.016)
orientation = st.selectbox('Vessel orientation', ('horizontal', 'vertical'))
orifice_diam = st.text_input('Orifice diam (mm):', 0.40)
orifice_diam = float(orifice_diam)/1000
tstep = st.text_input('Time step (s):', 1.0)
length = st.text_input("Vessel length (m):", 0.463)
diam = st.text_input("Vessel diam (m):", 0.254)
thk = st.text_input("Vessel thichness (m):", 0.016)
orientation = st.selectbox(
"Vessel orientation", ("horizontal", "vertical")
)
orifice_diam = st.text_input("Orifice diam (mm):", 0.40)
orifice_diam = float(orifice_diam) / 1000
tstep = st.text_input("Time step (s):", 1.0)

with c1:
pres = st.text_input('Initial pressure (bar):', 50.)
pres = float(pres)*1e5
pres = st.text_input("Initial pressure (bar):", 50.0)
pres = float(pres) * 1e5

back_pressure = st.text_input('Fill/back pres. (bar):', 240)
back_pressure= float(back_pressure)*1e5
back_pressure = st.text_input("Fill/back pres. (bar):", 240)
back_pressure = float(back_pressure) * 1e5

#fluid = st.selectbox('Select fluid', ('H2', 'He', 'N2', 'air', 'CH4', 'O2'))
fluid = st.selectbox('Select fluid', ('H2', 'NG', 'He', 'N2', 'air', 'CH4','O2'))
if fluid == 'NG':
fluid = "Methane[0.89571]&Ethane[5.6739e-02]&Propane[2.30395e-02]&Butane[1.03E-02]&Pentane[2.67E-03]&CO2[0.84e-02]&N2[0.3080e-2]"
mode = st.selectbox('Select mode', ('filling', 'discharge'))
temp = st.text_input("Initial temp. (C):", 25)
temp = float(temp) + 273.15
end_time = st.text_input("End time (s):", 240)

temp = st.text_input('Initial temp. (C):', 25)
temp = float(temp)+273.15
end_time = st.text_input('End time (s):', 240)

density = st.text_input('Vessel material density (kg/m3):', 7740)
density = st.text_input("Vessel material density (kg/m3):", 7740)
density = float(density)

cp = st.text_input('Vessel material heat capacity (J/kg K):', 470)
cp = st.text_input("Vessel material heat capacity (J/kg K):", 470)
cp = float(cp)


input = {}
input['calculation'] = {}
input['vessel'] = {}
input['initial'] = {}
input['valve'] = {}
input['heat_transfer'] = {}

input['calculation']['type'] = 'energybalance'
input['calculation']['time_step'] = float(tstep)
input['calculation']['end_time'] = float(end_time)
input['vessel']['length'] = float(length)
input['vessel']['diameter'] = float(diam)
input['vessel']['heat_capacity'] = cp
input['vessel']['density'] = density
input['vessel']['orientation'] = orientation
input['vessel']['thickness'] = float(thk)

input['initial']['pressure'] = pres
input['initial']['temperature'] = temp
input['initial']['fluid'] = fluid
input['valve']['flow'] = mode
input['valve']['type'] = 'orifice'
input['valve']['diameter'] = float(orifice_diam)
input['valve']['discharge_coef'] = 0.84
input['valve']['back_pressure'] = back_pressure
input["calculation"] = {}
input["vessel"] = {}
input["initial"] = {}
input["valve"] = {}
input["heat_transfer"] = {}

input["calculation"]["type"] = "energybalance"
input["calculation"]["time_step"] = float(tstep)
input["calculation"]["end_time"] = float(end_time)

input["vessel"]["length"] = float(length)
input["vessel"]["diameter"] = float(diam)
input["vessel"]["heat_capacity"] = cp
input["vessel"]["density"] = density
input["vessel"]["orientation"] = orientation
input["vessel"]["thickness"] = float(thk)

input["initial"]["pressure"] = pres
input["initial"]["temperature"] = temp
input["initial"]["fluid"] = fluid
input["valve"]["flow"] = mode
input["valve"]["type"] = "orifice"
input["valve"]["diameter"] = float(orifice_diam)
input["valve"]["discharge_coef"] = 0.84
input["valve"]["back_pressure"] = back_pressure
# input['valve']['end_pressure']=end_pressure

input['heat_transfer']['type'] = 'specified_h'
input['heat_transfer']['temp_ambient'] = 298
input['heat_transfer']['h_outer'] = 5
input["heat_transfer"]["type"] = "specified_h"
input["heat_transfer"]["temp_ambient"] = 298
input["heat_transfer"]["h_outer"] = 5
if heattran is True:
input['heat_transfer']['h_inner'] = 'calc'
input["heat_transfer"]["h_inner"] = "calc"
else:
input['heat_transfer']['h_inner'] = 0.0
input['heat_transfer']['D_throat'] = float(diam)
input["heat_transfer"]["h_inner"] = 0.0
input["heat_transfer"]["D_throat"] = float(diam)
return input


if __name__ == "__main__":
st.set_page_config(layout='wide')
st.set_page_config(layout="wide")

input = read_input()
hdown = HydDown(input)

with st.spinner('Calculating, please wait....'):
hdown.run(disable_pbar=True)
with st.spinner("Calculating, please wait...."):
hdown.run(disable_pbar=True)

st.title('HydDown rigorous demo')
st.subheader(r'https://github.com/andr1976/HydDown')
st.title("HydDown rigorous demo")
st.subheader(r"https://github.com/andr1976/HydDown")
my_expander = st.expander("Description")

my_expander.write('Real gas vessel pressurisation/depressurisation with heat transfer from gas to vessel and ambient and vice versa. Orifice size (Cd = 0.84) is specified for desired pressurisation/depressurisation rate.')
my_expander.write('For more information about the calculations and validation of the code please refer to the [manual](https://github.com/andr1976/HydDown/raw/main/docs/MANUAL.pdf)')
my_expander.write(
"Real gas vessel pressurisation/depressurisation with heat transfer from gas to vessel and ambient and vice versa. Orifice size (Cd = 0.84) is specified for desired pressurisation/depressurisation rate."
)
my_expander.write(
"For more information about the calculations and validation of the code please refer to the [manual](https://github.com/andr1976/HydDown/raw/main/docs/MANUAL.pdf)"
)

df = hdown.get_dataframe()
file_name = st.text_input('Filename for saving data:', 'saved_data')
file_name = st.text_input("Filename for saving data:", "saved_data")

st.markdown(get_table_download_link(df, file_name), unsafe_allow_html=True)

col1, col2 = st.columns(2)

if input['valve']['flow'] == 'discharge':
temp_data = pd.DataFrame({'Time (s)': hdown.time_array, 'Fluid temperature (C)': hdown.T_fluid-273.15, 'Wall temperature (C)': hdown.T_vessel-273.15, 'Vent temperature (C)': hdown.T_vent-273.15})
if input["valve"]["flow"] == "discharge":
temp_data = pd.DataFrame(
{
"Time (s)": hdown.time_array,
"Fluid temperature (C)": hdown.T_fluid - 273.15,
"Wall temperature (C)": hdown.T_vessel - 273.15,
"Vent temperature (C)": hdown.T_vent - 273.15,
}
)
else:
temp_data = pd.DataFrame({'Time (s)': hdown.time_array, 'Fluid temperature (C)': hdown.T_fluid-273.15, 'Wall temperature (C)': hdown.T_vessel-273.15})

pres_data = pd.DataFrame({'Time (s)': hdown.time_array, 'Pressure (bar)': hdown.P/1e5})

col1.line_chart(pres_data.rename(columns={'Time (s)': 'index'}).set_index('index'))
col1.text('Time (s)')
col2.line_chart(temp_data.rename(columns={'Time (s)': 'index'}).set_index('index'))
col2.text('Time (s)')

mdot_data = pd.DataFrame({'Time (s)': hdown.time_array, 'Mass rate (kg/s)': hdown.mass_rate})
mass_data = pd.DataFrame({'Time (s)': hdown.time_array, 'Fluid inventory (kg)': hdown.mass_fluid})
col1.line_chart(mdot_data.rename(columns={'Time (s)': 'index'}).set_index('index'))
col1.text('Time (s)')
col2.line_chart(mass_data.rename(columns={'Time (s)': 'index'}).set_index('index'))
col2.text('Time (s)')
temp_data = pd.DataFrame(
{
"Time (s)": hdown.time_array,
"Fluid temperature (C)": hdown.T_fluid - 273.15,
"Wall temperature (C)": hdown.T_vessel - 273.15,
}
)

pres_data = pd.DataFrame(
{"Time (s)": hdown.time_array, "Pressure (bar)": hdown.P / 1e5}
)

fig, ax = plt.subplots(figsize=(5, 2))

ax.plot(
pres_data["Time (s)"],
pres_data["Pressure (bar)"],
"k",
)
ax.set_xlabel("Time (s)")
ax.set_ylabel("Pressure (bar)")
col1.pyplot(fig)

fig, ax = plt.subplots(figsize=(5, 2))

ax.plot(
temp_data["Time (s)"], temp_data["Fluid temperature (C)"], "k", label="Fluid"
)
ax.plot(
temp_data["Time (s)"], temp_data["Wall temperature (C)"], "k--", label="Wall"
)
if input["valve"]["flow"] == "discharge":
ax.plot(
temp_data["Time (s)"],
temp_data["Vent temperature (C)"],
"k-.",
label="Vent",
)

ax.set_xlabel("Time (s)")
ax.set_ylabel("Temperature ($^\circ$C)")
ax.legend(loc="best")
col2.pyplot(fig)

mdot_data = pd.DataFrame(
{"Time (s)": hdown.time_array, "Mass rate (kg/s)": hdown.mass_rate}
)
mass_data = pd.DataFrame(
{"Time (s)": hdown.time_array, "Fluid inventory (kg)": hdown.mass_fluid}
)

fig, ax = plt.subplots(figsize=(5, 2))
ax.plot(
mdot_data["Time (s)"],
mdot_data["Mass rate (kg/s)"],
"k",
)
ax.set_xlabel("Time (s)")
ax.set_ylabel("Mass rate (kg/s)")
col1.pyplot(fig)

fig, ax = plt.subplots(figsize=(5, 2))
ax.plot(
mass_data["Time (s)"],
mass_data["Fluid inventory (kg)"],
"k",
)
ax.set_xlabel("Time (s)")
ax.set_ylabel("Fluid inventory (kg)")
col2.pyplot(fig)
14 changes: 10 additions & 4 deletions src/HydDown.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ Summary: Hydrogen (or other pure gas phase species) pressure vessel filling and
Home-page: https://github.com/andr1976/HydDown/
Author: Anders Andreasen
Author-email: [email protected]
License: UNKNOWN
Project-URL: Bug Tracker, https://github.com/andr1976/HydDown/new/main/issues
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: tqdm
Requires-Dist: streamlit>=0.89
Requires-Dist: pandas>=1.1.4
Requires-Dist: matplotlib>=3.3.3
Requires-Dist: numpy>=1.19.5
Requires-Dist: pytest>=6.2.3
Requires-Dist: Cerberus>=1.3.3
Requires-Dist: CoolProp>=6.4.1
Requires-Dist: PyYAML>=5.4.1
Requires-Dist: scipy>=1.6.0

[![DOI](https://zenodo.org/badge/353152239.svg)](https://zenodo.org/badge/latestdoi/353152239) ![license](https://img.shields.io/github/license/andr1976/HydDown) ![buil](https://github.com/andr1976/HydDown/actions/workflows/python-app.yml/badge.svg) [![codecov](https://codecov.io/gh/andr1976/HydDown/branch/main/graph/badge.svg)](https://codecov.io/gh/andr1976/HydDown) [![Streamlit App](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://share.streamlit.io/andr1976/hyddown/main/scripts/streamlit_app.py)
[![CodeQL](https://github.com/andr1976/HydDown/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/andr1976/HydDown/actions/workflows/codeql-analysis.yml)
Expand Down Expand Up @@ -108,5 +116,3 @@ If heat transfer is to be considered the calculation type "energybalance" is req
- Specified h, the external heat transfer coefficient is provided and either the internal is provided or calculated from assumption of natural convection from a vertical cylinder at high Gr number. Ambient temperature is required.
- Detailed
- Fire with heat load calculated from the Stefan-Boltzmann equation


Binary file modified src/hyddown/__pycache__/hdclass.cpython-38.pyc
Binary file not shown.
Binary file modified src/hyddown/__pycache__/transport.cpython-38.pyc
Binary file not shown.
Binary file modified src/hyddown/__pycache__/validator.cpython-38.pyc
Binary file not shown.
Loading

0 comments on commit 3b3d2da

Please sign in to comment.