Skip to content

Commit 8fa27af

Browse files
committed
Added script for checking stability
1 parent 1af6827 commit 8fa27af

File tree

2 files changed

+106
-21
lines changed

2 files changed

+106
-21
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import os
2+
import numpy as np
3+
from pySDC.helpers.fieldsIO import FieldsIO
4+
from pySDC.projects.GPU.configs.base_config import get_config
5+
6+
step_sizes = {'RBC3DG4Ra1e5': [1e3, 1e0, 1e-1, 8e-2, 6e-2], 'RBC3DG4R4Ra1e5': [2e0, 1e0, 1e-1, 5e-2]}
7+
n_freefall_times = {}
8+
9+
10+
def get_stability(args, dt):
11+
args['dt'] = dt
12+
config = get_config(args)
13+
path = config.get_file_name()
14+
15+
if not os.path.isfile(path):
16+
compute_stability(args, dt)
17+
18+
file = FieldsIO.fromFile(path)
19+
t, u = file.readField(-1)
20+
21+
reachedTend = t >= n_freefall_times.get(type(config).__name__, 3)
22+
isfinite = np.all(np.isfinite(u))
23+
if not reachedTend:
24+
print(f'Did not reach Tend with {dt=:.2e}')
25+
elif not isfinite:
26+
print(f'Solution not finite with {dt=:.2e}')
27+
return reachedTend and isfinite
28+
29+
30+
def compute_stability(args, dt):
31+
from pySDC.projects.GPU.run_experiment import run_experiment
32+
33+
args['mode'] = 'run'
34+
args['dt'] = dt
35+
36+
config = get_config(args)
37+
config.Tend = n_freefall_times.get(type(config).__name__, 3)
38+
config.ic_config = type(config)
39+
40+
run_experiment(args, config)
41+
42+
43+
if __name__ == '__main__':
44+
from pySDC.projects.GPU.run_experiment import parse_args
45+
46+
args = parse_args()
47+
config = get_config(args)
48+
49+
dts = step_sizes[type(config).__name__]
50+
stability = [None for _ in dts]
51+
52+
for i in range(len(dts)):
53+
stability[i] = get_stability(args, dts[i])
54+
print(stability)

pySDC/projects/GPU/analysis_scripts/compare_RBC3D.py

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -531,50 +531,81 @@ def plot_spectrum_over_time1e6R4():
531531

532532
# data = get_pySDC_data('1e6', res=48, dt=0.02, config_name='RBC3DG4')
533533
# data = get_pySDC_data('1e7', res=96, dt=0.009, config_name='RBC3DG4')
534-
# data = get_pySDC_data('1e7', res=64, dt=0.005, config_name='RBC3DG4R4')
535-
data = get_pySDC_data('1e8', res=96, dt=0.005, config_name='RBC3DG4R4')
534+
data = get_pySDC_data('1e7', res=64, dt=0.005, config_name='RBC3DG4R4D42')
535+
# data = get_pySDC_data('1e8', res=96, dt=0.005, config_name='RBC3DG4R4')
536+
# data = get_pySDC_data('1e8', res=256, dt=0.002, config_name='RBC3DG4R4RK')
536537

537538
s = data['spectrum']
538539
t = data['t']
539540
k = data['k']
540541

541-
# for i in range(len(s)):
542-
# for i in [0, 3, 10, 20, 40, 80, -1]:
543-
for i in [0, 5, 10, 20, 30, 40, -1]:
542+
for i in range(len(s)):
543+
# for i in [0, 3, 10, 20, 40, 80, -1]:
544+
# for i in [0, 5, 10, 20, 30, 40, -1]:
544545
print(i, t[i])
545546
_s = s[i][0, data['res_in_boundary_layer']]
546547
_s = np.max(s[i][0], axis=0)
547548
ax.loglog(k[_s > 1e-20], _s[_s > 1e-20], label=f't={t[i]:.1f}')
548549
ax.legend(frameon=False)
549550

550551

551-
def compare_spectra1e8():
552+
def compare_spectra(Ra=1e8):
552553
fig, ax = plt.subplots()
553554

554555
runs = []
555556
labels = []
556-
runs.append(get_pySDC_data('1e8', res=96, dt=0.005, config_name='RBC3DG4R4'))
557-
labels.append(r'$N=384^2\times96$')
558-
runs.append(get_pySDC_data('1e8', res=128, dt=0.005, config_name='RBC3DG4R4'))
559-
labels.append(r'$N=512^2\times128$')
560-
runs.append(get_pySDC_data('1e8', res=96, dt=0.006, config_name='RBC3DG4'))
561-
labels.append(r'$N=192^2\times96$')
557+
if Ra == 1e8:
558+
runs.append(get_pySDC_data('1e8', res=96, dt=0.005, config_name='RBC3DG4R4'))
559+
labels.append(r'$N=384^2\times96$')
560+
runs.append(get_pySDC_data('1e8', res=128, dt=0.005, config_name='RBC3DG4R4'))
561+
labels.append(r'$N=512^2\times128$')
562+
runs.append(get_pySDC_data('1e8', res=96, dt=0.006, config_name='RBC3DG4'))
563+
labels.append(r'$N=192^2\times96$')
564+
runs.append(get_pySDC_data('1e8', res=256, dt=0.002, config_name='RBC3DG4R4RK'))
565+
labels.append(r'$N=1024^2\times256$')
566+
elif Ra == 1e7:
567+
runs.append(get_pySDC_data('1e7', res=64, dt=0.005, config_name='RBC3DG4R4'))
568+
labels.append(r'$N=264^2\times64$')
569+
runs.append(get_pySDC_data('1e7', res=64, dt=0.005, config_name='RBC3DG4R4D2'))
570+
labels.append(r'$N=264^2\times64$, no dealiasing')
571+
runs.append(get_pySDC_data('1e7', res=64, dt=0.005, config_name='RBC3DG4R4D4'))
572+
labels.append(r'$N=264^2\times64$, dealiasing 2')
573+
runs.append(get_pySDC_data('1e7', res=96, dt=0.009, config_name='RBC3DG4'))
574+
labels.append(r'$N=192^2\times96$')
575+
runs.append(get_pySDC_data('1e7', res=96, dt=0.005, config_name='RBC3DG4R4'))
576+
labels.append(r'$N=384^2\times96$')
577+
runs.append(get_pySDC_data('1e7', res=128, dt=0.005, config_name='RBC3DG4R4'))
578+
labels.append(r'$N=512^2\times128$')
579+
elif Ra == 1e5:
580+
runs.append(get_pySDC_data('1e5', res=32, dt=0.06, config_name='RBC3DG4'))
581+
labels.append(r'$N=64^2\times32$')
582+
runs.append(get_pySDC_data('1e5', res=32, dt=0.06, config_name='RBC3DG4R4'))
583+
labels.append(r'$N=128^2\times32$')
584+
else:
585+
raise NotImplementedError
562586

563587
for data, label in zip(runs, labels):
564-
s = data['spectrum']
565-
t = data['t']
588+
s_all = data['spectrum']
566589
k = data['k']
567590

568-
k = data['k'] + 1
569-
spectrum = np.array(data['spectrum'])
570-
u_spectrum = np.mean(spectrum, axis=0)[1]
571-
idx = data['res_in_boundary_layer']
572-
_s = u_spectrum[idx]
573-
ax.loglog(k[_s > 1e-20], _s[_s > 1e-20], label=label)
591+
from pySDC.helpers.spectral_helper import ChebychevHelper
592+
593+
helper = ChebychevHelper(N=s_all[0].shape[1], x0=0, x1=1)
594+
weights = helper.get_integration_weights()
595+
s = np.array([weights @ helper.transform(me[0], axes=(0,)) for me in s_all]).mean(axis=0)
596+
597+
ax.loglog(k[s > 1e-20], s[s > 1e-20], label=label)
598+
599+
# spectrum = np.array(data['spectrum'])
600+
# u_spectrum = np.mean(spectrum, axis=0)[1]
601+
# idx = data['res_in_boundary_layer']
602+
# _s = u_spectrum[idx]
603+
# ax.loglog(k[_s > 1e-20], _s[_s > 1e-20], label=label)
574604

575605
ax.legend(frameon=False)
576606
ax.set_xlabel('$k$')
577607
ax.set_ylabel(r'$\|\hat{u}_x\|$')
608+
ax.set_title(f'Ra = {Ra:.1e}')
578609

579610

580611
if __name__ == '__main__':
@@ -586,6 +617,6 @@ def compare_spectra1e8():
586617
# compare_Nusselt_over_time1e8()
587618
# plot_thibaut_stuff()
588619
# plot_spectrum_over_time1e6R4()
589-
compare_spectra1e8()
620+
compare_spectra(Ra=1e5)
590621

591622
plt.show()

0 commit comments

Comments
 (0)