Exemplo n.º 1
0
        def resolve_sinks(self):
            print "processing high dens particles...",
            highdens=self.gas_particles.select_array(lambda rho:rho>self.density_threshold,["rho"])
            print "N=", len(highdens)
            candidate_stars=highdens.copy()
            self.gas_particles.remove_particles(highdens)
            self.gas_particles.synchronize_to(self.code.gas_particles)

            print "new sinks..."
            if len(candidate_stars)>0: # had to make some changes to prevent double adding particles
                print "Adding stars, N=", len(candidate_stars)
                newstars_in_code = self.code.dm_particles.add_particles(candidate_stars)
                newstars = Particles()
                for nsi in newstars_in_code:
                    if nsi not in self.star_particles:
                        newstars.add_particle(nsi)
                    else:
                        print "this star should not exicst"
                newstars.name = "Star" 
                newstars.birth_age = self.code.model_time
                newstars.Lx = 0 | (units.g * units.m**2)/units.s
                newstars.Ly = 0 | (units.g * units.m**2)/units.s
                newstars.Lz = 0 | (units.g * units.m**2)/units.s
                        
                print "pre N=", len(self.star_particles), len(newstars), len(self.code.dm_particles)
                #self.star_particles.add_sinks(newstars)
                self.star_particles.add_particles(newstars)
                print "post N=", len(self.star_particles), len(newstars), len(self.code.dm_particles)
            else:
                print "N candidates:", len(candidate_stars)
Exemplo n.º 2
0
    def resolve_sinks(self):
        print("processing high dens particles...", end=' ')
        highdens = self.gas_particles.select_array(
            lambda rho: rho > self.density_threshold, ["rho"])
        print("N=", len(highdens))
        candidate_stars = highdens.copy()
        self.gas_particles.remove_particles(highdens)
        self.gas_particles.synchronize_to(self.code.gas_particles)

        print("new sinks...")
        if len(
                candidate_stars
        ) > 0:  # had to make some changes to prevent double adding particles
            print("Adding stars, N=", len(candidate_stars))
            newstars_in_code = self.code.dm_particles.add_particles(
                candidate_stars)
            newstars = Particles()
            for nsi in newstars_in_code:
                if nsi not in self.star_particles:
                    newstars.add_particle(nsi)
                else:
                    print("this star should not exicst")
            newstars.name = "Star"
            newstars.birth_age = self.code.model_time
            newstars.Lx = 0 | (units.g * units.m**2) / units.s
            newstars.Ly = 0 | (units.g * units.m**2) / units.s
            newstars.Lz = 0 | (units.g * units.m**2) / units.s

            print("pre N=", len(self.star_particles), len(newstars),
                  len(self.code.dm_particles))
            # self.star_particles.add_sinks(newstars)
            self.star_particles.add_particles(newstars)
            print("post N=", len(self.star_particles), len(newstars),
                  len(self.code.dm_particles))
        else:
            print("N candidates:", len(candidate_stars))