Commits

Matthew Turk  committed 273edb8

Unifying code_units and chemistry_data wrapper classes, adding a bit of the
freefall translation.

  • Participants
  • Parent commits bf7d82d

Comments (0)

Files changed (3)

File src/python/examples/freefall.py

+# This is a translation of freefall.C from the clib distribution
+
+from pygrackle.grackle_wrapper import *
+
+my_chemistry = chemistry_data()
+my_chemistry.use_chemistry = 1
+my_chemistry.primordial_chemistry = 2
+#my_chemistry.metal_cooling = 1
+#my_chemistry.cloudy_table_file = "solar_2008_3D_metals.h5";
+
+my_chemistry.comoving_coordinates = 0
+my_chemistry.density_units = 1.67e-24
+my_chemistry.length_units = 1.0
+my_chemistry.time_units = 1.0e12
+my_chemistry.a_units = 1.0
+
+energy_units = (my_chemistry.length_units / my_chemistry.time_units)**2.0
+
+gravitational_constant = (4.0 * 3.1415926 * 6.6726e-8 * 
+  my_chemistry.density_units * my_chemistry.time_units**2)
+
+a_value = 1.0/(1.0+10.0)
+
+my_chemistry.initialize(a_value)

File src/python/pygrackle/grackle_defs.pxd

         # Most of the rest are not user-settable
 
 cdef extern from "code_units.h":
-    ctypedef struct code_units:
+    ctypedef struct c_code_units "code_units":
       gr_int comoving_coordinates
       gr_float density_units
       gr_float length_units
     c_chemistry_data set_default_chemistry_parameters()
 
     gr_int initialize_chemistry_data(c_chemistry_data &my_chemistry,
-                                  code_units &my_units, gr_float a_value)
+                                  c_code_units &my_units, gr_float a_value)
 
     gr_int solve_chemistry(
                 c_chemistry_data &my_chemistry,
-                code_units &my_units,
+                c_code_units &my_units,
                 gr_float a_value,
                 gr_float dt_value,
                 gr_int grid_rank,
 
     gr_int calculate_cooling_time(
                 c_chemistry_data &my_chemistry,
-                code_units &my_units,
+                c_code_units &my_units,
                 gr_float a_value,
                 gr_float dt_value,
                 gr_int grid_rank,
 
     gr_int calculate_gamma(
                 c_chemistry_data &my_chemistry,
-                code_units &my_units,
+                c_code_units &my_units,
                 gr_int grid_rank,
                 gr_int *grid_dimension,
                 gr_float *density,
 
     gr_int calculate_pressure(
                 c_chemistry_data &my_chemistry,
-                code_units &my_units,
+                c_code_units &my_units,
                 gr_int grid_rank,
                 gr_int *grid_dimension,
                 gr_float *density,
 
     gr_int calculate_temperature(
                 c_chemistry_data &my_chemistry,
-                code_units &my_units,
+                c_code_units &my_units,
                 gr_int grid_rank,
                 gr_int *grid_dimension,
                 gr_float *density,

File src/python/pygrackle/grackle_wrapper.pyx

 
 cdef class chemistry_data:
     cdef c_chemistry_data data
+    cdef c_code_units units
+
     def __cinit__(self):
         self.data = set_default_chemistry_parameters()
 
+    def initialize(self, a_value):
+        initialize_chemistry_data(self.data, self.units, a_value)
+
     property Gamma:
         def __get__(self):
             return self.data.Gamma
             return self.data.cloudy_table_file
         def __set__(self, val):
             raise NotImplementedError
+
+    property comoving_coordinates:
+        def __get__(self):
+            return self.units.comoving_coordinates
+        def __set__(self, val):
+            self.units.comoving_coordinates = val
+
+    property density_units:
+        def __get__(self):
+            return self.units.density_units
+        def __set__(self, val):
+            self.units.density_units = val
+
+    property length_units:
+        def __get__(self):
+            return self.units.length_units
+        def __set__(self, val):
+            self.units.length_units = val
+
+    property time_units:
+        def __get__(self):
+            return self.units.time_units
+        def __set__(self, val):
+            self.units.time_units = val
+
+    property a_units:
+        def __get__(self):
+            return self.units.a_units
+        def __set__(self, val):
+            self.units.a_units = val