Skip to content

Commit b92824f

Browse files
authored
Merge pull request #20 from mdidomiz/main
cleanup and prep for release 1.0
2 parents 4cf8538 + 9d037cc commit b92824f

7 files changed

Lines changed: 41 additions & 43 deletions

File tree

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# Editor directories and files
22
.vscode/*
33
.venv/*
4-
*.DS_Store
4+
.DS_Store
55

66
# Logs
77
*.log
8-
9-
.DS_Store

MANUAL.pdf

-693 Bytes
Binary file not shown.

Scripts/.DS_Store

-6 KB
Binary file not shown.

Scripts/2D_IHT_validation.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,29 @@
33
from scipy.integrate import solve_ivp
44

55
# Constants
6-
stefan_boltzmann_constant = 5.67e-8
7-
initial_temperature = 293 # make sure it is in kelvins
8-
k_steel = 45 # Thermal conductivity of steel in W/mK
6+
stefan_boltzmann_constant = 5.67e-8 # (W/m^2K^4)
7+
initial_temperature = 293 # Initial temperature of the plate sensor (K)
98

109
# User-defined variables
11-
emission_time = 20 * 60 # 1 minute in seconds
12-
wall_thickness = 0.001
13-
element_width = 0.05
14-
element_height = 0.10
15-
emissivity = 0.94
16-
steel_density = 8050
17-
cp_steel = 490
18-
convective_hfc_exposed = 10
19-
convective_hfc_unexposed = 8
20-
#Initializing grid heat flux for the forward model
10+
emission_time = 20 * 60 # Exposure time (s)
11+
wall_thickness = 0.001 # Thickness of the plate sensor (m)
12+
element_width = 0.05 # Size of a discrete element in the x dimension (m)
13+
element_height = 0.10 # Size of a discrete element in the y dimension (m)
14+
emissivity = 0.94 # Emissivity of the plate sensor
15+
steel_density = 8050 # Density of the plate sensor material (kg/m^3)
16+
cp_steel = 490 # Specific heat capacity of the plate sensor material (J/kgK)
17+
k_steel = 45 # Thermal conductivity of the plate sensor material (W/mK)
18+
convective_hfc_exposed = 10 # Convective heat transfer coefficient on the exposed side of the plate sensor (W/m^2K)
19+
convective_hfc_unexposed = 8 # Convective heat transfer coefficient on the unexposed side of the plate sensor (W/m^2K)
20+
21+
# Initializing grid heat flux for the forward model
2122
grid_size = 3 # 3x3 grid --> the simplest 2D case possible
2223
central_heat_flux = 50000 # Central cell
23-
surrounding_heat_flux = 10000 # neighboring cells
24+
surrounding_heat_flux = 10000 # neighboring cells
2425
heat_flux_grid = np.full((grid_size, grid_size), surrounding_heat_flux)
2526
heat_flux_grid[1, 1] = central_heat_flux # Set central cell heat flux
2627

27-
# energy blance for the 2D grid
28+
# Apply conservation of energy over the 2D grid
2829
def energy_balance_2d(t, T_flat):
2930
T = T_flat.reshape((grid_size, grid_size))
3031
dTdt = np.zeros_like(T)
@@ -47,7 +48,7 @@ def energy_balance_2d(t, T_flat):
4748
q_conv_exp = convective_hfc_exposed * area * (T[i, j] - initial_temperature)
4849
q_conv_unexp = convective_hfc_unexposed * area * (T[i, j] - initial_temperature)
4950
q_rad = 2*emissivity * stefan_boltzmann_constant * area * (T[i, j]**4 - initial_temperature**4)
50-
print(q_cond)
51+
# print(q_cond)
5152
# Energy balance
5253
dTdt[i, j] = (emissivity * q_in - q_conv_exp - q_conv_unexp - q_rad + q_cond) / (area * cp_steel * steel_density * wall_thickness)
5354

@@ -61,14 +62,15 @@ def energy_balance_2d(t, T_flat):
6162

6263
# Generate time steps
6364
t_eval = np.linspace(t_span[0], t_span[1],6000) # Creates an array from 0 to emission_time with a specified time step
64-
print(t_eval)
65+
# print(t_eval)
66+
6567
# Solve the 2D differential equation with specified time steps
6668
solution = solve_ivp(energy_balance_2d, t_span, T0_flat, method='RK45', t_eval=t_eval, dense_output=True)
67-
6869
num_time_steps = len(solution.t)
69-
print((solution.y).shape)
70+
# print((solution.y).shape)
7071
T_values_2d = solution.y.reshape((grid_size, grid_size, num_time_steps))
71-
print(T_values_2d.shape)
72+
# print(T_values_2d.shape)
73+
7274
# Plotting temperature distribution over time
7375
fig , ((ax1, ax2, ax3), (ax4, ax5, ax6), (ax7, ax8, ax9)) = plt.subplots(nrows=3, ncols=3, figsize=(14, 8) )
7476
axes = [ax1, ax2, ax3, ax4, ax5, ax6, ax7, ax8, ax9]
@@ -90,7 +92,7 @@ def energy_balance_2d(t, T_flat):
9092
# IHT Model Function
9193
def inverse_heat_transfer(T_values_2d, solution, k_steel, cp_steel, steel_density, element_width, element_height, wall_thickness, convective_hfc_exposed, convective_hfc_unexposed, emissivity):
9294
num_time_steps = T_values_2d.shape[2]
93-
print(num_time_steps)
95+
# print(num_time_steps)
9496
estimated_flux = np.zeros((grid_size, grid_size, num_time_steps))
9597

9698
temp_grad = np.gradient(T_values_2d, axis=2) / np.gradient(solution.t)
@@ -112,7 +114,6 @@ def inverse_heat_transfer(T_values_2d, solution, k_steel, cp_steel, steel_densit
112114
q_cond = np.sum(grad_T) * wall_thickness
113115
q_conv = (convective_hfc_exposed + convective_hfc_unexposed) * area * (T_values_2d[i, j, time_step] - initial_temperature)
114116
q_rad = 2*emissivity * stefan_boltzmann_constant * area * (T_values_2d[i, j, time_step]**4 - initial_temperature**4)
115-
116117
q_storage = cp_steel * steel_density * area * wall_thickness * temp_grad[i, j, time_step]
117118

118119
# Calculate the estimated incident heat flux
@@ -145,6 +146,6 @@ def inverse_heat_transfer(T_values_2d, solution, k_steel, cp_steel, steel_densit
145146
axx.legend(loc='upper right')
146147
# ax.grid(True)
147148
k += 1
148-
print(T_values_2d[1, 1, :])
149+
# print(T_values_2d[1, 1, :])
149150
plt.tight_layout()
150151
plt.show()

Scripts/IHT.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def k_gas(T_g):
4444
def k_metal(T_g):
4545
global global_state
4646
metal = global_state["wall material"].get()
47-
# from engineeringtoolbox.com
4847
if metal == 'steel (FSRI)':
4948
k_metal = (-3.38759644163437 * 10**(-6) * T_g**2) + 0.017732749 + 13.6405477360128
5049
elif metal == 'steel (Engineering Toolbox)':
@@ -54,11 +53,11 @@ def k_metal(T_g):
5453
elif metal == 'copper':
5554
k_metal = -47.15 * np.log(T_g) + 674.98
5655
else:
57-
print('Error: Metal is not in the list.')
56+
print('Selected material is invalid, default values assumed.')
57+
k_metal = 45
5858
return k_metal
5959

6060
def cp_metal(T_g):
61-
# from engineeringtoolbox.com
6261
global global_state
6362
metal = global_state["wall material"].get()
6463
if metal == 'steel (FSRI)':
@@ -70,11 +69,11 @@ def cp_metal(T_g):
7069
elif metal == 'copper':
7170
cp_metal = 0.0779 * np.log(T_g) - 0.0712
7271
else:
73-
print('Error: Metal is not in the list.')
72+
print('Selected material is invalid, default values assumed.')
73+
cp_metal = 490
7474
return 1000*cp_metal
7575

7676
def rho_metal(T_g):
77-
# from engineeringtoolbox.com
7877
global global_state
7978
metal = global_state["wall material"].get()
8079
if metal == 'steel (FSRI)':
@@ -86,7 +85,8 @@ def rho_metal(T_g):
8685
elif metal == 'copper':
8786
rho_metal = -0.5124*np.log(T_g) + 9075.6
8887
else:
89-
print('Error: Metal is not in the list.')
88+
print('Selected material is invalid, default values assumed.')
89+
rho_metal = 8050
9090
return rho_metal
9191

9292
def Grashof(dT_w, T_film, T_amb):
@@ -102,7 +102,6 @@ def calculate_gradients(T_values_2d, i, j, element_width, element_height, use_hi
102102
grad_T = np.zeros(2) # [grad_T_x, grad_T_y]
103103

104104
if use_higher_order:
105-
# Higher order discretization using numpy's gradient
106105
grad_y, grad_x = np.gradient(T_values_2d, axis=(0, 1))
107106
grad_T[0] = grad_y[i, j] * element_height / element_width
108107
grad_T[1] = grad_x[i, j] * element_width / element_height
@@ -121,9 +120,9 @@ def inverse_heat_transfer(time_series_data, element_width, element_height, time_
121120

122121
if global_state["temperature_unit_var"].get() == "Celsius":
123122
time_series_data += 273.15
124-
print('Temperature unit is set to Kelvin')
123+
print('Temperature unit will be converted from Celsius to Kelvin.')
125124
else:
126-
print('Temperature unit was already set to Kelvin')
125+
print('Temperature unit was set to Kelvin, no conversion needed.')
127126
rows, cols, num_time_steps = time_series_data.shape
128127
estimated_flux = np.zeros(time_series_data.shape)
129128
hfc = np.zeros(time_series_data.shape)
@@ -243,7 +242,7 @@ def Tfilm_interp(width , height , nt):
243242
grid_z.append(griddata(points, values, (grid_x, grid_y), method='nearest'))
244243
# Check the shape to confirm it matches the custom resolution
245244
output = np.stack(grid_z , axis = 2)
246-
print("Interpolated film temperature grid shape:", output.shape, output)
245+
print("Interpolated film temperature grid shape: ", output.shape, output)
247246
return(output)
248247

249248
def check_h5py_files(folder):
@@ -379,7 +378,7 @@ def process_directory_and_plot(source_dir, dest_dir, element_width, element_heig
379378
h5py_Tf.close()
380379
h5py_T0.close()
381380

382-
print("All files are processed and saved in the destination folder.")
381+
print("All files have been processed and saved in the destination folder.")
383382

384383
def apply_inverse_model():
385384
global global_state, DEFAULTS
@@ -514,7 +513,7 @@ def load_data_frames(folder, file_type, file_name = "", batch_start=None, batch_
514513
selected_files = files[batch_start:batch_end]
515514
else:
516515
selected_files = files
517-
return [pd.read_csv(file, header=None) for file in tqdm(selected_files, desc = "Loading dataframes for video generation ")]
516+
return [pd.read_csv(file, header=None) for file in tqdm(selected_files, desc = "Loading dataframes for video generation: ")]
518517

519518
def create_video(source_folder, dest_folder, source_file_type, dest_file_type,global_max_source, global_max_dest, Time_Step_Size_s, batch_size):
520519
# Determine the total number of frames based on file type and content
@@ -523,7 +522,7 @@ def create_video(source_folder, dest_folder, source_file_type, dest_file_type,gl
523522
if source_h5py_path:
524523
with h5py.File(source_h5py_path, 'r') as h5_file:
525524
total_frames = len(h5_file.keys())
526-
print(f"Total frames : {total_frames}")
525+
print(f"Total frames: {total_frames}")
527526

528527
else:
529528
total_frames = max(len(glob.glob(os.path.join(source_folder, '*.csv'))),

Scripts/Image_processing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,15 @@ def update_h5py_size_entry_state(self):
247247

248248
def select_source_folder(self):
249249
self.source_folder = filedialog.askdirectory()
250-
print("Selected Source Folder:", self.source_folder)
250+
print("Selected Source Folder: ", self.source_folder)
251251

252252
def select_dest_folder(self):
253253
self.dest_folder = filedialog.askdirectory()
254-
print("Selected Destination Folder:", self.dest_folder)
254+
print("Selected Destination Folder: ", self.dest_folder)
255255

256256
def select_Folder_for_Time_Array(self):
257257
self.Time_Array_folder = filedialog.askdirectory()
258-
print("Selected Time Array Folder:", self.Time_Array_folder)
258+
print("Selected Time Array Folder: ", self.Time_Array_folder)
259259

260260
def assemble_time_array(self):
261261
time_row = 3
@@ -291,7 +291,7 @@ def assemble_time_array(self):
291291

292292
def select_csv_file(self):
293293
self.csv_file = filedialog.askopenfilename(filetypes=[("CSV files", "*.csv")])
294-
print("Selected sample CSV File:", self.csv_file)
294+
print("Selected sample CSV File: ", self.csv_file)
295295

296296
def process_images(self):
297297
if self.source_folder and self.dest_folder and self.csv_file:

Scripts/Metal_properties.xlsx

46 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)