def test_h5_with_particles(self, tmpdir): fname = tmpdir.join('test_particle_source.h5') p1 = ParticleSource("test", Box(), 120, 5, np.array((1, 0, 0)), 0, -1, 2) p1.generate_initial_particles() with h5py.File(fname, mode="w") as h5file: p1.save_h5(h5file) with h5py.File(fname, mode="r") as h5file: p2 = ParticleSource.load_h5(h5file) assert p1 == p2
def test_particle_ids(self): p1 = ParticleSource("test", Box(), 120, 5, np.array((1, 0, 0)), 200, -1, 2) a1 = p1.generate_initial_particles() a2 = p1.generate_each_step() assert_array_equal(a1.ids, range(120)) assert_array_equal(a2.ids, range(5))
def test_generate(self): p1 = ParticleSource("test", Box(), 120, 5, np.array((1, 0, 0)), 200, -1, 2) p2 = ParticleSource("test", Box(), 120, 5, np.array((1, 0, 0)), 200, -1, 2) p3 = ParticleSource("test", Box(), 120, 5, np.array((1, 0, 0)), 200, -1, 2) p3._generator.set_state(p1._generator.get_state()) a1 = p1.generate_initial_particles() a2 = p2.generate_initial_particles() a3 = p3.generate_initial_particles() assert a1 != a2 assert a1 == a3 a32 = p3.generate_each_step() assert a1 != a32 a12 = p1.generate_each_step() assert a12 == a32
def test_generate_for_simulation(self): ps = ParticleSource('test', Box(6, 0), 17, 13, (4, 4, 4), 0, -2, 6) assert_dataclass_eq( ps.generate_initial_particles(), ParticleArray(range(17), -2, 6, np.full((17, 3), 6), np.full((17, 3), 4), False)) assert_dataclass_eq( ps.generate_each_step(), ParticleArray(range(13), -2, 6, np.full((13, 3), 6), np.full((13, 3), 4), False))