-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
134 lines (111 loc) · 3.46 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['text.usetex'] = True
plt.rcParams['font.family'] = 'serif'
plt.rcParams["font.size"] = 12
def calculate_cfl(DX, DT, heat_cond_coeff):
return DT * heat_cond_coeff / (DX**2)
def plot_heatmap(trj, Lt,Lx):
plt.figure(figsize=(22, 5))
plt.imshow(
trj.T,
cmap="hot",
aspect="auto",
origin="lower",
extent=(0, Lt, -Lx/2, Lx/2),
)
plt.colorbar()
plt.xlabel("Time")
plt.ylabel("Space")
plt.title("Temperature")
plt.show()
def plot_ref_and_test_heatmap(trj_ref,trj_test,Lt,Lx,x,test_case):
Tmax = np.max([trj_ref,trj_test])
Tmin = np.min([trj_ref,trj_test])
fig, axes = plt.subplots(1,2,figsize=(22, 5),layout = "compressed")
fig.suptitle(f"Temperature for {test_case} Source")
axes[0].imshow(
trj_ref.T,
cmap="hot",
aspect="auto",
origin="lower",
extent=(0, Lt, -Lx/2, Lx/2),
vmin = Tmin,
vmax = Tmax
)
axes[0].set_title("Reference solution")
axes[0].set_xlabel("Time")
axes[0].set_ylabel("Space")
im = axes[1].imshow(
trj_test.T,
cmap="hot",
aspect="auto",
origin="lower",
extent=(0, Lt, -Lx/2, Lx/2),
vmin = Tmin,
vmax = Tmax
)
axes[1].set_title("Test solution")
axes[1].set_xlabel("Time")
axes[1].set_ylabel("Space")
fig.colorbar(im, ax=axes.ravel().tolist())
plt.show()
return fig
def plot_ref__initial_and_test_heatmap(trj_ref,trj_ini,trj_test,Lt,Lx,x,test_case):
Tmax = np.max([trj_ref,trj_ini,trj_test])
Tmin = np.min([trj_ref,trj_ini,trj_test])
fig, axes = plt.subplots(1,3,figsize=(22, 5),layout = "compressed")
fig.suptitle(f"Heat source for {test_case} Source")
axes[0].imshow(
trj_ref.T,
cmap="hot",
aspect="auto",
origin="lower",
extent=(0, Lt, -Lx/2, Lx/2),
vmin = Tmin,
vmax = Tmax
)
axes[0].set_title("Reference solution")
axes[0].set_xlabel("Time")
axes[0].set_ylabel("Space")
axes[1].imshow(
trj_ini.T,
cmap="hot",
aspect="auto",
origin="lower",
extent=(0, Lt, -Lx/2, Lx/2),
vmin = Tmin,
vmax = Tmax,
)
axes[1].set_title("Initial guess")
axes[1].set_xlabel("Time")
axes[1].set_ylabel("Space")
im = axes[2].imshow(
trj_test.T,
cmap="hot",
aspect="auto",
origin="lower",
extent=(0, Lt, -Lx/2, Lx/2),
vmin = Tmin,
vmax = Tmax,
)
axes[2].set_title("Test solution")
axes[2].set_xlabel("Time")
axes[2].set_ylabel("Space")
fig.colorbar(im, ax=axes.ravel().tolist())
plt.show()
return fig
def plot_diffusivity(ref_diffusivity, initial_diffusivity, test_diffusivity, x, sensor_positions):
ymax = 1.1*np.max([np.max(ref_diffusivity),np.max(test_diffusivity),np.max(initial_diffusivity)])
ymin = 0.9*np.min([np.min(ref_diffusivity),np.min(test_diffusivity),np.min(initial_diffusivity)])
plt.figure(figsize=(20, 5))
plt.plot(x, ref_diffusivity, label="Reference")
plt.plot(x, initial_diffusivity,label="Initial")
plt.plot(x, test_diffusivity, label="Test")
plt.legend()
plt.xlabel("Space")
plt.ylabel("Diffusivity")
plt.ylim([ymin,ymax])
plt.xlim([np.min(x),np.max(x)])
#plt.vlines(sensor_positions, ymin=ymin, ymax=ymax, color="black", linestyles="dashed")
plt.show()