Example #1
0
def testglobind():
    domain = cowpy.DistributedDomain([10, 10, 10], guard=3)
    dfield = cowpy.DataField(domain, ["vx", "vy", "vz"])
    dfield.interior[:, :, :, :] = np.mgrid[0:10, 0:10,
                                           0:10].transpose([1, 2, 3, 0])
    x, y, z = dfield.index_global([2, 3, 4])
    assert abs(x - 2) < 1e-16
    assert abs(y - 3) < 1e-16
    assert abs(z - 4) < 1e-16
Example #2
0
def testio():
    domain = cowpy.DistributedDomain([12, 12, 16], guard=3)
    dfield = cowpy.DataField(domain, ["vx", "vy", "vz"], name="vel")
    dfield["vx"] = 2.1
    dfield["vy"] = 2.2
    dfield["vz"] = 2.3
    dfield.dump("test.h5")
    dfield.value[:] = 0.0
    dfield.read("test.h5")
    assert abs(dfield["vx"] - 2.1).all() < 1e-16
    assert abs(dfield["vy"] - 2.2).all() < 1e-16
    assert abs(dfield["vz"] - 2.3).all() < 1e-16
Example #3
0
def testverify():
    domain = cowpy.DistributedDomain([4, 4], guard=1)
    dfield = cowpy.DataField(domain, ["vx", "vy", "vz"], name="vel")
    dfield["vx"] = 2.1
    dfield["vy"] = 2.2
    dfield["vz"] = 2.3
    dfield["vx"][3, 3] = np.nan
    dfield["vx"][3, 4] = np.inf
    dfield.flags = 0
    dfield.setflags_infnan()
    assert (dfield.flags[3, 3] == 4)
    assert (dfield.flags[3, 4] == 8)
Example #4
0
def testsamp():
    domain = cowpy.DistributedDomain([10, 10, 10], guard=3)
    dfield = cowpy.DataField(domain, ["vx", "vy", "vz"])
    np.random.seed(domain.cart_rank)
    sampx = np.random.rand(10, 3)
    dfield["vx"] = 2.1
    dfield["vy"] = 2.2
    dfield["vz"] = 2.3
    x, P = dfield.sample_global(sampx)
    assert abs(P[:, 0] - 2.1).all() < 1e-16
    assert abs(P[:, 1] - 2.2).all() < 1e-16
    assert abs(P[:, 2] - 2.3).all() < 1e-16
    assert len(x) == len(sampx)
Example #5
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()
Example #6
0
def test1():
    domain = cowpy.DistributedDomain([N, N, N], guard=3)
    dfield = cowpy.DataField(domain, ["vx"], name="vel1")
    dfield.dump(fname)
Example #7
0
def testuserbuffer():
    buffer = np.zeros([10, 10, 10, 1], order='C')
    domain = cowpy.DistributedDomain([6, 6, 6], guard=2)
    dfield = cowpy.DataField(domain, members=['f'], buffer=buffer)