1. Sam Skillman
  2. yt-refactor

Commits

Britton Smith  committed 9279642 Merge

Merged.

  • Participants
  • Parent commits d0bcb60, c4cc476
  • Branches yt

Comments (0)

Files changed (2)

File yt/data_objects/derived_quantities.py

View file
     bv_x,bv_y,bv_z = data.quantities["BulkVelocity"]()
     # One-cell objects are NOT BOUND.
     if data["CellMass"].size == 1: return [0.0]
-    """
-    Changing data["CellMass"] to mass_to_use
-    Add the mass contribution of particles if include_particles = True
-    """
+
+    kinetic = 0.5 * (data["CellMass"] * 
+                     ((data["x-velocity"] - bv_x)**2 + 
+                      (data["y-velocity"] - bv_y)**2 +
+                      (data["z-velocity"] - bv_z)**2)).sum()
+
     if (include_particles):
 	mass_to_use = data["TotalMass"]
+        kinetic += 0.5 * (data["Dark_Matter_Mass"] *
+                          ((data["cic_particle_velocity_x"] - bv_x)**2 +
+                           (data["cic_particle_velocity_y"] - bv_y)**2 +
+                           (data["cic_particle_velocity_z"] - bv_z)**2)).sum()
     else:
 	mass_to_use = data["CellMass"]
-    kinetic = 0.5 * (mass_to_use * (
-                       (data["x-velocity"] - bv_x)**2
-                     + (data["y-velocity"] - bv_y)**2
-                     + (data["z-velocity"] - bv_z)**2 )).sum()
     # Add thermal energy to kinetic energy
     if (include_thermal_energy):
         thermal = (data["ThermalEnergy"] * mass_to_use).sum()

File yt/frontends/enzo/fields.py

View file
           display_name = "Dark\ Matter\ Density",
           not_in_all = True)
 
+def _Dark_Matter_Mass(field, data):
+    return data['Dark_Matter_Density'] * data["CellVolume"]
+add_field("Dark_Matter_Mass", function=_Dark_Matter_Mass,
+          validators=ValidateDataField("Dark_Matter_Density"),
+          display_name="Dark\ Matter\ Mass", units=r"\rm{g}")
+add_field("Dark_Matter_MassMsun", function=_Dark_Matter_Mass,
+          convert_function=_convertCellMassMsun,
+          validators=ValidateDataField("Dark_Matter_Density"),
+          display_name="Dark\ Matter\ Mass", units=r"M_{\odot}")
+
 KnownEnzoFields["Temperature"]._units = r"\rm{K}"
 KnownEnzoFields["Temperature"].units = r"K"
 KnownEnzoFields["Dust_Temperature"]._units = r"\rm{K}"
 add_field("dm_density", function=_dmpdensity,
           validators=[ValidateSpatial(0)], convert_function=_convertDensity)
 
+def _cic_particle_field(field, data):
+    """
+    Create a grid field for particle quantities weighted by particle mass, 
+    using cloud-in-cell deposit.
+    """
+    particle_field = field.name[4:]
+    top = na.zeros(data.ActiveDimensions, dtype='float32')
+    if data.NumberOfParticles == 0: return top
+    particle_field_data = data[particle_field] * data['particle_mass']
+    amr_utils.CICDeposit_3(data["particle_position_x"].astype(na.float64),
+                           data["particle_position_y"].astype(na.float64),
+                           data["particle_position_z"].astype(na.float64),
+                           particle_field_data.astype(na.float32),
+                           na.int64(data.NumberOfParticles),
+                           top, na.array(data.LeftEdge).astype(na.float64),
+                           na.array(data.ActiveDimensions).astype(na.int32), 
+                           na.float64(data['dx']))
+    del particle_field_data
+
+    bottom = na.zeros(data.ActiveDimensions, dtype='float32')
+    amr_utils.CICDeposit_3(data["particle_position_x"].astype(na.float64),
+                           data["particle_position_y"].astype(na.float64),
+                           data["particle_position_z"].astype(na.float64),
+                           data["particle_mass"].astype(na.float32),
+                           na.int64(data.NumberOfParticles),
+                           bottom, na.array(data.LeftEdge).astype(na.float64),
+                           na.array(data.ActiveDimensions).astype(na.int32), 
+                           na.float64(data['dx']))
+    top[bottom == 0] = 0.0
+    bnz = bottom.nonzero()
+    top[bnz] /= bottom[bnz]
+    return top
+
+add_field('cic_particle_velocity_x', function=_cic_particle_field,
+          take_log=False, validators=[ValidateSpatial(0)])
+add_field('cic_particle_velocity_y', function=_cic_particle_field,
+          take_log=False, validators=[ValidateSpatial(0)])
+add_field('cic_particle_velocity_z', function=_cic_particle_field,
+          take_log=False, validators=[ValidateSpatial(0)])
+
 def _star_field(field, data):
     """
     Create a grid field for star quantities, weighted by star mass.