Esempio n. 1
0
def runstats(fname, opts):
    V = cowpy.fromfile(fname,
                       "prim",
                       members=["vx", "vy", "vz"],
                       vec3d=True,
                       guard=2,
                       downsample=opts.downsample)
    B = cowpy.fromfile(fname,
                       "prim",
                       members=["Bx", "By", "Bz"],
                       vec3d=True,
                       guard=2,
                       downsample=opts.downsample)
    V.name = "V"
    B.name = "B"
    f = {}
    f["divV"] = V.divergence()
    f["divB"] = B.divergence()
    f["curlV"] = V.curl()
    f["curlB"] = B.curl()
    f["vdotB"] = cowpy.dot_product(V, B)
    f["vcrossB"] = cowpy.cross_product(V, B)
    f["curlBdotvcrossB"] = cowpy.cross_product(f["curlB"], f["vcrossB"])
    f["curlBdotB"] = cowpy.dot_product(f["curlB"], B)
    f["vcrossBcrossB"] = cowpy.cross_product(f["vcrossB"], B)
    f["divvcrossBcrossB"] = f["vcrossBcrossB"].divergence()

    if opts.output:
        for thing in f:
            hist = maghist(f[thing])
            hist.name = thing + "-hist"
            hist.dump(opts.output)
Esempio n. 2
0
def testfromfile():
    field = cowpy.fromfile("test.h5", group="vel")
    print field
    sparsefield = cowpy.fromfile("test.h5", group="vel", downsample=2)
    assert sparsefield.value.shape == (12 / 2, 12 / 2, 16 / 2, 3)
    print sparsefield
    # Test with a strange downsampling factor and with guard cells
    sparsefield = cowpy.fromfile("test.h5", group="vel", downsample=3, guard=3)
    print sparsefield
    assert sparsefield.value.shape == (4 + 2 * 3, 4 + 2 * 3, 6 + 2 * 3, 3)
Esempio n. 3
0
def testfromfile():
    field = cowpy.fromfile("test.h5", group="vel")
    print field
    sparsefield = cowpy.fromfile("test.h5", group="vel", downsample=2)
    assert sparsefield.value.shape == (12/2, 12/2, 16/2, 3)
    print sparsefield
    # Test with a strange downsampling factor and with guard cells
    sparsefield = cowpy.fromfile("test.h5", group="vel", downsample=3, guard=3)
    print sparsefield
    assert sparsefield.value.shape == (4+2*3, 4+2*3, 6+2*3, 3)
Esempio n. 4
0
def vrel(fname, opts):
    V = cowpy.fromfile(fname,
                       "prim",
                       members=["vx", "vy", "vz"],
                       vec3d=True,
                       guard=2,
                       downsample=opts.downsample)
    np.random.seed(V.domain.cart_rank)
    nsamp = int(opts.pairs * 2)
    npair = int(opts.pairs)
    sampx = np.random.rand(nsamp, 3)
    x, P = V.sample_global(sampx)
    histP = cowpy.Histogram1d(0.0, 1.5, bins=opts.bins, binmode="average")

    for n in range(npair):
        i0 = np.random.randint(0, len(P))
        i1 = np.random.randint(0, len(P))
        dx = np.dot(x[i1] - x[i0], x[i1] - x[i0])**0.5
        dP = np.dot(P[i1] - P[i0], P[i1] - P[i0])**0.5
        histP.add_sample(dx, weight=dP)
    histP.seal()

    if V.domain.cart_rank == 0:
        import matplotlib.pyplot as plt
        plt.plot(histP.binloc, histP.binval, label="P")
        plt.legend(loc='best')
        plt.show()
Esempio n. 5
0
def runstats(fname, opts):
    V = cowpy.fromfile(fname, "prim", members=["vx","vy","vz"], vec3d=True,
                       guard=2, downsample=opts.downsample)
    B = cowpy.fromfile(fname, "prim", members=["Bx","By","Bz"], vec3d=True,
                       guard=2, downsample=opts.downsample)
    V.name = "V"
    B.name = "B"
    f = { }
    f["divV"] = V.divergence()
    f["divB"] = B.divergence()
    f["curlV"] = V.curl()
    f["curlB"] = B.curl()
    f["vdotB"] = cowpy.dot_product(V, B)
    f["vcrossB"] = cowpy.cross_product(V, B)
    f["curlBdotvcrossB"] = cowpy.cross_product(f["curlB"], f["vcrossB"])
    f["curlBdotB"] = cowpy.dot_product(f["curlB"], B)
    f["vcrossBcrossB"] = cowpy.cross_product(f["vcrossB"], B)
    f["divvcrossBcrossB"] = f["vcrossBcrossB"].divergence()

    if opts.output:
        for thing in f:
            hist = maghist(f[thing])
            hist.name = thing + "-hist"
            hist.dump(opts.output)
Esempio n. 6
0
def cversion(fname, opts):
    V = cowpy.fromfile(fname, "prim", members=["vx","vy","vz"], vec3d=True,
                       guard=2, downsample=opts.downsample)
    histpro, histlab = pairs(V, opts.pairs, bins=opts.bins)
    histpro.name = "gamma-rel-drprop-hist"
    histlab.name = "gamma-rel-drlab-hist"

    if opts.output:
        histpro.dump(opts.output)
        histlab.dump(opts.output)

    if opts.plot and V.domain.cart_rank == 0:
        import matplotlib.pyplot as plt
        plt.plot(histpro.binloc, histpro.binval, label=histpro.name)
        plt.plot(histlab.binloc, histlab.binval, label=histlab.name)
        plt.legend(loc='best')
        #plt.ylim(1.0, 2.8)
        plt.show()
Esempio n. 7
0
def gammarel(fname, opts):
    V = cowpy.fromfile(fname,
                       "prim",
                       members=["vx", "vy", "vz"],
                       vec3d=True,
                       guard=2,
                       downsample=opts.downsample)
    U = cowpy.DataField(V.domain, members=["u0", "u1", "u2", "u3"])
    np.random.seed(V.domain.cart_rank)
    nsamp = int(opts.pairs * 2)
    npair = int(opts.pairs)
    sampx = np.random.rand(nsamp, 3)

    vx, vy, vz = V.value[..., 0], V.value[..., 1], V.value[..., 2]
    U.value[..., 0] = 1.0 / (1.0 - (vx**2 + vy**2 + vz**2))**0.5
    U.value[..., 1] = vx * U.value[..., 0]
    U.value[..., 2] = vy * U.value[..., 0]
    U.value[..., 3] = vz * U.value[..., 0]
    U.sync_guard()

    x, P = U.sample_global(sampx)
    histP = cowpy.Histogram1d(0.0, 1.5, bins=opts.bins, binmode="average")
    for n in range(npair):
        i0 = np.random.randint(0, len(P))
        i1 = np.random.randint(0, len(P))
        dx = np.dot(x[i1] - x[i0], x[i1] - x[i0])**0.5
        dg = P[i0][0] * P[i1][0] - np.dot(P[i0][1:], P[i1][1:])
        histP.add_sample(dx, weight=dg)
    histP.seal()
    histP.name = "gamma-rel-drlab-hist"

    if opts.output:
        histP.dump(opts.output)

    if opts.plot and V.domain.cart_rank == 0:
        import matplotlib.pyplot as plt
        plt.plot(histP.binloc, histP.binval, label="P")
        plt.legend(loc='best')
        plt.ylim(1.0, 2.8)
        plt.show()
Esempio n. 8
0
def cversion(fname, opts):
    V = cowpy.fromfile(fname,
                       "prim",
                       members=["vx", "vy", "vz"],
                       vec3d=True,
                       guard=2,
                       downsample=opts.downsample)
    histpro, histlab = pairs(V, opts.pairs, bins=opts.bins)
    histpro.name = "gamma-rel-drprop-hist"
    histlab.name = "gamma-rel-drlab-hist"

    if opts.output:
        histpro.dump(opts.output)
        histlab.dump(opts.output)

    if opts.plot and V.domain.cart_rank == 0:
        import matplotlib.pyplot as plt
        plt.plot(histpro.binloc, histpro.binval, label=histpro.name)
        plt.plot(histlab.binloc, histlab.binval, label=histlab.name)
        plt.legend(loc='best')
        #plt.ylim(1.0, 2.8)
        plt.show()
Esempio n. 9
0
def vrel(fname, opts):
    V = cowpy.fromfile(fname, "prim", members=["vx","vy","vz"], vec3d=True,
                       guard=2, downsample=opts.downsample)
    np.random.seed(V.domain.cart_rank)
    nsamp = int(opts.pairs * 2)
    npair = int(opts.pairs)
    sampx = np.random.rand(nsamp, 3)
    x, P = V.sample_global(sampx)
    histP = cowpy.Histogram1d(0.0, 1.5, bins=opts.bins, binmode="average")

    for n in range(npair):
        i0 = np.random.randint(0, len(P))
        i1 = np.random.randint(0, len(P))
        dx = np.dot(x[i1] - x[i0], x[i1] - x[i0])**0.5
        dP = np.dot(P[i1] - P[i0], P[i1] - P[i0])**0.5
        histP.add_sample(dx, weight=dP)
    histP.seal()

    if V.domain.cart_rank == 0:
        import matplotlib.pyplot as plt
        plt.plot(histP.binloc, histP.binval, label="P")
        plt.legend(loc='best')
        plt.show()
Esempio n. 10
0
def gammarel(fname, opts):
    V = cowpy.fromfile(fname, "prim", members=["vx","vy","vz"], vec3d=True,
                       guard=2, downsample=opts.downsample)
    U = cowpy.DataField(V.domain, members=["u0", "u1", "u2", "u3"])
    np.random.seed(V.domain.cart_rank)
    nsamp = int(opts.pairs * 2)
    npair = int(opts.pairs)
    sampx = np.random.rand(nsamp, 3)

    vx, vy, vz = V.value[...,0], V.value[...,1], V.value[...,2]
    U.value[...,0] = 1.0 / (1.0 - (vx**2 + vy**2 + vz**2))**0.5
    U.value[...,1] = vx * U.value[...,0]
    U.value[...,2] = vy * U.value[...,0]
    U.value[...,3] = vz * U.value[...,0]
    U.sync_guard()

    x, P = U.sample_global(sampx)
    histP = cowpy.Histogram1d(0.0, 1.5, bins=opts.bins, binmode="average")
    for n in range(npair):
        i0 = np.random.randint(0, len(P))
        i1 = np.random.randint(0, len(P))
        dx = np.dot(x[i1] - x[i0], x[i1] - x[i0])**0.5
        dg = P[i0][0]*P[i1][0] - np.dot(P[i0][1:], P[i1][1:])
        histP.add_sample(dx, weight=dg)
    histP.seal()
    histP.name = "gamma-rel-drlab-hist"

    if opts.output:
        histP.dump(opts.output)

    if opts.plot and V.domain.cart_rank == 0:
        import matplotlib.pyplot as plt
        plt.plot(histP.binloc, histP.binval, label="P")
        plt.legend(loc='best')
        plt.ylim(1.0, 2.8)
        plt.show()