def test5(self): print "Testing stellar collision..." instance = BSE() 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 instance.particles.add_particles(stars) binaries = Particles(1) binary = binaries[0] orbital_period = 200.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_bse_to_model = instance.particles.new_channel_to(stars) from_bse_to_model.copy() from_bse_to_model_binaries = instance.binaries.new_channel_to(binaries) from_bse_to_model_binaries.copy() instance.evolve_model(170 | units.Myr) from_bse_to_model.copy() from_bse_to_model_binaries.copy() print binaries self.assertAlmostEqual(binary.child1.mass.value_in(units.MSun), 3.300, 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()
def test4(self): print "Quick testing standard BSE example 2..." instance = BSE() 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 = 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_bse_to_model = instance.particles.new_channel_to(stars) from_bse_to_model.copy() from_bse_to_model_binaries = instance.binaries.new_channel_to(binaries) from_bse_to_model_binaries.copy() instance.evolve_model(170 | units.Myr) from_bse_to_model.copy() from_bse_to_model_binaries.copy() self.assertAlmostEqual(binary.child1.mass.value_in(units.MSun), 1.304, 3) self.assertAlmostEqual(binary.child2.mass.value_in(units.MSun), 0.800, 3) self.assertEquals(str(binary.child1.stellar_type), "Neutron Star") self.assertEquals(str(binary.child2.stellar_type), "Carbon/Oxygen White Dwarf") instance.stop()
def test8(self): print( "Testing adding and removing particles from stellar evolution code..." ) instance = BSE() 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.assertEqual(len(instance.particles), 0) self.assertEqual(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.assertEqual(len(instance.binaries), 2) # before remove self.assertAlmostEqual(instance.binaries.age, 1.0 | units.Myr) instance.binaries.remove_particle(binaries[0]) self.assertEqual(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.assertEqual(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()
def test5(self): print "Testing stellar collision..." instance = BSE() 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 instance.particles.add_particles(stars) binaries = Particles(1) binary = binaries[0] orbital_period = 200.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_bse_to_model = instance.particles.new_channel_to(stars) from_bse_to_model.copy() from_bse_to_model_binaries = instance.binaries.new_channel_to(binaries) from_bse_to_model_binaries.copy() instance.evolve_model(170 | units.Myr) from_bse_to_model.copy() from_bse_to_model_binaries.copy() print binaries self.assertAlmostEqual(binary.child1.mass.value_in(units.MSun), 3.300, 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()
def test4(self): print "Quick testing standard BSE example 2..." instance = BSE() 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 = 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_bse_to_model = instance.particles.new_channel_to(stars) from_bse_to_model.copy() from_bse_to_model_binaries = instance.binaries.new_channel_to(binaries) from_bse_to_model_binaries.copy() instance.evolve_model(170 | units.Myr) from_bse_to_model.copy() from_bse_to_model_binaries.copy() self.assertAlmostEqual(binary.child1.mass.value_in(units.MSun), 1.304, 3) self.assertAlmostEqual(binary.child2.mass.value_in(units.MSun), 0.800, 3) self.assertEquals(str(binary.child1.stellar_type), "Neutron Star") self.assertEquals(str(binary.child2.stellar_type), "Carbon/Oxygen White Dwarf") instance.stop()
def test8(self): print "Testing adding and removing particles from stellar evolution code..." instance = BSE() 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()
def test7(self): print "Test evolve_model optional arguments: end_time and keep_synchronous" instance = BSE() 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.8768] | 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.8768] | units.Myr), 3) self.assertAlmostEqual(instance.binaries.time_step, [550.1565, 58.2081, 18.8768] | units.Myr, 3) self.assertAlmostEqual(instance.model_time, 100.0 | units.Myr, 3) # Unchanged! instance.stop()
def test7(self): print "Test evolve_model optional arguments: end_time and keep_synchronous" instance = BSE() 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.8768] | 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.8768] | units.Myr), 3) self.assertAlmostEqual(instance.binaries.time_step, [550.1565, 58.2081, 18.8768] | units.Myr, 3) self.assertAlmostEqual(instance.model_time, 100.0 | units.Myr, 3) # Unchanged! instance.stop()
def test_binary_evolution(a0=0.3 | units.au, e0=0.6, m1=60 | units.MSun, m2=40 | units.MSun, t0=0 | units.yr, tend=3 | units.Myr, dt_out=1000 | units.yr, dt_kick_fP=0.1): ################### ### BSE ### ################### bse = BSE() bse.parameters.metallicity = 0.02 bse.parameters.neutron_star_mass_flag = 3 stars_bse = Particles(2) stars_bse[0].mass = m1 stars_bse[1].mass = m2 mu = stars_bse.mass.sum() * constants.G P0 = np.pi * (a0 * a0 * a0 / mu).sqrt() print("P0:", P0.as_string_in(units.yr)) print("a0:", a0.as_string_in(units.au)) print("e0:", e0) binaries = Particles(1) binary = binaries[0] binary.semi_major_axis = a0 binary.eccentricity = e0 binary.child1 = stars_bse[0] binary.child2 = stars_bse[1] bse.particles.add_particles(stars_bse) bse.binaries.add_particles(binaries) from_bse_to_model = bse.particles.new_channel_to(stars_bse) from_bse_to_model.copy() from_bse_to_model_binaries = bse.binaries.new_channel_to(binaries) from_bse_to_model_binaries.copy() ################### ### NBODY ### ################### converter = nbody_system.nbody_to_si(1 | units.MSun, 1 | units.au) directcode = Hermite(converter) binary_nbd, stars_nbd = make_binary_star(m1, m2, a0, e0) directcode.particles.add_particle(stars_nbd) from_nbody_to_model = directcode.particles.new_channel_to(stars_nbd) from_model_to_nbody = stars_nbd.new_channel_to(directcode.particles) ################## ### BEGIN LOOP ### ################## t = t0 t_next_out = t0 + dt_out dt_kick = P0 * dt_kick_fP * 10000000 data = [] while t < tend: t = t + dt_kick bse.evolve_model(t) from_bse_to_model_binaries.copy() from_bse_to_model.copy() if t >= t_next_out: data.append( (t.value_in(units.yr), binary.child1.mass.value_in(units.MSun), binary.child2.mass.value_in(units.MSun), binary.child1.radius.value_in(units.RSun), binary.child2.radius.value_in(units.RSun), binary.semi_major_axis.value_in(units.RSun), binary.eccentricity)) t_next_out = t + dt_out print("{:g}%".format(t / tend * 100), end="\r") bse.stop() ####################### ###### PLOTTING ####### ####################### data = np.array(data) time = data[:, 0] mass1 = data[:, 1] mass2 = data[:, 2] radius1 = data[:, 3] radius2 = data[:, 4] semi = data[:, 5] ecc = data[:, 6] peri = semi * (1 - ecc) figure = plt.figure(figsize=(16, 7)) plot = figure.add_subplot(1, 2, 1) plot.plot(time, mass1, label='m1') plot.plot(time, mass2, label='m2') plot.set_xlabel('Time [yr]') plot.set_ylabel('Mass [MSun]') plot.legend(loc='best') plot = figure.add_subplot(1, 2, 2) plot.plot(time, radius1, label='R1') plot.plot(time, radius2, label='R2') plot.plot(time, semi, label='semi BSE', c="blue") plot.plot(time, peri, label='peri BSE', c="blue", ls="-.") plot.set_xlabel('Time [yr]') plot.set_ylabel('R [RSun]') plot.legend() plt.show()
def test3(self): print "Testing standard BSE example 2..." instance = BSE() 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 = 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_bse_to_model = instance.particles.new_channel_to(stars) from_bse_to_model.copy() from_bse_to_model_binaries = instance.binaries.new_channel_to(binaries) from_bse_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_bse_to_model.copy() from_bse_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), 13) times = (38.9708 | units.Myr, 39.0897 | units.Myr, 39.1213 | units.Myr, 43.8025 | units.Myr, 43.9923 | units.Myr, 44.0686 | units.Myr, 141.7077 | units.Myr, 142.3448 | units.Myr, 142.7827 | units.Myr, 166.1043 | units.Myr, 166.5795 | units.Myr, 166.9627 | units.Myr, 166.9863 | 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 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.304, 3) self.assertAlmostEqual(binary.child2.mass.value_in(units.MSun), 0.800, 3) instance.stop()
def test2(self): print "Testing evolution of a wide binary system." instance = BSE() 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 = 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_bse_to_model = instance.particles.new_channel_to(stars) from_bse_to_model.copy() from_bse_to_model_binaries = instance.binaries.new_channel_to(binaries) from_bse_to_model_binaries.copy() previous_type = binary.child1.stellar_type results = [] current_time = 0 | units.Myr while current_time < (335 | 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_bse_to_model.copy() from_bse_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 = (284.8516 | units.Myr, 287.0595 | units.Myr, 287.7848 | units.Myr, 331.1454 | units.Myr, 332.7407 | units.Myr, 333.4146 | 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, 2.919 | units.MSun, 0.928 | 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()
def test3(self): print "Testing standard BSE example 2..." instance = BSE() 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 = 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_bse_to_model = instance.particles.new_channel_to(stars) from_bse_to_model.copy() from_bse_to_model_binaries = instance.binaries.new_channel_to(binaries) from_bse_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_bse_to_model.copy() from_bse_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), 13) times = ( 38.9708 | units.Myr, 39.0897 | units.Myr, 39.1213 | units.Myr, 43.8025 | units.Myr, 43.9923 | units.Myr, 44.0686 | units.Myr, 141.7077 | units.Myr, 142.3448 | units.Myr, 142.7827 | units.Myr, 166.1043 | units.Myr, 166.5795 | units.Myr, 166.9627 | units.Myr, 166.9863 | 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 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.304, 3) self.assertAlmostEqual(binary.child2.mass.value_in(units.MSun), 0.800, 3) instance.stop()
def test2(self): print "Testing evolution of a wide binary system." instance = BSE() 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 = 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_bse_to_model = instance.particles.new_channel_to(stars) from_bse_to_model.copy() from_bse_to_model_binaries = instance.binaries.new_channel_to(binaries) from_bse_to_model_binaries.copy() previous_type = binary.child1.stellar_type results = [] current_time = 0 | units.Myr while current_time < (335 | 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_bse_to_model.copy() from_bse_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 = ( 284.8516 | units.Myr, 287.0595 | units.Myr, 287.7848 | units.Myr, 331.1454 | units.Myr, 332.7407 | units.Myr, 333.4146 | 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, 2.919 | units.MSun, 0.928 | 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()