|
| 1 | +""" |
| 2 | +This script plots macroscopic verification of simulation data via comparison with data from https://doi.org/10.5281/zenodo.14205874 |
| 3 | +In order to run this script, you need to download the dataset and copy it to `pySDC/projects/RayleighBenard/data/Nek5000`. |
| 4 | +And, you need to have generated the pySDC simulation data, of course. |
| 5 | +""" |
| 6 | + |
| 7 | +import numpy as np |
| 8 | +from scipy import integrate |
| 9 | +import matplotlib.pyplot as plt |
| 10 | + |
| 11 | +ints = {'1e5': 1e5, '1e6': 1e6, '1e7': 1e7} |
| 12 | + |
| 13 | + |
| 14 | +def get_Nek5000_Data(Ra, base_path='data/Nek5000'): # pragma: no cover |
| 15 | + assert type(Ra) == str |
| 16 | + |
| 17 | + # append relative path to base path |
| 18 | + path = __file__ |
| 19 | + base_path = f'{path[::-1][path[::-1].index('/'):][::-1]}../{base_path}' |
| 20 | + Pr = 0.7 |
| 21 | + |
| 22 | + if Ra == '1e5': |
| 23 | + dir_name = '1_1e5' |
| 24 | + start_time = 3500 |
| 25 | + nelZ = 64 |
| 26 | + nPoly = 5 |
| 27 | + elif Ra == '1e6': |
| 28 | + dir_name = '2_1e6' |
| 29 | + start_time = 3500 |
| 30 | + nelZ = 64 |
| 31 | + nPoly = 7 |
| 32 | + elif Ra == '1e7': |
| 33 | + dir_name = '3_1e7' |
| 34 | + start_time = 3100 |
| 35 | + nelZ = 64 |
| 36 | + nPoly = 9 |
| 37 | + elif Ra == '1e8': |
| 38 | + dir_name = '4_1e8' |
| 39 | + start_time = 3000 |
| 40 | + nelZ = 96 |
| 41 | + nPoly = 7 |
| 42 | + elif Ra == '1e9': |
| 43 | + dir_name = '5_1e9' |
| 44 | + start_time = 4000 |
| 45 | + nelZ = 96 |
| 46 | + nPoly = 9 |
| 47 | + elif Ra == '1e10': |
| 48 | + dir_name = '6_1e10' |
| 49 | + start_time = 1700 |
| 50 | + nelZ = 200 |
| 51 | + nPoly = 7 |
| 52 | + elif Ra == '1e11': |
| 53 | + dir_name = '7_1e11' |
| 54 | + start_time = 260 |
| 55 | + nelZ = 256 |
| 56 | + nPoly = 7 |
| 57 | + else: |
| 58 | + raise |
| 59 | + |
| 60 | + path = f'{base_path}/{dir_name}' |
| 61 | + data = {} |
| 62 | + |
| 63 | + visc = np.sqrt(Pr / ints[Ra]) |
| 64 | + |
| 65 | + # get averaged data |
| 66 | + avg = np.load(f'{path}/average.npy') |
| 67 | + avg_Nu = np.mean(avg[avg[:, 0] > start_time, 3]) |
| 68 | + data['Nu'] = avg_Nu |
| 69 | + data['std_Nu'] = np.std(avg[avg[:, 0] > start_time, 3]) |
| 70 | + |
| 71 | + Re = np.sqrt(avg[:, 1]) / visc |
| 72 | + data['Re'] = np.mean(Re[avg[:, 0] > start_time]) |
| 73 | + |
| 74 | + # get profile data |
| 75 | + profiles = np.load(f'{path}/profile.npy') |
| 76 | + nzPts = nelZ * nPoly + 1 |
| 77 | + nSnap = int(profiles.shape[0] / nzPts) |
| 78 | + tVal = profiles[:, 0].reshape((nSnap, nzPts))[:, 0] |
| 79 | + tInterval = tVal[-1] - tVal[0] |
| 80 | + |
| 81 | + data['z'] = profiles[:nzPts, 1] |
| 82 | + data['profile_T'] = profiles[:, 3].reshape((nSnap, nzPts)) |
| 83 | + |
| 84 | + tRMS = profiles[:, 4].reshape((nSnap, nzPts)) |
| 85 | + data['rms_profile_T'] = np.sqrt(integrate.simpson(tRMS**2, tVal, axis=0) / tInterval) |
| 86 | + |
| 87 | + return data |
| 88 | + |
| 89 | + |
| 90 | +def get_pySDC_data(Ra): |
| 91 | + from pySDC.projects.RayleighBenard.analysis_scripts.process_RBC3D_data import get_pySDC_data as _get_data |
| 92 | + |
| 93 | + dts = {'1e5': 0.06, '1e6': 0.02} |
| 94 | + res = {'1e5': 32, '1e6': 64} |
| 95 | + return _get_data(config_name=f'RBC3DG4R4SDC34Ra{Ra}', dt=dts[Ra], res=res[Ra]) |
| 96 | + |
| 97 | + |
| 98 | +def plot_Nu_scaling(ax): # pragma: no cover |
| 99 | + |
| 100 | + # reference values |
| 101 | + for Ra in ['1e5', '1e6']: |
| 102 | + dat = get_Nek5000_Data(Ra) |
| 103 | + ax.errorbar(ints[Ra], dat['Nu'], yerr=dat['std_Nu'], fmt='o', color='black') |
| 104 | + |
| 105 | + # pySDC values |
| 106 | + for Ra in ['1e5', '1e6']: |
| 107 | + dat = get_pySDC_data(Ra) |
| 108 | + ax.errorbar(ints[Ra], dat['avg_Nu']['V'], yerr=dat['std_Nu']['V'], fmt='.', color='tab:blue') |
| 109 | + |
| 110 | + ax.errorbar(None, None, fmt='o', color='black', label='Nek5000') |
| 111 | + ax.errorbar(None, None, fmt='.', color='tab:blue', label='pySDC') |
| 112 | + ax.legend(frameon=False, loc='lower right') |
| 113 | + |
| 114 | + ax.set_xscale('log') |
| 115 | + ax.set_xlabel('$Ra$') |
| 116 | + ax.set_ylabel('$Nu$') |
| 117 | + |
| 118 | + |
| 119 | +def plot_T_profile(ax): # pragma: no cover |
| 120 | + colors = {'1e5': 'tab:blue', '1e6': 'tab:orange'} |
| 121 | + |
| 122 | + # reference values |
| 123 | + for Ra in ['1e5', '1e6']: |
| 124 | + dat = get_Nek5000_Data(Ra) |
| 125 | + ax.plot(dat['profile_T'].mean(axis=0), dat['z'], color=colors[Ra], label=f'Nek5000 Ra={Ra}') |
| 126 | + |
| 127 | + # pySDC values |
| 128 | + for Ra in ['1e5', '1e6']: |
| 129 | + dat = get_pySDC_data(Ra) |
| 130 | + ax.scatter(dat['profile_T'], dat['z'], color=colors[Ra], label=f'pySDC Ra={Ra}') |
| 131 | + |
| 132 | + ax.set_ylabel('$z$') |
| 133 | + ax.set_xlabel('$T$') |
| 134 | + ax.legend() |
| 135 | + |
| 136 | + |
| 137 | +def plot_T_rms_profile(ax): # pragma: no cover |
| 138 | + colors = {'1e5': 'tab:blue', '1e6': 'tab:orange'} |
| 139 | + |
| 140 | + # reference values |
| 141 | + for Ra in ['1e5', '1e6']: |
| 142 | + dat = get_Nek5000_Data(Ra) |
| 143 | + ax.plot(dat['rms_profile_T'], dat['z'], color=colors[Ra], label=f'Nek5000 Ra={Ra}') |
| 144 | + |
| 145 | + # pySDC values |
| 146 | + for Ra in ['1e5', '1e6']: |
| 147 | + dat = get_pySDC_data(Ra) |
| 148 | + ax.scatter(dat['rms_profile_T'], dat['z'], color=colors[Ra], label=f'pySDC Ra={Ra}') |
| 149 | + |
| 150 | + ax.set_ylabel('$z$') |
| 151 | + ax.set_xlabel('$T$') |
| 152 | + ax.legend() |
| 153 | + |
| 154 | + |
| 155 | +def plot_verification(): # pragma: no cover |
| 156 | + from pySDC.projects.RayleighBenard.analysis_scripts.plotting_utils import savefig, figsize |
| 157 | + |
| 158 | + fig, axs = plt.subplots(1, 2, figsize=figsize(scale=1, ratio=0.5)) |
| 159 | + plot_Nu_scaling(axs[0]) |
| 160 | + plot_T_profile(axs[1]) |
| 161 | + fig.tight_layout() |
| 162 | + fig.savefig('plots/verification.pdf') |
| 163 | + |
| 164 | + |
| 165 | +if __name__ == '__main__': |
| 166 | + plot_verification() |
| 167 | + plt.show() |
0 commit comments