示例#1
0
    def __init__(self, nsx=10.0, nsy=10.0 ,nx=200):
        nsy /= 2
        self.sigma = 4.0 * pi / sqrt(3.0)
        self.lx = self.sigma * nsx
        self.ly = self.sigma * nsy * sqrt(3.0)
        self.nx = nx
        self.ny = int(nx * self.ly / self.lx)
        vecx = linspace(0,self.lx,num=self.nx,endpoint=False)
        vecy = linspace(0,self.ly,num=self.ny,endpoint=False)
        self.X,self.Y = meshgrid(vecx, vecy)

        nthreads = 1
        # flags = ['measure']
        f = fftw3.fftw_flags
        
        self.y   = fftw3.create_aligned_array((self.ny, self.nx), dtype=typeDict['complex'])
        self.yp  = fftw3.create_aligned_array((self.ny, self.nx), dtype=typeDict['complex'])
        self.y3  = fftw3.create_aligned_array((self.ny, self.nx), dtype=typeDict['complex'])
        self.y3p = fftw3.create_aligned_array((self.ny, self.nx), dtype=typeDict['complex'])

        self.y_to_yp = lib.fftw_plan_dft_2d(self.y.shape[0], self.y.shape[1], self.y, self.yp, -1, f['measure'] | f['preserve input'])
        self.yp_to_y = lib.fftw_plan_dft_2d(self.y.shape[0], self.y.shape[1], self.yp, self.y, 1, f['measure'] | f['preserve input'])
        self.y3_to_y3p = lib.fftw_plan_dft_2d(self.y3.shape[0], self.y3.shape[1], self.y3, self.y3p, -1, f['measure'] | f['preserve input'])
        self.y3p_to_y3 = lib.fftw_plan_dft_2d(self.y3.shape[0], self.y3.shape[1], self.y3p, self.y3, 1, f['measure'] | f['preserve input'])

        xlen, ylen = self.nx, self.ny
        kx = array([x for x in range(xlen//2+1)] + [x for x in range(-(xlen-xlen//2-1), 0)])
        ky = array([x for x in range(ylen//2+1)] + [x for x in range(-(ylen-ylen//2-1), 0)])

        self.lap = zeros_like(self.yp)
        lx, ly = self.lx, self.ly
        for iy in xrange(self.lap.shape[0]):
            for ix in xrange(self.lap.shape[1]):
                self.lap[iy,ix] = (-2*pi*1j*kx[ix]/lx)**2.0+(-2*pi*1j*ky[iy]/ly)**2.0
        self.dop_partial = self.lap * (1 + self.lap)**2.0
        self.dop = None
示例#2
0
    def __init__(self,r=-0.2, psi0=-0.5, nsx=10.0, nsy=10.0 ,nx=200, init = 'hex'):
        self.frame_counter = 0
        nsy /= 2
        self.sigma = 4.0 * pi / sqrt(3.0)
        self.r,self.psi0 = float(r),float(psi0)
        self.lx = (2.0 * pi * nsx) if (init == 'stripe') else (self.sigma * nsx)
        self.ly = self.sigma * nsy * sqrt(3.0)
        self.nx = nx
        self.ny = int(nx * self.ly / self.lx)
        vecx = linspace(0,self.lx,num=self.nx,endpoint=False)
        self.xvec = vecx
        vecy = linspace(0,self.ly,num=self.ny,endpoint=False)
        self.X,self.Y = meshgrid(vecx, vecy)

        nthreads = 1
        # flags = ['measure']
        f = fftw3.fftw_flags
        
        self.y   = fftw3.create_aligned_array((self.ny, self.nx), dtype=typeDict['complex'])
        self.yp  = fftw3.create_aligned_array((self.ny, self.nx), dtype=typeDict['complex'])
        self.y3  = fftw3.create_aligned_array((self.ny, self.nx), dtype=typeDict['complex'])
        self.y3p = fftw3.create_aligned_array((self.ny, self.nx), dtype=typeDict['complex'])

        self.y_to_yp = lib.fftw_plan_dft_2d(self.y.shape[0], self.y.shape[1], self.y, self.yp, -1, f['measure'] | f['preserve input'])
        self.yp_to_y = lib.fftw_plan_dft_2d(self.y.shape[0], self.y.shape[1], self.yp, self.y, 1, f['measure'] | f['preserve input'])
        self.y3_to_y3p = lib.fftw_plan_dft_2d(self.y3.shape[0], self.y3.shape[1], self.y3, self.y3p, -1, f['measure'] | f['preserve input'])
        self.y3p_to_y3 = lib.fftw_plan_dft_2d(self.y3.shape[0], self.y3.shape[1], self.y3p, self.y3, 1, f['measure'] | f['preserve input'])

        sqrt3p2 = sqrt(3.0) / 2.0
        # init
        if init == 'ran':
            self.y[:] = self.psi0 + 0.001 * (rand(self.ny, self.nx)-0.5)[:]
        elif init == 'hex':
            self.y[:] = self.psi0 + (2.0 * cos(self.X[:] * sqrt3p2) * cos(self.Y[:] / 2.0) + cos(self.Y[:])) / 3.0
        elif init == 'hom':
            self.y[:] = self.psi0
        elif init == 'stripe':
            self.y[:] = self.psi0 + 0.5 * cos(self.X[:])
        elif init == 'stripe-exp':
            self.y[:] = self.psi0 + cos(self.X[:]) * sqrt(2.0 * (- self.r - 3.0 * self.psi0 ** 2.0) / 3.0) * exp(-0.0005 * (self.X[:] - self.lx / 2.0)**2.0)
        else:
            raise ValueError('not a proper initial condition')

        # envelope = 0.5 * (tanh(- 0.2 * (self.X - self.l / 2.0 - self.l / 15.0)) + 1.0) * 0.5 * (tanh(0.2 * (self.X - self.l / 2.0 + self.l / 15.0)) + 1.0)
        # self.y[:] = self.psi0 * (1.0 - envelope[:]) + envelope[:] * self.y[:]
        
        # for ix in xrange(self.y.shape[0]):
        #     for iy in xrange(self.y.shape[1]):
        #         if (ix-self.n/2)**2 + (iy-self.n/2)**2 > (self.n/8)**2:
        #             self.y[ix,iy] = self.psi0
 

        xlen, ylen = self.nx, self.ny
        kx = array([x for x in range(xlen//2+1)] + [x for x in range(-(xlen-xlen//2-1), 0)])
        ky = array([x for x in range(ylen//2+1)] + [x for x in range(-(ylen-ylen//2-1), 0)])

        self.lap = zeros_like(self.yp)
        lx, ly = self.lx, self.ly
        for iy in xrange(self.lap.shape[0]):
            for ix in xrange(self.lap.shape[1]):
                self.lap[iy,ix] = (-2*pi*1j*kx[ix]/lx)**2.0+(-2*pi*1j*ky[iy]/ly)**2.0
        self.dop = self.lap * (self.r + (1 + self.lap)**2.0)

        lib.fftw_execute(self.y_to_yp)
        
        #self.x = linspace(0, self.l, self.n, endpoint=False)
        #self.y = sin(2*2*pi/self.l*self.x)+sin(5*2*pi/self.l*self.x)+sin(3*2*pi/self.l*self.x)
        # tmp = rfft2(self.y)
        # mask = zeros_like(tmp)
        # mask[0:mask.shape[0]/2, 0:mask.shape[0]/2] = 1.0
        # self.y = irfft(tmp * mask)
        #self.y = self.psi0 + zeros_like(self.x)
        #        self.y = self.psi0 + zeros(self.n)#+ 0.000001 * randn(self.n)
        #        self.y = self.psi0+0.01*sin(2*pi*self.x)
        #        self.y = self.psi0+0.001*cos(2.0*pi*self.x)*exp(-2.0*(self.x-self.l/2.0)**2.0)
        # self.kmask=ones_like(self.yp)
        # self.kmask[:,:20]=0
        # self.kmask[:,-20:]=0
        # self.kmask[:20,:]=0
        # self.kmask[-20:,:]=0

        #        self.kmask = array([[exp(-0.08 * (k_x**2.0 + k_y**2.0)) for k_x in kx] for k_y in ky])
        self.kmask = array([[exp(-0.05 * (k_x**2.0 + (k_y ** 2.0 * self.lx / self.ly))) for k_x in kx] for k_y in ky])
        
        self.saved_curves = []