2Plot residual norm vs number of DG iterations and two-grid cycles
7import matplotlib.pyplot
as plt
13with open(
'out.txt',
'r')
as file:
14 lines = file.readlines()
17for i
in range(len(lines)):
18 if "DG smoother step, disable CG solver" in lines[i]:
20 next_line = lines[i + 1]
21 pattern =
r"([-+]?\d*\.?\d+(?:e[-+]?\d+)?)"
22 full_pattern = rf
"\|r\|\_max={pattern},\s*\|r\|\_2={pattern},\s*\|r\|\_h={pattern}"
23 norms = re.search(full_pattern, next_line)
25 r_max, r_2, r_h = map(float, norms.groups())
26 res_norm.append([r_max, r_2, r_h])
28res_norm_array = np.array(res_norm)
31plt.plot(res_norm_array[:,0], label=
'r_max', marker=
'o')
37max_id = len(res_norm_array[:,0])
38cycle_ticks = np.arange(3, max_id, steps)
41cycle_labels = np.arange(len(cycle_ticks))
44cycles = plt.gca().secondary_xaxis(
'top')
45cycles.set_xlabel(
'Two-grid cycles')
48cycles.set_xticks(cycle_ticks)
49cycles.set_xticklabels(cycle_labels)
52for i
in range(3, max_id, steps):
53 plt.axvline(x=i, color=
'gray', linestyle=
'--', linewidth=0.5)