|
| 1 | +import numpy as np |
| 2 | +# import os |
| 3 | +import matplotlib.pyplot as plt |
| 4 | +from pylab import rcParams |
| 5 | + |
| 6 | +axis_font = {'fontname': 'Arial', 'size': '8', 'family': 'serif'} |
| 7 | +fs = 8 |
| 8 | +ms = 8 |
| 9 | +lw = 2 |
| 10 | + |
| 11 | + |
| 12 | +def create_plots(cwd=''): |
| 13 | + """ |
| 14 | + Function to visualize the results of the Gray-Scott show case |
| 15 | +
|
| 16 | + Args: |
| 17 | + cwd: current working directory |
| 18 | + """ |
| 19 | + |
| 20 | + ref = 'PFASST_GRAYSCOTT_stats_hf_NOFAULT_P32.npz' |
| 21 | + |
| 22 | + list = [('PFASST_GRAYSCOTT_stats_hf_SPREAD_P32.npz', 'SPREAD', '1-sided', 'red', 's'), |
| 23 | + ('PFASST_GRAYSCOTT_stats_hf_INTERP_P32.npz', 'INTERP', '2-sided', 'orange', 'o'), |
| 24 | + ('PFASST_GRAYSCOTT_stats_hf_SPREAD_PREDICT_P32.npz', 'SPREAD_PREDICT', '1-sided+corr', 'blue', '^'), |
| 25 | + ('PFASST_GRAYSCOTT_stats_hf_INTERP_PREDICT_P32.npz', 'INTERP_PREDICT', '2-sided+corr', 'green', 'd'), |
| 26 | + ('PFASST_GRAYSCOTT_stats_hf_NOFAULT_P32.npz', 'NOFAULT', 'no fault', 'black', 'v')] |
| 27 | + # list = [('PFASST_GRAYSCOTT_stats_hf_INTERP_P32_cN512.npz', 'INTERP', '2-sided', 'orange', 'o'), |
| 28 | + # ('PFASST_GRAYSCOTT_stats_hf_INTERP_PREDICT_P32_cN512.npz', 'INTERP_PREDICT', '2-sided+corr', 'green', 'd'), |
| 29 | + # ('PFASST_GRAYSCOTT_stats_hf_NOFAULT_P32.npz', 'NOFAULT', 'no fault', 'black', 'v')] |
| 30 | + |
| 31 | + nprocs = 32 |
| 32 | + |
| 33 | + xtick_dist = 16 |
| 34 | + |
| 35 | + minstep = 288 |
| 36 | + maxstep = 384 |
| 37 | + # minstep = 0 |
| 38 | + # maxstep = 640 |
| 39 | + |
| 40 | + nblocks = int(640 / nprocs) |
| 41 | + |
| 42 | + # maxiter = 14 |
| 43 | + nsteps = 0 |
| 44 | + maxiter = 0 |
| 45 | + vmax = -99 |
| 46 | + for file, strategy, label, color, marker in list: |
| 47 | + data = np.load(cwd + 'data/' + file) |
| 48 | + |
| 49 | + iter_count = data['iter_count'][minstep:maxstep] |
| 50 | + residual = data['residual'][:, minstep:maxstep] |
| 51 | + |
| 52 | + residual[residual <= 0] = 1E-99 |
| 53 | + residual = np.log10(residual) |
| 54 | + vmin = -9 |
| 55 | + vmax = max(vmax, int(np.amax(residual))) |
| 56 | + |
| 57 | + maxiter = max(maxiter, int(max(iter_count))) |
| 58 | + nsteps = max(nsteps, len(iter_count)) |
| 59 | + |
| 60 | + data = np.load(cwd + 'data/' + ref) |
| 61 | + ref_iter_count = data['iter_count'][nprocs - 1::nprocs] |
| 62 | + |
| 63 | + rcParams['figure.figsize'] = 6.0, 2.5 |
| 64 | + fig, ax = plt.subplots() |
| 65 | + |
| 66 | + plt.plot(range(nblocks), [0] * nblocks, 'k-', linewidth=2) |
| 67 | + |
| 68 | + ymin = 99 |
| 69 | + ymax = 0 |
| 70 | + for file, strategy, label, color, marker in list: |
| 71 | + |
| 72 | + if file is not ref: |
| 73 | + data = np.load(cwd + 'data/' + file) |
| 74 | + iter_count = data['iter_count'][nprocs - 1::nprocs] |
| 75 | + |
| 76 | + ymin = min(ymin, min(iter_count - ref_iter_count)) |
| 77 | + ymax = max(ymax, max(iter_count - ref_iter_count)) |
| 78 | + |
| 79 | + plt.plot(range(nblocks), iter_count - ref_iter_count, color=color, label=label, marker=marker, linestyle='', |
| 80 | + linewidth=lw, markersize=ms) |
| 81 | + |
| 82 | + plt.xlabel('block', **axis_font) |
| 83 | + plt.ylabel('$K_\\mathrm{add}$', **axis_font) |
| 84 | + plt.title('ALL') |
| 85 | + plt.xlim(-1, nblocks) |
| 86 | + plt.ylim(-1 + ymin, ymax + 1) |
| 87 | + plt.legend(loc=2, numpoints=1, fontsize=fs) |
| 88 | + plt.tick_params(axis='both', which='major', labelsize=fs) |
| 89 | + ax.xaxis.labelpad = -0.5 |
| 90 | + ax.yaxis.labelpad = -1 |
| 91 | + # plt.tight_layout() |
| 92 | + |
| 93 | + fname = 'data/GRAYSCOTT_Kadd_vs_NOFAULT_hf.png' |
| 94 | + plt.savefig(fname, bbox_inches='tight', rasterize=True) |
| 95 | + # os.system('pdfcrop ' + fname + ' ' + fname) |
| 96 | + |
| 97 | + for file, strategy, label, color, marker in list: |
| 98 | + |
| 99 | + data = np.load(cwd + 'data/' + file) |
| 100 | + |
| 101 | + residual = data['residual'][:, minstep:maxstep] |
| 102 | + stats = data['hard_stats'] |
| 103 | + |
| 104 | + residual[residual <= 0] = 1E-99 |
| 105 | + residual = np.log10(residual) |
| 106 | + |
| 107 | + rcParams['figure.figsize'] = 8.0, 2.0 |
| 108 | + fig, ax = plt.subplots() |
| 109 | + |
| 110 | + cmap = plt.get_cmap('Reds', vmax - vmin + 1) |
| 111 | + pcol = plt.pcolor(residual, cmap=cmap, vmin=vmin, vmax=vmax) |
| 112 | + pcol.set_edgecolor('face') |
| 113 | + |
| 114 | + if file is not ref: |
| 115 | + for item in stats: |
| 116 | + if item[0] in range(minstep, maxstep): |
| 117 | + plt.text(item[0] + 0.5 - (maxstep - nsteps), item[1] - 1 + 0.5, 'x', horizontalalignment='center', |
| 118 | + verticalalignment='center') |
| 119 | + |
| 120 | + plt.axis([0, nsteps, 0, maxiter]) |
| 121 | + |
| 122 | + ticks = np.arange(vmin, vmax + 1, 2) |
| 123 | + tickpos = np.linspace(ticks[0] + 0.5, ticks[-1] - 0.5, len(ticks)) |
| 124 | + cax = plt.colorbar(pcol, ticks=tickpos, pad=0.02) |
| 125 | + cax.set_ticklabels(ticks) |
| 126 | + cax.ax.tick_params(labelsize=fs) |
| 127 | + |
| 128 | + cax.set_label('log10(residual)', **axis_font) |
| 129 | + plt.tick_params(axis='both', which='major', labelsize=fs) |
| 130 | + ax.xaxis.labelpad = -0.5 |
| 131 | + ax.yaxis.labelpad = -0.5 |
| 132 | + |
| 133 | + ax.set_xlabel('step', **axis_font) |
| 134 | + ax.set_ylabel('iteration', **axis_font) |
| 135 | + |
| 136 | + ax.set_yticks(np.arange(1, maxiter, 2) + 0.5, minor=False) |
| 137 | + ax.set_xticks(np.arange(0, nsteps, xtick_dist) + 0.5, minor=False) |
| 138 | + ax.set_yticklabels(np.arange(1, maxiter, 2) + 1, minor=False) |
| 139 | + ax.set_xticklabels(np.arange(minstep, maxstep, xtick_dist), minor=False) |
| 140 | + |
| 141 | + plt.title(strategy) |
| 142 | + # plt.tight_layout() |
| 143 | + |
| 144 | + fname = 'data/GRAYSCOTT_steps_vs_iteration_hf_' + strategy + '.png' |
| 145 | + plt.savefig(fname, bbox_inches='tight', rasterize=True) |
| 146 | + # os.system('pdfcrop ' + fname + ' ' + fname) |
| 147 | + |
| 148 | + |
| 149 | +if __name__ == "__main__": |
| 150 | + create_plots() |
0 commit comments