Esempio n. 1
0
def run_test_2d(f, main__file__, show=False):
    mpl.clf()
    slc = "x=-20f:12f, y=0f"
    plot_kwargs = dict(title=True, earth=True)
    mpl.subplot(141)
    mpl.plot(f['pp'], slc, logscale=True, **plot_kwargs)
    mpl.plot(np.abs(f['psi']), style='contour', logscale=True, levels=30,
             linewidths=0.8, colors='grey', linestyles='solid', cbar=None,
             x=(-20, 12))
    mpl.subplot(142)
    mpl.plot(viscid.magnitude(f['bcc']), slc, logscale=True, **plot_kwargs)
    mpl.plot2d_quiver(f['v'][slc], step=5, color='y', pivot='mid', width=0.03,
                      scale=600)
    mpl.subplot(143)
    mpl.plot(f['jy'], slc, clim=[-0.005, 0.005], **plot_kwargs)
    mpl.streamplot(f['v'][slc], linewidth=0.3)
    mpl.subplot(144)
    mpl.plot(f['jy'], "x=7f:12f, y=0f, z=0f")

    mpl.plt.suptitle("2D File")
    mpl.auto_adjust_subplots(subplot_params=dict(top=0.9, wspace=1.3))
    mpl.plt.gcf().set_size_inches(10, 4)

    mpl.savefig(next_plot_fname(main__file__))
    if show:
        mpl.show()
Esempio n. 2
0
def _main():
    x = np.linspace(-1, 1, 128)
    y = z = np.linspace(-0.25, 0.25, 8)
    B = viscid.zeros((x, y, z), nr_comps=3, layout='interlaced', name="B")
    X, Y, Z = B.get_crds("xyz", shaped=True)  # pylint: disable=unused-variable
    xl, yl, zl = B.xl  # pylint: disable=unused-variable
    xh, yh, zh = B.xh  # pylint: disable=unused-variable
    xm, ym, zm = 0.5 * (B.xl + B.xh)  # pylint: disable=unused-variable

    B['x'] = 0.0  # np.sin(1.0 * np.pi * X / (xh - xl) + 0.5 * np.pi)
    B['y'] = np.sin(1.0 * np.pi * X / (xh - xl) + 0.5 * np.pi)
    B['z'] = np.sin(1.0 * np.pi * X / (xh - xl) - 1.0 * np.pi)
    B += 0.33 * np.random.random_sample(B.shape)

    # R = viscid.make_rotation_matrix((0, 0, 0), (1, 0, 0), (1, 0, 1))
    # B[...] = np.einsum("ij,lmnj->lmni", R, B)

    lmn = find_minvar_lmn(B, (xl, ym, zm), (xh, ym, zm), l_basis=None)
    # lmn = find_minvar_lmn(B, (xl, ym, zm), (xh, ym, zm), l_basis=(0, 0, 1))
    print("LMN matrix:\n", lmn, sep='')

    ##########
    from viscid.plot import mpl
    p0 = np.array((xm, ym, zm)).reshape((3,))
    pl = p0 + 0.25 * lmn[:, 0]
    pm = p0 + 0.25 * lmn[:, 1]
    pn = p0 + 0.25 * lmn[:, 2]

    print("p0", p0)
    print("pl", pl)
    print("pm", pm)
    print("pn", pn)

    mpl.subplot(211)
    mpl.plot2d_quiver(B['z=0f'])
    mpl.plt.plot([p0[0], pl[0]], [p0[1], pl[1]], color='r', ls='-')
    mpl.plt.plot([p0[0], pm[0]], [p0[1], pm[1]], color='c', ls='-')
    mpl.plt.plot([p0[0], pn[0]], [p0[1], pn[1]], color='b', ls='-')
    mpl.plt.ylabel("Y")

    mpl.subplot(212)
    mpl.plot2d_quiver(B['y=0f'])
    mpl.plt.plot([p0[0], pl[0]], [p0[2], pl[2]], color='r', ls='-')
    mpl.plt.plot([p0[0], pm[0]], [p0[2], pm[2]], color='c', ls='-')
    mpl.plt.plot([p0[0], pn[0]], [p0[2], pn[2]], color='b', ls='-')
    mpl.plt.xlabel("X")
    mpl.plt.ylabel("Z")

    mpl.show()
    ##########

    return 0
Esempio n. 3
0
def run_test_3d(f, main__file__, show=False):
    mpl.clf()
    slc = "x=-20f:12f, y=0f"
    plot_kwargs = dict(title=True, earth=True)
    mpl.subplot(141)
    mpl.plot(f['pp'], slc, logscale=True, **plot_kwargs)
    mpl.subplot(142)
    mpl.plot(viscid.magnitude(f['bcc']), slc, logscale=True, **plot_kwargs)
    mpl.plot2d_quiver(f['v'][slc], step=5, color='y', pivot='mid', width=0.03,
                      scale=600)
    mpl.subplot(143)
    mpl.plot(f['jy'], slc, clim=(-0.005, 0.005), **plot_kwargs)
    mpl.streamplot(f['v'][slc], linewidth=0.3)
    mpl.subplot(144)
    mpl.plot(f['jy'], "x=7f:12f, y=0f, z=0f")

    mpl.plt.suptitle("3D File")
    mpl.auto_adjust_subplots(subplot_params=dict(top=0.9, wspace=1.3))
    mpl.plt.gcf().set_size_inches(10, 4)

    mpl.savefig(next_plot_fname(main__file__))
    if show:
        mpl.show()
Esempio n. 4
0
def main():
    parser = argparse.ArgumentParser(description="Test grad")
    parser.add_argument("--prof", action="store_true")
    parser.add_argument("--show", "--plot", action="store_true")
    args = vutil.common_argparse(parser)

    b = viscid.make_dipole(l=(-5, -5, -5), h=(5, 5, 5), n=(256, 256, 128),
                           m=(0, 0, -1))
    b2 = np.sum(b * b, axis=b.nr_comp)

    if args.prof:
        print("Without boundaries")
        viscid.timeit(viscid.grad, b2, bnd=False, timeit_repeat=10,
                      timeit_print_stats=True)
        print("With boundaries")
        viscid.timeit(viscid.grad, b2, bnd=True, timeit_repeat=10,
                      timeit_print_stats=True)

    grad_b2 = viscid.grad(b2)
    grad_b2.pretty_name = r"$\nabla$ B$^2$"
    conv = viscid.convective_deriv(b)
    conv.pretty_name = r"(B $\cdot \nabla$) B"

    _ = mpl.plt.figure(figsize=(9, 4.2))

    ax1 = mpl.subplot(231)
    mpl.plot(b2['z=0f'], logscale=True)
    mpl.plot(b2['z=0f'], logscale=True, style='contour', levels=10, colors='grey')
    # mpl.plot2d_quiver(viscid.normalize(b['z=0f']), step=16, pivot='mid')
    ax2 = mpl.subplot(234)
    mpl.plot(b2['y=0f'], logscale=True)
    mpl.plot(b2['y=0f'], logscale=True, style='contour', levels=10, colors='grey')
    mpl.plot2d_quiver(viscid.normalize(b['y=0f'], preferred='numpy'),
                      step=16, pivot='mid')

    mpl.subplot(232, sharex=ax1, sharey=ax1)
    mpl.plot(1e-4 + viscid.magnitude(grad_b2['z=0f']), logscale=True)
    mpl.plot(1e-4 + viscid.magnitude(grad_b2['z=0f']), logscale=True,
             style='contour', levels=10, colors='grey')
    mpl.plot2d_quiver(viscid.normalize(grad_b2['z=0f']), step=16, pivot='mid')
    mpl.subplot(235, sharex=ax2, sharey=ax2)
    mpl.plot(1e-4 + viscid.magnitude(grad_b2['y=0f']), logscale=True)
    mpl.plot(1e-4 + viscid.magnitude(grad_b2['y=0f']), logscale=True,
             style='contour', levels=10, colors='grey')
    mpl.plot2d_quiver(viscid.normalize(grad_b2['y=0f']), step=16, pivot='mid')

    mpl.subplot(233, sharex=ax1, sharey=ax1)
    mpl.plot(viscid.magnitude(conv['z=0f']), logscale=True)
    mpl.plot(viscid.magnitude(conv['z=0f']), logscale=True,
             style='contour', levels=10, colors='grey')
    mpl.plot2d_quiver(viscid.normalize(conv['z=0f']), step=16, pivot='mid')
    mpl.subplot(236, sharex=ax2, sharey=ax2)
    mpl.plot(viscid.magnitude(conv['y=0f']), logscale=True)
    mpl.plot(viscid.magnitude(conv['y=0f']), logscale=True,
             style='contour', levels=10, colors='grey')
    mpl.plot2d_quiver(viscid.normalize(conv['y=0f']), step=16, pivot='mid')

    mpl.auto_adjust_subplots()

    mpl.plt.savefig(next_plot_fname(__file__))
    if args.show:
        mpl.show()