10from scipy.optimize
import fmin
11import matplotlib.pyplot
as plt
19from scipy.optimize
import minimize
26def Serial_Computation(P, Num_Elements, Num_Modes, N_P, N_V_1, N_V_2, N_V_3, Num_Constants, constants, Scheme):
29 O_A_1 = 9 * Num_Elements * (P + 1) ** 2 * Num_Modes * m.log(Num_Modes, 2)
30 O_A_2 = Num_Elements * Num_Modes * (P + 1) ** 2
31 O_A_3 = 6 * Num_Elements * (P + 1) ** 4 * Num_Modes
32 O_A_4 = 15 * Num_Elements * (P + 1) ** 2 * Num_Modes
34 T_A = O_A_1 + O_A_2 + O_A_3 + O_A_4
36 if (Scheme ==
'IterativeFull'):
37 O_E_1 = 8 * Num_Elements * (P + 1) ** 2
38 O_E_2 = Num_Elements * (P + 1) ** 2
39 O_E_3 = Num_Elements * ((4 * P ** 3) + (18 * P ** 2) + (26 * P) + 12)
40 O_E_4 = 6 * Num_Elements * (P + 1) ** 2
42 t_e = O_E_1 + O_E_2 + O_E_3 + O_E_4
44 T_E = (N_P + N_V_1 + N_V_2 + N_V_3) * t_e
46 if (Scheme ==
'IterativeStaticCond'):
47 O_E_1 = 8 * ((P - 1) ** 2) * 4 * P * Num_Elements * Num_Modes
48 O_E_2 = (N_P + N_V_1 + N_V_2 + N_V_3) * 2 * 16 * (P ** 2) * Num_Elements
49 O_E_3 = (8 * 4 * ((P - 1) ** 2)) + (4 * ((P - 1) ** 2)) * Num_Elements * Num_Modes
50 O_E_4 = 8 * ((((P - 1) ** 2)) ** 2) * Num_Elements * Num_Modes
52 T_E = O_E_1 + O_E_2 + O_E_3 + O_E_4
56 if (Num_Constants == 1):
60 if (Num_Constants == 2):
61 T_A = T_A / constants[0]
62 T_E = T_E / constants[1]
75 O_A_1 = 9 * Num_Elements * (P + 1) ** 2 * Num_Modes * m.log(Num_Modes, 2)
76 O_A_2 = Num_Elements * Num_Modes * (P + 1) ** 2
77 O_A_3 = 6 * Num_Elements * (P + 1) ** 4 * Num_Modes
78 O_A_4 = 15 * Num_Elements * (P + 1) ** 2 * Num_Modes
80 T_A = O_A_1 + O_A_2 + O_A_3 + O_A_4
82 if (Scheme ==
'IterativeFull'):
83 O_E_1 = 8 * Num_Elements * (P + 1) ** 2
84 O_E_2 = Num_Elements * (P + 1) ** 2
85 O_E_3 = Num_Elements * ((4 * P ** 3) + (18 * P ** 2) + (26 * P) + 12)
86 O_E_4 = 6 * Num_Elements * (P + 1) ** 2
88 t_e = O_E_1 + O_E_2 + O_E_3 + O_E_4
90 T_E = (N_P + N_V_1 + N_V_2 + N_V_3) * t_e
92 if (Scheme ==
'IterativeStaticCond'):
93 O_E_1 = 8 * ((P - 1) ** 2) * 4 * P * Num_Elements * Num_Modes
94 O_E_2 = (N_P + N_V_1 + N_V_2 + N_V_3) * 2 * 16 * (P ** 2) * Num_Elements
95 O_E_3 = (8 * 4 * ((P - 1) ** 2)) + (4 * ((P - 1) ** 2)) * Num_Elements * Num_Modes
96 O_E_4 = 8 * ((((P - 1) ** 2)) ** 2) * Num_Elements * Num_Modes
98 T_E = O_E_1 + O_E_2 + O_E_3 + O_E_4
113 for i
in range(0, len(Data)):
115 if (Num_Constants == 1):
116 lemons.append(Data[i] - (T_A[i] + T_E[i])/constants)
118 if (Num_Constants == 2):
119 lemons.append(Data[i] - (T_A[i] / constants[0] + T_E[i] / constants[1]))
122 L_2_norm = np.linalg.norm(lemons, 2)
134 Data = np.array(Data)
139 if (Num_Constants == 1):
142 if (Num_Constants == 2):
143 inital = np.array([1e6, 1e06])
146 Fit = fmin(compare_data, inital, args=(Num_Constants, Data, T_A, T_E), xtol=0.0001, ftol=1, maxiter=1e04, maxfun=1e09)
156def Run_Serial_Fit(Compare_Serial, Consider_Modes, Num_Constants, P, Num_Elements, Nektar_Modes, Timings, Pressure, Velocity_1, Velocity_2, Velocity_3, Scheme):
162 for i
in range(0, len(Consider_Modes)):
163 Data.append(np.mean(Timings[str(Consider_Modes[i])])/10)
170 for i
in range(0, len(Consider_Modes)):
179 for j
in range(1, Consider_Modes[i] + 1):
188 N_P += Pressure[str(j)][0]
190 Turing =
'King of Computers'
193 N_V_1 += Velocity_1[str(j)][0]
195 Turing =
'King of Computers'
198 N_V_2 += Velocity_2[str(j)][0]
200 Turing =
'King of Computers'
203 N_V_3 += Velocity_3[str(j)][0]
205 Turing =
'King of Computers'
208 (t_a, t_e) =
Operation_Count(P, Num_Elements, Consider_Modes[i], N_P, N_V_1, N_V_2, N_V_3, Scheme)
213 Fit =
Fit_Model(Num_Constants, Data, T_A, T_E)
219 if Compare_Serial
is True:
224 for i
in range(1, len(Nektar_Modes)):
225 Data.append(np.mean(Timings[str(Nektar_Modes[i])])/10)
229 for i
in range(1, len(Nektar_Modes)):
235 for j
in range(1, Nektar_Modes[i] + 1):
241 N_P += Pressure[str(j)][0]
243 Turing =
'King of Computers'
246 N_V_1 += Velocity_1[str(j)][0]
248 Turing =
'King of Computers'
251 N_V_2 += Velocity_2[str(j)][0]
253 Turing =
'King of Computers'
256 N_V_3 += Velocity_3[str(j)][0]
258 Turing =
'King of Computers'
260 Time.append(
Serial_Computation(P, Num_Elements, Nektar_Modes[i], N_P, N_V_1, N_V_2, N_V_3, Num_Constants, Fit, Scheme))
262 Nektar_Modes = list(Nektar_Modes)
268 for i
in range(0, len(Nektar_Modes)):
269 difference.append(
abs(Data[i] - Time[i]))
271 mean_diff = np.mean(difference)
272 std_dev_diff = np.std(difference)
273 var_diff = np.var(difference)
276 print(
'The mean of the differences between the Data and the Model is ' + str(mean_diff))
277 print(
'The standard deviation of the differences between the Data and the Model is ' + str(std_dev_diff))
278 print(
'The variance of the differences between the Data and the Model is ' + str(var_diff))
281 fig, ax = plt.subplots()
282 ax.plot(Nektar_Modes, Data, label =
'Data')
283 ax.errorbar(Nektar_Modes, Time, label =
'Model')
284 ax.set_xlabel(
'$ N_Z $')
285 ax.set_ylabel(
'Timestep (s)')
286 ax.set_title(
'Length of Single Timestep: Model vs Data')
288 fig.savefig(
"Output/Figures/Model_vs_Data.png")
def Fit_Model(Num_Constants, Data, T_A, T_E)
def Run_Serial_Fit(Compare_Serial, Consider_Modes, Num_Constants, P, Num_Elements, Nektar_Modes, Timings, Pressure, Velocity_1, Velocity_2, Velocity_3, Scheme)
def Serial_Computation(P, Num_Elements, Num_Modes, N_P, N_V_1, N_V_2, N_V_3, Num_Constants, constants, Scheme)
def Operation_Count(P, Num_Elements, Num_Modes, N_P, N_V_1, N_V_2, N_V_3, Scheme)
def compare_data(constants, Num_Constants, Data, T_A, T_E)
scalarT< T > abs(scalarT< T > in)