More debugging. Temporarily disabled phase shifting

This commit is contained in:
Guilhem Lavaux 2014-06-03 12:35:58 +02:00
parent 7662ea98d4
commit 8f582707da
4 changed files with 51 additions and 17 deletions

View file

@ -42,13 +42,29 @@ class CosmoGrowth(object):
class LagrangianPerturbation(object):
def __init__(self,density,L, fourier=False):
def __init__(self,density,L, fourier=False, supersample=1):
self.L = L
self.N = density.shape[0]
self.dhat = np.fft.rfftn(density)*(L/self.N)**3 if not fourier else density
if supersample > 1:
self.upgrade_sampling(supersample)
self.ik = np.fft.fftfreq(self.N, d=L/self.N)*2*np.pi
self.cache = weakref.WeakValueDictionary()
self.cache = {}#weakref.WeakValueDictionary()
def upgrade_sampling(self, supersample):
N2 = self.N * supersample
N = self.N
dhat_new = np.zeros((N2, N2, N2/2+1), dtype=np.complex128)
hN = N/2
dhat_new[:hN, :hN, :hN+1] = self.dhat[:hN, :hN, :]
dhat_new[:hN, (N2-hN):N2, :hN+1] = self.dhat[:hN, hN:, :]
dhat_new[(N2-hN):N2, (N2-hN):N2, :hN+1] = self.dhat[hN:, hN:, :]
dhat_new[(N2-hN):N2, :hN, :hN+1] = self.dhat[hN:, :hN, :]
self.dhat = dhat_new
self.N = N2
def _gradient(self, phi, direction):
return np.fft.irfftn(self._kdir(direction)*1j*phi)*(self.N/self.L)**3
@ -85,15 +101,16 @@ class LagrangianPerturbation(object):
k2[0,0,0] = 1
if 'lpt2_potential' not in self.cache:
div_phi2 = np.zeros((N,N,N), dtype=np.float64)
print("Rebuilding potential...")
div_phi2 = np.zeros((self.N,self.N,self.N), dtype=np.float64)
for j in xrange(3):
q = np.fft.irfftn( build_dir(ik, j)**2*self.dhat / k2 )
q = np.fft.irfftn( self._kdir(j)**2*self.dhat / k2 )
for i in xrange(j+1, 3):
div_phi2 += q * np.fft.irfftn( build_dir(ik, i)**2*self.dhat / k2 )
div_phi2 -= (np.fft.irfftn( build_dir(ik, j)*build_dir(ik, i)*self.dhat / k2 ))**2
div_phi2 += q * np.fft.irfftn( self._kdir(i)**2*self.dhat / k2 )
div_phi2 -= (np.fft.irfftn( self._kdir(j)*self._kdir(i)*self.dhat / k2 ))**2
div_phi2 *= (self.N/self.L)**3
phi2_hat = np.fft.rfftn(div_phi2) * ((L/N)**3) / k2
div_phi2 *= (self.N/self.L)**6
phi2_hat = np.fft.rfftn(div_phi2) * ((self.L/self.N)**3) / k2
self.cache['lpt2_potential'] = phi2_hat
del div_phi2
else: