Spaces:
Sleeping
Sleeping
import pandas as pd | |
import numpy as np | |
import math | |
class SteamPipe: | |
def __init__(self, steam_flow, inlet_pressure, superheat, steam_temp, line_size, ambient_temp, ambient_velocity, insulation_material, cladding_material, insulation_data, cladding_data, steam_properties, user_insulation_thickness=None): | |
self.steam_flow = steam_flow # kg/hr | |
self.inlet_pressure = inlet_pressure # kg/cm²g | |
self.superheat = superheat # °C | |
self.steam_temp = steam_temp # °C | |
self.line_size = float(line_size) * 0.0254 # Convert inch to meters (direct input, no lookup) | |
self.ambient_temp = ambient_temp # °C | |
self.ambient_velocity = ambient_velocity # m/s | |
self.insulation_material = insulation_material | |
self.cladding_material = cladding_material | |
self.insulation_data = insulation_data | |
self.cladding_data = cladding_data | |
self.steam_properties = steam_properties | |
self.user_insulation_thickness = user_insulation_thickness # User-defined insulation thickness | |
def get_nearest_upper_value(self, df, column, value): | |
"""Gets the nearest upper value from a given dataframe column.""" | |
filtered_values = df[df[column] >= value] | |
return filtered_values[column].min() if not filtered_values.empty else df[column].max() | |
def get_steam_property(self): | |
"""Fetches steam property (enthalpy, specific heat, etc.) based on pressure.""" | |
pressure = self.get_nearest_upper_value(self.steam_properties, 'Pressure', self.inlet_pressure) | |
row = self.steam_properties[self.steam_properties['Pressure'] == pressure] | |
if not row.empty: | |
return row.iloc[0] | |
else: | |
raise ValueError("Steam property not found for given pressure") | |
def calculate_heat_loss(self, insulation_thickness): | |
"""Calculates heat loss per unit length using Fourier’s Law for cylindrical surfaces.""" | |
k_insulation = self.get_nearest_upper_value(self.insulation_data, 'Thermal Conductivity', 0) | |
r_inner = self.line_size / 2 # Inner radius (m) | |
r_outer = r_inner + insulation_thickness # Outer radius (m) | |
# Fourier’s Law for cylindrical coordinates | |
heat_loss = (2 * math.pi * (self.steam_temp - self.ambient_temp)) / (math.log(r_outer / r_inner) / k_insulation) | |
return heat_loss # W/m | |
def calculate_insulation_thickness(self): | |
"""Determines required insulation thickness to minimize heat loss, or uses user-defined value.""" | |
if self.user_insulation_thickness is not None: | |
return self.user_insulation_thickness * 0.001 # Convert mm to meters | |
thickness = self.get_nearest_upper_value(self.insulation_data[self.insulation_data['Material'] == self.insulation_material], 'Thickness', 0) | |
return thickness * 0.001 # Convert mm to meters | |
def calculate_outlet_temperature(self, heat_loss): | |
"""Estimates outlet temperature based on heat loss.""" | |
steam_property = self.get_steam_property() | |
specific_heat = steam_property['Specific Heat'] # J/kgK | |
mass_flow_rate = self.steam_flow / 3600 # Convert kg/hr to kg/s | |
delta_T = heat_loss / (mass_flow_rate * specific_heat) | |
return max(self.steam_temp - delta_T, self.ambient_temp) | |
def calculate(self): | |
insulation_thickness = self.calculate_insulation_thickness() | |
if np.isnan(insulation_thickness): | |
raise ValueError("Insulation thickness data not found.") | |
heat_loss = self.calculate_heat_loss(insulation_thickness) | |
outlet_temp = self.calculate_outlet_temperature(heat_loss) | |
return outlet_temp, insulation_thickness, heat_loss | |