Skip to content

Commit f36f448

Browse files
modified: source/solifluction.py to calculate viscosity as function of temperature
new file: pre_process/visocity_teperature_fit.py calculates A and B in the function of viscosity dependent on temperature
1 parent 9265845 commit f36f448

File tree

2 files changed

+76
-10
lines changed

2 files changed

+76
-10
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
from scipy.optimize import curve_fit
4+
5+
# Your data
6+
T_data = np.array([0, 5])
7+
mu_data = np.array([2e13, 2e11])
8+
9+
10+
# Initial guess for A=7.955 and B=0.479 ----> p0=(7.955, 0.479)
11+
# Define the model
12+
def viscosity_model(tpm, A, B):
13+
return A * np.exp(-abs(tpm) * B)
14+
15+
16+
# Fit it
17+
popt, pcov = curve_fit(viscosity_model, T_data, mu_data, p0=(2e13, 0.460))
18+
19+
A_fit, B_fit = popt
20+
print("mu = A exp(-T B)")
21+
print(f"Fitted A = {A_fit:.4e}")
22+
print(f"Fitted B = {B_fit:.4f}")
23+
24+
# Plot
25+
T_fit = np.linspace(T_data[0], T_data[-1], 100)
26+
mu_fit = viscosity_model(T_fit, A_fit, B_fit)
27+
28+
plt.plot(T_data, mu_data, "o", label="Data")
29+
plt.plot(T_fit, mu_fit, "-", label="Fit")
30+
plt.yscale("log")
31+
plt.xlabel("Temperature (°C)")
32+
plt.ylabel("Viscosity (Pa·s)")
33+
plt.legend()
34+
plt.show()

source/solifluction.py

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
)
2121
from source.momentum import momentum_ux
2222
from source.phase_detect import phase_detect_from_temperature
23+
from source.viscosity_calc import viscosity_exp_temp
2324
from source.vof import calculate_total_h, h_mesh_assign, mass_conservation_2D_vof
2425

2526
# from source.boundary_condition import boundary_set
@@ -209,21 +210,38 @@ def solifluction_simulate(
209210
# i,
210211
# )
211212

213+
# initial temperature assign (linear)
214+
215+
surface_temperature = temps_temperature_file[0]
216+
217+
surface_temperature_lue = lfr.create_array(
218+
array_shape,
219+
dtype=np.float64,
220+
fill_value=surface_temperature,
221+
partition_shape=partition_shape,
222+
)
223+
224+
layer_list[0].T = temperature_bed
225+
226+
for layer_id in range(1, num_layers):
227+
228+
layer_list[layer_id].T = (layer_id / num_layers) * surface_temperature_lue
229+
212230
if heat_transfer_warmup:
213231

214232
for _ in range(1, heat_transfer_warmup_iteration):
215233

216-
surface_temperature = temps_temperature_file[0]
234+
# surface_temperature = temps_temperature_file[0]
217235

218-
surface_temperature_lue = lfr.create_array(
219-
array_shape,
220-
dtype=np.float64,
221-
fill_value=surface_temperature,
222-
partition_shape=partition_shape,
223-
)
236+
# surface_temperature_lue = lfr.create_array(
237+
# array_shape,
238+
# dtype=np.float64,
239+
# fill_value=surface_temperature,
240+
# partition_shape=partition_shape,
241+
# )
224242

225-
layer_list[0].T = temperature_bed
226-
layer_list[num_layers - 1].T = surface_temperature_lue
243+
# layer_list[0].T = temperature_bed
244+
# layer_list[num_layers - 1].T = surface_temperature_lue
227245

228246
for layer_id in range(1, num_layers - 1):
229247

@@ -353,6 +371,13 @@ def solifluction_simulate(
353371

354372
for layer_id in range(1, num_layers):
355373

374+
# a, b: 2e13, 0.4605 (T_data = ([0, 5]), mu_data([2e13, 2e12]))
375+
# a, b: 2e13, 0.9210 (T_data = ([0, 5]), mu_data([2e13, 2e11]))
376+
377+
layer_list[layer_id].mu_soil = viscosity_exp_temp(
378+
layer_list[layer_id].T, 2e13, 0.9210
379+
)
380+
356381
gama_prim_surface: float = (2610 - 1000) * 9.81
357382

358383
rhs = (
@@ -370,7 +395,7 @@ def solifluction_simulate(
370395
)
371396
)
372397

373-
# NOTE: rhs cannot be negative as the flow cannot be to the upstream
398+
# NOTE: rhs cannot be negative as the fluid cannot flow to the upstream
374399
rhs = lfr.where(
375400
(rhs > 0),
376401
rhs,
@@ -525,6 +550,13 @@ def solifluction_simulate(
525550
layer_id,
526551
)
527552

553+
print(
554+
"layer_u_x_numpy[10,10] (cm/year)",
555+
layer_u_x_numpy[10, 10] * 3600 * 24 * 365 * 100,
556+
"layer_id",
557+
layer_id,
558+
)
559+
528560
for layer_id in range(0, num_layers):
529561

530562
layer_h_mesh_numpy = lfr.to_numpy(layer_list[layer_id].h_mesh)

0 commit comments

Comments
 (0)