def main(): gsize = (2, 2, 2) x1 = -10.0; x2 = -5.0 # pylint: disable=C0321 y1 = -5.0; y2 = 5.0 # pylint: disable=C0321 z1 = -5.0; z2 = 5.0 # pylint: disable=C0321 vol = seed.Volume((z1, y1, x1), (z2, y2, x2), gsize) f3d = readers.load_file("/Users/kmaynard/dev/work/t1/t1.3df.004320.xdmf") fld_bx = f3d["bx"] fld_by = f3d["by"] fld_bz = f3d["bz"] B = field.scalar_fields_to_vector([fld_bx, fld_by, fld_bz], name="B_cc", _force_layout=field.LAYOUT_INTERLACED) topo_arr = np.empty(gsize, order='C', dtype='int') lines, topo = None, None t0 = time() cProfile.runctx("nsegs = py_get_topo(B, topo_arr, x1, x2, y1, y2, z1, z2)", globals(), locals(), "topo.prof") t1 = time() s = pstats.Stats("topo.prof") s.strip_dirs().sort_stats("tottime").print_stats() nsegs = py_get_topo(B, topo_arr, x1, x2, y1, y2, z1, z2) t = t1 - t0 print(topo_arr) # print("numba time: {0}s, {1}s/seg".format(t, t / nsegs)) print("numba time: {0}s".format(t))
def main(): parser = argparse.ArgumentParser(description="Test xdmf") parser.add_argument("--show", "--plot", action="store_true") parser.add_argument('file', nargs="?", default=None) args = vutil.common_argparse(parser) # f3d = readers.load_file(_viscid_root + '/../../sample/sample.3df.xdmf') # b3d = f3d['b'] # bx, by, bz = b3d.component_fields() # pylint: disable=W0612 if args.file is None: args.file = "/Users/kmaynard/dev/work/cen4000/cen4000.3d.xdmf" f3d = readers.load_file(args.file) bx = f3d["bx"] by = f3d["by"] bz = f3d["bz"] B = field.scalar_fields_to_vector([bx, by, bz], name="B_cc", _force_layout=field.LAYOUT_INTERLACED) t0 = time() lines_single, topo = trace_cython(B, nr_procs=1) t1 = time() topo_single = vol.wrap_field(topo, name="CyTopo1") print("single proc:", t1 - t0, "s") nr_procs_list = np.array([1, 2, 3]) # nr_procs_list = np.array([1, 2, 3, 4, 5, 6, 7, 8]) times = np.empty_like(nr_procs_list, dtype="float") print("always parallel overhead now...") for i, nr_procs in enumerate(nr_procs_list): t0 = time() lines, topo = trace_cython(B, nr_procs=nr_procs, force_subprocess=True) t1 = time() fld = vol.wrap_field(topo, name="CyTopo") same_topo = (fld.data == topo_single.data).all() same_lines = True for j, line in enumerate(lines): same_lines = same_lines and (line == lines_single[j]).all() print("nr_procs:", nr_procs, "time:", t1 - t0, "s", "same topo:", same_topo, "same lines:", same_lines) times[i] = t1 - t0 plt.plot(nr_procs_list, times, 'k^') plt.plot(nr_procs_list, times[0] / nr_procs_list, 'b--') plt.xscale("log") plt.yscale("log") plt.show() if False: cmap = plt.get_cmap('spectral') levels = [4, 5, 6, 7, 8, 13, 14, 16, 17] norm = BoundaryNorm(levels, cmap.N) mpl.plot(topo_flds[-1], "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()
def main(): parser = argparse.ArgumentParser(description="Test xdmf") parser.add_argument("--show", "--plot", action="store_true") parser.add_argument('file', nargs="?", default=None) args = vutil.common_argparse(parser) # f3d = readers.load_file(_viscid_root + '/../../sample/sample.3df.xdmf') # b3d = f3d['b'] # bx, by, bz = b3d.component_fields() # pylint: disable=W0612 if args.file is None: # args.file = "/Users/kmaynard/dev/work/cen4000/cen4000.3d.xdmf" # args.file = "/Users/kmaynard/dev/work/tmp/cen2000.3d.004045.xdmf" args.file = "~/dev/work/api_05_180_0.00_5e2.3d.007200.xdmf" f3d = readers.load_file(args.file) bx = f3d["bx"] by = f3d["by"] bz = f3d["bz"] profile = False print("Fortran...") if profile: cProfile.runctx("lines, topo_fort = trace_fortran(bx, by, bz)", globals(), locals(), "topo_fort.prof") s = pstats.Stats("topo_fort.prof") s.strip_dirs().sort_stats("cumtime").print_stats(10) else: lines, topo_fort = trace_fortran(bx, by, bz) print("Cython...") if profile: cProfile.runctx("lines, topo_cy = trace_cython(bx, by, bz)", globals(), locals(), "topo_cy.prof") s = pstats.Stats("topo_cy.prof") s.strip_dirs().sort_stats("cumtime").print_stats(15) else: lines, topo_cy = trace_cython(bx, by, bz)
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