-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_table_4_info.py
152 lines (116 loc) · 6.07 KB
/
plot_table_4_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
"""
Plots convergence of specified tests
"""
import numpy as np
import matplotlib.pyplot as plt
from tomplot import (set_tomplot_style, plot_convergence,
only_minmax_ticklabels, tomplot_legend_ax,
tomplot_legend_fig)
import pandas as pd
# ---------------------------------------------------------------------------- #
# Options
# ---------------------------------------------------------------------------- #
main_test_cases = [2, 4]
regimes = ['small_cfl', 'big_cfl']
titles = [r'Small $c$', 'Big $c$']
equations = ['advective', 'advective', 'advective', 'advective',
'conservative', 'conservative',
'conservative', 'conservative', 'conservative', 'conservative', ]
labels = [r'COSMIC $m_{adv}$', r'SWIFT $m_{adv}$', r'COSMIC $m_{adv}^L$', r'SWIFT $m_{adv}^L$',
r'COSMIC $\rho$', r'SWIFT $\rho$',
r'COSMIC $m_{cons}$', r'SWIFT $m_{cons}$', r'COSMIC $m_{cons}^L$', r'SWIFT $m_{cons}^L$']
variables = ['tracer_con', 'tracer_con', 'tracer_adv', 'tracer_adv',
'rho', 'rho',
'tracer_con', 'tracer_con', 'tracer_adv', 'tracer_adv']
schemes = ['cosmic', 'swift', 'cosmic', 'swift', 'cosmic', 'swift', 'cosmic', 'swift', 'cosmic', 'swift']
colours = ['black', 'red', 'blue', 'cyan', 'purple', 'magenta', 'lime', 'brown', 'orange', 'pink']
markers = ['+', 'x', '^', 'v', 's', 'o', '+', 'x', '^', 'v']
legend = True
# ---------------------------------------------------------------------------- #
# Dictionary of resolutions for different tests
# ---------------------------------------------------------------------------- #
# ---------------------------------------------------------------------------- #
# Paths
# ---------------------------------------------------------------------------- #
results_stem = '/data/users/tbendall/results/swift_paper'
plot_stem = '/data/users/tbendall/results/swift_paper'
set_tomplot_style()
# ---------------------------------------------------------------------------- #
# Details about data structure
# ---------------------------------------------------------------------------- #
column_indices = {'measure': 4, 'variable': 5, 'value': 7}
for main_test_case in main_test_cases:
plot_name = f'{plot_stem}/tab_4_convergence_test_{main_test_case}.png'
fig, axarray = plt.subplots(1, len(regimes), figsize=(12, 6))
for i, (regime, ax) in enumerate(zip(regimes, axarray)):
if regime == 'big_cfl':
resolutions = {1: [64, 128, 256, 512],
2: [64, 128, 256, 512],
3: [64, 128, 256, 512],
4: [64, 128, 256, 512],
5: [64, 128, 256, 512],
6: [64, 128, 256, 512]}
dts = {1: ['4p0', '2p0', '1p0', '0p5'],
2: ['4p0', '2p0', '1p0', '0p5'],
3: ['4p0', '2p0', '1p0', '0p5'],
4: ['4p0', '2p0', '1p0', '0p5'],
5: ['4p0', '2p0', '1p0', '0p5'],
6: ['4p0', '2p0', '1p0', '0p5']}
elif regime == 'small_cfl':
resolutions = {1: [64, 128, 256, 512],
2: [64, 128, 256, 512],
3: [64, 128, 256, 512],
4: [64, 128, 256, 512],
5: [64, 128, 256, 512],
6: [64, 128, 256, 512]}
dts = {1: ['0p4', '0p2', '0p1', '0p05'],
2: ['0p4', '0p2', '0p1', '0p05'],
3: ['0p4', '0p2', '0p1', '0p05'],
4: ['0p4', '0p2', '0p1', '0p05'],
5: ['0p4', '0p2', '0p1', '0p05'],
6: ['0p4', '0p2', '0p1', '0p05']}
for j, variable in enumerate(variables):
if equations[j] == 'advective':
test_case = main_test_case - 1
else:
test_case = main_test_case
error_data = np.zeros(len(resolutions[test_case]))
dxs = [1000. / res for res in resolutions[test_case]]
for k, res in enumerate(resolutions[test_case]):
dt = dts[test_case][k]
data_file = f'{results_stem}/{schemes[j]}_test_{test_case}_conv_BiP{res}x{res}-1000x1000_dt-{dt}.log'
# ------------------------------------------------------------ #
# Extract data
# ------------------------------------------------------------ #
data = pd.read_csv(data_file, header=None, sep=' ', skipinitialspace=True, usecols=column_indices.values())
# Name columns
column_titles = {}
for key, value in column_indices.items():
column_titles[value] = key
data = data.rename(columns=column_titles)
# Convert data to float
data['value'] = data['value'].astype(float)
# Extract error value for this data point
error_data[k] = data[(data['measure'] == 'Rel-L2-error') & (data['variable'] == variable)]['value'].values[0]
# ---------------------------------------------------------------- #
# Plot
# ---------------------------------------------------------------- #
plot_convergence(ax, dxs, error_data, label=f'{labels[j]}:', color=colours[j],
marker=markers[j])
# Adjust x limits to fit legend on nicely
xlims = ax.get_xlim()
ax.set_xlim([xlims[0], xlims[1] + 0.1*(xlims[1] - xlims[0])])
ax.grid()
only_minmax_ticklabels(ax)
if legend:
ax.legend(loc='lower right', fontsize=14)
ax.set_title(titles[i])
ax.set_xlabel(r'$\log(\Delta x)$', labelpad=-10)
if i == 0:
ax.set_ylabel(r'$\log(||q-q_{true}||_{L^2})$', labelpad=-10)
# ------------------------------------------------------------------------ #
# Save figure
# ------------------------------------------------------------------------ #
print(f'Saving figure to {plot_name}')
fig.savefig(plot_name, bbox_inches='tight')
plt.close()