Esempio n. 1
0
    def test5(self):
        print "Testing stellar collision..."
        instance = MOBSE()
        instance.parameters.common_envelope_efficiency = 3.0
        instance.parameters.Eddington_mass_transfer_limit_factor = 10.0
        instance.commit_parameters()

        stars = Particles(2)
        stars[0].mass = 130.0 | units.MSun
        stars[1].mass = 50 | units.MSun

        instance.particles.add_particles(stars)

        binaries = Particles(1)

        binary = binaries[0]
        orbital_period = 300.0 | units.day
        semi_major_axis = instance.orbital_period_to_semi_major_axis(
            orbital_period, stars[0].mass, stars[1].mass)
        binary.semi_major_axis = semi_major_axis
        binary.eccentricity = 0.99
        binary.child1 = stars[0]
        binary.child2 = stars[1]

        instance.binaries.add_particles(binaries)

        from_mobse_to_model = instance.particles.new_channel_to(stars)
        from_mobse_to_model.copy()

        from_mobse_to_model_binaries = instance.binaries.new_channel_to(
            binaries)
        from_mobse_to_model_binaries.copy()

        instance.evolve_model(170 | units.Myr)

        from_mobse_to_model.copy()
        from_mobse_to_model_binaries.copy()
        print binaries
        self.assertAlmostEqual(binary.child1.mass.value_in(units.MSun), 180.00,
                               3)
        self.assertAlmostEqual(binary.child2.mass.value_in(units.MSun), 0.000,
                               3)
        self.assertEquals(str(binary.child1.stellar_type),
                          "Main Sequence star")
        self.assertEquals(str(binary.child2.stellar_type),
                          "Massless Supernova")

        instance.stop()
Esempio n. 2
0
    def test4(self):
        print "Quick testing standard MOBSE example 2..."
        instance = MOBSE()
        instance.parameters.common_envelope_efficiency = 3.0
        instance.parameters.common_envelope_binding_energy_factor = 0.5
        instance.parameters.Eddington_mass_transfer_limit_factor = 10.0
        instance.commit_parameters()

        stars = Particles(2)
        stars[0].mass = 7.816 | units.MSun
        stars[1].mass = 4.387 | units.MSun

        instance.particles.add_particles(stars)

        binaries = Particles(1)

        binary = binaries[0]
        orbital_period = 1964.18453 | units.day
        semi_major_axis = instance.orbital_period_to_semi_major_axis(
            orbital_period, stars[0].mass, stars[1].mass)
        binary.semi_major_axis = semi_major_axis
        binary.eccentricity = 0.0
        binary.child1 = stars[0]
        binary.child2 = stars[1]

        instance.binaries.add_particles(binaries)

        from_mobse_to_model = instance.particles.new_channel_to(stars)
        from_mobse_to_model.copy()

        from_mobse_to_model_binaries = instance.binaries.new_channel_to(
            binaries)
        from_mobse_to_model_binaries.copy()

        instance.evolve_model(170 | units.Myr)
        from_mobse_to_model.copy()
        from_mobse_to_model_binaries.copy()

        self.assertAlmostEqual(binary.child1.mass.value_in(units.MSun),
                               1.26079, 3)
        self.assertAlmostEqual(binary.child2.mass.value_in(units.MSun),
                               0.76080, 3)
        self.assertEquals(str(binary.child1.stellar_type), "Neutron Star")
        self.assertEquals(str(binary.child2.stellar_type),
                          "Carbon/Oxygen White Dwarf")

        instance.stop()
Esempio n. 3
0
    def test8(self):
        print "Testing adding and removing particles from stellar evolution code..."

        instance = MOBSE()
        instance.initialize_code()

        stars = Particles(6)
        stars.mass = [1.0, 1.0, 1.0, 0.2, 0.2, 0.2] | units.MSun

        binaries = Particles(3)
        binaries.eccentricity = 0.0
        for i in range(3):
            binaries[i].child1 = stars[i]
            binaries[i].child2 = stars[i + 3]
        orbital_period = 200.0 | units.day
        semi_major_axis = instance.orbital_period_to_semi_major_axis(
            orbital_period,
            binaries.child1.as_set().mass,
            binaries.child2.as_set().mass)
        binaries.semi_major_axis = semi_major_axis

        instance.commit_parameters()
        self.assertEquals(len(instance.particles), 0)
        self.assertEquals(len(instance.binaries), 0)  # before creation
        instance.particles.add_particles(stars)
        instance.binaries.add_particles(binaries[:-1])
        instance.commit_particles()
        instance.evolve_model(1.0 | units.Myr)
        self.assertEquals(len(instance.binaries), 2)  # before remove
        self.assertAlmostEqual(instance.binaries.age, 1.0 | units.Myr)

        instance.binaries.remove_particle(binaries[0])
        self.assertEquals(len(instance.binaries), 1)
        instance.evolve_model(2.0 | units.Myr)
        self.assertAlmostEqual(instance.binaries[0].age, 2.0 | units.Myr)

        instance.binaries.add_particles(binaries[::2])
        self.assertEquals(len(instance.binaries), 3)  # it's back...
        self.assertAlmostEqual(instance.binaries[0].age, 2.0 | units.Myr)
        self.assertAlmostEqual(instance.binaries[1].age, 0.0 | units.Myr)
        self.assertAlmostEqual(instance.binaries[2].age,
                               0.0 | units.Myr)  # ... and rejuvenated.

        instance.evolve_model(
            3.0 | units.Myr
        )  # The young stars keep their age offset from the old star
        self.assertAlmostEqual(instance.binaries.age,
                               [3.0, 1.0, 1.0] | units.Myr)
        instance.evolve_model(4.0 | units.Myr)
        self.assertAlmostEqual(instance.binaries.age,
                               [4.0, 2.0, 2.0] | units.Myr)
        instance.stop()
Esempio n. 4
0
    def test5(self):
        print "Testing stellar collision..."
        instance = MOBSE()
        instance.parameters.common_envelope_efficiency = 3.0
        instance.parameters.Eddington_mass_transfer_limit_factor = 10.0
        instance.commit_parameters()

        stars =  Particles(2)
        stars[0].mass = 130.0  | units.MSun
        stars[1].mass = 50 | units.MSun
        
        instance.particles.add_particles(stars)
        
        binaries =  Particles(1)
        
        binary = binaries[0]
        orbital_period =   300.0 | units.day
        semi_major_axis = instance.orbital_period_to_semi_major_axis(orbital_period,  stars[0].mass , stars[1].mass)
        binary.semi_major_axis = semi_major_axis
        binary.eccentricity = 0.99
        binary.child1 = stars[0]
        binary.child2 = stars[1]
        
        instance.binaries.add_particles(binaries)
        
        from_mobse_to_model = instance.particles.new_channel_to(stars)
        from_mobse_to_model.copy()

        from_mobse_to_model_binaries = instance.binaries.new_channel_to(binaries)
        from_mobse_to_model_binaries.copy()
        
        instance.evolve_model(170 | units.Myr)
        
        from_mobse_to_model.copy()
        from_mobse_to_model_binaries.copy()
        print binaries
        self.assertAlmostEqual(binary.child1.mass.value_in(units.MSun), 180.00, 3)
        self.assertAlmostEqual(binary.child2.mass.value_in(units.MSun), 0.000, 3)
        self.assertEquals(str(binary.child1.stellar_type), "Main Sequence star")
        self.assertEquals(str(binary.child2.stellar_type), "Massless Supernova")

        instance.stop()
Esempio n. 5
0
    def test4(self):
        print "Quick testing standard MOBSE example 2..."
        instance = MOBSE()
        instance.parameters.common_envelope_efficiency = 3.0
        instance.parameters.common_envelope_binding_energy_factor= 0.5
        instance.parameters.Eddington_mass_transfer_limit_factor = 10.0
        instance.commit_parameters()
        
        stars =  Particles(2)
        stars[0].mass = 7.816 | units.MSun
        stars[1].mass = 4.387 | units.MSun
        
        instance.particles.add_particles(stars)
        
        binaries =  Particles(1)
        
        binary = binaries[0]
        orbital_period =   1964.18453 | units.day
        semi_major_axis = instance.orbital_period_to_semi_major_axis(orbital_period,  stars[0].mass , stars[1].mass)
        binary.semi_major_axis = semi_major_axis
        binary.eccentricity = 0.0
        binary.child1 = stars[0]
        binary.child2 = stars[1]
        
        instance.binaries.add_particles(binaries)
        
        from_mobse_to_model = instance.particles.new_channel_to(stars)
        from_mobse_to_model.copy()

        from_mobse_to_model_binaries = instance.binaries.new_channel_to(binaries)
        from_mobse_to_model_binaries.copy()
        
        instance.evolve_model(170 | units.Myr)
        from_mobse_to_model.copy()
        from_mobse_to_model_binaries.copy()

        self.assertAlmostEqual(binary.child1.mass.value_in(units.MSun), 1.26079, 3)
        self.assertAlmostEqual(binary.child2.mass.value_in(units.MSun), 0.76080, 3)
        self.assertEquals(str(binary.child1.stellar_type), "Neutron Star")
        self.assertEquals(str(binary.child2.stellar_type), "Carbon/Oxygen White Dwarf")

        instance.stop()
Esempio n. 6
0
    def test8(self):
        print "Testing adding and removing particles from stellar evolution code..."
        
        instance = MOBSE()
        instance.initialize_code()
        
        stars =  Particles(6)
        stars.mass = [1.0,1.0, 1.0, 0.2, 0.2, 0.2]  | units.MSun
        
        binaries =  Particles(3)
        binaries.eccentricity = 0.0
        for i in range(3):
            binaries[i].child1 = stars[i]
            binaries[i].child2 = stars[i+3]
        orbital_period =   200.0 | units.day
        semi_major_axis = instance.orbital_period_to_semi_major_axis(
            orbital_period,  
            binaries.child1.as_set().mass , 
            binaries.child2.as_set().mass
        )
        binaries.semi_major_axis = semi_major_axis

        instance.commit_parameters()
        self.assertEquals(len(instance.particles), 0)
        self.assertEquals(len(instance.binaries), 0) # before creation
        instance.particles.add_particles(stars)
        instance.binaries.add_particles(binaries[:-1])
        instance.commit_particles()
        instance.evolve_model(1.0 | units.Myr)
        self.assertEquals(len(instance.binaries), 2) # before remove
        self.assertAlmostEqual(instance.binaries.age, 1.0 | units.Myr)
        
        instance.binaries.remove_particle(binaries[0])
        self.assertEquals(len(instance.binaries), 1)
        instance.evolve_model(2.0 | units.Myr)
        self.assertAlmostEqual(instance.binaries[0].age, 2.0 | units.Myr)
        
        instance.binaries.add_particles(binaries[::2])
        self.assertEquals(len(instance.binaries), 3) # it's back...
        self.assertAlmostEqual(instance.binaries[0].age, 2.0 | units.Myr)
        self.assertAlmostEqual(instance.binaries[1].age, 0.0 | units.Myr)
        self.assertAlmostEqual(instance.binaries[2].age, 0.0 | units.Myr) # ... and rejuvenated.
        
        instance.evolve_model(3.0 | units.Myr) # The young stars keep their age offset from the old star
        self.assertAlmostEqual(instance.binaries.age, [3.0, 1.0, 1.0] | units.Myr)
        instance.evolve_model(4.0 | units.Myr)
        self.assertAlmostEqual(instance.binaries.age, [4.0, 2.0, 2.0] | units.Myr)
        instance.stop()
Esempio n. 7
0
    def test7(self):
        print "Test evolve_model optional arguments: end_time and keep_synchronous"

        instance = MOBSE()
        instance.commit_parameters()

        stars = Particles(6)
        stars.mass = [1.0, 2.0, 3.0, 0.1, 0.2, 0.3] | units.MSun

        binaries = Particles(3)
        binaries.eccentricity = 0.0
        for i in range(3):
            binaries[i].child1 = stars[i]
            binaries[i].child2 = stars[i + 3]
        orbital_period = 200.0 | units.day
        semi_major_axis = instance.orbital_period_to_semi_major_axis(
            orbital_period,
            binaries.child1.as_set().mass,
            binaries.child2.as_set().mass)
        binaries.semi_major_axis = semi_major_axis

        instance.particles.add_particles(stars)
        instance.binaries.add_particles(binaries)

        self.assertAlmostEqual(instance.binaries.age,
                               [0.0, 0.0, 0.0] | units.yr)
        self.assertAlmostEqual(instance.binaries.time_step,
                               [550.1565, 58.2081, 18.8768] | units.Myr, 3)

        print "evolve_model without arguments: use shared timestep = min(particles.time_step)"
        instance.evolve_model()
        self.assertAlmostEqual(instance.binaries.age,
                               [18.8768, 18.8768, 18.8768] | units.Myr, 3)
        self.assertAlmostEqual(instance.binaries.time_step,
                               [550.1565, 58.2081, 18.8768] | units.Myr, 3)
        self.assertAlmostEqual(instance.model_time, 18.8768 | units.Myr, 3)

        print "evolve_model with end_time: take timesteps, until end_time is reached exactly"
        instance.evolve_model(100 | units.Myr)
        self.assertAlmostEqual(instance.binaries.age,
                               [100.0, 100.0, 100.0] | units.Myr, 3)
        self.assertAlmostEqual(instance.binaries.time_step,
                               [550.1565, 58.2081, 18.8785] | units.Myr, 3)
        self.assertAlmostEqual(instance.model_time, 100.0 | units.Myr, 3)

        print "evolve_model with keep_synchronous: use non-shared timestep, particle ages will typically diverge"
        instance.evolve_model(keep_synchronous=False)
        self.assertAlmostEqual(instance.binaries.age, (100 | units.Myr) +
                               ([550.1565, 58.2081, 18.8785] | units.Myr), 3)
        self.assertAlmostEqual(instance.binaries.time_step,
                               [550.1565, 58.2081, 18.8785] | units.Myr, 3)
        self.assertAlmostEqual(instance.model_time, 100.0 | units.Myr,
                               3)  # Unchanged!
        instance.stop()
Esempio n. 8
0
    def test7(self):
        print "Test evolve_model optional arguments: end_time and keep_synchronous"

        instance = MOBSE()
        instance.commit_parameters()
        
        stars =  Particles(6)
        stars.mass = [1.0,2.0,3.0, 0.1, 0.2, 0.3]  | units.MSun
        
        binaries =  Particles(3)
        binaries.eccentricity = 0.0
        for i in range(3):
            binaries[i].child1 = stars[i]
            binaries[i].child2 = stars[i+3]
        orbital_period =   200.0 | units.day
        semi_major_axis = instance.orbital_period_to_semi_major_axis(
            orbital_period,  
            binaries.child1.as_set().mass , 
            binaries.child2.as_set().mass
        )
        binaries.semi_major_axis = semi_major_axis
        
        instance.particles.add_particles(stars)
        instance.binaries.add_particles(binaries)
        
        self.assertAlmostEqual(instance.binaries.age, [0.0, 0.0, 0.0] | units.yr)
        self.assertAlmostEqual(instance.binaries.time_step, [550.1565, 58.2081, 18.8768] | units.Myr, 3)
        
        print "evolve_model without arguments: use shared timestep = min(particles.time_step)"
        instance.evolve_model()
        self.assertAlmostEqual(instance.binaries.age, [18.8768, 18.8768, 18.8768] | units.Myr, 3)
        self.assertAlmostEqual(instance.binaries.time_step, [550.1565, 58.2081, 18.8768] | units.Myr, 3)
        self.assertAlmostEqual(instance.model_time, 18.8768 | units.Myr, 3)
        
        print "evolve_model with end_time: take timesteps, until end_time is reached exactly"
        instance.evolve_model(100 | units.Myr)
        self.assertAlmostEqual(instance.binaries.age, [100.0, 100.0, 100.0] | units.Myr, 3)
        self.assertAlmostEqual(instance.binaries.time_step, [550.1565, 58.2081, 18.8785] | units.Myr, 3)
        self.assertAlmostEqual(instance.model_time, 100.0 | units.Myr, 3)
        
        print "evolve_model with keep_synchronous: use non-shared timestep, particle ages will typically diverge"
        instance.evolve_model(keep_synchronous = False)
        self.assertAlmostEqual(instance.binaries.age, (100 | units.Myr) + ([550.1565, 58.2081, 18.8785] | units.Myr), 3)
        self.assertAlmostEqual(instance.binaries.time_step, [550.1565, 58.2081, 18.8785] | units.Myr, 3)
        self.assertAlmostEqual(instance.model_time, 100.0 | units.Myr, 3) # Unchanged!
        instance.stop()
Esempio n. 9
0
    def test3(self):
        print("Testing standard MOBSE example 2...")
        instance = MOBSE()
        instance.parameters.common_envelope_efficiency = 3.0
        instance.parameters.common_envelope_binding_energy_factor= 0.5
        instance.parameters.Eddington_mass_transfer_limit_factor = 10.0
        instance.commit_parameters()
        
        stars =  Particles(2)
        stars[0].mass = 7.816 | units.MSun
        stars[1].mass = 4.387 | units.MSun
        
        orbital_period =   1964.18453 | units.day
        semi_major_axis = instance.orbital_period_to_semi_major_axis(orbital_period,  stars[0].mass , stars[1].mass)
        instance.particles.add_particles(stars)
        
        binaries =  Particles(1)
        
        binary = binaries[0]
        binary.semi_major_axis = semi_major_axis
        binary.eccentricity = 0.0
        binary.child1 = stars[0]
        binary.child2 = stars[1]
        
        instance.binaries.add_particles(binaries)
        
        from_mobse_to_model = instance.particles.new_channel_to(stars)
        from_mobse_to_model.copy()

        from_mobse_to_model_binaries = instance.binaries.new_channel_to(binaries)
        from_mobse_to_model_binaries.copy()
        
        previous_type1 = binary.child1.stellar_type
        previous_type2 = binary.child2.stellar_type
        results = []
        current_time = 0 | units.Myr
        
        while current_time < (170 | units.Myr):
            instance.update_time_steps()
            # The next line appears a bit weird, but saves time for this simple test.
            current_time = current_time + max(2.0*instance.binaries[0].time_step, 0.04 | units.Myr)
            instance.evolve_model(current_time)
            from_mobse_to_model.copy()
            from_mobse_to_model_binaries.copy()        
            if not (binary.child1.stellar_type  == previous_type1 and binary.child2.stellar_type == previous_type2):
                results.append((binary.age, str(binary.child1.stellar_type)+" and "+str(binary.child2.stellar_type)))
                previous_type1 = binary.child1.stellar_type
                previous_type2 = binary.child2.stellar_type
        
            
        print('\n'.join(map(str, results)))
        self.assertEqual(len(results), 12)
        times = ( 
            39.1037 | units.Myr, 
            39.2242 | units.Myr, 
            39.2565 | units.Myr, 
            43.9911 | units.Myr,
            44.1842 | units.Myr,
            44.2644 | units.Myr,
            141.8444 | units.Myr, 
            142.4835 | units.Myr, 
            142.9234 | units.Myr,
            166.3238 | units.Myr,
            166.8385 | units.Myr,
            167.1731 | units.Myr
        )
        for result, expected in zip(results, times):
            self.assertAlmostEqual(result[0].value_in(units.Myr), expected.value_in(units.Myr), 0)
            
        types = (
            "Hertzsprung Gap and Main Sequence star",
            "First Giant Branch and Main Sequence star",
            "Core Helium Burning and Main Sequence star",
            "First Asymptotic Giant Branch and Main Sequence star",
            "Second Asymptotic Giant Branch and Main Sequence star",
            "Oxygen/Neon White Dwarf and Main Sequence star",
            "Oxygen/Neon White Dwarf and Hertzsprung Gap",
            "Oxygen/Neon White Dwarf and First Giant Branch",
            "Oxygen/Neon White Dwarf and Core Helium Burning",
            "Oxygen/Neon White Dwarf and First Asymptotic Giant Branch",
            "Oxygen/Neon White Dwarf and Hertzsprung Gap Naked Helium star",
            "Neutron Star and Carbon/Oxygen White Dwarf",
        )
        
        for result, expected in zip(results, types):
            self.assertEqual(result[1], expected)
        
        self.assertAlmostEqual(binary.child1.mass.value_in(units.MSun), 1.26079, 3)
        self.assertAlmostEqual(binary.child2.mass.value_in(units.MSun), 0.76080, 3)
        
        instance.stop()
Esempio n. 10
0
    def test2(self):
        print("Testing evolution of a wide binary system.")
        instance = MOBSE()
        instance.parameters.metallicity = 0.001
        instance.parameters.common_envelope_efficiency = 3.0
        instance.parameters.Eddington_mass_transfer_limit_factor = 10.0
        instance.commit_parameters()
        
        stars =  Particles(2)
        stars[0].mass = 4.0 | units.MSun
        stars[1].mass = 0.3 | units.MSun
        orbital_period =  2.0e5 | units.day
        semi_major_axis = instance.orbital_period_to_semi_major_axis(orbital_period,  stars[0].mass , stars[1].mass)
        
        instance.particles.add_particles(stars)
        
        binaries =  Particles(1)
        
        binary = binaries[0]
        binary.semi_major_axis = semi_major_axis
        binary.eccentricity = 0.5
        binary.child1 = stars[0]
        binary.child2 = stars[1]
        
        instance.binaries.add_particles(binaries)
        
        from_mobse_to_model = instance.particles.new_channel_to(stars)
        from_mobse_to_model.copy()

        from_mobse_to_model_binaries = instance.binaries.new_channel_to(binaries)
        from_mobse_to_model_binaries.copy()
        
        previous_type = binary.child1.stellar_type
        results = []
        current_time = 0 | units.Myr
        
        while current_time < (170 | units.Myr):
            instance.update_time_steps()
            # The next line appears a bit weird, but saves time for this simple test.
            current_time = current_time + max(2.0*instance.binaries[0].time_step, 0.04 | units.Myr)
            instance.evolve_model(current_time)
            from_mobse_to_model.copy()
            from_mobse_to_model_binaries.copy()
            if not binary.child1.stellar_type == previous_type:
                results.append((binary.age, binary.child1.mass, binary.child1.stellar_type))
                previous_type = binary.child1.stellar_type
        print(results)
        self.assertEqual(len(results), 6)
        
        times = ( 
            147.1282 | units.Myr, 
            148.0345 | units.Myr, 
            148.2282 | units.Myr, 
            167.2811 | units.Myr,
            168.0344 | units.Myr,
            168.7475 | units.Myr
        )
        for result, expected in zip(results, times):
            self.assertAlmostEqual(result[0].value_in(units.Myr), expected.value_in(units.Myr), 0)
            
        masses = ( 
            4.000 | units.MSun, 
            3.999 | units.MSun, 
            3.999 | units.MSun, 
            3.942 | units.MSun,
            3.906 | units.MSun,
            1.016 | units.MSun
        )
        for result, expected in zip(results, masses):
            self.assertAlmostEqual(result[1].value_in(units.MSun), expected.value_in(units.MSun), 2)
         
        types = (
            "Hertzsprung Gap",
            "First Giant Branch",
            "Core Helium Burning",
            "First Asymptotic Giant Branch",
            "Second Asymptotic Giant Branch",
            "Carbon/Oxygen White Dwarf",
        )
        
        for result, expected in zip(results, types):
            self.assertEqual(str(result[2]), expected)
        
        instance.stop()
Esempio n. 11
0
    def test1(self):
        print("Testing evolution of a close binary system...")
        instance = MOBSE()
        instance.initialize_code()
        instance.parameters.metallicity = 0.001
        instance.parameters.common_envelope_efficiency = 3.0
        instance.parameters.Eddington_mass_transfer_limit_factor = 10.0
        instance.commit_parameters()
        stars =  Particles(2)
        stars[0].mass = 3.0 | units.MSun
        stars[1].mass = 0.3 | units.MSun
        
        orbital_period = 200.0 | units.day
        semi_major_axis = instance.orbital_period_to_semi_major_axis(orbital_period,  stars[0].mass , stars[1].mass)
        
        instance.particles.add_particles(stars)
        
        binaries =  Particles(1)
        
        binary = binaries[0]
        binary.semi_major_axis = semi_major_axis
        binary.eccentricity = 0.5
        binary.child1 = stars[0]
        binary.child2 = stars[1]
        
        instance.binaries.add_particles(binaries)
        
        from_mobse_to_model = instance.particles.new_channel_to(stars)
        from_mobse_to_model.copy()

        from_mobse_to_model_binaries = instance.binaries.new_channel_to(binaries)
        from_mobse_to_model_binaries.copy()
        
        previous_type = binary.child1.stellar_type
        results = []
        current_time = 0 | units.Myr
        
        while current_time < (480 | units.Myr):
            instance.update_time_steps()
            # The next line appears a bit weird, but saves time for this simple test.
            current_time = current_time + max(5.0*instance.binaries[0].time_step, 0.3 | units.Myr)
            instance.evolve_model(current_time)
            from_mobse_to_model.copy()
            from_mobse_to_model_binaries.copy()
            if not binary.child1.stellar_type == previous_type:
                results.append((binary.age, binary.child1.mass, binary.child1.stellar_type))
                previous_type = binary.child1.stellar_type
            
        self.assertEqual(len(results), 6)
        
        types = (
            "Hertzsprung Gap",
            "First Giant Branch",
            "Core Helium Burning",
            "First Asymptotic Giant Branch",
            "Hertzsprung Gap Naked Helium star",
            "Carbon/Oxygen White Dwarf",
        )
        
        for result, expected in zip(results, types):
            self.assertEqual(str(result[2]), expected)
        
        times = ( 
            284.8632 | units.Myr, 
            287.0713 | units.Myr, 
            287.7967 | units.Myr, 
            331.1631 | units.Myr, 
            331.4164 | units.Myr, 
            332.2864 | units.Myr,
        )
        for result, expected in zip(results, times):
            self.assertAlmostEqual(result[0].value_in(units.Myr), expected.value_in(units.Myr), 0)
            
        masses = ( 
            3.000 | units.MSun, 
            3.000 | units.MSun, 
            2.999 | units.MSun, 
            2.956 | units.MSun,
            0.888 | units.MSun,
            0.701 | units.MSun,
        )
        for result, expected in zip(results, masses):
            self.assertAlmostEqual(result[1].value_in(units.MSun), expected.value_in(units.MSun), 2)
         
        instance.stop()
Esempio n. 12
0
    def test3(self):
        print "Testing standard MOBSE example 2..."
        instance = MOBSE()
        instance.parameters.common_envelope_efficiency = 3.0
        instance.parameters.common_envelope_binding_energy_factor= 0.5
        instance.parameters.Eddington_mass_transfer_limit_factor = 10.0
        instance.commit_parameters()
        
        stars =  Particles(2)
        stars[0].mass = 7.816 | units.MSun
        stars[1].mass = 4.387 | units.MSun
        
        orbital_period =   1964.18453 | units.day
        semi_major_axis = instance.orbital_period_to_semi_major_axis(orbital_period,  stars[0].mass , stars[1].mass)
        instance.particles.add_particles(stars)
        
        binaries =  Particles(1)
        
        binary = binaries[0]
        binary.semi_major_axis = semi_major_axis
        binary.eccentricity = 0.0
        binary.child1 = stars[0]
        binary.child2 = stars[1]
        
        instance.binaries.add_particles(binaries)
        
        from_mobse_to_model = instance.particles.new_channel_to(stars)
        from_mobse_to_model.copy()

        from_mobse_to_model_binaries = instance.binaries.new_channel_to(binaries)
        from_mobse_to_model_binaries.copy()
        
        previous_type1 = binary.child1.stellar_type
        previous_type2 = binary.child2.stellar_type
        results = []
        current_time = 0 | units.Myr
        
        while current_time < (170 | units.Myr):
            instance.update_time_steps()
            # The next line appears a bit weird, but saves time for this simple test.
            current_time = current_time + max(2.0*instance.binaries[0].time_step, 0.04 | units.Myr)
            instance.evolve_model(current_time)
            from_mobse_to_model.copy()
            from_mobse_to_model_binaries.copy()        
            if not (binary.child1.stellar_type  == previous_type1 and binary.child2.stellar_type == previous_type2):
                results.append((binary.age, str(binary.child1.stellar_type)+" and "+str(binary.child2.stellar_type)))
                previous_type1 = binary.child1.stellar_type
                previous_type2 = binary.child2.stellar_type
        
            
        print '\n'.join(map(str, results))
        self.assertEqual(len(results), 12)
        times = ( 
            39.1037 | units.Myr, 
            39.2242 | units.Myr, 
            39.2565 | units.Myr, 
            43.9911 | units.Myr,
            44.1842 | units.Myr,
            44.2644 | units.Myr,
            141.8444 | units.Myr, 
            142.4835 | units.Myr, 
            142.9234 | units.Myr,
            166.3238 | units.Myr,
            166.8385 | units.Myr,
            167.1731 | units.Myr
        )
        for result, expected in zip(results, times):
            self.assertAlmostEqual(result[0].value_in(units.Myr), expected.value_in(units.Myr), 0)
            
        types = (
            "Hertzsprung Gap and Main Sequence star",
            "First Giant Branch and Main Sequence star",
            "Core Helium Burning and Main Sequence star",
            "First Asymptotic Giant Branch and Main Sequence star",
            "Second Asymptotic Giant Branch and Main Sequence star",
            "Oxygen/Neon White Dwarf and Main Sequence star",
            "Oxygen/Neon White Dwarf and Hertzsprung Gap",
            "Oxygen/Neon White Dwarf and First Giant Branch",
            "Oxygen/Neon White Dwarf and Core Helium Burning",
            "Oxygen/Neon White Dwarf and First Asymptotic Giant Branch",
            "Oxygen/Neon White Dwarf and Hertzsprung Gap Naked Helium star",
            "Neutron Star and Carbon/Oxygen White Dwarf",
        )
        
        for result, expected in zip(results, types):
            self.assertEquals(result[1], expected)
        
        self.assertAlmostEqual(binary.child1.mass.value_in(units.MSun), 1.26079, 3)
        self.assertAlmostEqual(binary.child2.mass.value_in(units.MSun), 0.76080, 3)
        
        instance.stop()
Esempio n. 13
0
    def test2(self):
        print "Testing evolution of a wide binary system."
        instance = MOBSE()
        instance.parameters.metallicity = 0.001
        instance.parameters.common_envelope_efficiency = 3.0
        instance.parameters.Eddington_mass_transfer_limit_factor = 10.0
        instance.commit_parameters()
        
        stars =  Particles(2)
        stars[0].mass = 4.0 | units.MSun
        stars[1].mass = 0.3 | units.MSun
        orbital_period =  2.0e5 | units.day
        semi_major_axis = instance.orbital_period_to_semi_major_axis(orbital_period,  stars[0].mass , stars[1].mass)
        
        instance.particles.add_particles(stars)
        
        binaries =  Particles(1)
        
        binary = binaries[0]
        binary.semi_major_axis = semi_major_axis
        binary.eccentricity = 0.5
        binary.child1 = stars[0]
        binary.child2 = stars[1]
        
        instance.binaries.add_particles(binaries)
        
        from_mobse_to_model = instance.particles.new_channel_to(stars)
        from_mobse_to_model.copy()

        from_mobse_to_model_binaries = instance.binaries.new_channel_to(binaries)
        from_mobse_to_model_binaries.copy()
        
        previous_type = binary.child1.stellar_type
        results = []
        current_time = 0 | units.Myr
        
        while current_time < (170 | units.Myr):
            instance.update_time_steps()
            # The next line appears a bit weird, but saves time for this simple test.
            current_time = current_time + max(2.0*instance.binaries[0].time_step, 0.04 | units.Myr)
            instance.evolve_model(current_time)
            from_mobse_to_model.copy()
            from_mobse_to_model_binaries.copy()
            if not binary.child1.stellar_type == previous_type:
                results.append((binary.age, binary.child1.mass, binary.child1.stellar_type))
                previous_type = binary.child1.stellar_type
        print results
        self.assertEqual(len(results), 6)
        
        times = ( 
            147.1282 | units.Myr, 
            148.0345 | units.Myr, 
            148.2282 | units.Myr, 
            167.2811 | units.Myr,
            168.0344 | units.Myr,
            168.7475 | units.Myr
        )
        for result, expected in zip(results, times):
            self.assertAlmostEqual(result[0].value_in(units.Myr), expected.value_in(units.Myr), 0)
            
        masses = ( 
            4.000 | units.MSun, 
            3.999 | units.MSun, 
            3.999 | units.MSun, 
            3.942 | units.MSun,
            3.906 | units.MSun,
            1.016 | units.MSun
        )
        for result, expected in zip(results, masses):
            self.assertAlmostEqual(result[1].value_in(units.MSun), expected.value_in(units.MSun), 2)
         
        types = (
            "Hertzsprung Gap",
            "First Giant Branch",
            "Core Helium Burning",
            "First Asymptotic Giant Branch",
            "Second Asymptotic Giant Branch",
            "Carbon/Oxygen White Dwarf",
        )
        
        for result, expected in zip(results, types):
            self.assertEquals(str(result[2]), expected)
        
        instance.stop()
Esempio n. 14
0
    def test1(self):
        print "Testing evolution of a close binary system..."
        instance = MOBSE()
        instance.initialize_code()
        instance.parameters.metallicity = 0.001
        instance.parameters.common_envelope_efficiency = 3.0
        instance.parameters.Eddington_mass_transfer_limit_factor = 10.0
        instance.commit_parameters()
        stars =  Particles(2)
        stars[0].mass = 3.0 | units.MSun
        stars[1].mass = 0.3 | units.MSun
        
        orbital_period = 200.0 | units.day
        semi_major_axis = instance.orbital_period_to_semi_major_axis(orbital_period,  stars[0].mass , stars[1].mass)
        
        instance.particles.add_particles(stars)
        
        binaries =  Particles(1)
        
        binary = binaries[0]
        binary.semi_major_axis = semi_major_axis
        binary.eccentricity = 0.5
        binary.child1 = stars[0]
        binary.child2 = stars[1]
        
        instance.binaries.add_particles(binaries)
        
        from_mobse_to_model = instance.particles.new_channel_to(stars)
        from_mobse_to_model.copy()

        from_mobse_to_model_binaries = instance.binaries.new_channel_to(binaries)
        from_mobse_to_model_binaries.copy()
        
        previous_type = binary.child1.stellar_type
        results = []
        current_time = 0 | units.Myr
        
        while current_time < (480 | units.Myr):
            instance.update_time_steps()
            # The next line appears a bit weird, but saves time for this simple test.
            current_time = current_time + max(5.0*instance.binaries[0].time_step, 0.3 | units.Myr)
            instance.evolve_model(current_time)
            from_mobse_to_model.copy()
            from_mobse_to_model_binaries.copy()
            if not binary.child1.stellar_type == previous_type:
                results.append((binary.age, binary.child1.mass, binary.child1.stellar_type))
                previous_type = binary.child1.stellar_type
            
        self.assertEqual(len(results), 6)
        
        types = (
            "Hertzsprung Gap",
            "First Giant Branch",
            "Core Helium Burning",
            "First Asymptotic Giant Branch",
            "Hertzsprung Gap Naked Helium star",
            "Carbon/Oxygen White Dwarf",
        )
        
        for result, expected in zip(results, types):
            self.assertEquals(str(result[2]), expected)
        
        times = ( 
            284.8632 | units.Myr, 
            287.0713 | units.Myr, 
            287.7967 | units.Myr, 
            331.1631 | units.Myr, 
            331.4164 | units.Myr, 
            332.2864 | units.Myr,
        )
        for result, expected in zip(results, times):
            self.assertAlmostEqual(result[0].value_in(units.Myr), expected.value_in(units.Myr), 0)
            
        masses = ( 
            3.000 | units.MSun, 
            3.000 | units.MSun, 
            2.999 | units.MSun, 
            2.956 | units.MSun,
            0.888 | units.MSun,
            0.701 | units.MSun,
        )
        for result, expected in zip(results, masses):
            self.assertAlmostEqual(result[1].value_in(units.MSun), expected.value_in(units.MSun), 2)
         
        instance.stop()