def __init__(self, original_particles, sink_radius=None, mass=None, position=None, velocity=None, angular_momentum=None, looping_over="sinks"): ParticlesOverlay.__init__(self, original_particles) self._private.looping_over = looping_over self.sink_radius = sink_radius or original_particles.radius if not hasattr(original_particles, "mass"): self.mass = mass or (([0.] * len(self)) | units.kg) if not hasattr(original_particles, "x"): self.position = position or (([[0., 0., 0.]] * len(self)) | units.m) if not hasattr(original_particles, "vx"): self.velocity = velocity or (([[0., 0., 0.]] * len(self)) | units.m / units.s) if not hasattr(original_particles, "lx"): self.angular_momentum = angular_momentum or ( ([[0., 0., 0.]] * len(self)) | units.g * units.m**2 / units.s)
def test22(self): test_results_path = self.get_path_to_results() output_file = os.path.join(test_results_path, "test22" + self.store_version() + ".hdf5") if os.path.exists(output_file): os.remove(output_file) stars = Particles(2) stars.x = 1.0 | units.km overlay = ParticlesOverlay(stars) overlay.y = 2.0 | units.km io.write_set_to_file(overlay, output_file, "hdf5", version=self.store_version()) loaded = io.read_set_from_file(output_file, "hdf5", close_file=True, version=self.store_version()) self.assertEqual(loaded[0].x, 1.0 | units.km) self.assertEqual(loaded[1].y, 2.0 | units.km)
def stars_with_mechanical_luminosity(self, particles): result = ParticlesOverlay(particles) def lmech_function(temperature, mass, luminosity, radius): T = temperature.value_in(units.K) M = mass.value_in(units.MSun) L = luminosity.value_in(units.LSun) R = radius.value_in(units.RSun) # Reimers wind below 8000K mass_loss = (4.0e-13 | units.MSun / units.yr) * L * R / M # ... wind above 8000K i = numpy.where(temperature > 8000 | units.K)[0] mass_loss[i] = (10**-24.06 | units.MSun / units.yr) * ( L**2.45 * M**(-1.1) * T.clip(1000, 8.0e4)**(1.31)) t4 = numpy.log10(T * 1.0e-4).clip(0.0, 1.0) v_terminal = (30 + 4000 * t4) | units.km / units.s return 0.5 * mass_loss * v_terminal**2 result.add_calculated_attribute( "mechanical_luminosity", lmech_function, attributes_names=["temperature", "mass", "luminosity", "radius"]) result.L_mech = result.mechanical_luminosity result.E_mech = (0.0 | units.Myr) * result.L_mech result.E_mech_last_feedback = result.E_mech result.previous_mass = result.mass # Store the mass of the star at the last moment of feedback return result
def __init__(self, original_particles, sink_radius=None, mass=None, position=None, velocity=None, angular_momentum=None, looping_over="sinks"): ParticlesOverlay.__init__(self, original_particles) self._private.looping_over=looping_over self.sink_radius = sink_radius or original_particles.radius if not hasattr(original_particles, "mass"): self.mass = mass or (([0.]*len(self)) | units.kg) if not hasattr(original_particles, "x"): self.position=position or (([[0.,0.,0.]]*len(self)) | units.m) if not hasattr(original_particles, "vx"): self.velocity=velocity or (([[0.,0.,0.]]*len(self)) | units.m/units.s) if not hasattr(original_particles, "lx"): self.angular_momentum=angular_momentum or (([[0.,0.,0.]]*len(self)) | units.g*units.m**2/units.s)
def test22(self): test_results_path = self.get_path_to_results() output_file = os.path.join(test_results_path, "test22"+self.store_version()+".hdf5") if os.path.exists(output_file): os.remove(output_file) stars = Particles(2) stars.x = 1.0 | units.km overlay = ParticlesOverlay(stars) overlay.y = 2.0 | units.km io.write_set_to_file(overlay, output_file, "hdf5", version = self.store_version()) loaded = io.read_set_from_file(output_file, "hdf5", close_file = True, version = self.store_version()) self.assertEquals(loaded[0].x, 1.0 | units.km) self.assertEquals(loaded[1].y, 2.0 | units.km)
def add_particles(self, sys): parts = ParticlesOverlay.add_particles(self, sys) if not hasattr(sys, "subsystem"): parts.subsystem = None return parts
def __init__(self, *args, **kwargs): ParticlesOverlay.__init__(self, *args, **kwargs)