[Yt-svn] yt: Enabling particle IO with cylindrical/disk volumes.

hg at spacepope.org hg at spacepope.org
Fri Jun 11 16:33:34 PDT 2010


hg Repository: yt
details:   yt/rev/9c6b422253b0
changeset: 1775:9c6b422253b0
user:      Stephen Skory <stephenskory at yahoo.com>
date:
Fri Jun 11 16:33:10 2010 -0700
description:
Enabling particle IO with cylindrical/disk volumes.

diffstat:

 yt/lagos/BaseDataTypes.py  |    4 +-
 yt/lagos/HDF5LightReader.c |  194 ++++++++++++++++++++++++++++++++++++++++++++++++
 yt/lagos/ParticleIO.py     |   17 ++++
 3 files changed, 213 insertions(+), 2 deletions(-)

diffs (274 lines):

diff -r 140f3178c9cf -r 9c6b422253b0 yt/lagos/BaseDataTypes.py
--- a/yt/lagos/BaseDataTypes.py	Fri Jun 11 14:43:06 2010 -0600
+++ b/yt/lagos/BaseDataTypes.py	Fri Jun 11 16:33:10 2010 -0700
@@ -2022,8 +2022,8 @@
               + (grid['z'] - self.center[2])**2.0
                 )
             r = na.sqrt(d**2.0-h**2.0)
-            cm = ( (na.abs(h) < self._height)
-                 & (r < self._radius))
+            cm = ( (na.abs(h) <= self._height)
+                 & (r <= self._radius))
         return cm
 
     def volume(self, unit="unitary"):
diff -r 140f3178c9cf -r 9c6b422253b0 yt/lagos/HDF5LightReader.c
--- a/yt/lagos/HDF5LightReader.c	Fri Jun 11 14:43:06 2010 -0600
+++ b/yt/lagos/HDF5LightReader.c	Fri Jun 11 16:33:10 2010 -0700
@@ -80,9 +80,18 @@
     npy_float64 radius;
 } sphere_validation;
 
+typedef struct cylinder_validation_ {
+    /* These cannot contain any pointers */
+    npy_float64 center[3];
+    npy_float64 normal[3];
+    npy_float64 radius;
+    npy_float64 height;
+} cylinder_validation;
+
 /* Forward declarations */
 int setup_validator_region(particle_validation *data, PyObject *InputData);
 int setup_validator_sphere(particle_validation *data, PyObject *InputData);
+int setup_validator_cylinder(particle_validation *data, PyObject *InputData);
 int run_validators(particle_validation *pv, char *filename, 
                    int grid_id, const int read, const int packed,
                    int grid_index);
@@ -97,6 +106,10 @@
 int count_particles_sphere_DOUBLE(particle_validation *data);
 int count_particles_sphere_LONGDOUBLE(particle_validation *data);
 
+int count_particles_cylinder_FLOAT(particle_validation *data);
+int count_particles_cylinder_DOUBLE(particle_validation *data);
+int count_particles_cylinder_LONGDOUBLE(particle_validation *data);
+
 int get_my_desc_type(hid_t native_type_id){
 
    /*
@@ -820,6 +833,10 @@
             /* Sphere type */
             setup_validator_sphere(&pv, vargs);
             break;
+        case 2:
+            /* Cylinder type */
+            setup_validator_cylinder(&pv, vargs);
+            break;
         default:
             PyErr_Format(_hdf5ReadError,
                     "Unrecognized data source.\n");
@@ -995,6 +1012,40 @@
     return 1;
 }
 
+int setup_validator_cylinder(particle_validation *data, PyObject *InputData)
+{
+    int i;
+    /* These are borrowed references */
+    PyArrayObject *center = (PyArrayObject *) PyTuple_GetItem(InputData, 0);
+    PyArrayObject *normal = (PyArrayObject *) PyTuple_GetItem(InputData, 1);
+    PyObject *radius = (PyObject *) PyTuple_GetItem(InputData, 2);
+    PyObject *height = (PyObject *) PyTuple_GetItem(InputData, 3);
+
+    /* This will get freed in the finalization of particle validation */
+    cylinder_validation *cv = (cylinder_validation *)
+                malloc(sizeof(cylinder_validation));
+    data->validation_reqs = (void *) cv;
+
+    for (i = 0; i < 3; i++){
+        cv->center[i] = *(npy_float64*) PyArray_GETPTR1(center, i);
+    }
+
+    for (i = 0; i < 3; i++){
+        cv->normal[i] = *(npy_float64*) PyArray_GETPTR1(normal, i);
+    }
+
+    cv->radius = (npy_float64) PyFloat_AsDouble(radius);
+    cv->height = (npy_float64) PyFloat_AsDouble(height);
+
+    data->count_func = NULL;
+    data->count_func_float = count_particles_cylinder_FLOAT;
+    data->count_func_double = count_particles_cylinder_DOUBLE;
+    data->count_func_longdouble = count_particles_cylinder_LONGDOUBLE;
+
+    return 1;
+}
+
+
 int run_validators(particle_validation *pv, char *filename, 
                    int grid_id, const int read, const int packed,
                    int grid_index)
@@ -1563,6 +1614,149 @@
     return n;
 }
 
+int count_particles_cylinder_FLOAT(particle_validation *data)
+{
+    /* Our data comes packed in a struct, off which our pointers all hang */
+
+    /* First is our validation requirements, which are a set of three items: */
+
+    int ind, n=0;
+    cylinder_validation *vdata;
+
+    vdata = (cylinder_validation*) data->validation_reqs;
+    
+    float **particle_data = (float **) data->particle_position;
+
+    float *particle_position_x = particle_data[0];
+    float *particle_position_y = particle_data[1];
+    float *particle_position_z = particle_data[2];
+    float temph, tempd, d;
+    
+    d = -1. * (vdata->normal[0] * vdata->center[0] +
+               vdata->normal[1] * vdata->center[1] +
+               vdata->normal[2] * vdata->center[2]);
+
+    double pradius, ph, pd;
+
+      for (ind = 0; ind < data->particles_to_check; ind++) {
+        pradius = 0.0; ph = 0.0; pd = 0.0;
+        
+        temph = (particle_position_x[ind] * vdata->normal[0]); ph += temph;
+        temph = (particle_position_y[ind] * vdata->normal[1]); ph += temph;
+        temph = (particle_position_z[ind] * vdata->normal[2]); ph += temph;
+        ph += d;
+        
+        tempd = (particle_position_x[ind] - vdata->center[0]); pd += tempd*tempd;
+        tempd = (particle_position_y[ind] - vdata->center[1]); pd += tempd*tempd;
+        tempd = (particle_position_z[ind] - vdata->center[2]); pd += tempd*tempd;
+
+        pradius = pow(pd - ph*ph, 0.5);
+        if ((pradius <= vdata->radius) && (fabs(ph) <= vdata->height)) {
+          if(data->update_count == 1) data->total_valid_particles++;
+          data->mask[ind] = 1;
+          n++;
+        } else {
+          data->mask[ind] = 0;
+        }
+      }
+    return n;
+}
+
+int count_particles_cylinder_DOUBLE(particle_validation *data)
+{
+    /* Our data comes packed in a struct, off which our pointers all hang */
+
+    /* First is our validation requirements, which are a set of three items: */
+
+    int ind, n=0;
+    cylinder_validation *vdata;
+
+    vdata = (cylinder_validation*) data->validation_reqs;
+    
+    double **particle_data = (double **) data->particle_position;
+
+    double *particle_position_x = particle_data[0];
+    double *particle_position_y = particle_data[1];
+    double *particle_position_z = particle_data[2];
+    double temph, tempd, d;
+    
+    d = -1. * (vdata->normal[0] * vdata->center[0] +
+               vdata->normal[1] * vdata->center[1] +
+               vdata->normal[2] * vdata->center[2]);
+
+    double pradius, ph, pd;
+
+      for (ind = 0; ind < data->particles_to_check; ind++) {
+        pradius = 0.0; ph = 0.0; pd = 0.0;
+        
+        temph = (particle_position_x[ind] * vdata->normal[0]); ph += temph;
+        temph = (particle_position_y[ind] * vdata->normal[1]); ph += temph;
+        temph = (particle_position_z[ind] * vdata->normal[2]); ph += temph;
+        ph += d;
+        
+        tempd = (particle_position_x[ind] - vdata->center[0]); pd += tempd*tempd;
+        tempd = (particle_position_y[ind] - vdata->center[1]); pd += tempd*tempd;
+        tempd = (particle_position_z[ind] - vdata->center[2]); pd += tempd*tempd;
+
+        pradius = pow(pd - ph*ph, 0.5);
+        if ((pradius <= vdata->radius) && (fabs(ph) <= vdata->height)) {
+          if(data->update_count == 1) data->total_valid_particles++;
+          data->mask[ind] = 1;
+          n++;
+        } else {
+          data->mask[ind] = 0;
+        }
+    }
+    return n;
+}
+
+int count_particles_cylinder_LONGDOUBLE(particle_validation *data)
+{
+    /* Our data comes packed in a struct, off which our pointers all hang */
+
+    /* First is our validation requirements, which are a set of three items: */
+
+    int ind, n=0;
+    cylinder_validation *vdata;
+
+    vdata = (cylinder_validation*) data->validation_reqs;
+    
+    long double **particle_data = (long double **) data->particle_position;
+
+    long double *particle_position_x = particle_data[0];
+    long double *particle_position_y = particle_data[1];
+    long double *particle_position_z = particle_data[2];
+    long double temph, tempd, d;
+    
+    d = -1. * (vdata->normal[0] * vdata->center[0] +
+               vdata->normal[1] * vdata->center[1] +
+               vdata->normal[2] * vdata->center[2]);
+
+    long double pradius, ph, pd;
+
+      for (ind = 0; ind < data->particles_to_check; ind++) {
+        pradius = 0.0; ph = 0.0; pd = 0.0;
+        
+        temph = (particle_position_x[ind] * vdata->normal[0]); ph += temph;
+        temph = (particle_position_y[ind] * vdata->normal[1]); ph += temph;
+        temph = (particle_position_z[ind] * vdata->normal[2]); ph += temph;
+        ph += d;
+        
+        tempd = (particle_position_x[ind] - vdata->center[0]); pd += tempd*tempd;
+        tempd = (particle_position_y[ind] - vdata->center[1]); pd += tempd*tempd;
+        tempd = (particle_position_z[ind] - vdata->center[2]); pd += tempd*tempd;
+
+        pradius = pow(pd - ph*ph, 0.5);
+        if ((pradius <= vdata->radius) && (fabsl(ph) <= vdata->height)) {
+          if(data->update_count == 1) data->total_valid_particles++;
+          data->mask[ind] = 1;
+          n++;
+        } else {
+          data->mask[ind] = 0;
+        }
+      }
+    return n;
+}
 
 static PyMethodDef _hdf5LightReaderMethods[] = {
     {"ReadData", Py_ReadHDF5DataSet, METH_VARARGS},
diff -r 140f3178c9cf -r 9c6b422253b0 yt/lagos/ParticleIO.py
--- a/yt/lagos/ParticleIO.py	Fri Jun 11 14:43:06 2010 -0600
+++ b/yt/lagos/ParticleIO.py	Fri Jun 11 16:33:10 2010 -0700
@@ -128,3 +128,20 @@
 
     def _get_args(self):
         return (1, (na.array(self.center, dtype='float64'), self.radius))
+
+class ParticleIOHandlerDisk(ParticleIOHandlerImplemented):
+    _source_type = "disk"
+    
+    def __init__(self, pf, source):
+        self.center = source.center
+        self.normal = source._norm_vec
+        self.radius = source._radius
+        self.height = source._height
+        ParticleIOHandler.__init__(self, pf, source)
+    
+    def _get_args(self):
+        args = (na.array(self.center, dtype='float64'),
+                na.array(self.normal, dtype='float64'),
+                self.radius, self.height)
+        return (2, args)
+        
\ No newline at end of file



More information about the yt-svn mailing list