def read(self, real): import bigfile if self.comm.rank == 0: self.logger.info("Reading from Nmesh = %d to Nmesh = %d" % (self.Nmesh, real.Nmesh[0])) if any(real.Nmesh != self.Nmesh): pmread = ParticleMesh(BoxSize=real.BoxSize, Nmesh=(self.Nmesh, self.Nmesh, self.Nmesh), dtype='f4', comm=self.comm) else: pmread = real.pm f = bigfile.BigFileMPI(self.comm, self.path) with f[self.dataset] as ds: if self.isfourier: if self.comm.rank == 0: self.logger.info("reading complex field") complex2 = ComplexField(pmread) assert self.comm.allreduce(complex2.size) == ds.size start = sum( self.comm.allgather(complex2.size)[:self.comm.rank]) end = start + complex2.size complex2.unsort(ds[start:end]) complex2.resample(real) else: if self.comm.rank == 0: self.logger.info("reading real field") real2 = RealField(pmread) start = sum(self.comm.allgather(real2.size)[:self.comm.rank]) end = start + real2.size real2.unsort(ds[start:end]) real2.resample(real)
def read(self, real): import bigfile if self.comm.rank == 0: self.logger.info("Reading from Nmesh = %d to Nmesh = %d" %(self.Nmesh, real.Nmesh[0])) if any(real.Nmesh != self.Nmesh): pmread = ParticleMesh(BoxSize=real.BoxSize, Nmesh=(self.Nmesh, self.Nmesh, self.Nmesh), dtype='f4', comm=self.comm) else: pmread = real.pm f = bigfile.BigFileMPI(self.comm, self.path) with f[self.dataset] as ds: if self.isfourier: if self.comm.rank == 0: self.logger.info("reading complex field") complex2 = ComplexField(pmread) assert self.comm.allreduce(complex2.size) == ds.size start = sum(self.comm.allgather(complex2.size)[:self.comm.rank]) end = start + complex2.size complex2.unsort(ds[start:end]) complex2.resample(real) else: if self.comm.rank == 0: self.logger.info("reading real field") real2 = RealField(pmread) start = sum(self.comm.allgather(real2.size)[:self.comm.rank]) end = start + real2.size real2.unsort(ds[start:end]) real2.resample(real)
def test_fupsample(comm): pm1 = ParticleMesh(BoxSize=8.0, Nmesh=[8, 8], comm=comm, dtype='f8') pm2 = ParticleMesh(BoxSize=8.0, Nmesh=[4, 4], comm=comm, dtype='f8') numpy.random.seed(3333) truth = numpy.fft.rfftn(numpy.random.normal(size=(8, 8))) complex1 = ComplexField(pm1) for ind in numpy.ndindex(*complex1.cshape): complex1.csetitem(ind, truth[ind]) if any(i == 4 for i in ind): complex1.csetitem(ind, 0) else: complex1.csetitem(ind, truth[ind]) if any(i >= 2 and i < 7 for i in ind): complex1.csetitem(ind, 0) assert_almost_equal(complex1[...], complex1.c2r().r2c()) complex2 = ComplexField(pm2) for ind in numpy.ndindex(*complex2.cshape): newind = tuple([i if i <= 2 else 8 - (4 - i) for i in ind]) if any(i == 2 for i in ind): complex2.csetitem(ind, 0) else: complex2.csetitem(ind, truth[newind]) tmpr = RealField(pm1) tmp = ComplexField(pm1) complex2.resample(tmp) assert_almost_equal(complex1[...], tmp[...], decimal=5) complex2.c2r().resample(tmp) assert_almost_equal(complex1[...], tmp[...], decimal=5) complex2.resample(tmpr) assert_almost_equal(tmpr.r2c(), tmp[...]) complex2.c2r().resample(tmpr) assert_almost_equal(tmpr.r2c(), tmp[...])