Update to plot PML diffs

这个提交包含在:
Craig Warren
2023-08-31 20:59:24 +01:00
父节点 631d9a8414
当前提交 b5fe96ae21

查看文件

@@ -21,6 +21,7 @@ import logging
from operator import add from operator import add
from pathlib import Path from pathlib import Path
import matplotlib.gridspec as gridspec
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
@@ -30,7 +31,7 @@ logger = logging.getLogger(__name__)
# Create/setup plot figure # Create/setup plot figure
# Plot colours from http://tools.medialab.sciences-po.fr/iwanthue/index.php # Plot colours from http://tools.medialab.sciences-po.fr/iwanthue/index.php
colorIDs = ["#79c72e", "#5774ff", "#ff7c2c", "#4b4e80", "#d7004e", "#007545", "#ff83ec"] colorIDs = ["#79c72e", "#5774ff", "#ff7c2c", "#4b4e80", "#d7004e", "#007545"]
colors = itertools.cycle(colorIDs) colors = itertools.cycle(colorIDs)
lines = itertools.cycle(("--", ":", "-.", "-")) lines = itertools.cycle(("--", ":", "-.", "-"))
markers = ["o", "d", "^", "s", "*"] markers = ["o", "d", "^", "s", "*"]
@@ -40,36 +41,42 @@ basename = "pml_basic"
PMLIDs = ["off", "x0", "y0", "z0", "xmax", "ymax", "zmax"] PMLIDs = ["off", "x0", "y0", "z0", "xmax", "ymax", "zmax"]
maxerrors = [] maxerrors = []
for x in range(len(PMLIDs)): for x, PMLID in enumerate(PMLIDs):
file1 = fn.parent.joinpath(basename + str(x + 1) + "_CPU.h5") file1 = fn.parent.joinpath(basename + str(x + 1) + "_CPU.h5")
file2 = fn.parent.joinpath(basename + str(x + 1) + "_GPU.h5") file2 = fn.parent.joinpath(basename + str(x + 1) + "_GPU.h5")
time, datadiffs = diff_output_files(file1, file2) time, datadiffs = diff_output_files(file1, file2)
# Print maximum error value # Print maximum error value
start = 0 start = 150
maxerrors.append(f": {np.amax(datadiffs[start::, 1]):.1f} [dB]") maxerrors.append(f": {np.amax(np.amax(datadiffs[start::, :])):.1f} [dB]")
logger.info(f"{file1.name} - {file2.name}: Max. error {maxerrors[x]}") print(f"{PMLID}: Max. error {maxerrors[x]}")
fig, ax = plt.subplots( # Plot diffs
subplot_kw=dict(xlabel="Iterations", ylabel="Error [dB]"), figsize=(20, 10), facecolor="w", edgecolor="w") gs = gridspec.GridSpec(3, 2, hspace=0.3, wspace=0.3)
fig, ax = plt.subplots(figsize=(20, 10), facecolor="w", edgecolor="w")
ax.remove()
fig.suptitle(f"{PMLID}")
# Plot diffs (select column to choose field component, 0-Ex, 1-Ey etc..) outputs = ["Ex", "Ey", "Ez", "Hx", "Hy", "Hz"]
ax.plot(time[start::], datadiffs[start::, 1], color=next(colors), lw=2, ls=next(lines), label=f"{file1.name} - {file2.name}") for i, output in enumerate(outputs):
ax.set_xticks(np.arange(0, 2200, step=100)) if i < 3:
ax.set_xlim([0, 2100]) ax = plt.subplot(gs[i, 0])
ax.set_yticks(np.arange(-160, 0, step=20)) else:
ax.set_ylim([-160, -20]) ax = plt.subplot(gs[i - 3, 1])
ax.set_axisbelow(True) ax.plot(time[start::], datadiffs[start::, i], color=next(colors), lw=2)
ax.grid(color=(0.75, 0.75, 0.75), linestyle="dashed") ax.set_xticks(np.arange(0, 1800, step=200))
ax.set_xlim([0, 1600])
ax.set_yticks(np.arange(-400, 80, step=40))
ax.set_ylim([-400, 40])
ax.set_axisbelow(True)
ax.grid(color=(0.75, 0.75, 0.75), linestyle="dashed")
ax.set_xlabel("Time [iterations]")
ax.set_ylabel(f"{output} error [dB]")
mylegend = list(map(add, PMLIDs, maxerrors)) # Save a PDF/PNG of the figure
legend = ax.legend(mylegend, loc=1, fontsize=14) fig.savefig(basename + "_diffs_" + PMLID + ".pdf", dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1)
frame = legend.get_frame() # fig.savefig(basename + "_diffs_" + PMLID + ".png", dpi=150, format='png', bbox_inches='tight', pad_inches=0.1)
frame.set_edgecolor("white")
frame.set_alpha(0)
plt.show() plt.show()
# Save a PDF/PNG of the figure
# fig.savefig(basepath + '.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1)
# fig.savefig(savename + '.png', dpi=150, format='png', bbox_inches='tight', pad_inches=0.1)