def test_gravity(comm): from pmesh.pm import ParticleMesh import fastpm.operators as operators pm = ParticleMesh(BoxSize=4.0, Nmesh=(4, 4), comm=comm, method='cic', dtype='f8') vm = fastpm.Evolution(pm, shift=0.5) dlink = pm.generate_whitenoise(12345, mode='complex') code = vm.code() code.Decompress(C='dlin_k') code.LPTDisplace(dlin_k='dlin_k', D1=1.0, v1=0, D2=0.0, v2=0.0) code.ForcePaint() code.Force(factor=0.1) code.Chi2(variable='f') print(code) # FIXME: without the shift some particles have near zero dx1. # or near 1 dx1. # the gradient is not well approximated by the numerical if # any of the left or right value shifts beyond the support of # the window. # dlink, ampl = _addampl(dlink) _test_model(code, dlink, ampl)
def test_kdk(comm): # Or use an object from astropy. cosmo = lambda : None cosmo.Om0 = 0.3 cosmo.Ode0 = 0.7 cosmo.Ok0 = 0.0 pm = ParticleMesh(BoxSize=128.0, Nmesh=(4,4,4), comm=comm, dtype='f8') vm = fastpm.Evolution(pm, B=1, shift=0.5) dlink = pm.generate_whitenoise(12345, mode='complex', unitary=True) dlink, ampl = _addampl(dlink) data = dlink.c2r() data[...] = 0 sigma = data.copy() sigma[...] = 1.0 code = vm.code() code.Decompress(C='dlin_k') code.KDKSimulation(dlin_k='dlin_k', mesh='mesh', cosmo=cosmo, astart=0.1, aend=1.0, Nsteps=5) code.Decompose() code.Paint() code.Residual(data_x=data, sigma_x=sigma) code.Chi2(variable='residual') _test_model(code, dlink, ampl)
def test_prior(comm): from pmesh.pm import ParticleMesh pm = ParticleMesh(BoxSize=128.0, Nmesh=(4, 4), comm=comm) vm = fastpm.Evolution(pm, shift=0.5) dlink = pm.generate_whitenoise(1234, mode='complex') code = vm.code() code.Prior(dlin_k='dlin_k', powerspectrum=lambda k : 1.0) code.CopyVariable(x='prior', y='chi2') dlink, ampl = _addampl(dlink) _test_model(code, dlink, ampl)
def test_lpt(comm): from pmesh.pm import ParticleMesh pm = ParticleMesh(BoxSize=128.0, Nmesh=(4, 4), comm=comm) vm = fastpm.Evolution(pm, shift=0.5) dlink = pm.generate_whitenoise(1234, mode='complex') code = vm.code() code.Decompress(C='dlin_k') code.LPTDisplace(dlin_k='dlin_k', D1=1.0, v1=0, D2=0.0, v2=0.0) code.Chi2(variable='s') dlink, ampl = _addampl(dlink) _test_model(code, dlink, ampl)
def test_resample(comm): if comm.size == 4: comm.barrier() from pmesh.pm import ParticleMesh # testing the gradient of down sampling, which we use the most. pm = ParticleMesh(BoxSize=128.0, Nmesh=(8, 8), comm=comm) vm = fastpm.Evolution(pm, shift=0.5) dlink = pm.generate_whitenoise(1234, mode='complex') dlink, ampl = _addampl(dlink) code = vm.code() code.Decompress(C='dlin_k') code.C2R(C='dlin_k', R='mesh') code.Resample(Neff=4) code.Chi2(variable='mesh') _test_model(code, dlink, ampl)
def test_lpt_prior(comm): from pmesh.pm import ParticleMesh pm = ParticleMesh(BoxSize=128.0, Nmesh=(4, 4), comm=comm) vm = fastpm.Evolution(pm, shift=0.5) dlink = pm.generate_whitenoise(1234, mode='complex') code = vm.code() code.Decompress(C='dlin_k') code.LPTDisplace(dlin_k='dlin_k', D1=1.0, v1=0, D2=0.0, v2=0.0) code.Decompose() code.Paint() code.Chi2(variable='mesh') code.Prior(powerspectrum=lambda k : 1.0) code.Multiply(a='prior', b='prior', f=0.1) code.Add(a='prior', b='chi2', c='chi2') dlink, ampl = _addampl(dlink) _test_model(code, dlink, ampl)