Skip to content

Commit 2fd8f26

Browse files
committed
Stuff
1 parent 865622d commit 2fd8f26

File tree

2 files changed

+64
-24
lines changed

2 files changed

+64
-24
lines changed

pySDC/projects/GPU/analysis_scripts/RBC3D_order.py

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import matplotlib.pyplot as plt
99

1010
step_sizes = {
11-
'RBC3DG4Ra1e5': [3, 1e0, 1e-1, 8e-2, 6e-2],
12-
'RBC3DG4RKRa1e5': [1e3, 5, 4, 1e0, 1e-1, 8e-2, 6e-2],
1311
'RBC3DG4R4Ra1e5': [8e-2, 4e-2, 2e-2, 1e-2, 5e-3],
1412
'RBC3DG4R4RKRa1e5': [8e-2, 4e-2, 2e-2, 1e-2, 5e-3],
1513
}
@@ -23,7 +21,6 @@ def no_logging_hook(*args, **kwargs):
2321
def get_path(args):
2422
config = get_config(args)
2523
fname = config.get_file_name()
26-
print(fname.index('dt'))
2724
return f'{fname[:fname.index('dt')]}order.pickle'
2825

2926

@@ -42,25 +39,54 @@ def compute_errors(args, dts, Tend):
4239
e_comp = MPI.COMM_WORLD.allreduce(e_comp, op=MPI.MAX)
4340
errors[comp].append(e_comp)
4441
errors['dt'].append(dt)
45-
print(errors)
4642

4743
path = get_path(args)
48-
with open(path, 'wb') as file:
49-
pickle.dump(errors, file)
50-
print(f'Saved errors to {path}', config.get_file_name())
44+
if MPI.COMM_WORLD.rank == 0:
45+
with open(path, 'wb') as file:
46+
pickle.dump(errors, file)
47+
print(f'Saved errors to {path}', flush=True)
5148

5249

53-
def plot_errors(args):
50+
def plot_error_all_components(args):
51+
fig, ax = plt.subplots()
52+
print(get_path(args))
5453
with open(get_path(args), 'rb') as file:
5554
errors = pickle.load(file)
5655

57-
for comp in errors.keys():
58-
plt.loglog(errors['dt'], errors[comp], label=comp)
56+
for comp in ['u', 'v', 'w', 'T', 'p']:
57+
e = np.array(errors[comp])
58+
dt = np.array(errors['dt'])
59+
order = np.log(e[1:] / e[:-1]) / np.log(dt[1:] / dt[:-1])
60+
ax.loglog(errors['dt'], errors[comp], label=f'{comp} order {np.mean(order):.1f}')
5961

60-
plt.loglog(errors['dt'], np.array(errors['dt']) ** 4, label='Order 4')
61-
plt.loglog(errors['dt'], np.array(errors['dt']) ** 2, label='Order 2')
62-
plt.legend()
63-
plt.show()
62+
ax.loglog(errors['dt'], np.array(errors['dt']) ** 4, label='Order 4', ls='--')
63+
ax.loglog(errors['dt'], np.array(errors['dt']) ** 2, label='Order 2', ls='--')
64+
ax.legend()
65+
ax.set_xlabel(r'$\Delta t$')
66+
ax.set_ylabel(r'$e$')
67+
68+
69+
def compare_order(Ra):
70+
fig, ax = plt.subplots()
71+
ls = {'SDC': '-', 'RK': '--', 'Euler': '-.'}
72+
if Ra == 1e5:
73+
paths = [f'./data/RBC3DG4R4{me}Ra1e5-res-1-order.pickle' for me in ['', 'RK', 'Euler']]
74+
labels = ['SDC', 'RK', 'Euler']
75+
else:
76+
raise NotImplementedError
77+
78+
for path, label in zip(paths, labels):
79+
with open(path, 'rb') as file:
80+
errors = pickle.load(file)
81+
82+
e = np.array(errors['T'])
83+
dt = np.array(errors['dt'])
84+
order = np.log(e[1:] / e[:-1]) / np.log(dt[1:] / dt[:-1])
85+
ax.loglog(dt, e, label=f'{label} order {np.mean(order):.1f}', ls=ls[label])
86+
87+
ax.legend(frameon=False)
88+
ax.set_xlabel(r'$\Delta t$')
89+
ax.set_ylabel(r'$e$')
6490

6591

6692
def run(args, dt, Tend):
@@ -89,5 +115,10 @@ def run(args, dt, Tend):
89115
config = get_config(args)
90116

91117
dts = step_sizes[type(config).__name__]
92-
compute_errors(args, dts, max(dts))
93-
plot_errors(args)
118+
if args['mode'] == 'run':
119+
compute_errors(args, dts, max(dts))
120+
121+
plot_error_all_components(args)
122+
compare_order(1e5)
123+
if MPI.COMM_WORLD.rank == 0:
124+
plt.show()

pySDC/projects/GPU/analysis_scripts/compare_RBC3D.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,24 @@ def compare_Nusselt_over_time1e5():
353353
rms_ax.plot(
354354
dat['rms_profile_T'], dat['z'], color=last_line.get_color(), ls=last_line.get_linestyle(), label=label
355355
)
356-
if 'dissipation' in dat.keys():
357356

358-
mean_ke = np.mean([me[1] for me in dat['dissipation']])
359-
print(
360-
f'Energy error: {(dat["dissipation"][-1][1] - np.sum([me[0] for me in dat["dissipation"]])/2)/mean_ke:.2e}'
361-
)
362-
ting_ax.plot(t, np.cumsum([me[0] for me in dat['dissipation']]) / 2, label=label)
363-
ting_ax.plot(t, [me[1] for me in dat['dissipation']], label=label, ls='--')
364-
ting_ax.legend()
357+
print(dat['avg_Nu'])
358+
try:
359+
ting_ax.scatter(abs(dat['avg_Nu']['V'] - dat['avg_Nu']['thermal']), dat['avg_Nu']['b'], label=label)
360+
except:
361+
pass
362+
ting_ax.set_xscale('log')
363+
ting_ax.legend()
364+
365+
# if 'dissipation' in dat.keys():
366+
367+
# mean_ke = np.mean([me[1] for me in dat['dissipation']])
368+
# print(
369+
# f'Energy error: {(dat["dissipation"][-1][1] - np.sum([me[0] for me in dat["dissipation"]])/2)/mean_ke:.2e}'
370+
# )
371+
# ting_ax.plot(t, np.cumsum([me[0] for me in dat['dissipation']]) / 2, label=label)
372+
# ting_ax.plot(t, [me[1] for me in dat['dissipation']], label=label, ls='--')
373+
# ting_ax.legend()
365374

366375
Nu_ax.legend(frameon=True)
367376
Nu_ax.set_xlabel('t')

0 commit comments

Comments
 (0)