0

I have some difficulty in running the code. When I run it, this kind of error always appears:

Traceback (most recent call last):
  File "C:\Users\zhangjq058\workspace\22222222\src\222.py", line 20, in <module>
    x, y = meshgrid(fftfreq(th.shape[0], dx), fftfreq(th.shape[1], dx))
  File "C:\Python27\lib\site-packages\numpy\fft\helper.py", line 153, in fftfreq
    assert isinstance(n,types.IntType) or isinstance(n, integer)
AssertionError

The code is:

from pylab import *
from numpy import *
N = 100 #lattice points per axis
dt = 1 #time step
dx = 1 #lattice spacing
t = arange(0, 10000*dt, dt) #time
a = 1 #cofficient
epsilon = 100 #cofficient
M = 1.0 #cofficient
every = 100 #dump an image every
phi_0 = 0.5 #initial mean value of the order parameter
noise = 0.1 #initial amplitude of thermal fluctuations in the order parameter
th = phi_0*ones((N, N)) + noise*(rand(N, N) - 0.5) #initial condition
x, y = meshgrid(fftfreq(th.shape[0], dx), fftfreq(th.shape[1], dx))
k2 = (x*x + y*y) #k is a victor in the Fourier space, k2=x^2+y^2
g = lambda th, a: 4*a*th*(1-th)*(1-2*th) #function g
def update(th, dt, a, k2): 
    return ifft2((fft2(th)-dt*M*k2*fft2(g(th,a)))/(1+2*epsilon*M*dt*k2**2))

for i in range(size(t)):
    print t[i]
    if mod(i, every)==0:
        imshow(abs(th), vmin=0.0, vmax=1.0)
        colorbar()
        savefig('t'+str(i/every).zfill(3)+'.png', dpi=100)
        clf()
th=update(th, dt, a, k2)
7
  • 2
    Please edit this post, and re-post the code, selecting it and clicking the {} (code format) button, instead of double-spacing every line. Commented May 21, 2014 at 8:42
  • I can't reproduce the error. Commented May 21, 2014 at 9:15
  • Neither can I on Python 2.7.6, Fedora 19; can you share your setup? Commented May 21, 2014 at 10:03
  • Hey, mine's Python 2.7. But I use PyDev (Python IDE). I think probably there is something wrong with the IDE. Commented May 21, 2014 at 10:18
  • By the way, did you both run the code successfully? Is there any other problem? Thank you! Commented May 21, 2014 at 10:40

1 Answer 1

2

You are under Windows 64-bit i assume. There is a bug in your numpy version, where windows Long type is not recognized as int. Either update numpy or cast your shapes manually:

fftfreq(int(th.shape[0]), dx)
Sign up to request clarification or add additional context in comments.

1 Comment

You are right! I modified the code according to your advice. It works! :>. But one is that the code aims at demonstrating the change of th (composition) in 2D real space with time. why couldn't I see the figure while I was running it? Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.