예제 #1
0
    def __init__(self, grid, base, dimensions=None):
        self.base = base

        if dimensions is None:
            dimensions = list(range(grid.nd))

        self.fft = g.fft(dimensions)

        # create FA mask
        cache = {}
        self.weight = g.complex(grid)
        self.weight[:] = 0
        coor = g.coordinates(self.weight)
        for mu in dimensions:
            c_mu = coor[:, mu].astype(np.complex128)
            c_mu_l = g.complex(grid)
            c_mu_l[coor, cache] = c_mu
            c_mu_l @= g.component.sin(c_mu_l * (np.pi / grid.gdimensions[mu]))
            c_mu_l @= c_mu_l * c_mu_l * complex(4.0)
            self.weight += c_mu_l

        # special consideration for zero
        self.weight[0, 0, 0, 0] = (2.0 * np.pi)**2.0 / np.prod(
            [grid.gdimensions[mu]
             for mu in dimensions])**(2.0 / len(dimensions))

        # invert
        self.weight @= g.component.inv(self.weight) * complex(
            4.0 * len(dimensions))
        self.weight = [self.weight]
예제 #2
0
def correlate(a, b, dims=None):
    # c[x] = (1/vol) sum_y a[y]*adj(b[y+x])
    F = gpt.fft(dims=dims)
    if dims is not None:
        norm = numpy.prod([a.grid.gdimensions[d] for d in dims])
    else:
        norm = a.grid.fsites
    return F(gpt(float(norm) * F(a) * gpt.adj(F(b))))
예제 #3
0
g.message("Momentum inverse test: ", eps)
assert eps < 1e-20

eps = g.norm2(g.adj(exp_ixp) * exp_ixp * l_dp - l_dp) / g.norm2(l_dp)
g.message("Momentum adj test: ", eps)
assert eps < 1e-20

eps = g.norm2(g.adj(exp_ixp * exp_ixp) * exp_ixp * exp_ixp * l_dp -
              l_dp) / g.norm2(l_dp)
g.message("Momentum adj test (2): ", eps)
assert eps < 1e-20

################################################################################
# Test FFT
################################################################################
fft_l_sp = g.eval(g.fft() * l_sp)
eps = g.norm2(g.adj(g.fft()) * fft_l_sp - l_sp) / g.norm2(l_sp)
g.message("FFTinv * FFT:", eps)
assert eps < 1e-12

eps = g.norm2(g.sum(exp_ixp * l_sp) / np.prod(L) - fft_l_sp[1, 2, 3, 4])
g.message("FFT forward test:", eps)
assert eps < 1e-12

fft_mom_A = g.slice(
    g.exp_ixp(2.0 * np.pi * np.array([1, 2, 3, 0]) / L) * l_sp, 3) / np.prod(
        L[0:3])
fft_mom_B = [
    g.vcolor(x) for x in g.eval(g.fft([0, 1, 2]) * l_sp)[1, 2, 3, 0:L[3]]
]
for t in range(L[3]):
예제 #4
0
파일: coordinates.py 프로젝트: waterret/gpt
def correlate(a, b, dims=None):
    # c[x] = (1/vol) sum_y a[y]*b[y+x]
    F = gpt.fft(dims=dims)
    G = gpt.adj(F)
    return F(gpt(F(a) * G(b)))