[yt-svn] commit/yt: xarthisius: Merged in ngoldbaum/yt (pull request #1335)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Dec 9 11:23:06 PST 2014


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/a43f02e6bea1/
Changeset:   a43f02e6bea1
Branch:      yt
User:        xarthisius
Date:        2014-12-09 19:22:53+00:00
Summary:     Merged in ngoldbaum/yt (pull request #1335)

Ramses unit conversions.
Affected #:  4 files

diff -r 4ce155015ea95a99e4c6d2c805b0db6536bdc6f3 -r a43f02e6bea17aa9d8758344689f7f7004b5bc4f yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -618,9 +618,11 @@
         import yt.units.dimensions as dimensions
         self.unit_registry.add("code_length", 1.0, dimensions.length)
         self.unit_registry.add("code_mass", 1.0, dimensions.mass)
+        self.unit_registry.add("code_density", 1.0, dimensions.density)
         self.unit_registry.add("code_time", 1.0, dimensions.time)
         self.unit_registry.add("code_magnetic", 1.0, dimensions.magnetic_field)
         self.unit_registry.add("code_temperature", 1.0, dimensions.temperature)
+        self.unit_registry.add("code_pressure", 1.0, dimensions.pressure)
         self.unit_registry.add("code_velocity", 1.0, dimensions.velocity)
         self.unit_registry.add("code_metallicity", 1.0,
                                dimensions.dimensionless)
@@ -676,9 +678,17 @@
         self.unit_registry.modify("code_length", self.length_unit)
         self.unit_registry.modify("code_mass", self.mass_unit)
         self.unit_registry.modify("code_time", self.time_unit)
-        vel_unit = getattr(self, "velocity_unit",
-                    self.length_unit / self.time_unit)
+        vel_unit = getattr(
+            self, "velocity_unit", self.length_unit / self.time_unit)
+        pressure_unit = getattr(
+            self, "pressure_unit",
+            self.mass_unit / (self.length_unit * self.time_unit)**2)
+        temperature_unit = getattr(self, "temperature_unit", 1.0)
+        density_unit = getattr(self, "density_unit", self.mass_unit / self.length_unit**3)
         self.unit_registry.modify("code_velocity", vel_unit)
+        self.unit_registry.modify("code_temperature", temperature_unit)
+        self.unit_registry.modify("code_pressure", pressure_unit)
+        self.unit_registry.modify("code_density", density_unit)
         # domain_width does not yet exist
         if (self.domain_left_edge is not None and
             self.domain_right_edge is not None):

diff -r 4ce155015ea95a99e4c6d2c805b0db6536bdc6f3 -r a43f02e6bea17aa9d8758344689f7f7004b5bc4f yt/frontends/ramses/data_structures.py
--- a/yt/frontends/ramses/data_structures.py
+++ b/yt/frontends/ramses/data_structures.py
@@ -33,8 +33,9 @@
     get_box_grids_level
 from yt.utilities.io_handler import \
     io_registry
+from yt.utilities.physical_constants import mp, kb
 from .fields import \
-    RAMSESFieldInfo
+    RAMSESFieldInfo, _X
 import yt.utilities.fortran_utils as fpu
 from yt.geometry.oct_container import \
     RAMSESOctreeContainer
@@ -489,19 +490,28 @@
         # Note that unit_l *already* converts to proper!
         # Also note that unit_l must be multiplied by the boxlen parameter to
         # ensure we are correctly set up for the current domain.
-        length_unit = self.parameters['unit_l'] * self.parameters['boxlen']
-        rho_u = self.parameters['unit_d']
-        # We're not multiplying by the boxlength here.
-        mass_unit = rho_u * self.parameters['unit_l']**3
+        length_unit = self.parameters['unit_l']
+        boxlen = self.parameters['boxlen']
+        density_unit = self.parameters['unit_d']
+        mass_unit = density_unit * (length_unit * boxlen)**3
         time_unit = self.parameters['unit_t']
-
         magnetic_unit = np.sqrt(4*np.pi * mass_unit /
                                 (time_unit**2 * length_unit))
+        pressure_unit = density_unit * (length_unit / time_unit)**2
+        # TODO:
+        # Generalize the temperature field to account for ionization
+        # For now assume an atomic ideal gas with cosmic abundances (x_H = 0.76)
+        mean_molecular_weight_factor = _X**-1
+
+        self.density_unit = self.quan(density_unit, 'g/cm**3')
         self.magnetic_unit = self.quan(magnetic_unit, "gauss")
-        self.length_unit = self.quan(length_unit, "cm")
+        self.length_unit = self.quan(length_unit * boxlen, "cm")
         self.mass_unit = self.quan(mass_unit, "g")
         self.time_unit = self.quan(time_unit, "s")
-        self.velocity_unit = self.length_unit / self.time_unit
+        self.velocity_unit = self.quan(length_unit, 'cm') / self.time_unit
+        self.temperature_unit = (self.velocity_unit**2 * mp *
+                                 mean_molecular_weight_factor / kb)
+        self.pressure_unit = self.quan(pressure_unit, 'dyne/cm**2')
 
     def _parse_parameter_file(self):
         # hardcoded for now
@@ -546,15 +556,21 @@
         self.domain_dimensions = np.ones(3, dtype='int32') * \
                         2**(self.min_level+1)
         self.domain_right_edge = np.ones(3, dtype='float64')
-        # This is likely not true, but I am not sure how to otherwise
-        # distinguish them.
-        mylog.warning("RAMSES frontend assumes all simulations are cosmological!")
-        self.cosmological_simulation = 1
+        # This is likely not true, but it's not clear how to determine the boundary conditions
         self.periodicity = (True, True, True)
-        self.current_redshift = (1.0 / rheader["aexp"]) - 1.0
-        self.omega_lambda = rheader["omega_l"]
-        self.omega_matter = rheader["omega_m"]
-        self.hubble_constant = rheader["H0"] / 100.0 # This is H100
+        # These conditions seem to always be true for non-cosmological datasets
+        if rheader["time"] > 0 and rheader["H0"] == 1 and rheader["aexp"] == 1:
+            self.cosmological_simulation = 0
+            self.current_redshift = 0
+            self.hubble_constant = 0
+            self.omega_matter = 0
+            self.omega_lambda = 0
+        else:
+            self.cosmological_simulation = 1
+            self.current_redshift = (1.0 / rheader["aexp"]) - 1.0
+            self.omega_lambda = rheader["omega_l"]
+            self.omega_matter = rheader["omega_m"]
+            self.hubble_constant = rheader["H0"] / 100.0 # This is H100
         self.max_level = rheader['levelmax'] - self.min_level - 1
         f.close()
 

diff -r 4ce155015ea95a99e4c6d2c805b0db6536bdc6f3 -r a43f02e6bea17aa9d8758344689f7f7004b5bc4f yt/frontends/ramses/fields.py
--- a/yt/frontends/ramses/fields.py
+++ b/yt/frontends/ramses/fields.py
@@ -32,8 +32,9 @@
 
 b_units = "code_magnetic"
 ra_units = "code_length / code_time**2"
-rho_units = "code_mass / code_length**3"
-vel_units = "code_length / code_time"
+rho_units = "code_density"
+vel_units = "code_velocity"
+pressure_units = "code_pressure"
 
 known_species_masses = dict(
   (sp, mh * v) for sp, v in [
@@ -70,7 +71,7 @@
         ("x-velocity", (vel_units, ["velocity_x"], None)),
         ("y-velocity", (vel_units, ["velocity_y"], None)),
         ("z-velocity", (vel_units, ["velocity_z"], None)),
-        ("Pressure", ("code_mass / (code_length * code_time**2)", ["pressure"], None)),
+        ("Pressure", (pressure_units, ["pressure"], None)),
         ("Metallicity", ("", ["metallicity"], None)),
     )
     known_particle_fields = (

diff -r 4ce155015ea95a99e4c6d2c805b0db6536bdc6f3 -r a43f02e6bea17aa9d8758344689f7f7004b5bc4f yt/units/dimensions.py
--- a/yt/units/dimensions.py
+++ b/yt/units/dimensions.py
@@ -42,6 +42,7 @@
 volume   = area * length
 momentum = mass * velocity
 force    = mass * acceleration
+pressure = force / area
 energy   = force * length
 power    = energy / time
 flux     = power / area

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list