示例#1
0
def trace_cython(B, nr_procs, force_subprocess=False):
    lines, topo = streamline.streamlines(B, vol, ds0=0.02, ibound=3.7,
                            maxit=5000, output=streamline.OUTPUT_BOTH,
                            method=streamline.EULER1,
                            tol_lo=0.005, tol_hi=0.1,
                            fac_refine=0.75, fac_coarsen=1.5,
                            nr_procs=nr_procs,
                            force_subprocess=force_subprocess)
    return lines, topo
示例#2
0
def trace_cython(fld_bx, fld_by, fld_bz):
    # print("Cython...")
    B = field.scalar_fields_to_vector([fld_bx, fld_by, fld_bz], name="B_cc",
                                      _force_layout=field.LAYOUT_INTERLACED)
    t0 = time()
    lines, topo = None, None
    lines, topo = streamline.streamlines(B, vol, ds0=0.02, ibound=3.7,
                            maxit=5000, output=streamline.OUTPUT_BOTH,
                            method=streamline.EULER1,
                            tol_lo=0.005, tol_hi=0.1,
                            fac_refine=0.75, fac_coarsen=1.5)
    t1 = time()
    topo_fld = vol.wrap_field(topo, name="CyTopo")

    # cmap = plt.get_cmap('spectral')
    # levels = [4, 5, 6, 7, 8, 13, 14, 16, 17]
    # norm = BoundaryNorm(levels, cmap.N)
    # mpl.plot(topo_fld, "y=0", cmap=cmap, norm=norm, show=False)
    # # mpl.plot_streamlines2d(lines[::5], "y", topology=topo[::5], show=False)
    # # mpl.plot_streamlines(lines, topology=topo, show=False)
    # mpl.mplshow()

    # topo_src = mvi.add_field(topo_fld, center='node')
    # mvi.plot_lines(mlab.pipeline, lines[::5], topo[::5], opacity=0.8,
    #                tube_radius=0.02)
    # mvi.plod_earth_3d(mlab.pipeline)
    # mlab.show()

    nsegs = 1  # keep from divding by 0 is no streamlines
    if lines is not None:
        nsegs = 0
        for line in lines:
            nsegs += len(line[0])

    t = t1 - t0
    print("total segments calculated: ", nsegs)
    print("time: {0:.4}s ... {1:.4}s/segment".format(t, t / float(nsegs)))

    return lines, topo_fld
示例#3
0
def main():
    parser = argparse.ArgumentParser(description="Streamline a PSC file")
    parser.add_argument("-t", default="2000",
                        help="which time to plot (finds closest)")
    parser.add_argument('infile', nargs=1, help='input file')
    args = vutil.common_argparse(parser)

    # f = readers.load_file("pfd.020000.xdmf")
    # ... or ...
    # using this way of loading files, one probably wants just to give
    # pfd.xdmf to the command line
    f = readers.load_file(args.infile[0])
    f.activate_time(args.t)

    jz = f["jz"]
    # recreate hx as a field of 0 to keep streamlines from moving in
    # that direction
    hx = field.zeros_like(jz, name="hx")
    h1 = field.scalar_fields_to_vector([hx, f["hy"], f["hz"]], name="H",
                                       _force_layout="Interlaced",
                                       forget_source=True)
    e = field.scalar_fields_to_vector([f["ex"], f["ey"], f["ez"]], name="E",
                                      _force_layout="Interlaced",
                                      forget_source=True)

    # plot magnetic fields, just a sanity check
    # ax1 = plt.subplot(211)
    # mpl.plot(f["hy"], flip_plot=True)
    # ax2 = plt.subplot(212, sharex=ax1, sharey=ax1)
    # mpl.plot(f["hz"], flip_plot=True)
    # mpl.mplshow()

    # make a line of 30 seeds straight along the z axis (x, y, z ordered)
    seeds1 = seed.Line((0.0, 0.0, 2.0), (1022.0, 0.0, 0.0), 60)
    # set outer boundary limits for streamlines
    ds = 0.005  # spatial step along the stream line curve
    obound0 = np.array([1, -128, -1000], dtype=h1.dtype)
    obound1 = np.array([1023, 128, 1000], dtype=h1.dtype)
    # calc the streamlines
    lines1, topo1 = streamline.streamlines(h1, seeds1, ds0=ds, maxit=200000,
                                           obound0=obound0, obound1=obound1,
                                           ibound=0.0)
    # run with -v to see this
    logger.info("Topology flags: {0}".format(topo1))

    # rotate plot puts the z axis along the horizontal
    flip_plot = True
    mpl.plot(jz, flip_plot=flip_plot, plot_opts="lin_-.05_.05")
    # mpl.plot_streamlines2d(lines1, "x", flip_plot=flip_plot, color='k')
    plt.xlim([0, 1024])
    plt.ylim([-128, 128])
    plt.show()

    # interpolate e onto each point of the first field line of lines1
    e1 = cycalc.interp_trilin(e, seed.Point(lines1[0]))
    print(e1.shape, lines1[0].shape)
    plt.clf()
    plt.plot(np.linspace(0, ds * e1.shape[0], e1.shape[0]), e1[:, 0])
    plt.xlabel("length along field line")
    plt.ylabel("Ex")
    plt.show()

    return 0