Esempio n. 1
0
def fake_decomp_hilbert_uniform(npart,
                                nfiles,
                                ifile,
                                DLE,
                                DRE,
                                buff=0.0,
                                order=6,
                                verbose=False):
    np.random.seed(int(0x4D3D3D3) + ifile)
    DW = DRE - DLE
    dim_hilbert = 1 << order
    nH = dim_hilbert**3
    if nH < nfiles:
        raise Exception("Fewer hilbert cells than files.")
    nHPF = nH / nfiles
    rHPF = nH % nfiles
    nPH = npart / nH
    nRH = npart % nH
    hind = np.arange(nH, dtype="int64")
    hpos = get_hilbert_points(order, hind)
    hdiv = DW / dim_hilbert
    if ifile == 0:
        hlist = range(0, nHPF + rHPF)
        nptot = nPH * len(hlist) + nRH
    else:
        hlist = range(ifile * nHPF + rHPF, (ifile + 1) * nHPF + rHPF)
        nptot = nPH * len(hlist)
    pos = np.empty((nptot, 3), dtype="float")
    pc = 0
    for i in hlist:
        iLE = DLE + hdiv * hpos[i, :]
        iRE = iLE + hdiv
        for k in range(3):  # Don't add buffer past domain bounds
            if hpos[i, k] != 0:
                iLE[k] -= buff * hdiv[k]
            if hpos[i, k] != (dim_hilbert - 1):
                iRE[k] += buff * hdiv[k]
        inp = nPH
        if (ifile == 0) and (i == 0):
            inp += nRH
        for k in range(3):
            pos[pc:(pc + inp), k] = np.random.uniform(iLE[k], iRE[k], inp)
        pc += inp
    return pos
Esempio n. 2
0
def fake_decomp_hilbert_gaussian(npart,
                                 nfiles,
                                 ifile,
                                 DLE,
                                 DRE,
                                 buff=0.0,
                                 order=6,
                                 verbose=False,
                                 fname=None):
    np.random.seed(int(0x4D3D3D3))
    DW = DRE - DLE
    dim_hilbert = 1 << order
    nH = dim_hilbert**3
    if nH < nfiles:
        raise Exception("Fewer hilbert cells than files.")
    nHPF = nH / nfiles
    rHPF = nH % nfiles
    hdiv = DW / dim_hilbert
    if ifile == 0:
        hlist = np.arange(0, nHPF + rHPF, dtype="int64")
    else:
        hlist = np.arange(ifile * nHPF + rHPF, (ifile + 1) * nHPF + rHPF,
                          dtype="int64")
    hpos = get_hilbert_points(order, hlist)
    iLE = np.empty((len(hlist), 3), dtype="float")
    iRE = np.empty((len(hlist), 3), dtype="float")
    count = np.zeros(3, dtype="int64")
    pos = np.empty((npart, 3), dtype="float")
    for k in range(3):
        iLE[:, k] = DLE[k] + hdiv[k] * hpos[:, k]
        iRE[:, k] = iLE[:, k] + hdiv[k]
        iLE[hpos[:, k] != 0, k] -= buff * hdiv[k]
        iRE[hpos[:, k] != (dim_hilbert - 1), k] += buff * hdiv[k]
        gpos = np.clip(
            np.random.normal(DLE[k] + DW[k] / 2.0, DW[k] / 10.0, npart),
            DLE[k], DRE[k])
        for ipos in gpos:
            for i in range(len(hlist)):
                if iLE[i, k] <= ipos < iRE[i, k]:
                    pos[count[k], k] = ipos
                    count[k] += 1
                    break
    return pos[:count.min(), :]