Shivraj8615 commited on
Commit
87d8d0b
·
verified ·
1 Parent(s): 0da3d3c

Update calculation.py

Browse files
Files changed (1) hide show
  1. calculation.py +73 -44
calculation.py CHANGED
@@ -1,44 +1,73 @@
1
- import pandas as pd
2
- import numpy as np
3
-
4
- class SteamPipe:
5
- def __init__(self, steam_flow, inlet_pressure, superheat, steam_temp, line_size, ambient_temp, ambient_velocity, insulation_material, cladding_material):
6
- self.steam_flow = steam_flow
7
- self.inlet_pressure = inlet_pressure
8
- self.superheat = superheat
9
- self.steam_temp = steam_temp
10
- self.line_size = float(line_size)
11
- self.ambient_temp = ambient_temp
12
- self.ambient_velocity = ambient_velocity
13
- self.insulation_material = insulation_material
14
- self.cladding_material = cladding_material
15
-
16
- self.load_data()
17
-
18
- def load_data(self):
19
- self.insulation_data = pd.read_csv("insulation_data.csv")
20
- self.cladding_data = pd.read_csv("cladding_data.csv")
21
- self.steam_properties = pd.read_csv("steam_properties.csv")
22
-
23
- def calculate_heat_loss(self):
24
- # Placeholder heat loss calculation (to be replaced with actual formula)
25
- return np.random.uniform(50, 200) # Example random value
26
-
27
- def calculate_insulation_thickness(self):
28
- # Placeholder insulation thickness calculation
29
- return np.random.uniform(10, 100) # Example random value
30
-
31
- def calculate_outlet_temperature(self, heat_loss):
32
- # Placeholder outlet temperature calculation
33
- delta_T = heat_loss * 0.01 # Example coefficient
34
- return max(self.steam_temp - delta_T, self.ambient_temp)
35
-
36
- def calculate(self):
37
- heat_loss = self.calculate_heat_loss()
38
- required_thickness = self.calculate_insulation_thickness()
39
- outlet_temp = self.calculate_outlet_temperature(heat_loss)
40
-
41
- return outlet_temp, required_thickness, heat_loss
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
+