def test2(self): print "Test CollisionHandler with collision code instance (same instance for each collision)" colliders = Particles(2) handler = CollisionHandler(CollisionCodeForTesting()) result = handler.handle_collision(colliders[0], colliders[1]) self.assertTrue(isinstance(result, Particles)) self.assertEqual(result.mass, 1 | units.kg) result = handler.handle_collision(colliders[0], colliders[1]) self.assertEqual(result.mass, 2 | units.kg)
def test1(self): print( "Test CollisionHandler with collision code class (creates new instance for each collision)" ) colliders = Particles(2) handler = CollisionHandler(CollisionCodeForTesting) result = handler.handle_collision(colliders[0], colliders[1]) self.assertTrue(isinstance(result, Particles)) self.assertEqual(result.mass, 1 | units.kg) result = handler.handle_collision(colliders[0], colliders[1]) self.assertEqual(result.mass, 1 | units.kg)
def merge_two_stars_and_evolve(Mprim, Msec, tcoll, tend): stars = Particles(2) stars.mass = [Mprim.value_in(units.MSun), Msec.value_in(units.MSun)] | units.MSun stellar_evolution = MESA() stellar_evolution.particles.add_particles(stars) while stellar_evolution.model_time < tcoll: stellar_evolution.evolve_model() print_stars(stellar_evolution) n_shell = min(stellar_evolution.particles[0].get_number_of_zones(), stellar_evolution.particles[1].get_number_of_zones()) merger_code = MakeMeAMassiveStar(**default_options) merger_code.parameters.target_n_shells = n_shell merger_code.parameters.dump_mixed_flag = True merger_code.parameters.do_shock_heating_flag = True merger_code.commit_parameters() handler = CollisionHandler(merger_code, stellar_evolution_code=stellar_evolution) merger_product = handler.handle_collision(stellar_evolution.particles[0], stellar_evolution.particles[1]) merged = stellar_evolution.particles[0] print "Stars merged:", merged stellar_evolution.evolve_model(keep_synchronous=True) ###BOOKLISTSTOP1### time = [] | units.Myr stellar_type = [] mass = [] | units.MSun radius = [] | units.RSun temperature = [] | units.K luminosity = [] | units.LSun ###BOOKLISTSTART2### p = stellar_evolution.particles[0] while stellar_evolution.model_time < tend: stellar_evolution.evolve_model() ###BOOKLISTSTOP2### time.append(stellar_evolution.model_time) stellar_type.append(p.stellar_type) mass.append(p.mass) radius.append(p.radius) temperature.append(p.temperature) luminosity.append(p.luminosity) ###BOOKLISTSTART3### print "Time=", stellar_evolution.model_time, p.stellar_type, \ p.mass, p.radius, p.temperature.in_(units.K), \ p.luminosity.in_(units.LSun) if p.stellar_type >= 4 | units.stellar_type: break merger_code.stop() stellar_evolution.stop() ###BOOKLISTSTOP3### return time, stellar_type, mass, radius, temperature, luminosity
def merge_two_stars_and_evolve(Mprim, Msec, tcoll, tend): stars = Particles(2) stars.mass = [Mprim.value_in(units.MSun), Msec.value_in(units.MSun)] | units.MSun stellar_evolution = MESA() stellar_evolution.particles.add_particles(stars) while stellar_evolution.model_time < tcoll: stellar_evolution.evolve_model() print_stars(stellar_evolution) n_shell = min(stellar_evolution.particles[0].get_number_of_zones(), stellar_evolution.particles[1].get_number_of_zones()) merger_code = MakeMeAMassiveStar(**default_options) merger_code.parameters.target_n_shells = n_shell merger_code.parameters.dump_mixed_flag = True merger_code.parameters.do_shock_heating_flag = True merger_code.commit_parameters() ###BOOKLISTSTOP1### ###BOOKLISTSTART2### handler = CollisionHandler(merger_code, stellar_evolution_code = stellar_evolution) merger_product = handler.handle_collision(stellar_evolution.particles[0], stellar_evolution.particles[1]) merged = stellar_evolution.particles[0] ###BOOKLISTSTOP2### print "Stars merged:", merged time = [] | units.Myr stellar_type = [] mass = [] | units.MSun radius = [] | units.RSun temperature = [] | units.K luminosity = [] | units.LSun ###BOOKLISTSTART3### stellar_evolution.evolve_model(keep_synchronous=True) p = stellar_evolution.particles[0] while stellar_evolution.model_time < tend: stellar_evolution.evolve_model() ###BOOKLISTSTOP3### time.append(stellar_evolution.model_time) stellar_type.append(p.stellar_type) mass.append(p.mass) radius.append(p.radius) temperature.append(p.temperature) luminosity.append(p.luminosity) ###BOOKLISTSTART4### print "Time=", stellar_evolution.model_time, p.stellar_type, \ p.mass, p.radius, p.temperature.in_(units.K), \ p.luminosity.in_(units.LSun) if p.stellar_type >= 4 | units.stellar_type: break merger_code.stop() stellar_evolution.stop() ###BOOKLISTSTOP4### return time, stellar_type, mass, radius, temperature, luminosity
def test3(self): print "Test CollisionHandler with collision code class, arguments and parameters" colliders = Particles(2) handler = CollisionHandler( CollisionCodeForTesting, collision_code_arguments=dict(next_mass=5 | units.kg), collision_code_parameters=dict(mass_unit=units.g)) result = handler.handle_collision(colliders[0], colliders[1]) self.assertTrue(isinstance(result, Particles)) self.assertEqual(result.mass, 5 | units.kg) self.assertTrue(result.mass.unit is units.g) result = handler.handle_collision(colliders[0], colliders[1]) self.assertEqual(result.mass, 5 | units.kg) self.assertTrue(result.mass.unit is units.g) handler.collision_code_arguments = dict(next_mass=42 | units.kg) handler.collision_code_parameters = dict(mass_unit=units.MSun) result = handler.handle_collision(colliders[0], colliders[1]) self.assertEqual(result.mass, 42 | units.kg) self.assertTrue(result.mass.unit is units.MSun)
def test3(self): print "Test CollisionHandler with collision code class, arguments and parameters" colliders = Particles(2) handler = CollisionHandler( CollisionCodeForTesting, collision_code_arguments=dict(next_mass=5|units.kg), collision_code_parameters=dict(mass_unit=units.g) ) result = handler.handle_collision(colliders[0], colliders[1]) self.assertTrue(isinstance(result, Particles)) self.assertEqual(result.mass, 5 | units.kg) self.assertTrue(result.mass.unit is units.g) result = handler.handle_collision(colliders[0], colliders[1]) self.assertEqual(result.mass, 5 | units.kg) self.assertTrue(result.mass.unit is units.g) handler.collision_code_arguments = dict(next_mass=42|units.kg) handler.collision_code_parameters = dict(mass_unit=units.MSun) result = handler.handle_collision(colliders[0], colliders[1]) self.assertEqual(result.mass, 42 | units.kg) self.assertTrue(result.mass.unit is units.MSun)
def merge_two_stars(Mprim, Msec, n_shell, tcoll, tend): stars = Particles(2) stars.mass = [Mprim.value_in(units.MSun), Msec.value_in(units.MSun)] | units.MSun stellar_evolution = MESA() stellar_evolution.particles.add_particles(stars) while stellar_evolution.model_time<tcoll: stellar_evolution.evolve_model() print_stars(stellar_evolution) n_shell = min(stellar_evolution.particles[0].get_number_of_zones(), stellar_evolution.particles[1].get_number_of_zones()) print "n_shells=", n_shell instance = MakeMeAMassiveStar(**default_options) instance.parameters.target_n_shells = n_shell instance.parameters.dump_mixed_flag = True instance.parameters.do_shock_heating_flag = True instance.commit_parameters() instance.particles.add_particles(stars) handler = CollisionHandler(instance, stellar_evolution_code = stellar_evolution) merger_product = handler.handle_collision(stellar_evolution.particles[0], stellar_evolution.particles[1]) merged = stellar_evolution.particles[0] stellar_evolution.evolve_model(keep_synchronous = True) time = [] | units.Myr mass = [] | units.MSun radius = [] | units.RSun temperature = [] | units.K luminosity = [] | units.LSun while stellar_evolution.model_time<tend: # while stellar_evolution.particles[0].radius<24|units.RSun: stellar_evolution.evolve_model() time.append(stellar_evolution.model_time) mass.append(stellar_evolution.particles[0].mass) radius.append(stellar_evolution.particles[0].radius) temperature.append(stellar_evolution.particles[0].temperature) luminosity.append(stellar_evolution.particles[0].luminosity) print "Time=", time[-1], mass[-1], radius[-1], temperature[-1].in_(units.K), luminosity[-1].in_(units.LSun) rho_profile = merged.get_density_profile() radius_profile = merged.get_radius_profile() instance.stop() stellar_evolution.stop() return time, mass, radius, temperature, luminosity
def merge_two_stars(Mprim, Msec, tcoll, tend): stars = Particles(2) stars.mass = [Mprim.value_in(units.MSun), Msec.value_in(units.MSun)] | units.MSun stellar_evolution = MESA() stellar_evolution.particles.add_particles(stars) time = [] | units.Myr mass = [] | units.MSun radius = [] | units.RSun temperature = [] | units.K luminosity = [] | units.LSun stellar_type = [] nmerge = 0 while stellar_evolution.model_time < tcoll: stellar_evolution.evolve_model() print_stars(stellar_evolution) time.append(stellar_evolution.model_time) mass.append(stellar_evolution.particles[0].mass) radius.append(stellar_evolution.particles[0].radius) temperature.append(stellar_evolution.particles[0].temperature) luminosity.append(stellar_evolution.particles[0].luminosity) stellar_type.append(stellar_evolution.particles[0].stellar_type) nmerge += 1 n_shell = min(stellar_evolution.particles[0].get_number_of_zones(), stellar_evolution.particles[1].get_number_of_zones()) merger = MakeMeAMassiveStar(**default_options) merger.parameters.target_n_shells = n_shell merger.parameters.dump_mixed_flag = True merger.parameters.do_shock_heating_flag = True merger.commit_parameters() handler = CollisionHandler(merger, stellar_evolution_code=stellar_evolution) merger_product = handler.handle_collision(stellar_evolution.particles[0], stellar_evolution.particles[1]) merged = stellar_evolution.particles[0] print "Stars merged:", merged stellar_evolution.evolve_model(keep_synchronous=True) print "star A:", stellar_evolution.particles while stellar_evolution.model_time < tend: stellar_evolution.evolve_model() time.append(stellar_evolution.model_time) mass.append(stellar_evolution.particles[0].mass) radius.append(stellar_evolution.particles[0].radius) temperature.append(stellar_evolution.particles[0].temperature) luminosity.append(stellar_evolution.particles[0].luminosity) stellar_type.append(stellar_evolution.particles[0].stellar_type) print "Time=", time[-1], stellar_type[-1], mass[-1], radius[-1], \ temperature[-1].in_(units.K), luminosity[-1].in_(units.LSun) if stellar_type[-1] >= 4 | units.stellar_type: break print "star B:", stellar_evolution.particles rho_profile = merged.get_density_profile() radius_profile = merged.get_radius_profile() merger.stop() stellar_evolution.stop() return time, stellar_type, mass, radius, temperature, luminosity, nmerge
def merge_two_stars(Mprim, Msec, tcoll, tend): stars = Particles(2) stars.mass = [Mprim.value_in(units.MSun), Msec.value_in(units.MSun)] | units.MSun stellar_evolution = MESA() stellar_evolution.particles.add_particles(stars) time = [] | units.Myr mass = [] | units.MSun radius = [] | units.RSun temperature = [] | units.K luminosity = [] | units.LSun stellar_type = [] nmerge = 0 while stellar_evolution.model_time < tcoll: stellar_evolution.evolve_model() print_stars(stellar_evolution) time.append(stellar_evolution.model_time) mass.append(stellar_evolution.particles[0].mass) radius.append(stellar_evolution.particles[0].radius) temperature.append(stellar_evolution.particles[0].temperature) luminosity.append(stellar_evolution.particles[0].luminosity) stellar_type.append(stellar_evolution.particles[0].stellar_type) nmerge += 1 n_shell = min(stellar_evolution.particles[0].get_number_of_zones(), stellar_evolution.particles[1].get_number_of_zones()) merger = MakeMeAMassiveStar(**default_options) merger.parameters.target_n_shells = n_shell merger.parameters.dump_mixed_flag = True merger.parameters.do_shock_heating_flag = True merger.commit_parameters() handler = CollisionHandler(merger, stellar_evolution_code = stellar_evolution) merger_product = handler.handle_collision(stellar_evolution.particles[0], stellar_evolution.particles[1]) merged = stellar_evolution.particles[0] print "Stars merged:", merged stellar_evolution.evolve_model(keep_synchronous=True) print "star A:", stellar_evolution.particles while stellar_evolution.model_time < tend: stellar_evolution.evolve_model() time.append(stellar_evolution.model_time) mass.append(stellar_evolution.particles[0].mass) radius.append(stellar_evolution.particles[0].radius) temperature.append(stellar_evolution.particles[0].temperature) luminosity.append(stellar_evolution.particles[0].luminosity) stellar_type.append(stellar_evolution.particles[0].stellar_type) print "Time=", time[-1], stellar_type[-1], mass[-1], radius[-1], \ temperature[-1].in_(units.K), luminosity[-1].in_(units.LSun) if stellar_type[-1] >= 4 | units.stellar_type: break print "star B:", stellar_evolution.particles rho_profile = merged.get_density_profile() radius_profile = merged.get_radius_profile() merger.stop() stellar_evolution.stop() return time, stellar_type, mass, radius, temperature, luminosity, nmerge