3D网格在现实空间和傅立叶空间中的磁能应相等吗?

时间:2018-10-31 15:14:00

标签: fftpack

我试图在矢量大小为A的3D盒子中找到nx,ny和nz网格点的lx,ly和lz的磁能,其中矢量势使用傅里叶变换作为E_magnetic = 0.5 * k ^ 2 * A ^ 2。在现实空间中,该能量是否等于E_magnetic = 0.5 * B ^ 2?看起来我在下面的代码中缺少了一些东西。我们非常感谢您的帮助。

from numpy import newaxis as nna


def create_kgrid(nx, ny, nz, lx, ly, lz):
"""
Create a 3D k grid for Fourier space calculations
"""
kx = nf.fftshift(nf.fftfreq(nx))*nx*2*pi/lx
ky = nf.fftshift(nf.fftfreq(ny))*ny*2*pi/ly
kz = nf.fftshift(nf.fftfreq(nz))*nz*2*pi/lz

mg = np.meshgrid(kx,ky,kz)

km = np.sqrt(np.sum((m**2 for m in mg)))

return kx[:,nna,nna], ky[nna,:,nna], kz[nna,nna,:], km


def vecpot(arx,ary,arz, lx, ly, lz):
"""
Function to compute vector potential of a 3D array
"""
nx,ny,nz=arx.shape

#   COMPUTE THE ARRAY SIZE
kx, ky, kz, km = create_kgrid(*arx.shape, lx=lx, ly=ly, lz=lz)
k2=km**2
k2[nx/2,ny/2,nz/2]=1.

#  FOURIER TRANSFORM THE ARRAY
farx = nf.fftshift(nf.fftn(arx))
fary = nf.fftshift(nf.fftn(ary))
farz = nf.fftshift(nf.fftn(arz))

#  FIND THE CORRESPONDING VECTOR POTENTIAL A = -ik x B /k^2
axf = -1j*(ky*farz-kz*fary)/k2
ayf = -1j*(kz*farx-kx*farz)/k2
azf = -1j*(kx*fary-ky*farx)/k2

#  BACK TRANSFORM TO REAL SPACE
ax  = np.real(nf.ifftn(nf.ifftshift(axf)))
ay  = np.real(nf.ifftn(nf.ifftshift(ayf)))
az  = np.real(nf.ifftn(nf.ifftshift(azf)))
return ax,ay,az

E_magnetic= 0.5*np.mean((kx**2+ky**2+kz**2)*(ax**2+ay**2+az**2))

0 个答案:

没有答案