2Plot residual norm vs number of DG iterations for DG solver
7import matplotlib.pyplot
as plt
13with open(
'out.txt',
'r')
as file:
14 lines = file.readlines()
19 match = re.search(
r'h_min=([\d.]+)', line)
21 n_mesh = round(1.0/float(match.group(1)))
22 print(f
"Mesh size detected: {n_mesh}x{n_mesh}")
25 print(
"Mesh size not detected")
28for i
in range(len(lines)):
29 if "run Solve" in lines[i]:
31 next_line = lines[i + 1]
32 pattern =
r"([-+]?\d*\.?\d+(?:e[-+]?\d+)?)"
33 full_pattern = rf
"\|r\|\_max={pattern},\s*\|r\|\_2={pattern},\s*\|r\|\_h={pattern}"
34 norms = re.search(full_pattern, next_line)
36 r_max, r_2, r_h = map(float, norms.groups())
37 res_norm.append([r_max, r_2, r_h])
39res_norm_array = np.array(res_norm)
41degree = input(
"Enter polynomial degree: ")
44plt.plot(res_norm_array[:,0], label=
'r_max', marker=
'o')
45plt.plot(res_norm_array[:,1], label=
'r_2', marker=
'o')
47plt.xlabel(
'DG iterations')
51res_norm_stable = np.load(f
"../../../../../PeanoData/res_norm_dg_mesh_{n_mesh}_p_{degree}_STABLE.npy")
52plt.plot(res_norm_stable[:,0], label=
'r_max stable', marker=
'x')
53plt.plot(res_norm_stable[:,1], label=
'r_2 stable', marker=
'x')
58dir =
'../../../../../PeanoData/'
59file_name = f
'res_norm_dg_mesh_{n_mesh}_p_{degree}.npy'
61np.save(f
"{dir}{file_name}", res_norm_array)
62print(f
"Saved residual norms to {dir}{file_name}")