Skip to content

Commit 6cbb58b

Browse files
committed
Added spectrum plot
1 parent d19a4ee commit 6cbb58b

File tree

6 files changed

+100
-22
lines changed

6 files changed

+100
-22
lines changed

pySDC/projects/GPU/analysis_scripts/RBC3D_order.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from pySDC.implementations.problem_classes.RayleighBenard3D import RayleighBenard3D
77
from mpi4py import MPI
88
import matplotlib.pyplot as plt
9-
from pySDC.helpers.plot_helper import setup_mpl, figsize_by_journal
9+
from pySDC.helpers.plot_helper import figsize_by_journal
10+
from pySDC.projects.GPU.analysis_scripts.RBC3D_plotting_utils import get_plotting_style, savefig
1011

1112
step_sizes = {
1213
'RBC3DG4R4Ra1e5': [8e-2, 4e-2, 2e-2, 1e-2, 5e-3],
@@ -53,7 +54,6 @@ def compute_errors(args, dts, Tend):
5354

5455

5556
def plot_error_all_components(args): # pragma: no cover
56-
setup_mpl()
5757
fig, ax = plt.subplots()
5858
with open(get_path(args), 'rb') as file:
5959
errors = pickle.load(file)
@@ -72,27 +72,24 @@ def plot_error_all_components(args): # pragma: no cover
7272

7373

7474
def compare_order(Ra): # pragma: no cover
75-
setup_mpl()
7675
fig, ax = plt.subplots(figsize=figsize_by_journal('Nature_CS', 1, 0.6))
77-
ls = {'SD': '-', 'RK': '--', 'Eu': '-.'}
7876
if Ra == 1e5:
79-
labels = ['RK443', 'Euler', 'SDC23', 'SDC34', 'SDC44'][::-1]
8077
names = ['RK', 'Euler', 'SDC23', 'SDC34', 'SDC44'][::-1]
81-
markers = ['>', '.', 'o', '<', 'x'][::-1]
78+
configs = [f'RBC3DG4R4{me}Ra1e5' for me in names]
8279
paths = [f'./data/RBC3DG4R4{me}Ra1e5-res-1-order.pickle' for me in names]
8380

8481
else:
8582
raise NotImplementedError
8683

87-
for path, label, marker in zip(paths, labels, markers, strict=True):
84+
for path, config in zip(paths, configs, strict=True):
8885
with open(path, 'rb') as file:
8986
errors = pickle.load(file)
9087

9188
e = np.array(errors['T'])
9289
dt = np.array(errors['dt'])
9390
order = np.log(e[1:] / e[:-1]) / np.log(dt[1:] / dt[:-1])
94-
print(f'{label}: order: mean={np.mean(order):.1f} / median={np.median(order):.1f}')
95-
ax.loglog(dt, e, label=f'{label}', ls=ls[label[:2]], marker=marker, markersize=6)
91+
print(f'{config}: order: mean={np.mean(order):.1f} / median={np.median(order):.1f}')
92+
ax.loglog(dt, e, **get_plotting_style(config))
9693

9794
for _dt in dt:
9895
for i in [1, 3, 4]:
@@ -102,7 +99,7 @@ def compare_order(Ra): # pragma: no cover
10299
ax.legend(frameon=False)
103100
ax.set_xlabel(r'$\Delta t$')
104101
ax.set_ylabel(r'$e$')
105-
fig.savefig('plots/SDC_order_Ra1e5.pdf', bbox_inches='tight')
102+
savefig(fig, 'RBC3D_order_Ra1e5')
106103

107104

108105
def run(args, dt, Tend):
@@ -140,13 +137,15 @@ def run(args, dt, Tend):
140137
from pySDC.projects.GPU.run_experiment import parse_args
141138

142139
args = parse_args()
143-
config = get_config(args)
144140

145-
dts = step_sizes[type(config).__name__]
146141
if args['mode'] == 'run':
142+
config = get_config(args)
143+
dts = step_sizes[type(config).__name__]
147144
compute_errors(args, dts, max(dts))
148145

149-
plot_error_all_components(args)
146+
if args['config'] is not None:
147+
plot_error_all_components(args)
148+
150149
compare_order(1e5)
151150
if MPI.COMM_WORLD.rank == 0:
152151
plt.show()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from pySDC.helpers.plot_helper import figsize_by_journal, setup_mpl
2+
import warnings
3+
4+
setup_mpl()
5+
6+
7+
def get_plotting_style(config):
8+
9+
args = {'color': None, 'ls': None, 'marker': None, 'markersize': 6, 'label': None}
10+
11+
if config == 'RBC3DG4R4SDC23Ra1e5':
12+
args['color'] = 'tab:blue'
13+
args['ls'] = '-'
14+
args['marker'] = 'o'
15+
args['label'] = 'SDC23'
16+
elif config == 'RBC3DG4R4SDC34Ra1e5':
17+
args['color'] = 'tab:orange'
18+
args['ls'] = '-'
19+
args['marker'] = '<'
20+
args['label'] = 'SDC34'
21+
elif config in ['RBC3DG4R4SDC44Ra1e5', 'RBC3DG4R4Ra1e5']:
22+
args['color'] = 'tab:green'
23+
args['ls'] = '-'
24+
args['marker'] = 'x'
25+
args['label'] = 'SDC44'
26+
elif config == 'RBC3DG4R4EulerRa1e5':
27+
args['color'] = 'tab:purple'
28+
args['ls'] = '--'
29+
args['marker'] = '.'
30+
args['label'] = 'Euler'
31+
elif config == 'RBC3DG4R4RKRa1e5':
32+
args['color'] = 'tab:red'
33+
args['ls'] = '--'
34+
args['marker'] = '>'
35+
args['label'] = 'RK444'
36+
else:
37+
warnings.warn(f'No plotting style for {config=!r}')
38+
39+
return args
40+
41+
42+
def savefig(fig, name, format='pdf', base_path='./plots', **kwargs):
43+
path = f'{base_path}/{name}.{format}'
44+
fig.savefig(path, bbox_inches='tight', **kwargs)
45+
print(f'Saved figure {path!r}')
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from pySDC.projects.GPU.analysis_scripts.process_RBC3D_data import get_pySDC_data
2+
from pySDC.projects.GPU.analysis_scripts.RBC3D_plotting_utils import figsize_by_journal, get_plotting_style, savefig
3+
import matplotlib.pyplot as plt
4+
5+
6+
def plot_spectrum(res, dt, config_name, ax): # pragma: no cover
7+
data = get_pySDC_data(res=res, dt=dt, config_name=config_name)
8+
9+
spectrum = data['avg_spectrum']
10+
k = data['k']
11+
ax.loglog(k[spectrum > 1e-16], spectrum[spectrum > 1e-16], **get_plotting_style(config_name), markevery=5)
12+
ax.set_xlabel('$k$')
13+
ax.set_ylabel(r'$\|\hat{u}_x\|$')
14+
15+
16+
def plot_spectra_Ra1e5(): # pragma: no cover
17+
fig, ax = plt.subplots(figsize=figsize_by_journal('Nature_CS', 1, 0.6))
18+
19+
configs = [f'RBC3DG4R4{name}Ra1e5' for name in ['SDC34', 'SDC23', '', 'Euler', 'RK']]
20+
dts = [0.06, 0.06, 0.06, 0.02, 0.04]
21+
res = 32
22+
23+
for config, dt in zip(configs, dts):
24+
plot_spectrum(res, dt, config, ax)
25+
26+
ax.legend(frameon=False)
27+
savefig(fig, 'RBC3D_spectrum_Ra1e5')
28+
29+
30+
if __name__ == '__main__':
31+
plot_spectra_Ra1e5()
32+
33+
plt.show()

pySDC/projects/GPU/analysis_scripts/plot_Nu.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,11 @@
33
import numpy as np
44
from scipy import integrate
55
from pySDC.helpers.plot_helper import figsize_by_journal, setup_mpl
6+
from pySDC.projects.GPU.analysis_scripts.process_RBC3D_data import get_pySDC_data
67

78
setup_mpl()
89

910

10-
def get_pySDC_data(res=-1, dt=-1, config_name='RBC3DG4', base_path='data/RBC_time_averaged'):
11-
path = f'{base_path}/{config_name}-res{res}-dt{dt:.0e}.pickle'
12-
with open(path, 'rb') as file:
13-
data = pickle.load(file)
14-
15-
return data
16-
17-
1811
def interpolate_NuV_to_reference_times(data, reference_data, order=12):
1912
from qmat.lagrange import getSparseInterpolationMatrix
2013

pySDC/projects/GPU/analysis_scripts/process_RBC3D_data.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,5 +204,13 @@ def process_RBC3D_data(base_path='./data/RBC_time_averaged', plot=True, args=Non
204204
return path
205205

206206

207+
def get_pySDC_data(res=-1, dt=-1, config_name='RBC3DG4', base_path='data/RBC_time_averaged'):
208+
path = f'{base_path}/{config_name}-res{res}-dt{dt:.0e}.pickle'
209+
with open(path, 'rb') as file:
210+
data = pickle.load(file)
211+
212+
return data
213+
214+
207215
if __name__ == '__main__':
208216
process_RBC3D_data()

pySDC/projects/GPU/tests/test_RBC_3D_analysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_processing(tmp_processed_data):
8080

8181

8282
def test_get_pySDC_data(tmp_processed_data, tmp_path):
83-
from pySDC.projects.GPU.analysis_scripts.plot_Nu import get_pySDC_data
83+
from pySDC.projects.GPU.analysis_scripts.process_RBC3D_data import get_pySDC_data
8484

8585
args = get_args(tmp_path)
8686
data = get_pySDC_data(res=args['res'], dt=args['dt'], config_name=args['config'], base_path=tmp_path)

0 commit comments

Comments
 (0)