Created
May 9, 2013 18:53
-
-
Save certik/5549650 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from numpy import empty, pi, meshgrid, linspace, sum, sin | |
from numpy.fft import fftn, fftfreq | |
E_exact = 3*pi/8 | |
print "Hartree Energy (exact): %.15f" % E_exact | |
f = open("conv.txt", "w") | |
for N in range(3, 180, 10): | |
print "N =", N | |
L = 2. | |
x1d = linspace(0, L, N) | |
x, y, z = meshgrid(x1d, x1d, x1d) | |
nr = 3*pi*sin(pi*x)*sin(pi*y)*sin(pi*z)/4 | |
ng = fftn(nr) / N**3 | |
G1d = N * fftfreq(N) * 2*pi/L | |
kx, ky, kz = meshgrid(G1d, G1d, G1d) | |
G2 = kx**2+ky**2+kz**2 | |
G2[0, 0, 0] = 1 # omit the G=0 term | |
tmp = 2*pi*abs(ng)**2 / G2 | |
tmp[0, 0, 0] = 0 # omit the G=0 term | |
E = sum(tmp) * L**3 | |
print "Hartree Energy (calculated): %.15f" % E | |
f.write("%d %.15f\n" % (N, E)) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment