def update(self): zmax = self.atoms.get_cell()[2,2] z = self.atoms.get_positions()[:,2] group = np.round(z/zmax * self.blocks).astype(int) group = np.clip(group, 0, self.blocks-1) p = self.atoms.get_momenta() ekin = (p*p).sum(axis=1) / (2 * self.atoms.get_masses()) ekinsum = np.zeros(self.blocks) blocksum = np.zeros(self.blocks, int) for i in range(self.blocks): thisblock = np.equal(group, i) ekinsum[i] = ekin[thisblock].sum() blocksum[i] = thisblock.sum() world.sum(ekinsum) world.sum(blocksum) if master: np.clip(blocksum, 1, blocksum.max(), out=blocksum) T = ekinsum / ( 1.5 * units.kB * blocksum) for i in range(self.blocks): self.output.write("%i %.1f\n" % (i, T[i],)) self.output.write("&\n") self.output.flush()
atoms = FaceCenteredCubic(size=size*layout, symbol='Cu') atoms.set_calculator(EMT()) natoms = atoms.get_number_of_atoms() print "Number of atoms:", natoms assert natoms == ncpu * 500000 print "Potential energy:", atoms.get_potential_energy() start = time.time() d = 0.1 for i in range(nsteps): atoms.arrays['positions'][50][0] += d d = -d f = atoms.get_forces() wall = time.time() - start if cmd in "SM": master = world.rank == 0 wall = world.sum(wall) wall /= world.size else: master = True if master: report_timing() print "Wall time elapsed:", wall f = open(sys.argv[2], "a") pickle.dump((cmd, ncpu, wall), f) f.close()
def get_center_of_mass_momentum(self): "Get the center of mass momentum." cm = self.atoms.get_momenta().sum(0) world.sum(cm) return cm
to = 0 fr = world.rank - 1 if fr < 0: fr += world.size print "%d: to=%d from=%d" % (world.rank, to, fr) rq = world.send(outdata, to, block=False) world.receive(indata, fr) #world.wait(rq) print "Request completed:", rq.test() rq.wait() assert (indata == fr * np.arange(10000000)).all() s = world.sum(2.5 * world.rank) ReportTest("Float sum", s, 2.5 * 0.5 * world.size * (world.size - 1), 1e-9) s = world.sum(world.rank) ReportTest("Integer sum", s, world.size * (world.size - 1) / 2, 0) s = world.max(1.0 * world.rank) ReportTest("Float max", s, world.size - 1, 0) s = world.max(world.rank) ReportTest("Int max", s, world.size - 1, 0) print "Checking reduces on arrays..." d0 = np.arange(10) + world.rank f0 = d0 + 0.0
atoms = FaceCenteredCubic(size=size * layout, symbol='Cu') atoms.set_calculator(EMT()) natoms = atoms.get_number_of_atoms() print "Number of atoms:", natoms assert natoms == ncpu * 500000 print "Potential energy:", atoms.get_potential_energy() start = time.time() d = 0.1 for i in range(nsteps): atoms.arrays['positions'][50][0] += d d = -d f = atoms.get_forces() wall = time.time() - start if cmd in "SM": master = world.rank == 0 wall = world.sum(wall) wall /= world.size else: master = True if master: report_timing() print "Wall time elapsed:", wall f = open(sys.argv[2], "a") pickle.dump((cmd, ncpu, wall), f) f.close()
def main(element, T_up, T_low, T_expect, bulkmodulus, makepot): def set_temp_fric(dyn, atoms): z = atoms.get_positions()[:,2] zmax = atoms.get_cell()[2,2] zmin = 0 T = T_low + (T_up - T_low) * (z - zmin) / (zmax - zmin) dyn.set_temperature(T * units.kB) rnd = world.sum(random.randint(0,2**32)) # Insures the same number on all nodes. prefix = "melt-%s-%s" % (element, hex(rnd)[2:]) if master: print "Using output directory", prefix os.mkdir(prefix) else: while not os.path.exists(prefix): time.sleep(1) if master: atoms = FaceCenteredCubic(symbol=element, size=size, pbc=(True, True, False)) atoms.center(vacuum=10.0, axis=2) else: atoms = None atoms = MakeParallelAtoms(atoms, cpulayout1) print world.rank, '-', len(atoms), atoms.get_number_of_atoms() atoms.set_calculator(makepot()) #view(atoms) dyn = Langevin(atoms, 5*units.fs, 0.0, friction) logger = MDLogger(dyn, atoms, prefix+'/Melt-phase1.log', stress=True, peratom=True) dyn.attach(logger, interval=100) set_temp_fric(dyn, atoms) unstress = Inhomogeneous_NPTBerendsen(atoms, 50*units.fs, 0, taup=500*units.fs, compressibility=1/bulkmodulus) dyn.attach(unstress.scale_positions_and_cell, interval=10) #traj = PickleTrajectory("melting-phase1.traj", "w", atoms) fn1 = prefix + "/Melt-phase1.bundle" if master: print "Opening file", fn1 traj = BundleTrajectory(fn1, "w", atoms, split=True) dyn.attach(traj, interval=500) therm = Thermometer(atoms, prefix+"/TempProfile-phase1.dat") dyn.attach(therm.update, interval=500) for i in range(steps1 / 100): dyn.run(100) set_temp_fric(dyn, atoms) if master: print "Closing file", fn1 traj.close() del traj, atoms # Reread the bundle atoms = BundleTrajectory(fn1).get_atoms(-1, cpulayout2) atoms.set_calculator(makepot()) dyn = VelocityVerlet(atoms, 5*units.fs) logger = MDLogger(dyn, atoms, prefix+'/PtMelt-phase2.log', stress=True, peratom=True) dyn.attach(logger, interval=1000) unstress = Inhomogeneous_NPTBerendsen(atoms, 50*units.fs, 0, taup=5000*units.fs, compressibility=1/bulkmodulus) dyn.attach(unstress.scale_positions_and_cell, interval=10) fn2 = prefix + "/Melt-phase2.bundle" if master: print "Opening file", fn2 traj = BundleTrajectory(fn2, "w", atoms) dyn.attach(traj, interval=steps2/100) therm = Thermometer(atoms, prefix+"/TempProfile-phase2.dat") dyn.attach(therm.update, interval=steps2/10) dyn.run(steps2 - takedata) therm2 = AveragingThermometer(atoms) dyn.attach(therm2.update, interval=100) dyn.run(takedata) # Run the last part T = therm2.get_temp() if master: print "Melting temperature:", T ReportTest("Melting temperature", T, T_expect, 3) if cleanup: world.barrier() # Cleanup may fail due to the directory not being updated from # writes on the other nodes. Wait for NFS file system. time.sleep(60) if master: shutil.rmtree(prefix) world.barrier() ReportTest.Summary()