def run_div_test(fld, exact, show=False, ignore_inexact=False): t0 = time() result_numexpr = viscid.div(fld, preferred="numexpr", only=True) t1 = time() logger.info("numexpr magnitude runtime: %g", t1 - t0) result_diff = viscid.diff(result_numexpr, exact[1:-1, 1:-1, 1:-1]) if not ignore_inexact and not (result_diff.data < 5e-5).all(): logger.warn("numexpr result is far from the exact result") logger.info("min/max(abs(numexpr - exact)): %g / %g", np.min(result_diff.data), np.max(result_diff.data)) planes = ["y=0f", "z=0f"] nrows = 2 ncols = len(planes) ax = plt.subplot2grid((nrows, ncols), (0, 0)) ax.axis("equal") for i, p in enumerate(planes): plt.subplot2grid((nrows, ncols), (0, i), sharex=ax, sharey=ax) mpl.plot(result_numexpr, p, show=False) plt.subplot2grid((nrows, ncols), (1, i), sharex=ax, sharey=ax) mpl.plot(result_diff, p, show=False) if show: mpl.mplshow()
def run_div_test(fld, exact, title='', show=False, ignore_inexact=False): t0 = time() result_numexpr = viscid.div(fld, preferred="numexpr", only=False) t1 = time() logger.info("numexpr magnitude runtime: %g", t1 - t0) result_diff = viscid.diff(result_numexpr, exact)['x=1:-1, y=1:-1, z=1:-1'] if not ignore_inexact and not (result_diff.data < 5e-5).all(): logger.warning("numexpr result is far from the exact result") logger.info("min/max(abs(numexpr - exact)): %g / %g", np.min(result_diff.data), np.max(result_diff.data)) planes = ["y=0j", "z=0j"] nrows = 2 ncols = len(planes) _, axes = plt.subplots(nrows, ncols, squeeze=False) for i, p in enumerate(planes): vlt.plot(result_numexpr, p, ax=axes[0, i], show=False) vlt.plot(result_diff, p, ax=axes[1, i], show=False) plt.suptitle(title) vlt.auto_adjust_subplots(subplot_params=dict(top=0.9)) plt.savefig(next_plot_fname(__file__)) if show: vlt.mplshow()
def run_div_test(fld, exact, title='', show=False, ignore_inexact=False): t0 = time() result_numexpr = viscid.div(fld, preferred="numexpr", only=False) t1 = time() logger.info("numexpr magnitude runtime: %g", t1 - t0) result_diff = viscid.diff(result_numexpr, exact)['x=1:-1, y=1:-1, z=1:-1'] if not ignore_inexact and not (result_diff.data < 5e-5).all(): logger.warn("numexpr result is far from the exact result") logger.info("min/max(abs(numexpr - exact)): %g / %g", np.min(result_diff.data), np.max(result_diff.data)) planes = ["y=0f", "z=0f"] nrows = 2 ncols = len(planes) ax = plt.subplot2grid((nrows, ncols), (0, 0)) ax.axis("equal") for i, p in enumerate(planes): plt.subplot2grid((nrows, ncols), (0, i), sharex=ax, sharey=ax) mpl.plot(result_numexpr, p, show=False) plt.subplot2grid((nrows, ncols), (1, i), sharex=ax, sharey=ax) mpl.plot(result_diff, p, show=False) mpl.plt.suptitle(title) mpl.auto_adjust_subplots(subplot_params=dict(top=0.9)) mpl.plt.savefig(next_plot_fname(__file__)) if show: mpl.mplshow()