Spaces:
Sleeping
Sleeping
import streamlit as st | |
import math | |
def design_heat_exchanger(duty, t_hot_in, t_hot_out, t_cold_in, t_cold_out, overall_heat_transfer_coeff, fouling_factor): | |
""" | |
Calculate heat transfer area and LMTD for shell-and-tube heat exchanger. | |
Parameters: | |
- duty: Heat duty (kW) | |
- t_hot_in: Hot fluid inlet temperature (°C) | |
- t_hot_out: Hot fluid outlet temperature (°C) | |
- t_cold_in: Cold fluid inlet temperature (°C) | |
- t_cold_out: Cold fluid outlet temperature (°C) | |
- overall_heat_transfer_coeff: Overall heat transfer coefficient (W/m²°C) | |
- fouling_factor: Fouling resistance (m²°C/W) | |
Returns: | |
- Heat transfer area (m²) | |
- Log Mean Temperature Difference (°C) | |
""" | |
try: | |
# Convert duty from kW to W | |
duty_w = duty * 1000 | |
# Calculate Log Mean Temperature Difference (LMTD) | |
delta_t1 = t_hot_in - t_cold_out | |
delta_t2 = t_hot_out - t_cold_in | |
if delta_t1 <= 0 or delta_t2 <= 0: | |
return "Invalid temperature inputs!", "N/A" | |
lmtd = (delta_t1 - delta_t2) / math.log(delta_t1 / delta_t2) | |
# Calculate heat transfer area | |
effective_u = overall_heat_transfer_coeff * (1 - fouling_factor) | |
if effective_u <= 0: | |
return "Invalid fouling factor or heat transfer coefficient!", "N/A" | |
area = duty_w / (effective_u * lmtd) | |
return round(area, 2), round(lmtd, 2) | |
except Exception as e: | |
return str(e), "N/A" | |
# Streamlit App | |
st.title("Shell-and-Tube Heat Exchanger Design") | |
st.write("Enter the design parameters to calculate the heat transfer area and LMTD.") | |
# Input fields | |
duty = st.number_input("Heat Duty (kW)", min_value=0.1, step=0.1) | |
t_hot_in = st.number_input("Hot Fluid Inlet Temperature (°C)", step=0.1) | |
t_hot_out = st.number_input("Hot Fluid Outlet Temperature (°C)", step=0.1) | |
t_cold_in = st.number_input("Cold Fluid Inlet Temperature (°C)", step=0.1) | |
t_cold_out = st.number_input("Cold Fluid Outlet Temperature (°C)", step=0.1) | |
overall_heat_transfer_coeff = st.number_input("Overall Heat Transfer Coefficient (W/m²°C)", min_value=1.0, step=0.1) | |
fouling_factor = st.number_input("Fouling Factor (m²°C/W)", min_value=0.0, max_value=1.0, step=0.01) | |
# Perform calculation on button click | |
if st.button("Calculate"): | |
area, lmtd = design_heat_exchanger( | |
duty, t_hot_in, t_hot_out, t_cold_in, t_cold_out, | |
overall_heat_transfer_coeff, fouling_factor | |
) | |
st.write("### Results") | |
st.write(f"**Heat Transfer Area:** {area} m²") | |
st.write(f"**Log Mean Temperature Difference:** {lmtd} °C") | |