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, 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.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()
def main(): mhd_type = "C3" make_plots = 1 mhd_type = mhd_type.upper() if mhd_type.startswith("C"): if mhd_type in ("C",): f = viscid.load_file("$WORK/tmedium/*.3d.[-1].xdmf") elif mhd_type in ("C2", "C3"): f = viscid.load_file("$WORK/tmedium2/*.3d.[-1].xdmf") else: raise ValueError() catol = 1e-8 rtol = 2e-6 elif mhd_type in ("F", "FORTRAN"): f = viscid.load_file("$WORK/tmedium3/*.3df.[-1]") catol = 1e-8 rtol = 7e-2 else: raise ValueError() b = f['b_cc'] b1 = f['b_fc'] e_cc = f['e_cc'] e_ec = f['e_ec'] # divb = f['divB'] # viscid.interact() if True: bD = viscid.empty_like(b) bD.data = np.array(b.data) b1D = viscid.empty_like(b1) b1D.data = np.array(b1.data) mask5 = viscid.make_spherical_mask(bD, rmax=3.5) mask1_5 = viscid.make_spherical_mask(bD, rmax=1.5) viscid.fill_dipole(bD, mask=mask5) viscid.set_in_region(bD, bD, 0.0, 0.0, mask=mask1_5, out=bD) # compare_vectors(_b, bD, make_plots=True) mask5 = viscid.make_spherical_mask(b1D, rmax=3.5) mask1_5 = viscid.make_spherical_mask(b1D, rmax=1.5) viscid.fill_dipole(b1D, mask=mask5) viscid.set_in_region(b1D, b1D, 0.0, 0.0, mask=mask1_5, out=b1D) compare_vectors(bD["x=1:-1, y=1:-1, z=1:-1"], b1D.as_cell_centered(), make_plots=True) # plt.clf() # dkwargs = dict(symmetric=True, earth=True, clim=(-1e2, 1e2)) # ax1 = plt.subplot(311) # vlt.plot(viscid.div(b1)['y=0j'], **dkwargs) # plt.subplot(312, sharex=ax1, sharey=ax1) # vlt.plot(viscid.div(b)['y=0j'], **dkwargs) # plt.subplot(313, sharex=ax1, sharey=ax1) # vlt.plot(viscid.div(b1D)['y=0j'], **dkwargs) # vlt.show() bD = b1D = mask5 = mask1_5 = None # straight up interpolate b1 to cc crds and compare with b if True: b1_cc = viscid.interp_trilin(b1, b).as_flat() viscid.set_in_region(b, b, alpha=0.0, beta=0.0, out=b, mask=viscid.make_spherical_mask(b, rmax=5.0)) viscid.set_in_region(b1_cc, b1_cc, alpha=0.0, beta=0.0, out=b1_cc, mask=viscid.make_spherical_mask(b1_cc, rmax=5.0)) compare_vectors(b, b1_cc, make_plots=True) # make div? if True: # make seeds for 1.5x supersampling b1 n = 128 seeds = viscid.Volume((5.1, -0.02, -5.0), (12.0, 0.02, 5.0), (n, 3, n)) # do interpolation onto new seeds b2 = viscid.interp_trilin(b1, seeds) div_b = viscid.div(b) div_b1 = viscid.div(b1) div_b2 = viscid.div(b2) viscid.set_in_region(div_b, div_b, alpha=0.0, beta=0.0, out=div_b, mask=viscid.make_spherical_mask(div_b, rmax=5.0)) viscid.set_in_region(div_b1, div_b1, alpha=0.0, beta=0.0, out=div_b1, mask=viscid.make_spherical_mask(div_b1, rmax=5.0)) viscid.set_in_region(div_b2, div_b2, alpha=0.0, beta=0.0, out=div_b2, mask=viscid.make_spherical_mask(div_b2, rmax=5.0)) viscid.set_in_region(divb, divb, alpha=0.0, beta=0.0, out=divb, mask=viscid.make_spherical_mask(divb, rmax=5.0)) plt.clf() ax1 = vlt.subplot(311) vlt.plot(div_b['y=0j'], symmetric=True, earth=True) vlt.subplot(312, sharex=ax1, sharey=ax1) # vlt.plot(div_b1['y=0j'], symmetric=True, earth=True) vlt.plot(div_b2['y=0j'], symmetric=True, earth=True) vlt.subplot(313, sharex=ax1, sharey=ax1) vlt.plot(divb['y=0j'], symmetric=True, earth=True) vlt.show() return 0
def main(): mhd_type = "C3" make_plots = 1 mhd_type = mhd_type.upper() if mhd_type.startswith("C"): if mhd_type in ("C", ): f = viscid.load_file("$WORK/tmedium/*.3d.[-1].xdmf") elif mhd_type in ("C2", "C3"): f = viscid.load_file("$WORK/tmedium2/*.3d.[-1].xdmf") else: raise ValueError() catol = 1e-8 rtol = 2e-6 elif mhd_type in ("F", "FORTRAN"): f = viscid.load_file("$WORK/tmedium3/*.3df.[-1]") catol = 1e-8 rtol = 7e-2 else: raise ValueError() b = f['b_cc'] b1 = f['b_fc'] e_cc = f['e_cc'] e_ec = f['e_ec'] # divb = f['divB'] # viscid.interact() if True: bD = viscid.empty_like(b) bD.data = np.array(b.data) b1D = viscid.empty_like(b1) b1D.data = np.array(b1.data) mask5 = viscid.make_spherical_mask(bD, rmax=3.5) mask1_5 = viscid.make_spherical_mask(bD, rmax=1.5) viscid.fill_dipole(bD, mask=mask5) viscid.set_in_region(bD, bD, 0.0, 0.0, mask=mask1_5, out=bD) # compare_vectors(_b, bD, make_plots=True) mask5 = viscid.make_spherical_mask(b1D, rmax=3.5) mask1_5 = viscid.make_spherical_mask(b1D, rmax=1.5) viscid.fill_dipole(b1D, mask=mask5) viscid.set_in_region(b1D, b1D, 0.0, 0.0, mask=mask1_5, out=b1D) compare_vectors(bD["x=1:-1, y=1:-1, z=1:-1"], b1D.as_cell_centered(), make_plots=True) # plt.clf() # dkwargs = dict(symmetric=True, earth=True, clim=(-1e2, 1e2)) # ax1 = plt.subplot(311) # vlt.plot(viscid.div(b1)['y=0j'], **dkwargs) # plt.subplot(312, sharex=ax1, sharey=ax1) # vlt.plot(viscid.div(b)['y=0j'], **dkwargs) # plt.subplot(313, sharex=ax1, sharey=ax1) # vlt.plot(viscid.div(b1D)['y=0j'], **dkwargs) # vlt.show() bD = b1D = mask5 = mask1_5 = None # straight up interpolate b1 to cc crds and compare with b if True: b1_cc = viscid.interp_trilin(b1, b).as_flat() viscid.set_in_region(b, b, alpha=0.0, beta=0.0, out=b, mask=viscid.make_spherical_mask(b, rmax=5.0)) viscid.set_in_region(b1_cc, b1_cc, alpha=0.0, beta=0.0, out=b1_cc, mask=viscid.make_spherical_mask(b1_cc, rmax=5.0)) compare_vectors(b, b1_cc, make_plots=True) # make div? if True: # make seeds for 1.5x supersampling b1 n = 128 seeds = viscid.Volume((5.1, -0.02, -5.0), (12.0, 0.02, 5.0), (n, 3, n)) # do interpolation onto new seeds b2 = viscid.interp_trilin(b1, seeds) div_b = viscid.div(b) div_b1 = viscid.div(b1) div_b2 = viscid.div(b2) viscid.set_in_region(div_b, div_b, alpha=0.0, beta=0.0, out=div_b, mask=viscid.make_spherical_mask(div_b, rmax=5.0)) viscid.set_in_region(div_b1, div_b1, alpha=0.0, beta=0.0, out=div_b1, mask=viscid.make_spherical_mask(div_b1, rmax=5.0)) viscid.set_in_region(div_b2, div_b2, alpha=0.0, beta=0.0, out=div_b2, mask=viscid.make_spherical_mask(div_b2, rmax=5.0)) viscid.set_in_region(divb, divb, alpha=0.0, beta=0.0, out=divb, mask=viscid.make_spherical_mask(divb, rmax=5.0)) plt.clf() ax1 = vlt.subplot(311) vlt.plot(div_b['y=0j'], symmetric=True, earth=True) vlt.subplot(312, sharex=ax1, sharey=ax1) # vlt.plot(div_b1['y=0j'], symmetric=True, earth=True) vlt.plot(div_b2['y=0j'], symmetric=True, earth=True) vlt.subplot(313, sharex=ax1, sharey=ax1) vlt.plot(divb['y=0j'], symmetric=True, earth=True) vlt.show() return 0