Updated icgen to support padded phases from BORG

This commit is contained in:
Guilhem Lavaux 2014-11-07 15:33:26 +01:00
parent 09998c39f4
commit c5ad407b20
4 changed files with 90 additions and 53 deletions

View file

@ -116,7 +116,7 @@ class LagrangianPerturbation(object):
def _gradient(self, phi, direction):
ne.evaluate('phi_hat * i * kv / (kx**2 + ky**2 + kz**2)', out=self.cube.dhat,
local_dict={'i':-1j, 'phi_hat':phi, 'kv':self._kdir(direction),
'kx':self._kx, 'ky':self._ky, 'kz':self._kz}
'kx':self._kx, 'ky':self._ky, 'kz':self._kz},casting='unsafe')
# self.cube.dhat = self._kdir(direction)*1j*phi
self.cube.dhat[0,0,0] = 0
return self.cube.irfft()
@ -159,8 +159,10 @@ class LagrangianPerturbation(object):
# k2 = self._get_k2()
# k2[0,0,0] = 1
potgen0 = lambda i: ne.evaluate('kdir**2*d/k2',out=self.cube.dhat,local_dict={'kdir':self._kdir(i),'d':self.dhat,'k2':k2} )
potgen = lambda i,j: ne.evaluate('kdir0*kdir1*d/k2',out=self.cube.dhat,local_dict={'kdir0':self._kdir(i),'kdir1':self._kdir(j),'d':self.dhat,'k2':k2} )
inv_k2 = ne.evaluate('1/(kx**2+ky**2+kz**2)', {'kx':self._kdir(0),'ky':self._kdir(1),'kz':self._kdir(2)})
inv_k2[0,0,0]=0
potgen0 = lambda i: ne.evaluate('kdir**2*d*ik2',out=self.cube.dhat,local_dict={'kdir':self._kdir(i),'d':self.dhat,'ik2':inv_k2}, casting='unsafe' )
potgen = lambda i,j: ne.evaluate('kdir0*kdir1*d*ik2',out=self.cube.dhat,local_dict={'kdir0':self._kdir(i),'kdir1':self._kdir(j),'d':self.dhat,'ik2':inv_k2}, casting='unsafe' )
if 'lpt2_potential' not in self.cache:
print("Rebuilding potential...")
@ -169,7 +171,7 @@ class LagrangianPerturbation(object):
q = self._do_irfft( potgen0(j) ).copy()
for i in xrange(j+1, 3):
ne.evaluate('div + q * pot', out=div_phi2,
local_dict={'q':q,'pot':self._do_irfft( potgen0(i), copy=False ) }
local_dict={'div':div_phi2, 'q':q,'pot':self._do_irfft( potgen0(i), copy=False ) }
)
ne.evaluate('div - pot**2',out=div_phi2,
local_dict={'div':div_phi2,'pot':self._do_irfft(potgen(i,j), copy=False) }