Spaces:
Sleeping
Sleeping
Update calculation.py
Browse files- calculation.py +73 -44
calculation.py
CHANGED
@@ -1,44 +1,73 @@
|
|
1 |
-
import pandas as pd
|
2 |
-
import numpy as np
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
self.
|
8 |
-
self.
|
9 |
-
self.
|
10 |
-
self.
|
11 |
-
self.
|
12 |
-
self.
|
13 |
-
self.
|
14 |
-
self.
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
self.
|
20 |
-
self.
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
return
|
26 |
-
|
27 |
-
def
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
def
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import numpy as np
|
3 |
+
import math
|
4 |
+
|
5 |
+
class SteamPipe:
|
6 |
+
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):
|
7 |
+
self.steam_flow = steam_flow # kg/hr
|
8 |
+
self.inlet_pressure = inlet_pressure # kg/cm²g
|
9 |
+
self.superheat = superheat # °C
|
10 |
+
self.steam_temp = steam_temp # °C
|
11 |
+
self.line_size = float(line_size) * 0.0254 # Convert inch to meters (direct input, no lookup)
|
12 |
+
self.ambient_temp = ambient_temp # °C
|
13 |
+
self.ambient_velocity = ambient_velocity # m/s
|
14 |
+
self.insulation_material = insulation_material
|
15 |
+
self.cladding_material = cladding_material
|
16 |
+
|
17 |
+
self.insulation_data = insulation_data
|
18 |
+
self.cladding_data = cladding_data
|
19 |
+
self.steam_properties = steam_properties
|
20 |
+
self.user_insulation_thickness = user_insulation_thickness # User-defined insulation thickness
|
21 |
+
|
22 |
+
def get_nearest_upper_value(self, df, column, value):
|
23 |
+
"""Gets the nearest upper value from a given dataframe column."""
|
24 |
+
filtered_values = df[df[column] >= value]
|
25 |
+
return filtered_values[column].min() if not filtered_values.empty else df[column].max()
|
26 |
+
|
27 |
+
def get_steam_property(self):
|
28 |
+
"""Fetches steam property (enthalpy, specific heat, etc.) based on pressure."""
|
29 |
+
pressure = self.get_nearest_upper_value(self.steam_properties, 'Pressure', self.inlet_pressure)
|
30 |
+
row = self.steam_properties[self.steam_properties['Pressure'] == pressure]
|
31 |
+
if not row.empty:
|
32 |
+
return row.iloc[0]
|
33 |
+
else:
|
34 |
+
raise ValueError("Steam property not found for given pressure")
|
35 |
+
|
36 |
+
def calculate_heat_loss(self, insulation_thickness):
|
37 |
+
"""Calculates heat loss per unit length using Fourier’s Law for cylindrical surfaces."""
|
38 |
+
k_insulation = self.get_nearest_upper_value(self.insulation_data, 'Thermal Conductivity', 0)
|
39 |
+
|
40 |
+
r_inner = self.line_size / 2 # Inner radius (m)
|
41 |
+
r_outer = r_inner + insulation_thickness # Outer radius (m)
|
42 |
+
|
43 |
+
# Fourier’s Law for cylindrical coordinates
|
44 |
+
heat_loss = (2 * math.pi * (self.steam_temp - self.ambient_temp)) / (math.log(r_outer / r_inner) / k_insulation)
|
45 |
+
return heat_loss # W/m
|
46 |
+
|
47 |
+
def calculate_insulation_thickness(self):
|
48 |
+
"""Determines required insulation thickness to minimize heat loss, or uses user-defined value."""
|
49 |
+
if self.user_insulation_thickness is not None:
|
50 |
+
return self.user_insulation_thickness * 0.001 # Convert mm to meters
|
51 |
+
thickness = self.get_nearest_upper_value(self.insulation_data[self.insulation_data['Material'] == self.insulation_material], 'Thickness', 0)
|
52 |
+
return thickness * 0.001 # Convert mm to meters
|
53 |
+
|
54 |
+
def calculate_outlet_temperature(self, heat_loss):
|
55 |
+
"""Estimates outlet temperature based on heat loss."""
|
56 |
+
steam_property = self.get_steam_property()
|
57 |
+
specific_heat = steam_property['Specific Heat'] # J/kgK
|
58 |
+
mass_flow_rate = self.steam_flow / 3600 # Convert kg/hr to kg/s
|
59 |
+
delta_T = heat_loss / (mass_flow_rate * specific_heat)
|
60 |
+
return max(self.steam_temp - delta_T, self.ambient_temp)
|
61 |
+
|
62 |
+
def calculate(self):
|
63 |
+
insulation_thickness = self.calculate_insulation_thickness()
|
64 |
+
if np.isnan(insulation_thickness):
|
65 |
+
raise ValueError("Insulation thickness data not found.")
|
66 |
+
|
67 |
+
heat_loss = self.calculate_heat_loss(insulation_thickness)
|
68 |
+
outlet_temp = self.calculate_outlet_temperature(heat_loss)
|
69 |
+
|
70 |
+
return outlet_temp, insulation_thickness, heat_loss
|
71 |
+
|
72 |
+
|
73 |
+
|