Skip to content

Commit f6c4cf7

Browse files
committed
Stuff
#!!!!!!!!!! WARNING: RUFF FAILED !!!!!!!!!!: #pySDC/projects/GPU/analysis_scripts/compare_RBC3D.py:298:5: F841 Local variable `data` is assigned to but never used # | Parallel-in-Time#296 | res = 32 Parallel-in-Time#297 | Parallel-in-Time#298 | data = [] # | ^^^^ F841 Parallel-in-Time#299 | labels = [] Parallel-in-Time#300 | linestyles = [] # | # = help: Remove assignment to unused variable `data` # #pySDC/projects/GPU/analysis_scripts/compare_RBC3D.py:299:5: F841 Local variable `labels` is assigned to but never used # | Parallel-in-Time#298 | data = [] Parallel-in-Time#299 | labels = [] # | ^^^^^^ F841 Parallel-in-Time#300 | linestyles = [] # | # = help: Remove assignment to unused variable `labels` # #pySDC/projects/GPU/analysis_scripts/compare_RBC3D.py:300:5: F841 Local variable `linestyles` is assigned to but never used # | Parallel-in-Time#298 | data = [] Parallel-in-Time#299 | labels = [] Parallel-in-Time#300 | linestyles = [] # | ^^^^^^^^^^ F841 Parallel-in-Time#301 | Parallel-in-Time#302 | ref_data = get_pySDC_data(Ra, res=res, dt=0.01, config_name='RBC3DG4R4') # | # = help: Remove assignment to unused variable `linestyles` # #pySDC/projects/GPU/analysis_scripts/compare_RBC3D.py:312:9: F841 Local variable `t` is assigned to but never used # | Parallel-in-Time#310 | ax.set_title(title) Parallel-in-Time#311 | Nu_ref = np.array(ref['Nu']['V']) Parallel-in-Time#312 | t = ref['t'] # | ^ F841 Parallel-in-Time#313 | Parallel-in-Time#314 | for dt in dts: # | # = help: Remove assignment to unused variable `t` # #pySDC/projects/GPU/analysis_scripts/compare_RBC3D.py:587:9: E722 Do not use bare `except` # | Parallel-in-Time#585 | k[_s > 1e-16], _s[_s > 1e-16], color=last_line.get_color(), ls=last_line.get_linestyle(), label=label Parallel-in-Time#586 | ) Parallel-in-Time#587 | except: # | ^^^^^^ E722 Parallel-in-Time#588 | pass # | # #pySDC/projects/GPU/analysis_scripts/compare_RBC3D.py:686:5: F841 Local variable `Delta_Nu` is assigned to but never used # | #684 | t = data['t'] #685 | avg_Nu = np.array([np.mean(Nu[40 : 40 + i + 1]) for i in range(len(Nu[40:]))]) #686 | Delta_Nu = np.array([abs(avg_Nu[i + 1] - avg_Nu[i]) for i in range(len(avg_Nu) - 1)]) # | ^^^^^^^^ F841 #687 | # ax.plot(data['t'][40:-1], Delta_Nu / avg_Nu[:-1]) #688 | # ax.plot(data['t'], np.abs(avg_Nu - avg_Nu[-1]) / avg_Nu[-1]) # | # = help: Remove assignment to unused variable `Delta_Nu`:
1 parent 3853e3e commit f6c4cf7

File tree

3 files changed

+158
-89
lines changed

3 files changed

+158
-89
lines changed

pySDC/helpers/plot_helper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ def figsize_by_journal(journal, scale, ratio): # pragma: no cover
4545
'Springer_proceedings': 347.12354,
4646
'JSC_thesis': 434.26027,
4747
'TUHH_thesis': 426.79135,
48+
'Nature_CS': 372.0,
4849
}
4950
# store text height in points here, get this from LaTeX using \the\textheight
5051
textheights = {
5152
'JSC_beamer': 214.43411,
5253
'JSC_thesis': 635.5,
5354
'TUHH_thesis': 631.65118,
5455
'Springer_proceedings': 549.13828,
56+
'Nature_CS': 552.69478,
5557
}
5658
assert (
5759
journal in textwidths.keys()

pySDC/projects/GPU/analysis_scripts/RBC3D_order.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,13 @@ def compare_order(Ra):
7373
fig, ax = plt.subplots()
7474
ls = {'SDC': '-', 'RK': '--', 'Euler': '-.'}
7575
if Ra == 1e5:
76-
paths = [f'./data/RBC3DG4R4{me}Ra1e5-res-1-order.pickle' for me in ['', 'RK', 'Euler']]
77-
labels = ['SDC', 'RK', 'Euler']
76+
paths = [f'./data/RBC3DG4R4{me}Ra1e5-res-1-order.pickle' for me in ['', 'RK', 'Euler', 'O3']]
77+
labels = ['SDC', 'RK', 'Euler', 'SDC']
78+
7879
else:
7980
raise NotImplementedError
8081

81-
for path, label in zip(paths, labels):
82+
for path, label in zip(paths, labels, strict=True):
8283
with open(path, 'rb') as file:
8384
errors = pickle.load(file)
8485

pySDC/projects/GPU/analysis_scripts/compare_RBC3D.py

Lines changed: 152 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import matplotlib.pyplot as plt
33
import numpy as np
44
from scipy import integrate
5+
from pySDC.helpers.plot_helper import figsize_by_journal, setup_mpl
6+
7+
setup_mpl()
58

69

710
def get_pySDC_data(Ra, RK=False, res=-1, dt=-1, config_name='RBC3DG4'):
@@ -282,11 +285,12 @@ def interpolate_NuV_to_reference_times(data, reference_data, order=12):
282285

283286

284287
def compare_Nusselt_over_time1e5():
285-
fig, Nu_ax = plt.subplots()
286-
_, axs = plt.subplots(1, 3, figsize=(10, 3))
287-
prof_ax = axs[0]
288-
rms_ax = axs[1]
289-
spectrum_ax = axs[2]
288+
Nu_fig, Nu_axs = plt.subplots(4, 1, sharex=True, sharey=True, figsize=figsize_by_journal('Nature_CS', 1, 1.4))
289+
# _, axs = plt.subplots(1, 3, figsize=(10, 3))
290+
# prof_ax = axs[0]
291+
# rms_ax = axs[1]
292+
# spectrum_ax = axs[2]
293+
# deviation_fig, deviation_ax = plt.subplots(figsize=figsize_by_journal('Nature_CS', 0.7, 0.7))
290294

291295
Ra = '1e5'
292296
res = 32
@@ -296,89 +300,151 @@ def compare_Nusselt_over_time1e5():
296300
linestyles = []
297301

298302
ref_data = get_pySDC_data(Ra, res=res, dt=0.01, config_name='RBC3DG4R4')
303+
# deviations = {'SDC 3': [], 'SDC': [], 'RK': [], 'Euler': []}
304+
# Nu_all = {'SDC 3': [], 'SDC': [], 'RK': [], 'Euler': []}
305+
306+
_Nu_axs = {'SDC 3': Nu_axs[1], 'SDC': Nu_axs[0], 'RK': Nu_axs[2], 'Euler': Nu_axs[3]}
307+
308+
def _plot_Nu_(Ra, res, dts, config_name, ref, ax, title):
309+
ax.plot(ref['t'], ref['Nu']['V'], color='black', ls='--')
310+
ax.set_title(title)
311+
Nu_ref = np.array(ref['Nu']['V'])
312+
t = ref['t']
313+
314+
for dt in dts:
315+
data = get_pySDC_data(Ra=Ra, res=res, dt=dt, config_name=config_name)
316+
t_i, Nu_i = interpolate_NuV_to_reference_times(data, ref)
317+
ax.plot(t_i, Nu_i, label=rf'$\Delta t={{{dt}}}$')
318+
319+
# error = np.maximum.accumulate(np.abs(Nu_ref[: Nu_i.shape[0]] - Nu_i) / np.abs(Nu_ref[: Nu_i.shape[0]]))
320+
error = np.abs(Nu_ref[: Nu_i.shape[0]] - Nu_i) / np.abs(Nu_ref[: Nu_i.shape[0]])
321+
322+
# compute mean Nu
323+
mask = np.logical_and(t_i >= 100, t_i <= 200)
324+
Nu_mean = np.mean(Nu_i[mask])
325+
Nu_std = np.std(Nu_i[mask])
326+
327+
last_line = ax.get_lines()[-1]
328+
if any(error > 1e-2):
329+
deviates = min(t_i[error > 1e-2])
330+
ax.axvline(deviates, color=last_line.get_color(), ls=':')
331+
print(f'{title} dt={dt} Nu={Nu_mean:.3f}+={Nu_std:.3f}, deviates more than 1% from t={deviates:.2f}')
332+
else:
333+
print(f'{title} dt={dt} Nu={Nu_mean:.3f}+={Nu_std:.3f}')
334+
ax.legend(frameon=True, loc='upper left')
335+
336+
_plot_Nu_('1e5', 32, [0.06, 0.04, 0.02], 'RBC3DG4R4', ref_data, Nu_axs[0], 'SDC44')
337+
_plot_Nu_(
338+
'1e5',
339+
32,
340+
[
341+
0.06,
342+
0.04,
343+
0.02,
344+
],
345+
'RBC3DG4R4O4',
346+
ref_data,
347+
Nu_axs[0],
348+
'SDC34',
349+
)
350+
_plot_Nu_('1e5', 32, [0.06, 0.05, 0.02, 0.01], 'RBC3DG4R4O3', ref_data, Nu_axs[1], 'SDC23')
351+
_plot_Nu_('1e5', 32, [0.05, 0.04, 0.02, 0.01, 0.005], 'RBC3DG4R4RK', ref_data, Nu_axs[2], 'RK443')
352+
_plot_Nu_('1e5', 32, [0.02, 0.01, 0.005], 'RBC3DG4R4Euler', ref_data, Nu_axs[3], 'RK111')
353+
354+
# for dt in [0.06, 0.02, 0.01]:
355+
# data.append(get_pySDC_data(Ra, res=res, dt=dt, config_name='RBC3DG4R4'))
356+
# labels.append(f'SDC, dt={dt:.4f}')
357+
# linestyles.append('-')
358+
359+
# for dt in [0.06, 0.05, 0.02, 0.01]:
360+
# data.append(get_pySDC_data(Ra, res=res, dt=dt, config_name='RBC3DG4R4O3'))
361+
# labels.append(f'SDC 3, dt={dt:.4f}')
362+
# linestyles.append('-')
299363

300-
_, ting_ax = plt.subplots()
301-
302-
for dt in [0.06, 0.02, 0.01]:
303-
data.append(get_pySDC_data(Ra, res=res, dt=dt, config_name='RBC3DG4R4'))
304-
labels.append(f'SDC, dt={dt:.4f}')
305-
linestyles.append('-')
306-
307-
# ----------------- RK ------------------------
308-
309-
for dt in [0.05, 0.04, 0.02, 0.01, 0.005]:
310-
data.append(get_pySDC_data(Ra, res=res, dt=dt, RK=True, config_name='RBC3DG4R4'))
311-
labels.append(f'RK, dt={dt:.3f}')
312-
linestyles.append('--')
313-
314-
# ----------------- Euler ---------------------
315-
316-
for dt in [0.02, 0.005]:
317-
data.append(get_pySDC_data(Ra, res=res, dt=dt, config_name='RBC3DG4R4Euler'))
318-
labels.append(f'Euler, dt={dt:.3f}')
319-
linestyles.append('-.')
320-
321-
for dat, label, linestyle in zip(data, labels, linestyles):
322-
Nu = np.array(dat['Nu']['V'])
323-
t = dat['t']
324-
Nu_ref = np.array(ref_data['Nu']['V'])
325-
t_i, Nu_i = interpolate_NuV_to_reference_times(dat, ref_data)
326-
Nu_ax.plot(t, Nu, label=label, ls=linestyle)
327-
328-
error = np.maximum.accumulate(np.abs(Nu_ref[: Nu_i.shape[0]] - Nu_i) / np.abs(Nu_ref[: Nu_i.shape[0]]))
329-
330-
# compute mean Nu
331-
mask = np.logical_and(t >= 20, t <= 200)
332-
Nu_mean = np.mean(Nu[mask])
333-
Nu_std = np.std(Nu[mask])
334-
335-
last_line = Nu_ax.get_lines()[-1]
336-
if any(error > 1e-2):
337-
deviates = min(t_i[error > 1e-2])
338-
Nu_ax.axvline(deviates, color=last_line.get_color(), ls=last_line.get_linestyle())
339-
print(f'{label} Nu={Nu_mean:.3f}+={Nu_std:.3f}, deviates more than 1% from t={deviates:.2f}')
340-
else:
341-
print(f'{label} Nu={Nu_mean:.3f}+={Nu_std:.3f}')
342-
343-
k = dat['k']
344-
spectrum = np.array(dat['spectrum'])
345-
u_spectrum = np.mean(spectrum, axis=0)[1]
346-
idx = dat['res_in_boundary_layer']
347-
_s = u_spectrum[idx]
348-
spectrum_ax.loglog(
349-
k[_s > 1e-16], _s[_s > 1e-16], color=last_line.get_color(), ls=last_line.get_linestyle(), label=label
350-
)
351-
352-
prof_ax.plot(dat['profile_T'], dat['z'], color=last_line.get_color(), ls=last_line.get_linestyle(), label=label)
353-
rms_ax.plot(
354-
dat['rms_profile_T'], dat['z'], color=last_line.get_color(), ls=last_line.get_linestyle(), label=label
355-
)
356-
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()
374-
375-
Nu_ax.legend(frameon=True)
376-
Nu_ax.set_xlabel('t')
377-
Nu_ax.set_ylabel('Nu')
364+
# # ----------------- RK ------------------------
378365

379-
spectrum_ax.legend(frameon=False)
380-
spectrum_ax.set_xlabel('$k$')
381-
spectrum_ax.set_ylabel(r'$\|\hat{u}_x\|$')
366+
# for dt in [0.05, 0.04, 0.02, 0.01, 0.005]:
367+
# data.append(get_pySDC_data(Ra, res=res, dt=dt, RK=True, config_name='RBC3DG4R4'))
368+
# labels.append(f'RK, dt={dt:.3f}')
369+
# linestyles.append('--')
370+
371+
# # ----------------- Euler ---------------------
372+
373+
# for dt in [0.02, 0.01, 0.005]:
374+
# data.append(get_pySDC_data(Ra, res=res, dt=dt, config_name='RBC3DG4R4Euler'))
375+
# labels.append(f'Euler, dt={dt:.3f}')
376+
# linestyles.append('-.')
377+
378+
# for dat, label, linestyle in zip(data, labels, linestyles):
379+
# Nu_ax = _Nu_axs[label[:label.index('dt')-2]]
380+
# Nu = np.array(dat['Nu']['V'])
381+
# t = dat['t']
382+
# Nu_ref = np.array(ref_data['Nu']['V'])
383+
# t_i, Nu_i = interpolate_NuV_to_reference_times(dat, ref_data)
384+
# Nu_ax.plot(t, Nu, label=label, ls=linestyle)
385+
# dt = float(label[label.index('dt')+3:])
386+
387+
# error = np.maximum.accumulate(np.abs(Nu_ref[: Nu_i.shape[0]] - Nu_i) / np.abs(Nu_ref[: Nu_i.shape[0]]))
388+
389+
# # compute mean Nu
390+
# mask = np.logical_and(t >= 20, t <= 200)
391+
# Nu_mean = np.mean(Nu[mask])
392+
# Nu_std = np.std(Nu[mask])
393+
394+
# for key in Nu_all.keys():
395+
# if str(key) in label:
396+
# Nu_all[key].append((Nu_mean, Nu_std, dt))
397+
# break
398+
399+
# last_line = Nu_ax.get_lines()[-1]
400+
# if any(error > 1e-2):
401+
# deviates = min(t_i[error > 1e-2])
402+
# for key in deviations.keys():
403+
# if str(key) in label:
404+
# deviations[key].append((dt, deviates))
405+
# break
406+
# Nu_ax.axvline(deviates, color=last_line.get_color(), ls=last_line.get_linestyle())
407+
# print(f'{label} Nu={Nu_mean:.3f}+={Nu_std:.3f}, deviates more than 1% from t={deviates:.2f}')
408+
# else:
409+
# print(f'{label} Nu={Nu_mean:.3f}+={Nu_std:.3f}')
410+
411+
# k = dat['k']
412+
# spectrum = np.array(dat['spectrum'])
413+
# u_spectrum = np.mean(spectrum, axis=0)[1]
414+
# idx = dat['res_in_boundary_layer']
415+
# _s = u_spectrum[idx]
416+
# spectrum_ax.loglog(
417+
# k[_s > 1e-16], _s[_s > 1e-16], color=last_line.get_color(), ls=last_line.get_linestyle(), label=label
418+
# )
419+
420+
# prof_ax.plot(dat['profile_T'], dat['z'], color=last_line.get_color(), ls=last_line.get_linestyle(), label=label)
421+
# rms_ax.plot(
422+
# dat['rms_profile_T'], dat['z'], color=last_line.get_color(), ls=last_line.get_linestyle(), label=label
423+
# )
424+
425+
# for key, value in deviations.items():
426+
# deviation_ax.plot([me[0] for me in value], [me[1] for me in value], label=key, marker='.')
427+
# deviation_ax.set_xscale('log')
428+
# deviation_ax.legend(frameon=False)
429+
# deviation_ax.set_xlabel(r'$\Delta t$')
430+
# deviation_ax.set_ylabel('Nu deviates from reference')
431+
432+
# _, Nu_summary_ax = plt.subplots()
433+
# for key in list(Nu_all.keys())[::-1]:
434+
# value = Nu_all[key]
435+
# Nu_summary_ax.errorbar([me[2] for me in value], [me[0] for me in value], yerr=[me[1] for me in value], label=key, marker='.')
436+
# Nu_summary_ax.legend(frameon=False)
437+
438+
# spectrum_ax.legend(frameon=False)
439+
# spectrum_ax.set_xlabel('$k$')
440+
# spectrum_ax.set_ylabel(r'$\|\hat{u}_x\|$')
441+
442+
Nu_axs[-1].set_xlabel('$t$')
443+
Nu_axs[-1].set_ylabel('$Nu$')
444+
445+
Nu_fig.tight_layout()
446+
Nu_fig.savefig('./plots/Nu_over_time_Ra1e5.pdf', bbox_inches='tight')
447+
# deviation_fig.savefig('./plots/Nu_deviation_Ra1e5.pdf', bbox_inches='tight')
382448

383449

384450
def compare_Nusselt_over_time1e6():

0 commit comments

Comments
 (0)