def test17(self): solsys = new_solar_system() mercury = Mercury() mercury.particles.add_particles(solsys) mercury.evolve_model(5.|units.yr) mercury.evolve_model(10.|units.yr) dpos1=mercury.particles[0].position-mercury.particles[5].position mercury.stop() mercury = Mercury() mercury.particles.add_particles(solsys) mercury.evolve_model(5.|units.yr) mercury.particles.x+=1 | units.AU mercury.particles.y+=2 | units.AU mercury.particles.z+=3 | units.AU mercury.particles.vx+=10. | units.kms mercury.particles.vy+=20. | units.kms mercury.particles.vz+=30. | units.kms mercury.evolve_model(10.|units.yr) dpos2=mercury.particles[0].position-mercury.particles[5].position mercury.stop() self.assertAlmostEqual(dpos1, dpos2, 12)
def test13(self): solsys = new_solar_system() mercury = Mercury() mercury.particles.add_particles(solsys) idpos1 = [ (p.position - q.position) for p in mercury.particles[1:10] for q in mercury.particles[1:10] ] mercury.evolve_model(11.8618|units.yr) edpos1 = [ (p.position - q.position) for p in mercury.particles[1:10] for q in mercury.particles[1:10] ] mercury.stop() centre, orbiters = new_solar_system_for_mercury() mercury = MercuryWayWard() mercury.central_particle.add_particles(centre) mercury.orbiters.add_particles(orbiters) idpos2 = [ (p.position - q.position) for p in mercury.orbiters[0:9] for q in mercury.orbiters[0:9] ] mercury.evolve_model(11.8618|units.yr) edpos2 = [ (p.position - q.position) for p in mercury.orbiters[0:9] for q in mercury.orbiters[0:9] ] mercury.stop() for d1,d2 in zip(idpos1,idpos2): self.assertAlmostEqual(d1,d2, 7) for d1,d2 in zip(edpos1,edpos2): self.assertAlmostEqual(d1,d2, 7)
def test18(self): solsys = new_solar_system() mercury = Mercury() mercury.initialize_code() self.assertEqual(mercury.parameters.integrator,10) mercury.parameters.integrator=2 self.assertEqual(mercury.parameters.integrator,2) mercury.stop()
def test11(self): solsys = new_solar_system() mercury = Mercury() self.assertEqual(mercury.parameters.timestep, 8 | units.day) mercury.parameters.timestep = 1 | units.day self.assertEqual(mercury.parameters.timestep, 1 | units.day) mercury.particles.add_particles(solsys) start_pos = mercury.particles[5].position mercury.evolve_model(11.8618|units.yr) self.assertAlmostEqual(mercury.particles[5].position, start_pos, 1) mercury.stop()
def test3(self): solsys = new_solar_system() mercury = Mercury() mercury.initialize_code() mercury.particles.add_particles(solsys) mercury.commit_particles() start_pos = mercury.orbiters[2].position mercury.evolve_model(365.14|units.day) self.assertAlmostEqual(mercury.orbiters[2].position, start_pos, 1) mercury.stop()
def test11(self): solsys = new_solar_system() mercury = Mercury() self.assertEquals(mercury.parameters.timestep, 8 | units.day) mercury.parameters.timestep = 1 | units.day self.assertEquals(mercury.parameters.timestep, 1 | units.day) mercury.particles.add_particles(solsys) start_pos = mercury.particles[5].position mercury.evolve_model(11.8618|units.yr) self.assertAlmostEqual(mercury.particles[5].position, start_pos, 1) mercury.stop()
def test12(self): solsys = new_solar_system() mercury = Mercury() mercury.parameters.timestep = 1. | units.day mercury.particles.add_particles(solsys) start_pos = mercury.particles[5].position mercury.evolve_model(11.8618|units.yr) self.assertAlmostEqual(mercury.particles[5].position, start_pos, 1) mercury.particles.remove_particles(mercury.particles[1:5]) self.assertAlmostEqual(mercury.particles[1].position, start_pos, 1) start_pos = mercury.particles[1].position mercury.evolve_model(2*11.8618|units.yr) self.assertAlmostEqual(mercury.particles[1].position, start_pos, 1) mercury.stop()
def test21(self): solsys = new_solar_system() mercury = Mercury() mercury.initialize_code() names=["elements_file","close_encounters_file","info_file", "bigbody_file","smallbody_file","integration_parameters_file","restart_file"] for name in names: self.assertEqual(getattr(mercury.parameters,name),"/dev/null") for name in names: setattr(mercury.parameters,name,os.path.join(mercury.output_directory,name)) for name in names: self.assertEqual(getattr(mercury.parameters,name),os.path.join(mercury.output_directory,name)) mercury.stop()
def xtest22(self): """ collision test hangs or fails if internal collision detection is enabled """ def collision(): M=1.| units.MSun m=1.| units.MJupiter r=5. | units.AU vcirc=(constants.G*(M+m)/r)**0.5 sys=datamodel.Particles(4) sys[0].mass=M sys[0].radius=1. | units.RSun sys[0].x=0 | units.AU sys[0].y=0 | units.AU sys[0].z=0 | units.AU sys[0].vx=0 | units.kms sys[0].vy=0 | units.kms sys[0].vz=0 | units.kms sys[1].mass=m sys[1].radius=0.01 | units.RSun sys[1].x=r sys[1].y=0 | units.AU sys[1].z=0 | units.AU sys[1].vx=0 | units.kms sys[1].vy=vcirc sys[1].vz=0 | units.kms sys[2].mass=m sys[2].radius=0.01 | units.RSun sys[2].x=-r sys[2].y=0 | units.AU sys[2].z=0 | units.AU sys[2].vx=0 | units.kms sys[2].vy=vcirc sys[2].vz=0 | units.kms sys[3].mass=m sys[3].radius=0.01 | units.RSun sys[3].x=0 | units.AU sys[3].y=r sys[3].z=0 | units.AU sys[3].vx=0 | units.kms sys[3].vy=0 | units.kms sys[3].vz=0 | units.kms return sys code=Mercury() sys=collision() code.particles.add_particles(sys) tend=3.5| units.yr dt=100. | units.day tnow=code.model_time while tnow<tend: code.evolve_model(tnow+dt) tnow=code.model_time print(tnow.in_(units.yr)) code.stop()