Skip to content

Commit 1db3543

Browse files
modified: run_simulation.py source/interpolation.py source/io_data_process.py source/momentum.py source/solifluction.py
heat_transfer does not work correct in the previous version as the surface temperature does not pass corectly from the file in time. It is revised in the current version.
1 parent 3275a65 commit 1db3543

File tree

5 files changed

+473
-834
lines changed

5 files changed

+473
-834
lines changed

run_simulation.py

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ def main() -> None:
5757
days_temperature_file,
5858
temps_temperature_file,
5959
results_pathname,
60-
g_sin,
60+
slope_radian,
6161
) = read_config_file(param_path)
6262

6363
# --------------------- initial information --------------------
6464

6565
dx, dz, array_shape, max_h_total = read_tif_info_from_gdal(
6666
h_total_initial_file_name
6767
)
68-
num_rows, num_cols = array_shape
68+
# num_rows, num_cols = array_shape
6969

7070
partition_shape: tuple[int, int] = 2 * (partition_shape_size,)
7171

@@ -81,36 +81,6 @@ def main() -> None:
8181

8282
# --------------------- initial information --------------------
8383

84-
# solifluction_simulate(
85-
# dx,
86-
# dz,
87-
# num_cols,
88-
# num_rows,
89-
# max_h_total,
90-
# bed_depth_elevation,
91-
# h_total_initial_file,
92-
# mu_value,
93-
# density_value,
94-
# k_conductivity_value,
95-
# rho_c_heat_value,
96-
# dt_momentum,
97-
# dt_mass_conservation,
98-
# dt_heat_transfer,
99-
# write_intervals_time,
100-
# momentum_iteration_threshold,
101-
# time_end_simulation,
102-
# heat_transfer_warmup,
103-
# heat_transfer_warmup_iteration,
104-
# h_mesh_step_value,
105-
# g_sin,
106-
# nu_x,
107-
# nu_z,
108-
# days_temperature_file,
109-
# temps_temperature_file,
110-
# partition_shape,
111-
# results_pathname,
112-
# )
113-
11484
solifluction(
11585
array_shape=array_shape,
11686
partition_shape=partition_shape,
@@ -133,7 +103,7 @@ def main() -> None:
133103
density_value=density_value,
134104
k_conductivity_value=k_conductivity_value,
135105
rho_c_heat_value=rho_c_heat_value,
136-
g_sin=g_sin,
106+
slope_radian=slope_radian,
137107
nu_x=nu_x,
138108
nu_z=nu_z,
139109
days_temperature_file=days_temperature_file,

source/interpolation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ def interpolate_temperature(
44
seconds_per_day = 86400
55
t_days = t_seconds / seconds_per_day
66

7+
# print("t_days: ", t_days)
8+
79
# handel the values out of input data boundaries
810
if t_days <= days[0]:
911
return temps[0]
@@ -12,7 +14,7 @@ def interpolate_temperature(
1214

1315
# linear interpolation
1416
for i in range(len(days) - 1):
15-
if days[i] <= t_days < days[i + 1]:
17+
if days[i] <= t_days <= days[i + 1]:
1618
temp_lower = temps[i]
1719
temp_upper = temps[i + 1]
1820
frac = (t_days - days[i]) / (days[i + 1] - days[i])

source/io_data_process.py

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def read_config_file(param_path: Path) -> tuple[
221221
list[float], # days_temperature_file
222222
list[float], # temps_temperature_file
223223
str, # results_pathname
224-
float, # g_sin
224+
float, # slope_radian
225225
]:
226226

227227
input_variables: ConfigParser = load_config(param_path)
@@ -292,7 +292,7 @@ def clean_int(val: str) -> int:
292292
raise ValueError(f"Missing results path: {err}") from err
293293

294294
slope_radian = clean_float(input_variables["simulation"]["alfa_slope"])
295-
g_sin = np.sin(slope_radian) * 9.81
295+
# g_sin = np.sin(slope_radian) * 9.81
296296

297297
return (
298298
number_of_iterations,
@@ -315,7 +315,7 @@ def clean_int(val: str) -> int:
315315
days_temperature_file,
316316
temps_temperature_file,
317317
results_pathname,
318-
g_sin,
318+
slope_radian,
319319
)
320320

321321

@@ -371,11 +371,16 @@ def initiate_layers_variables(
371371
print("initiate_initial_layers_variables is in run")
372372

373373
num_layers: int = int(
374-
np.ceil(max_h_total - bed_depth_elevation)
375-
/ h_mesh_step_value
374+
np.ceil((max_h_total - bed_depth_elevation) / h_mesh_step_value)
376375
# np.ceil(max_h_total - bed_depth_elevation) / h_mesh_step_value + 1
377376
)
378377

378+
print("max_h_total: ", max_h_total)
379+
print("h_mesh_step_value: ", h_mesh_step_value)
380+
print("bed_depth_elevation: ", bed_depth_elevation)
381+
382+
print("num_layers: ", num_layers)
383+
379384
h_total_initial = lfr.from_gdal(
380385
h_total_initial_file, partition_shape=partition_shape
381386
)
@@ -526,15 +531,39 @@ def write_tif_file(
526531
lfr.to_gdal(array, output_path)
527532

528533

529-
def save_tif_file(
530-
array: Any, output_file_name: str, time_label: float, output_folder_path: Path
531-
) -> None:
532-
"""Write a lue array to a .tif file using lfr.to_gdal."""
534+
# def save_tif_file(
535+
# array: Any, output_file_name: str, time_label: float, output_folder_path: Path
536+
# ) -> None:
537+
# """Write a lue array to a .tif file using lfr.to_gdal."""
533538

534-
os.makedirs(output_folder_path, exist_ok=True)
539+
# os.makedirs(output_folder_path, exist_ok=True)
535540

536-
output_path: str = os.path.join(
537-
output_folder_path, f"{output_file_name}-{time_label}.tif"
538-
)
541+
# output_path: str = os.path.join(
542+
# output_folder_path, f"{output_file_name}-{time_label}.tif"
543+
# )
539544

540-
lfr.to_gdal(array, output_path)
545+
# lfr.to_gdal(array, output_path)
546+
547+
548+
def save_u_x_tem_time(u_x_tem_time, filename="u_x_tem_time.csv") -> None:
549+
"""
550+
Save simulation results surface u_x and temperature in time to CSV file.
551+
552+
Parameters
553+
----------
554+
filename : str
555+
Output CSV file name.
556+
"""
557+
data = np.array(u_x_tem_time)
558+
559+
print("Data shape:", data.shape)
560+
print("Data type:", data.dtype)
561+
562+
np.savetxt(
563+
filename,
564+
data,
565+
delimiter=",",
566+
header="time,surface_temp,u_x_50_50",
567+
comments="",
568+
fmt="%.10e",
569+
)

source/momentum.py

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,201 @@ def momentum_ux(
399399
# )
400400

401401
return phi
402+
403+
404+
# def momentum_ux_steady_state(
405+
# phi: Any,
406+
# phase_state: Any,
407+
# dx: float,
408+
# dz: float,
409+
# lue_u_x: Any,
410+
# lue_u_z: Any,
411+
# nu_x: float,
412+
# nu_z: float,
413+
# rhs: Any,
414+
# h_mesh: Any,
415+
# boundary_loc: Any,
416+
# boundary_type: Any,
417+
# Dirichlet_boundary_value: Any, # noqa: N803
418+
# Neumann_boundary_value: Any, # noqa: N803
419+
# ) -> Any:
420+
421+
# # lue_u_x : phi
422+
# # lue_u_y : 0
423+
# # nu_x : +(mu_mesh/gama_soil_mesh)
424+
# # rhs_g_sin : g*sin(alfa)
425+
# # gama_prime_mesh: (gama_soil/cos(alfa))-(gama_water*cos(alfa))
426+
# # rhs : g*sin(alfa) - ((gama_soil/cos(alfa))-(gama_water*cos(alfa)))*dh/dx
427+
428+
# # kernel_i_j = np.array(
429+
# # [
430+
# # [0, 0, 0],
431+
# # [0, 1, 0],
432+
# # [0, 0, 0],
433+
# # ],
434+
# # dtype=np.uint8,
435+
# # )
436+
437+
# dt: float = 1
438+
439+
# # kernel_im1_j i-1, j
440+
# kernel_im1_j: NDArray[np.uint8] = np.array(
441+
# [
442+
# [0, 0, 0],
443+
# [1, 0, 0],
444+
# [0, 0, 0],
445+
# ],
446+
# dtype=np.uint8,
447+
# )
448+
449+
# """
450+
# # kernel_i_jm1 i, j-1
451+
# kernel_i_jm1 = np.array(
452+
# [
453+
# [0, 0, 0],
454+
# [0, 0, 0],
455+
# [0, 1, 0],
456+
# ],
457+
# dtype=np.uint8,
458+
# )
459+
# """
460+
461+
# # kernel_i_jm1 i, j-1
462+
# kernel_i_jm1: NDArray[np.uint8] = np.array(
463+
# [
464+
# [0, 1, 0],
465+
# [0, 0, 0],
466+
# [0, 0, 0],
467+
# ],
468+
# dtype=np.uint8,
469+
# )
470+
471+
# # kernel_ip1_j i+1, j
472+
# kernel_ip1_j: NDArray[np.uint8] = np.array(
473+
# [
474+
# [0, 0, 0],
475+
# [0, 0, 1],
476+
# [0, 0, 0],
477+
# ],
478+
# dtype=np.uint8,
479+
# )
480+
481+
# """
482+
# # kernel_i_jp1 i, j+1
483+
# kernel_i_jp1 = np.array(
484+
# [
485+
# [0, 1, 0],
486+
# [0, 0, 0],
487+
# [0, 0, 0],
488+
# ],
489+
# dtype=np.uint8,
490+
# )
491+
# """
492+
493+
# # kernel_i_jp1 i, j+1
494+
# kernel_i_jp1: NDArray[np.uint8] = np.array(
495+
# [
496+
# [0, 0, 0],
497+
# [0, 0, 0],
498+
# [0, 1, 0],
499+
# ],
500+
# dtype=np.uint8,
501+
# )
502+
503+
# # coeff_map_i_j = (
504+
# # 1
505+
# # + (-(dt / dx) * lfr.abs(lue_u_x))
506+
# # + (-(dt / dy) * lfr.abs(lue_u_y))
507+
# # + (2 * (dt / (dx**2)) * nu_x)
508+
# # + (2 * (dt / (dy**2)) * nu_y)
509+
# # )
510+
511+
# # coeff_map_i_j: Any = (
512+
# # # 1 # check this # This term is omitted since ∂u/∂t = 0 in the steady-state case
513+
# # +(-(dt / dx) * lfr.abs(lue_u_x))
514+
# # + (-(dt / dz) * lfr.abs(lue_u_z))
515+
# # + (2 * (dt / (dx**2)) * nu_x)
516+
# # + (2 * (dt / (dz**2)) * nu_z)
517+
# # )
518+
519+
# coeff_map_i_j: Any = (
520+
# (-(dt / dx) * lfr.abs(lue_u_x))
521+
# + (-(dt / dz) * lfr.abs(lue_u_z))
522+
# + (2 * (dt / (dx**2)) * nu_x)
523+
# + (2 * (dt / (dz**2)) * nu_z)
524+
# )
525+
526+
# coeff_map_im1_j: Any = lfr.where(
527+
# lue_u_x >= 0,
528+
# ((dt / dx) * lfr.abs(lue_u_x)) + (-(dt / (dx**2)) * nu_x),
529+
# (-(dt / (dx**2)) * nu_x),
530+
# )
531+
532+
# coeff_map_ip1_j: Any = lfr.where(
533+
# lue_u_x < 0,
534+
# ((dt / dx) * lfr.abs(lue_u_x)) + (-(dt / (dx**2)) * nu_x),
535+
# (-(dt / (dx**2)) * nu_x),
536+
# )
537+
538+
# coeff_map_i_jm1: Any = lfr.where(
539+
# lue_u_z >= 0,
540+
# ((dt / dz) * lfr.abs(lue_u_z)) + (-(dt / (dz**2)) * nu_z),
541+
# (-(dt / (dz**2)) * nu_z),
542+
# )
543+
544+
# coeff_map_i_jp1: Any = lfr.where(
545+
# lue_u_z < 0,
546+
# ((dt / dz) * lfr.abs(lue_u_z)) + (-(dt / (dz**2)) * nu_z),
547+
# (-(dt / (dz**2)) * nu_z),
548+
# )
549+
550+
# # NOTE: coeff_<.> should be implemented on boundaries, for instance on boundary_tpe
551+
# # 1 (left boundary) phi_i-1,j is located outside of domain and we need
552+
# # forward discretization
553+
# # For now this implementation is ignored as we impose certain boundary conditions
554+
# # on the boundaries which overwrite phi on the boundaries but in the future
555+
# # this should be considered and for each boundary use exclusive discretization
556+
557+
# phi_all_internal_domain_i_j: Any = -(
558+
# (coeff_map_i_j * phi) # (coeff_map_i_j * lfr.focal_sum(solution, kernel_i_j))
559+
# + (coeff_map_im1_j * lfr.focal_sum(phi, kernel_im1_j))
560+
# + (coeff_map_i_jm1 * lfr.focal_sum(phi, kernel_i_jm1))
561+
# + (coeff_map_ip1_j * lfr.focal_sum(phi, kernel_ip1_j))
562+
# + (coeff_map_i_jp1 * lfr.focal_sum(phi, kernel_i_jp1))
563+
# + (dt * rhs)
564+
# )
565+
566+
# # phase_state: 0 solid --> (frozen soil), 1 --> (fluid or unfrozen), now vegetation
567+
# # is ignored in phase_state but it is considered in vegetation_vol_fraction
568+
569+
# phi_internal: Any = lfr.where(
570+
# (phase_state != 0) & (h_mesh > 0), # fluid or unfrozen
571+
# phi_all_internal_domain_i_j,
572+
# 0,
573+
# )
574+
575+
# phi = boundary_set(
576+
# phi_internal,
577+
# boundary_loc,
578+
# boundary_type,
579+
# Dirichlet_boundary_value,
580+
# Neumann_boundary_value,
581+
# dx,
582+
# dz,
583+
# )
584+
585+
# # ----------------
586+
587+
# # phi_u_x_numpy = lfr.to_numpy(phi)
588+
# # print(
589+
# # "inside momentum_ux function phi_u_x_numpy[10,10]",
590+
# # phi_u_x_numpy[10, 10],
591+
# # )
592+
593+
# # rhs_numpy = lfr.to_numpy(rhs)
594+
# # print(
595+
# # "inside momentum_ux function rhs_numpy[10,10]",
596+
# # rhs_numpy[10, 10],
597+
# # )
598+
599+
# return phi

0 commit comments

Comments
 (0)