Changeset 1645

Show
Ignore:
Timestamp:
02/25/10 15:03:17 (5 months ago)
Author:
sskory
Message:

Modified the halo RMS velocity to weight particles by mass.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/yt/lagos/HaloFinding.py

    r1641 r1645  
    125125    def rms_velocity(self): 
    126126        """ 
    127         Returns the RMS velocity for the halo particles in code units. 
     127        Returns the mass-weighted RMS velocity for the halo 
     128        particles in code units. 
    128129        """ 
    129130        bv = self.bulk_velocity() 
    130         vx = self["particle_velocity_x"] - bv[0] 
    131         vy = self["particle_velocity_y"] - bv[1] 
    132         vz = self["particle_velocity_z"] - bv[2] 
    133         s = vx**2 + vy**2 + vz**2 
     131        pm = self["ParticleMassMsun"] 
     132        sm = pm.sum() 
     133        vx = (self["particle_velocity_x"] - bv[0]) * pm/sm 
     134        vy = (self["particle_velocity_y"] - bv[1]) * pm/sm 
     135        vz = (self["particle_velocity_z"] - bv[2]) * pm/sm 
     136        s = vx**2. + vy**2. + vz**2. 
    134137        ms = na.mean(s) 
    135         return na.sqrt(ms) 
     138        return na.sqrt(ms) * pm.size 
    136139 
    137140    def maximum_radius(self, center_of_mass=True): 
     
    385388            return self.rms_vel 
    386389        bv = self.bulk_velocity() 
     390        pm = self["ParticleMassMsun"] 
     391        sm = pm.sum() 
    387392        if self.indices is not None: 
    388             vx = self["particle_velocity_x"] - bv[0] 
    389             vy = self["particle_velocity_y"] - bv[1] 
    390             vz = self["particle_velocity_z"] - bv[2] 
     393            vx = (self["particle_velocity_x"] - bv[0]) * pm/sm 
     394            vy = (self["particle_velocity_y"] - bv[1]) * pm/sm 
     395            vz = (self["particle_velocity_z"] - bv[2]) * pm/sm 
    391396            s = vx**2 + vy**2 + vz**2 
    392397            s = na.sum(s) 
     
    397402        global_ss = self._mpi_allsum(ss) 
    398403        ms = global_ss[0] / global_ss[1] 
    399         return na.sqrt(ms) 
     404        return na.sqrt(ms) * global_ss[1] 
    400405 
    401406    def maximum_radius(self, center_of_mass=True): 
     
    915920            for i, u in enumerate(uniq_subchain): 
    916921                self.bulk_vel[u] = na.sum(vel[marks[i]:marks[i+1]], axis=0) 
    917             del vel, ms, subchain, sort_subchain 
     922            del vel, subchain, sort_subchain 
    918923            del diff_subchain 
    919924        # Bring it together, and divide by the previously computed total mass 
     
    929934        if calc: 
    930935            vel = na.empty((calc, 3), dtype='float64') 
    931             vel[:,0] = xv[select] 
    932             vel[:,1] = yv[select] 
    933             vel[:,2] = zv[select] 
     936            vel[:,0] = xv[select] * ms 
     937            vel[:,1] = yv[select] * ms 
     938            vel[:,2] = zv[select] * ms 
    934939            vel = vel[sort] 
    935             vel = vel**2 # Squared 
    936940            for i, u in enumerate(uniq_subchain): 
    937                 # This finds the Mean 
    938                 rms_vel_temp[u][0] = na.sum(vel[marks[i]:marks[i+1]] - self.bulk_vel[u]) 
     941                # This finds the sum locally. 
     942                rms_vel_temp[u][0] = na.sum(((vel[marks[i]:marks[i+1]] - \ 
     943                    self.bulk_vel[u]) / self.Tot_M[u])**2.) 
     944                # I could use self.group_sizes... 
    939945                rms_vel_temp[u][1] = marks[i+1] - marks[i] 
    940946            del vel, marks, uniq_subchain 
     
    943949        self.rms_vel = na.empty(self.group_count, dtype='float64') 
    944950        for groupID in xrange(self.group_count): 
    945             # Here we do the Root. 
     951            # Here we do the Mean and the Root. 
    946952            self.rms_vel[groupID] = \ 
    947                 na.sqrt(rms_vel_temp[groupID][0] / rms_vel_temp[groupID][1]) 
    948         del rms_vel_temp 
     953                na.sqrt(rms_vel_temp[groupID][0] / rms_vel_temp[groupID][1]) * \ 
     954                self.group_sizes[groupID] 
     955        del rms_vel_temp, ms 
    949956        yt_counters("rms vel computing") 
    950957        self.taskID = obj.mine