Beispiel #1
0
    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)
Beispiel #2
0
    def test16(self):
        solsys = new_solar_system()

        solsys.x-=1.| units.AU

        p=datamodel.Particles(3)
        p.mass=[1,2,3] | units.MSun
        p.x=[1,10,100] | units.AU
        p.y=[0,0,-10] | units.AU
        p.z=[0,0,10] | units.AU

        from amuse.community.huayno.interface import Huayno
        from amuse.units import nbody_system        
        conv=nbody_system.nbody_to_si(1. | units.AU, 1.| units.MSun)
        h = Huayno(conv)
        h.particles.add_particles(solsys)
        
        ax1,ay1,az1=h.get_gravity_at_point(p.x*0.,p.x,p.y,p.z)
        
        mercury = Mercury()        
        mercury.particles.add_particles(solsys)

        ax2,ay2,az2=mercury.get_gravity_at_point(p.x*0.,p.x,p.y,p.z)


        self.assertAlmostRelativeEqual(ax1,ax2,12)
        self.assertAlmostRelativeEqual(ay1,ay2,12)
        self.assertAlmostRelativeEqual(az1,az2,12)
Beispiel #3
0
    def test16(self):
        solsys = new_solar_system()

        solsys.x-=1.| units.AU

        p=datamodel.Particles(3)
        p.mass=[1,2,3] | units.MSun
        p.x=[1,10,100] | units.AU
        p.y=[0,0,-10] | units.AU
        p.z=[0,0,10] | units.AU

        from amuse.community.huayno.interface import Huayno
        from amuse.units import nbody_system        
        conv=nbody_system.nbody_to_si(1. | units.AU, 1.| units.MSun)
        h = Huayno(conv)
        h.particles.add_particles(solsys)
        
        ax1,ay1,az1=h.get_gravity_at_point(p.x*0.,p.x,p.y,p.z)
        
        mercury = Mercury()        
        mercury.particles.add_particles(solsys)

        ax2,ay2,az2=mercury.get_gravity_at_point(p.x*0.,p.x,p.y,p.z)


        self.assertAlmostRelativeEqual(ax1,ax2,12)
        self.assertAlmostRelativeEqual(ay1,ay2,12)
        self.assertAlmostRelativeEqual(az1,az2,12)
Beispiel #4
0
    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()
Beispiel #5
0
    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()
Beispiel #6
0
    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()
Beispiel #7
0
    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()
Beispiel #8
0
    def test15(self):
        solsys = new_solar_system()

        solsys.x-=1.| units.AU

        p=datamodel.Particles(3)
        p.mass=[1,2,3] | units.MSun
        p.x=[1,10,100] | units.AU
        p.y=[0,0,-10] | units.AU
        p.z=[0,0,10] | units.AU

        pe=p.potential_energy_in_field(solsys)

        mercury = Mercury()
        mercury.particles.add_particles(solsys)
        pot=mercury.get_potential_at_point(p.x*0.,p.x,p.y,p.z)

        self.assertAlmostRelativeEqual((pot*p.mass).sum(),pe,12)
Beispiel #9
0
    def test15(self):
        solsys = new_solar_system()

        solsys.x-=1.| units.AU

        p=datamodel.Particles(3)
        p.mass=[1,2,3] | units.MSun
        p.x=[1,10,100] | units.AU
        p.y=[0,0,-10] | units.AU
        p.z=[0,0,10] | units.AU

        pe=p.potential_energy_in_field(solsys)

        mercury = Mercury()
        mercury.particles.add_particles(solsys)
        pot=mercury.get_potential_at_point(p.x*0.,p.x,p.y,p.z)

        self.assertAlmostRelativeEqual((pot*p.mass).sum(),pe,12)
Beispiel #10
0
    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 sub_worker(parts):
     mode = system_type(parts)
     if mode == "twobody":
         code = TwoBody(conv_sub)
     elif mode == "solarsystem":
         code = Mercury(conv_sub)
     elif mode == "nbody":
         code = Huayno(conv_sub)
         code.parameters.inttype_parameter = code.inttypes.SHARED4
     return code
Beispiel #12
0
    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()
Beispiel #13
0
    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()
Beispiel #14
0
    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()
Beispiel #15
0
    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()
Beispiel #16
0
    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()
Beispiel #17
0
    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()
Beispiel #18
0
    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)
Beispiel #19
0
    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)
Beispiel #20
0
    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)