Index: sansmodels/src/sans/models/c_models/CFlexibleCylinderModel.cpp
===================================================================
--- sansmodels/src/sans/models/c_models/CFlexibleCylinderModel.cpp	(revision 50686972861f70ebff2c64a50118cfb6b905253a)
+++ sansmodels/src/sans/models/c_models/CFlexibleCylinderModel.cpp	(revision 50686972861f70ebff2c64a50118cfb6b905253a)
@@ -0,0 +1,402 @@
+/**
+	This software was developed by the University of Tennessee as part of the
+	Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
+	project funded by the US National Science Foundation.
+
+	If you use DANSE applications to do scientific research that leads to
+	publication, we ask that you acknowledge the use of the software with the
+	following sentence:
+
+	"This work benefited from DANSE software developed under NSF award DMR-0520547."
+
+	copyright 2008, University of Tennessee
+ */
+
+/** CFlexibleCylinderModel
+ *
+ * C extension 
+ *
+ * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY
+ *          DO NOT MODIFY THIS FILE, MODIFY flexible_cylinder.h
+ *          AND RE-RUN THE GENERATOR SCRIPT
+ *
+ */
+ 
+extern "C" {
+#include <Python.h>
+#include "structmember.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <time.h>
+#include "flexible_cylinder.h"
+}
+
+#include "models.hh"
+#include "dispersion_visitor.hh"
+
+/// Error object for raised exceptions
+static PyObject * CFlexibleCylinderModelError = NULL;
+
+
+// Class definition
+typedef struct {
+    PyObject_HEAD
+    /// Parameters
+    PyObject * params;
+    /// Dispersion parameters
+    PyObject * dispersion;
+    /// Underlying model object
+    FlexibleCylinderModel * model;
+    /// Log for unit testing
+    PyObject * log;
+} CFlexibleCylinderModel;
+
+
+static void
+CFlexibleCylinderModel_dealloc(CFlexibleCylinderModel* self)
+{
+    self->ob_type->tp_free((PyObject*)self);
+    
+
+}
+
+static PyObject *
+CFlexibleCylinderModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+    CFlexibleCylinderModel *self;
+    
+    self = (CFlexibleCylinderModel *)type->tp_alloc(type, 0);
+   
+    return (PyObject *)self;
+}
+
+static int
+CFlexibleCylinderModel_init(CFlexibleCylinderModel *self, PyObject *args, PyObject *kwds)
+{
+    if (self != NULL) {
+    	
+    	// Create parameters
+        self->params = PyDict_New();
+        self->dispersion = PyDict_New();
+        self->model = new FlexibleCylinderModel();
+        
+        // Initialize parameter dictionary
+        PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",1.000000));
+        PyDict_SetItemString(self->params,"axis_theta",Py_BuildValue("d",1.000000));
+        PyDict_SetItemString(self->params,"length",Py_BuildValue("d",1000.000000));
+        PyDict_SetItemString(self->params,"axis_phi",Py_BuildValue("d",1.000000));
+        PyDict_SetItemString(self->params,"radius",Py_BuildValue("d",20.000000));
+        PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.000100));
+        PyDict_SetItemString(self->params,"kuhn_length",Py_BuildValue("d",100.000000));
+        PyDict_SetItemString(self->params,"contrast",Py_BuildValue("d",0.000005));
+        // Initialize dispersion / averaging parameter dict
+        DispersionVisitor* visitor = new DispersionVisitor();
+        PyObject * disp_dict;
+        disp_dict = PyDict_New();
+        self->model->length.dispersion->accept_as_source(visitor, self->model->length.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "length", disp_dict);
+        disp_dict = PyDict_New();
+        self->model->radius.dispersion->accept_as_source(visitor, self->model->radius.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "radius", disp_dict);
+        disp_dict = PyDict_New();
+        self->model->axis_theta.dispersion->accept_as_source(visitor, self->model->axis_theta.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "axis_theta", disp_dict);
+        disp_dict = PyDict_New();
+        self->model->axis_phi.dispersion->accept_as_source(visitor, self->model->axis_phi.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "axis_phi", disp_dict);
+
+
+         
+        // Create empty log
+        self->log = PyDict_New();
+        
+        
+
+    }
+    return 0;
+}
+
+static PyMemberDef CFlexibleCylinderModel_members[] = {
+    {"params", T_OBJECT, offsetof(CFlexibleCylinderModel, params), 0,
+     "Parameters"},
+	{"dispersion", T_OBJECT, offsetof(CFlexibleCylinderModel, dispersion), 0,
+	  "Dispersion parameters"},     
+    {"log", T_OBJECT, offsetof(CFlexibleCylinderModel, log), 0,
+     "Log"},
+    {NULL}  /* Sentinel */
+};
+
+/** Read double from PyObject
+    @param p PyObject
+    @return double
+*/
+double CFlexibleCylinderModel_readDouble(PyObject *p) {
+    if (PyFloat_Check(p)==1) {
+        return (double)(((PyFloatObject *)(p))->ob_fval);
+    } else if (PyInt_Check(p)==1) {
+        return (double)(((PyIntObject *)(p))->ob_ival);
+    } else if (PyLong_Check(p)==1) {
+        return (double)PyLong_AsLong(p);
+    } else {
+        return 0.0;
+    }
+}
+
+
+/**
+ * Function to call to evaluate model
+ * @param args: input q or [q,phi]
+ * @return: function value
+ */
+static PyObject * run(CFlexibleCylinderModel *self, PyObject *args) {
+	double q_value, phi_value;
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->axis_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_theta") );
+    self->model->length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "length") );
+    self->model->axis_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_phi") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->kuhn_length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "kuhn_length") );
+    self->model->contrast = PyFloat_AsDouble( PyDict_GetItemString(self->params, "contrast") );
+    // Read in dispersion parameters
+    PyObject* disp_dict;
+    DispersionVisitor* visitor = new DispersionVisitor();
+    disp_dict = PyDict_GetItemString(self->dispersion, "length");
+    self->model->length.dispersion->accept_as_destination(visitor, self->model->length.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
+    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "axis_theta");
+    self->model->axis_theta.dispersion->accept_as_destination(visitor, self->model->axis_theta.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "axis_phi");
+    self->model->axis_phi.dispersion->accept_as_destination(visitor, self->model->axis_phi.dispersion, disp_dict);
+
+	
+	// Get input and determine whether we have to supply a 1D or 2D return value.
+	if ( !PyArg_ParseTuple(args,"O",&pars) ) {
+	    PyErr_SetString(CFlexibleCylinderModelError, 
+	    	"CFlexibleCylinderModel.run expects a q value.");
+		return NULL;
+	}
+	  
+	// Check params
+	if( PyList_Check(pars)==1) {
+		
+		// Length of list should be 2 for I(q,phi)
+	    npars = PyList_GET_SIZE(pars); 
+	    if(npars!=2) {
+	    	PyErr_SetString(CFlexibleCylinderModelError, 
+	    		"CFlexibleCylinderModel.run expects a double or a list of dimension 2.");
+	    	return NULL;
+	    }
+	    // We have a vector q, get the q and phi values at which
+	    // to evaluate I(q,phi)
+	    q_value = CFlexibleCylinderModel_readDouble(PyList_GET_ITEM(pars,0));
+	    phi_value = CFlexibleCylinderModel_readDouble(PyList_GET_ITEM(pars,1));
+	    // Skip zero
+	    if (q_value==0) {
+	    	return Py_BuildValue("d",0.0);
+	    }
+		return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value));
+
+	} else {
+
+		// We have a scalar q, we will evaluate I(q)
+		q_value = CFlexibleCylinderModel_readDouble(pars);		
+		
+		return Py_BuildValue("d",(*(self->model))(q_value));
+	}	
+}
+
+/**
+ * Function to call to evaluate model in cartesian coordinates
+ * @param args: input q or [qx, qy]]
+ * @return: function value
+ */
+static PyObject * runXY(CFlexibleCylinderModel *self, PyObject *args) {
+	double qx_value, qy_value;
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->axis_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_theta") );
+    self->model->length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "length") );
+    self->model->axis_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_phi") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->kuhn_length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "kuhn_length") );
+    self->model->contrast = PyFloat_AsDouble( PyDict_GetItemString(self->params, "contrast") );
+    // Read in dispersion parameters
+    PyObject* disp_dict;
+    DispersionVisitor* visitor = new DispersionVisitor();
+    disp_dict = PyDict_GetItemString(self->dispersion, "length");
+    self->model->length.dispersion->accept_as_destination(visitor, self->model->length.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
+    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "axis_theta");
+    self->model->axis_theta.dispersion->accept_as_destination(visitor, self->model->axis_theta.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "axis_phi");
+    self->model->axis_phi.dispersion->accept_as_destination(visitor, self->model->axis_phi.dispersion, disp_dict);
+
+	
+	// Get input and determine whether we have to supply a 1D or 2D return value.
+	if ( !PyArg_ParseTuple(args,"O",&pars) ) {
+	    PyErr_SetString(CFlexibleCylinderModelError, 
+	    	"CFlexibleCylinderModel.run expects a q value.");
+		return NULL;
+	}
+	  
+	// Check params
+	if( PyList_Check(pars)==1) {
+		
+		// Length of list should be 2 for I(qx, qy))
+	    npars = PyList_GET_SIZE(pars); 
+	    if(npars!=2) {
+	    	PyErr_SetString(CFlexibleCylinderModelError, 
+	    		"CFlexibleCylinderModel.run expects a double or a list of dimension 2.");
+	    	return NULL;
+	    }
+	    // We have a vector q, get the qx and qy values at which
+	    // to evaluate I(qx,qy)
+	    qx_value = CFlexibleCylinderModel_readDouble(PyList_GET_ITEM(pars,0));
+	    qy_value = CFlexibleCylinderModel_readDouble(PyList_GET_ITEM(pars,1));
+	    return Py_BuildValue("d",(*(self->model))(qx_value,qy_value));
+
+	} else {
+
+		// We have a scalar q, we will evaluate I(q)
+		qx_value = CFlexibleCylinderModel_readDouble(pars);		
+		
+		return Py_BuildValue("d",(*(self->model))(qx_value));
+	}	
+}
+
+static PyObject * reset(CFlexibleCylinderModel *self, PyObject *args) {
+    
+
+    return Py_BuildValue("d",0.0);
+}
+
+static PyObject * set_dispersion(CFlexibleCylinderModel *self, PyObject *args) {
+	PyObject * disp;
+	const char * par_name;
+
+	if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
+	    PyErr_SetString(CFlexibleCylinderModelError,
+	    	"CFlexibleCylinderModel.set_dispersion expects a DispersionModel object.");
+		return NULL;
+	}
+	void *temp = PyCObject_AsVoidPtr(disp);
+	DispersionModel * dispersion = static_cast<DispersionModel *>(temp);
+
+
+	// Ugliness necessary to go from python to C
+	    // TODO: refactor this
+    if (!strcmp(par_name, "length")) {
+        self->model->length.dispersion = dispersion;
+    } else    if (!strcmp(par_name, "radius")) {
+        self->model->radius.dispersion = dispersion;
+    } else    if (!strcmp(par_name, "axis_theta")) {
+        self->model->axis_theta.dispersion = dispersion;
+    } else    if (!strcmp(par_name, "axis_phi")) {
+        self->model->axis_phi.dispersion = dispersion;
+    } else {
+	    PyErr_SetString(CFlexibleCylinderModelError,
+	    	"CFlexibleCylinderModel.set_dispersion expects a valid parameter name.");
+		return NULL;
+	}
+
+	DispersionVisitor* visitor = new DispersionVisitor();
+	PyObject * disp_dict = PyDict_New();
+	dispersion->accept_as_source(visitor, dispersion, disp_dict);
+	PyDict_SetItemString(self->dispersion, par_name, disp_dict);
+    return Py_BuildValue("i",1);
+}
+
+
+static PyMethodDef CFlexibleCylinderModel_methods[] = {
+    {"run",      (PyCFunction)run     , METH_VARARGS,
+      "Evaluate the model at a given Q or Q, phi"},
+    {"runXY",      (PyCFunction)runXY     , METH_VARARGS,
+      "Evaluate the model at a given Q or Qx, Qy"},
+    {"reset",    (PyCFunction)reset   , METH_VARARGS,
+      "Reset pair correlation"},
+    {"set_dispersion",      (PyCFunction)set_dispersion     , METH_VARARGS,
+      "Set the dispersion model for a given parameter"},
+   {NULL}
+};
+
+static PyTypeObject CFlexibleCylinderModelType = {
+    PyObject_HEAD_INIT(NULL)
+    0,                         /*ob_size*/
+    "CFlexibleCylinderModel",             /*tp_name*/
+    sizeof(CFlexibleCylinderModel),             /*tp_basicsize*/
+    0,                         /*tp_itemsize*/
+    (destructor)CFlexibleCylinderModel_dealloc, /*tp_dealloc*/
+    0,                         /*tp_print*/
+    0,                         /*tp_getattr*/
+    0,                         /*tp_setattr*/
+    0,                         /*tp_compare*/
+    0,                         /*tp_repr*/
+    0,                         /*tp_as_number*/
+    0,                         /*tp_as_sequence*/
+    0,                         /*tp_as_mapping*/
+    0,                         /*tp_hash */
+    0,                         /*tp_call*/
+    0,                         /*tp_str*/
+    0,                         /*tp_getattro*/
+    0,                         /*tp_setattro*/
+    0,                         /*tp_as_buffer*/
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+    "CFlexibleCylinderModel objects",           /* tp_doc */
+    0,		               /* tp_traverse */
+    0,		               /* tp_clear */
+    0,		               /* tp_richcompare */
+    0,		               /* tp_weaklistoffset */
+    0,		               /* tp_iter */
+    0,		               /* tp_iternext */
+    CFlexibleCylinderModel_methods,             /* tp_methods */
+    CFlexibleCylinderModel_members,             /* tp_members */
+    0,                         /* tp_getset */
+    0,                         /* tp_base */
+    0,                         /* tp_dict */
+    0,                         /* tp_descr_get */
+    0,                         /* tp_descr_set */
+    0,                         /* tp_dictoffset */
+    (initproc)CFlexibleCylinderModel_init,      /* tp_init */
+    0,                         /* tp_alloc */
+    CFlexibleCylinderModel_new,                 /* tp_new */
+};
+
+
+static PyMethodDef module_methods[] = {
+    {NULL} 
+};
+
+/**
+ * Function used to add the model class to a module
+ * @param module: module to add the class to
+ */ 
+void addCFlexibleCylinderModel(PyObject *module) {
+	PyObject *d;
+	
+    if (PyType_Ready(&CFlexibleCylinderModelType) < 0)
+        return;
+
+    Py_INCREF(&CFlexibleCylinderModelType);
+    PyModule_AddObject(module, "CFlexibleCylinderModel", (PyObject *)&CFlexibleCylinderModelType);
+    
+    d = PyModule_GetDict(module);
+    CFlexibleCylinderModelError = PyErr_NewException("CFlexibleCylinderModel.error", NULL, NULL);
+    PyDict_SetItemString(d, "CFlexibleCylinderModelError", CFlexibleCylinderModelError);
+}
+
Index: sansmodels/src/sans/models/c_models/CStackedDisksModel.cpp
===================================================================
--- sansmodels/src/sans/models/c_models/CStackedDisksModel.cpp	(revision 50686972861f70ebff2c64a50118cfb6b905253a)
+++ sansmodels/src/sans/models/c_models/CStackedDisksModel.cpp	(revision 50686972861f70ebff2c64a50118cfb6b905253a)
@@ -0,0 +1,414 @@
+/**
+	This software was developed by the University of Tennessee as part of the
+	Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
+	project funded by the US National Science Foundation.
+
+	If you use DANSE applications to do scientific research that leads to
+	publication, we ask that you acknowledge the use of the software with the
+	following sentence:
+
+	"This work benefited from DANSE software developed under NSF award DMR-0520547."
+
+	copyright 2008, University of Tennessee
+ */
+
+/** CStackedDisksModel
+ *
+ * C extension 
+ *
+ * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY
+ *          DO NOT MODIFY THIS FILE, MODIFY stacked_disks.h
+ *          AND RE-RUN THE GENERATOR SCRIPT
+ *
+ */
+ 
+extern "C" {
+#include <Python.h>
+#include "structmember.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <time.h>
+#include "stacked_disks.h"
+}
+
+#include "models.hh"
+#include "dispersion_visitor.hh"
+
+/// Error object for raised exceptions
+static PyObject * CStackedDisksModelError = NULL;
+
+
+// Class definition
+typedef struct {
+    PyObject_HEAD
+    /// Parameters
+    PyObject * params;
+    /// Dispersion parameters
+    PyObject * dispersion;
+    /// Underlying model object
+    StackedDisksModel * model;
+    /// Log for unit testing
+    PyObject * log;
+} CStackedDisksModel;
+
+
+static void
+CStackedDisksModel_dealloc(CStackedDisksModel* self)
+{
+    self->ob_type->tp_free((PyObject*)self);
+    
+
+}
+
+static PyObject *
+CStackedDisksModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+    CStackedDisksModel *self;
+    
+    self = (CStackedDisksModel *)type->tp_alloc(type, 0);
+   
+    return (PyObject *)self;
+}
+
+static int
+CStackedDisksModel_init(CStackedDisksModel *self, PyObject *args, PyObject *kwds)
+{
+    if (self != NULL) {
+    	
+    	// Create parameters
+        self->params = PyDict_New();
+        self->dispersion = PyDict_New();
+        self->model = new StackedDisksModel();
+        
+        // Initialize parameter dictionary
+        PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",0.010000));
+        PyDict_SetItemString(self->params,"axis_theta",Py_BuildValue("d",1.000000));
+        PyDict_SetItemString(self->params,"spacing",Py_BuildValue("d",0.000000));
+        PyDict_SetItemString(self->params,"nlayers",Py_BuildValue("d",1.000000));
+        PyDict_SetItemString(self->params,"layer_sld",Py_BuildValue("d",-0.000000));
+        PyDict_SetItemString(self->params,"solvent_sld",Py_BuildValue("d",0.000005));
+        PyDict_SetItemString(self->params,"thickness",Py_BuildValue("d",15.000000));
+        PyDict_SetItemString(self->params,"axis_phi",Py_BuildValue("d",1.000000));
+        PyDict_SetItemString(self->params,"length",Py_BuildValue("d",10.000000));
+        PyDict_SetItemString(self->params,"core_sld",Py_BuildValue("d",0.000004));
+        PyDict_SetItemString(self->params,"radius",Py_BuildValue("d",3000.000000));
+        PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.001000));
+        // Initialize dispersion / averaging parameter dict
+        DispersionVisitor* visitor = new DispersionVisitor();
+        PyObject * disp_dict;
+        disp_dict = PyDict_New();
+        self->model->length.dispersion->accept_as_source(visitor, self->model->length.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "length", disp_dict);
+        disp_dict = PyDict_New();
+        self->model->radius.dispersion->accept_as_source(visitor, self->model->radius.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "radius", disp_dict);
+        disp_dict = PyDict_New();
+        self->model->axis_theta.dispersion->accept_as_source(visitor, self->model->axis_theta.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "axis_theta", disp_dict);
+        disp_dict = PyDict_New();
+        self->model->axis_phi.dispersion->accept_as_source(visitor, self->model->axis_phi.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "axis_phi", disp_dict);
+
+
+         
+        // Create empty log
+        self->log = PyDict_New();
+        
+        
+
+    }
+    return 0;
+}
+
+static PyMemberDef CStackedDisksModel_members[] = {
+    {"params", T_OBJECT, offsetof(CStackedDisksModel, params), 0,
+     "Parameters"},
+	{"dispersion", T_OBJECT, offsetof(CStackedDisksModel, dispersion), 0,
+	  "Dispersion parameters"},     
+    {"log", T_OBJECT, offsetof(CStackedDisksModel, log), 0,
+     "Log"},
+    {NULL}  /* Sentinel */
+};
+
+/** Read double from PyObject
+    @param p PyObject
+    @return double
+*/
+double CStackedDisksModel_readDouble(PyObject *p) {
+    if (PyFloat_Check(p)==1) {
+        return (double)(((PyFloatObject *)(p))->ob_fval);
+    } else if (PyInt_Check(p)==1) {
+        return (double)(((PyIntObject *)(p))->ob_ival);
+    } else if (PyLong_Check(p)==1) {
+        return (double)PyLong_AsLong(p);
+    } else {
+        return 0.0;
+    }
+}
+
+
+/**
+ * Function to call to evaluate model
+ * @param args: input q or [q,phi]
+ * @return: function value
+ */
+static PyObject * run(CStackedDisksModel *self, PyObject *args) {
+	double q_value, phi_value;
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->axis_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_theta") );
+    self->model->spacing = PyFloat_AsDouble( PyDict_GetItemString(self->params, "spacing") );
+    self->model->nlayers = PyFloat_AsDouble( PyDict_GetItemString(self->params, "nlayers") );
+    self->model->layer_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "layer_sld") );
+    self->model->solvent_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "solvent_sld") );
+    self->model->thickness = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thickness") );
+    self->model->axis_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_phi") );
+    self->model->length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "length") );
+    self->model->core_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "core_sld") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    // Read in dispersion parameters
+    PyObject* disp_dict;
+    DispersionVisitor* visitor = new DispersionVisitor();
+    disp_dict = PyDict_GetItemString(self->dispersion, "length");
+    self->model->length.dispersion->accept_as_destination(visitor, self->model->length.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
+    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "axis_theta");
+    self->model->axis_theta.dispersion->accept_as_destination(visitor, self->model->axis_theta.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "axis_phi");
+    self->model->axis_phi.dispersion->accept_as_destination(visitor, self->model->axis_phi.dispersion, disp_dict);
+
+	
+	// Get input and determine whether we have to supply a 1D or 2D return value.
+	if ( !PyArg_ParseTuple(args,"O",&pars) ) {
+	    PyErr_SetString(CStackedDisksModelError, 
+	    	"CStackedDisksModel.run expects a q value.");
+		return NULL;
+	}
+	  
+	// Check params
+	if( PyList_Check(pars)==1) {
+		
+		// Length of list should be 2 for I(q,phi)
+	    npars = PyList_GET_SIZE(pars); 
+	    if(npars!=2) {
+	    	PyErr_SetString(CStackedDisksModelError, 
+	    		"CStackedDisksModel.run expects a double or a list of dimension 2.");
+	    	return NULL;
+	    }
+	    // We have a vector q, get the q and phi values at which
+	    // to evaluate I(q,phi)
+	    q_value = CStackedDisksModel_readDouble(PyList_GET_ITEM(pars,0));
+	    phi_value = CStackedDisksModel_readDouble(PyList_GET_ITEM(pars,1));
+	    // Skip zero
+	    if (q_value==0) {
+	    	return Py_BuildValue("d",0.0);
+	    }
+		return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value));
+
+	} else {
+
+		// We have a scalar q, we will evaluate I(q)
+		q_value = CStackedDisksModel_readDouble(pars);		
+		
+		return Py_BuildValue("d",(*(self->model))(q_value));
+	}	
+}
+
+/**
+ * Function to call to evaluate model in cartesian coordinates
+ * @param args: input q or [qx, qy]]
+ * @return: function value
+ */
+static PyObject * runXY(CStackedDisksModel *self, PyObject *args) {
+	double qx_value, qy_value;
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->axis_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_theta") );
+    self->model->spacing = PyFloat_AsDouble( PyDict_GetItemString(self->params, "spacing") );
+    self->model->nlayers = PyFloat_AsDouble( PyDict_GetItemString(self->params, "nlayers") );
+    self->model->layer_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "layer_sld") );
+    self->model->solvent_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "solvent_sld") );
+    self->model->thickness = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thickness") );
+    self->model->axis_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_phi") );
+    self->model->length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "length") );
+    self->model->core_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "core_sld") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    // Read in dispersion parameters
+    PyObject* disp_dict;
+    DispersionVisitor* visitor = new DispersionVisitor();
+    disp_dict = PyDict_GetItemString(self->dispersion, "length");
+    self->model->length.dispersion->accept_as_destination(visitor, self->model->length.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
+    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "axis_theta");
+    self->model->axis_theta.dispersion->accept_as_destination(visitor, self->model->axis_theta.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "axis_phi");
+    self->model->axis_phi.dispersion->accept_as_destination(visitor, self->model->axis_phi.dispersion, disp_dict);
+
+	
+	// Get input and determine whether we have to supply a 1D or 2D return value.
+	if ( !PyArg_ParseTuple(args,"O",&pars) ) {
+	    PyErr_SetString(CStackedDisksModelError, 
+	    	"CStackedDisksModel.run expects a q value.");
+		return NULL;
+	}
+	  
+	// Check params
+	if( PyList_Check(pars)==1) {
+		
+		// Length of list should be 2 for I(qx, qy))
+	    npars = PyList_GET_SIZE(pars); 
+	    if(npars!=2) {
+	    	PyErr_SetString(CStackedDisksModelError, 
+	    		"CStackedDisksModel.run expects a double or a list of dimension 2.");
+	    	return NULL;
+	    }
+	    // We have a vector q, get the qx and qy values at which
+	    // to evaluate I(qx,qy)
+	    qx_value = CStackedDisksModel_readDouble(PyList_GET_ITEM(pars,0));
+	    qy_value = CStackedDisksModel_readDouble(PyList_GET_ITEM(pars,1));
+	    return Py_BuildValue("d",(*(self->model))(qx_value,qy_value));
+
+	} else {
+
+		// We have a scalar q, we will evaluate I(q)
+		qx_value = CStackedDisksModel_readDouble(pars);		
+		
+		return Py_BuildValue("d",(*(self->model))(qx_value));
+	}	
+}
+
+static PyObject * reset(CStackedDisksModel *self, PyObject *args) {
+    
+
+    return Py_BuildValue("d",0.0);
+}
+
+static PyObject * set_dispersion(CStackedDisksModel *self, PyObject *args) {
+	PyObject * disp;
+	const char * par_name;
+
+	if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
+	    PyErr_SetString(CStackedDisksModelError,
+	    	"CStackedDisksModel.set_dispersion expects a DispersionModel object.");
+		return NULL;
+	}
+	void *temp = PyCObject_AsVoidPtr(disp);
+	DispersionModel * dispersion = static_cast<DispersionModel *>(temp);
+
+
+	// Ugliness necessary to go from python to C
+	    // TODO: refactor this
+    if (!strcmp(par_name, "length")) {
+        self->model->length.dispersion = dispersion;
+    } else    if (!strcmp(par_name, "radius")) {
+        self->model->radius.dispersion = dispersion;
+    } else    if (!strcmp(par_name, "axis_theta")) {
+        self->model->axis_theta.dispersion = dispersion;
+    } else    if (!strcmp(par_name, "axis_phi")) {
+        self->model->axis_phi.dispersion = dispersion;
+    } else {
+	    PyErr_SetString(CStackedDisksModelError,
+	    	"CStackedDisksModel.set_dispersion expects a valid parameter name.");
+		return NULL;
+	}
+
+	DispersionVisitor* visitor = new DispersionVisitor();
+	PyObject * disp_dict = PyDict_New();
+	dispersion->accept_as_source(visitor, dispersion, disp_dict);
+	PyDict_SetItemString(self->dispersion, par_name, disp_dict);
+    return Py_BuildValue("i",1);
+}
+
+
+static PyMethodDef CStackedDisksModel_methods[] = {
+    {"run",      (PyCFunction)run     , METH_VARARGS,
+      "Evaluate the model at a given Q or Q, phi"},
+    {"runXY",      (PyCFunction)runXY     , METH_VARARGS,
+      "Evaluate the model at a given Q or Qx, Qy"},
+    {"reset",    (PyCFunction)reset   , METH_VARARGS,
+      "Reset pair correlation"},
+    {"set_dispersion",      (PyCFunction)set_dispersion     , METH_VARARGS,
+      "Set the dispersion model for a given parameter"},
+   {NULL}
+};
+
+static PyTypeObject CStackedDisksModelType = {
+    PyObject_HEAD_INIT(NULL)
+    0,                         /*ob_size*/
+    "CStackedDisksModel",             /*tp_name*/
+    sizeof(CStackedDisksModel),             /*tp_basicsize*/
+    0,                         /*tp_itemsize*/
+    (destructor)CStackedDisksModel_dealloc, /*tp_dealloc*/
+    0,                         /*tp_print*/
+    0,                         /*tp_getattr*/
+    0,                         /*tp_setattr*/
+    0,                         /*tp_compare*/
+    0,                         /*tp_repr*/
+    0,                         /*tp_as_number*/
+    0,                         /*tp_as_sequence*/
+    0,                         /*tp_as_mapping*/
+    0,                         /*tp_hash */
+    0,                         /*tp_call*/
+    0,                         /*tp_str*/
+    0,                         /*tp_getattro*/
+    0,                         /*tp_setattro*/
+    0,                         /*tp_as_buffer*/
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+    "CStackedDisksModel objects",           /* tp_doc */
+    0,		               /* tp_traverse */
+    0,		               /* tp_clear */
+    0,		               /* tp_richcompare */
+    0,		               /* tp_weaklistoffset */
+    0,		               /* tp_iter */
+    0,		               /* tp_iternext */
+    CStackedDisksModel_methods,             /* tp_methods */
+    CStackedDisksModel_members,             /* tp_members */
+    0,                         /* tp_getset */
+    0,                         /* tp_base */
+    0,                         /* tp_dict */
+    0,                         /* tp_descr_get */
+    0,                         /* tp_descr_set */
+    0,                         /* tp_dictoffset */
+    (initproc)CStackedDisksModel_init,      /* tp_init */
+    0,                         /* tp_alloc */
+    CStackedDisksModel_new,                 /* tp_new */
+};
+
+
+static PyMethodDef module_methods[] = {
+    {NULL} 
+};
+
+/**
+ * Function used to add the model class to a module
+ * @param module: module to add the class to
+ */ 
+void addCStackedDisksModel(PyObject *module) {
+	PyObject *d;
+	
+    if (PyType_Ready(&CStackedDisksModelType) < 0)
+        return;
+
+    Py_INCREF(&CStackedDisksModelType);
+    PyModule_AddObject(module, "CStackedDisksModel", (PyObject *)&CStackedDisksModelType);
+    
+    d = PyModule_GetDict(module);
+    CStackedDisksModelError = PyErr_NewException("CStackedDisksModel.error", NULL, NULL);
+    PyDict_SetItemString(d, "CStackedDisksModelError", CStackedDisksModelError);
+}
+
Index: sansmodels/src/sans/models/c_models/CStakedDisksModel.cpp
===================================================================
--- sansmodels/src/sans/models/c_models/CStakedDisksModel.cpp	(revision 50686972861f70ebff2c64a50118cfb6b905253a)
+++ sansmodels/src/sans/models/c_models/CStakedDisksModel.cpp	(revision 50686972861f70ebff2c64a50118cfb6b905253a)
@@ -0,0 +1,414 @@
+/**
+	This software was developed by the University of Tennessee as part of the
+	Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
+	project funded by the US National Science Foundation.
+
+	If you use DANSE applications to do scientific research that leads to
+	publication, we ask that you acknowledge the use of the software with the
+	following sentence:
+
+	"This work benefited from DANSE software developed under NSF award DMR-0520547."
+
+	copyright 2008, University of Tennessee
+ */
+
+/** CStakedDisksModel
+ *
+ * C extension 
+ *
+ * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY
+ *          DO NOT MODIFY THIS FILE, MODIFY stacked_disks.h
+ *          AND RE-RUN THE GENERATOR SCRIPT
+ *
+ */
+ 
+extern "C" {
+#include <Python.h>
+#include "structmember.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <time.h>
+#include "stacked_disks.h"
+}
+
+#include "models.hh"
+#include "dispersion_visitor.hh"
+
+/// Error object for raised exceptions
+static PyObject * CStakedDisksModelError = NULL;
+
+
+// Class definition
+typedef struct {
+    PyObject_HEAD
+    /// Parameters
+    PyObject * params;
+    /// Dispersion parameters
+    PyObject * dispersion;
+    /// Underlying model object
+    StakedDisksModel * model;
+    /// Log for unit testing
+    PyObject * log;
+} CStakedDisksModel;
+
+
+static void
+CStakedDisksModel_dealloc(CStakedDisksModel* self)
+{
+    self->ob_type->tp_free((PyObject*)self);
+    
+
+}
+
+static PyObject *
+CStakedDisksModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+    CStakedDisksModel *self;
+    
+    self = (CStakedDisksModel *)type->tp_alloc(type, 0);
+   
+    return (PyObject *)self;
+}
+
+static int
+CStakedDisksModel_init(CStakedDisksModel *self, PyObject *args, PyObject *kwds)
+{
+    if (self != NULL) {
+    	
+    	// Create parameters
+        self->params = PyDict_New();
+        self->dispersion = PyDict_New();
+        self->model = new StakedDisksModel();
+        
+        // Initialize parameter dictionary
+        PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",0.010000));
+        PyDict_SetItemString(self->params,"axis_theta",Py_BuildValue("d",1.000000));
+        PyDict_SetItemString(self->params,"spacing",Py_BuildValue("d",0.000000));
+        PyDict_SetItemString(self->params,"nlayers",Py_BuildValue("d",1.000000));
+        PyDict_SetItemString(self->params,"layer_sld",Py_BuildValue("d",-0.000000));
+        PyDict_SetItemString(self->params,"solvent_sld",Py_BuildValue("d",0.000005));
+        PyDict_SetItemString(self->params,"thickness",Py_BuildValue("d",15.000000));
+        PyDict_SetItemString(self->params,"axis_phi",Py_BuildValue("d",1.000000));
+        PyDict_SetItemString(self->params,"length",Py_BuildValue("d",10.000000));
+        PyDict_SetItemString(self->params,"core_sld",Py_BuildValue("d",0.000004));
+        PyDict_SetItemString(self->params,"radius",Py_BuildValue("d",3000.000000));
+        PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.000100));
+        // Initialize dispersion / averaging parameter dict
+        DispersionVisitor* visitor = new DispersionVisitor();
+        PyObject * disp_dict;
+        disp_dict = PyDict_New();
+        self->model->length.dispersion->accept_as_source(visitor, self->model->length.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "length", disp_dict);
+        disp_dict = PyDict_New();
+        self->model->radius.dispersion->accept_as_source(visitor, self->model->radius.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "radius", disp_dict);
+        disp_dict = PyDict_New();
+        self->model->axis_theta.dispersion->accept_as_source(visitor, self->model->axis_theta.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "axis_theta", disp_dict);
+        disp_dict = PyDict_New();
+        self->model->axis_phi.dispersion->accept_as_source(visitor, self->model->axis_phi.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "axis_phi", disp_dict);
+
+
+         
+        // Create empty log
+        self->log = PyDict_New();
+        
+        
+
+    }
+    return 0;
+}
+
+static PyMemberDef CStakedDisksModel_members[] = {
+    {"params", T_OBJECT, offsetof(CStakedDisksModel, params), 0,
+     "Parameters"},
+	{"dispersion", T_OBJECT, offsetof(CStakedDisksModel, dispersion), 0,
+	  "Dispersion parameters"},     
+    {"log", T_OBJECT, offsetof(CStakedDisksModel, log), 0,
+     "Log"},
+    {NULL}  /* Sentinel */
+};
+
+/** Read double from PyObject
+    @param p PyObject
+    @return double
+*/
+double CStakedDisksModel_readDouble(PyObject *p) {
+    if (PyFloat_Check(p)==1) {
+        return (double)(((PyFloatObject *)(p))->ob_fval);
+    } else if (PyInt_Check(p)==1) {
+        return (double)(((PyIntObject *)(p))->ob_ival);
+    } else if (PyLong_Check(p)==1) {
+        return (double)PyLong_AsLong(p);
+    } else {
+        return 0.0;
+    }
+}
+
+
+/**
+ * Function to call to evaluate model
+ * @param args: input q or [q,phi]
+ * @return: function value
+ */
+static PyObject * run(CStakedDisksModel *self, PyObject *args) {
+	double q_value, phi_value;
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->axis_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_theta") );
+    self->model->spacing = PyFloat_AsDouble( PyDict_GetItemString(self->params, "spacing") );
+    self->model->nlayers = PyFloat_AsDouble( PyDict_GetItemString(self->params, "nlayers") );
+    self->model->layer_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "layer_sld") );
+    self->model->solvent_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "solvent_sld") );
+    self->model->thickness = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thickness") );
+    self->model->axis_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_phi") );
+    self->model->length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "length") );
+    self->model->core_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "core_sld") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    // Read in dispersion parameters
+    PyObject* disp_dict;
+    DispersionVisitor* visitor = new DispersionVisitor();
+    disp_dict = PyDict_GetItemString(self->dispersion, "length");
+    self->model->length.dispersion->accept_as_destination(visitor, self->model->length.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
+    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "axis_theta");
+    self->model->axis_theta.dispersion->accept_as_destination(visitor, self->model->axis_theta.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "axis_phi");
+    self->model->axis_phi.dispersion->accept_as_destination(visitor, self->model->axis_phi.dispersion, disp_dict);
+
+	
+	// Get input and determine whether we have to supply a 1D or 2D return value.
+	if ( !PyArg_ParseTuple(args,"O",&pars) ) {
+	    PyErr_SetString(CStakedDisksModelError, 
+	    	"CStakedDisksModel.run expects a q value.");
+		return NULL;
+	}
+	  
+	// Check params
+	if( PyList_Check(pars)==1) {
+		
+		// Length of list should be 2 for I(q,phi)
+	    npars = PyList_GET_SIZE(pars); 
+	    if(npars!=2) {
+	    	PyErr_SetString(CStakedDisksModelError, 
+	    		"CStakedDisksModel.run expects a double or a list of dimension 2.");
+	    	return NULL;
+	    }
+	    // We have a vector q, get the q and phi values at which
+	    // to evaluate I(q,phi)
+	    q_value = CStakedDisksModel_readDouble(PyList_GET_ITEM(pars,0));
+	    phi_value = CStakedDisksModel_readDouble(PyList_GET_ITEM(pars,1));
+	    // Skip zero
+	    if (q_value==0) {
+	    	return Py_BuildValue("d",0.0);
+	    }
+		return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value));
+
+	} else {
+
+		// We have a scalar q, we will evaluate I(q)
+		q_value = CStakedDisksModel_readDouble(pars);		
+		
+		return Py_BuildValue("d",(*(self->model))(q_value));
+	}	
+}
+
+/**
+ * Function to call to evaluate model in cartesian coordinates
+ * @param args: input q or [qx, qy]]
+ * @return: function value
+ */
+static PyObject * runXY(CStakedDisksModel *self, PyObject *args) {
+	double qx_value, qy_value;
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->axis_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_theta") );
+    self->model->spacing = PyFloat_AsDouble( PyDict_GetItemString(self->params, "spacing") );
+    self->model->nlayers = PyFloat_AsDouble( PyDict_GetItemString(self->params, "nlayers") );
+    self->model->layer_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "layer_sld") );
+    self->model->solvent_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "solvent_sld") );
+    self->model->thickness = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thickness") );
+    self->model->axis_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_phi") );
+    self->model->length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "length") );
+    self->model->core_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "core_sld") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    // Read in dispersion parameters
+    PyObject* disp_dict;
+    DispersionVisitor* visitor = new DispersionVisitor();
+    disp_dict = PyDict_GetItemString(self->dispersion, "length");
+    self->model->length.dispersion->accept_as_destination(visitor, self->model->length.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
+    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "axis_theta");
+    self->model->axis_theta.dispersion->accept_as_destination(visitor, self->model->axis_theta.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "axis_phi");
+    self->model->axis_phi.dispersion->accept_as_destination(visitor, self->model->axis_phi.dispersion, disp_dict);
+
+	
+	// Get input and determine whether we have to supply a 1D or 2D return value.
+	if ( !PyArg_ParseTuple(args,"O",&pars) ) {
+	    PyErr_SetString(CStakedDisksModelError, 
+	    	"CStakedDisksModel.run expects a q value.");
+		return NULL;
+	}
+	  
+	// Check params
+	if( PyList_Check(pars)==1) {
+		
+		// Length of list should be 2 for I(qx, qy))
+	    npars = PyList_GET_SIZE(pars); 
+	    if(npars!=2) {
+	    	PyErr_SetString(CStakedDisksModelError, 
+	    		"CStakedDisksModel.run expects a double or a list of dimension 2.");
+	    	return NULL;
+	    }
+	    // We have a vector q, get the qx and qy values at which
+	    // to evaluate I(qx,qy)
+	    qx_value = CStakedDisksModel_readDouble(PyList_GET_ITEM(pars,0));
+	    qy_value = CStakedDisksModel_readDouble(PyList_GET_ITEM(pars,1));
+	    return Py_BuildValue("d",(*(self->model))(qx_value,qy_value));
+
+	} else {
+
+		// We have a scalar q, we will evaluate I(q)
+		qx_value = CStakedDisksModel_readDouble(pars);		
+		
+		return Py_BuildValue("d",(*(self->model))(qx_value));
+	}	
+}
+
+static PyObject * reset(CStakedDisksModel *self, PyObject *args) {
+    
+
+    return Py_BuildValue("d",0.0);
+}
+
+static PyObject * set_dispersion(CStakedDisksModel *self, PyObject *args) {
+	PyObject * disp;
+	const char * par_name;
+
+	if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
+	    PyErr_SetString(CStakedDisksModelError,
+	    	"CStakedDisksModel.set_dispersion expects a DispersionModel object.");
+		return NULL;
+	}
+	void *temp = PyCObject_AsVoidPtr(disp);
+	DispersionModel * dispersion = static_cast<DispersionModel *>(temp);
+
+
+	// Ugliness necessary to go from python to C
+	    // TODO: refactor this
+    if (!strcmp(par_name, "length")) {
+        self->model->length.dispersion = dispersion;
+    } else    if (!strcmp(par_name, "radius")) {
+        self->model->radius.dispersion = dispersion;
+    } else    if (!strcmp(par_name, "axis_theta")) {
+        self->model->axis_theta.dispersion = dispersion;
+    } else    if (!strcmp(par_name, "axis_phi")) {
+        self->model->axis_phi.dispersion = dispersion;
+    } else {
+	    PyErr_SetString(CStakedDisksModelError,
+	    	"CStakedDisksModel.set_dispersion expects a valid parameter name.");
+		return NULL;
+	}
+
+	DispersionVisitor* visitor = new DispersionVisitor();
+	PyObject * disp_dict = PyDict_New();
+	dispersion->accept_as_source(visitor, dispersion, disp_dict);
+	PyDict_SetItemString(self->dispersion, par_name, disp_dict);
+    return Py_BuildValue("i",1);
+}
+
+
+static PyMethodDef CStakedDisksModel_methods[] = {
+    {"run",      (PyCFunction)run     , METH_VARARGS,
+      "Evaluate the model at a given Q or Q, phi"},
+    {"runXY",      (PyCFunction)runXY     , METH_VARARGS,
+      "Evaluate the model at a given Q or Qx, Qy"},
+    {"reset",    (PyCFunction)reset   , METH_VARARGS,
+      "Reset pair correlation"},
+    {"set_dispersion",      (PyCFunction)set_dispersion     , METH_VARARGS,
+      "Set the dispersion model for a given parameter"},
+   {NULL}
+};
+
+static PyTypeObject CStakedDisksModelType = {
+    PyObject_HEAD_INIT(NULL)
+    0,                         /*ob_size*/
+    "CStakedDisksModel",             /*tp_name*/
+    sizeof(CStakedDisksModel),             /*tp_basicsize*/
+    0,                         /*tp_itemsize*/
+    (destructor)CStakedDisksModel_dealloc, /*tp_dealloc*/
+    0,                         /*tp_print*/
+    0,                         /*tp_getattr*/
+    0,                         /*tp_setattr*/
+    0,                         /*tp_compare*/
+    0,                         /*tp_repr*/
+    0,                         /*tp_as_number*/
+    0,                         /*tp_as_sequence*/
+    0,                         /*tp_as_mapping*/
+    0,                         /*tp_hash */
+    0,                         /*tp_call*/
+    0,                         /*tp_str*/
+    0,                         /*tp_getattro*/
+    0,                         /*tp_setattro*/
+    0,                         /*tp_as_buffer*/
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+    "CStakedDisksModel objects",           /* tp_doc */
+    0,		               /* tp_traverse */
+    0,		               /* tp_clear */
+    0,		               /* tp_richcompare */
+    0,		               /* tp_weaklistoffset */
+    0,		               /* tp_iter */
+    0,		               /* tp_iternext */
+    CStakedDisksModel_methods,             /* tp_methods */
+    CStakedDisksModel_members,             /* tp_members */
+    0,                         /* tp_getset */
+    0,                         /* tp_base */
+    0,                         /* tp_dict */
+    0,                         /* tp_descr_get */
+    0,                         /* tp_descr_set */
+    0,                         /* tp_dictoffset */
+    (initproc)CStakedDisksModel_init,      /* tp_init */
+    0,                         /* tp_alloc */
+    CStakedDisksModel_new,                 /* tp_new */
+};
+
+
+static PyMethodDef module_methods[] = {
+    {NULL} 
+};
+
+/**
+ * Function used to add the model class to a module
+ * @param module: module to add the class to
+ */ 
+void addCStakedDisksModel(PyObject *module) {
+	PyObject *d;
+	
+    if (PyType_Ready(&CStakedDisksModelType) < 0)
+        return;
+
+    Py_INCREF(&CStakedDisksModelType);
+    PyModule_AddObject(module, "CStakedDisksModel", (PyObject *)&CStakedDisksModelType);
+    
+    d = PyModule_GetDict(module);
+    CStakedDisksModelError = PyErr_NewException("CStakedDisksModel.error", NULL, NULL);
+    PyDict_SetItemString(d, "CStakedDisksModelError", CStakedDisksModelError);
+}
+
Index: sansmodels/src/sans/models/c_models/CTriaxialEllipsoidModel.cpp
===================================================================
--- sansmodels/src/sans/models/c_models/CTriaxialEllipsoidModel.cpp	(revision 50686972861f70ebff2c64a50118cfb6b905253a)
+++ sansmodels/src/sans/models/c_models/CTriaxialEllipsoidModel.cpp	(revision 50686972861f70ebff2c64a50118cfb6b905253a)
@@ -0,0 +1,384 @@
+/**
+	This software was developed by the University of Tennessee as part of the
+	Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
+	project funded by the US National Science Foundation.
+
+	If you use DANSE applications to do scientific research that leads to
+	publication, we ask that you acknowledge the use of the software with the
+	following sentence:
+
+	"This work benefited from DANSE software developed under NSF award DMR-0520547."
+
+	copyright 2008, University of Tennessee
+ */
+
+/** CTriaxialEllipsoidModel
+ *
+ * C extension 
+ *
+ * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY
+ *          DO NOT MODIFY THIS FILE, MODIFY triaxial_ellipsoid.h
+ *          AND RE-RUN THE GENERATOR SCRIPT
+ *
+ */
+ 
+extern "C" {
+#include <Python.h>
+#include "structmember.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <time.h>
+#include "triaxial_ellipsoid.h"
+}
+
+#include "models.hh"
+#include "dispersion_visitor.hh"
+
+/// Error object for raised exceptions
+static PyObject * CTriaxialEllipsoidModelError = NULL;
+
+
+// Class definition
+typedef struct {
+    PyObject_HEAD
+    /// Parameters
+    PyObject * params;
+    /// Dispersion parameters
+    PyObject * dispersion;
+    /// Underlying model object
+    TriaxialEllipsoidModel * model;
+    /// Log for unit testing
+    PyObject * log;
+} CTriaxialEllipsoidModel;
+
+
+static void
+CTriaxialEllipsoidModel_dealloc(CTriaxialEllipsoidModel* self)
+{
+    self->ob_type->tp_free((PyObject*)self);
+    
+
+}
+
+static PyObject *
+CTriaxialEllipsoidModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+    CTriaxialEllipsoidModel *self;
+    
+    self = (CTriaxialEllipsoidModel *)type->tp_alloc(type, 0);
+   
+    return (PyObject *)self;
+}
+
+static int
+CTriaxialEllipsoidModel_init(CTriaxialEllipsoidModel *self, PyObject *args, PyObject *kwds)
+{
+    if (self != NULL) {
+    	
+    	// Create parameters
+        self->params = PyDict_New();
+        self->dispersion = PyDict_New();
+        self->model = new TriaxialEllipsoidModel();
+        
+        // Initialize parameter dictionary
+        PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",1.000000));
+        PyDict_SetItemString(self->params,"axis_theta",Py_BuildValue("d",1.000000));
+        PyDict_SetItemString(self->params,"semi_axisA",Py_BuildValue("d",100.000000));
+        PyDict_SetItemString(self->params,"semi_axisB",Py_BuildValue("d",35.000000));
+        PyDict_SetItemString(self->params,"semi_axisC",Py_BuildValue("d",400.000000));
+        PyDict_SetItemString(self->params,"axis_phi",Py_BuildValue("d",1.000000));
+        PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.000000));
+        PyDict_SetItemString(self->params,"contrast",Py_BuildValue("d",0.000005));
+        // Initialize dispersion / averaging parameter dict
+        DispersionVisitor* visitor = new DispersionVisitor();
+        PyObject * disp_dict;
+        disp_dict = PyDict_New();
+        self->model->axis_theta.dispersion->accept_as_source(visitor, self->model->axis_theta.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "axis_theta", disp_dict);
+        disp_dict = PyDict_New();
+        self->model->axis_phi.dispersion->accept_as_source(visitor, self->model->axis_phi.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "axis_phi", disp_dict);
+
+
+         
+        // Create empty log
+        self->log = PyDict_New();
+        
+        
+
+    }
+    return 0;
+}
+
+static PyMemberDef CTriaxialEllipsoidModel_members[] = {
+    {"params", T_OBJECT, offsetof(CTriaxialEllipsoidModel, params), 0,
+     "Parameters"},
+	{"dispersion", T_OBJECT, offsetof(CTriaxialEllipsoidModel, dispersion), 0,
+	  "Dispersion parameters"},     
+    {"log", T_OBJECT, offsetof(CTriaxialEllipsoidModel, log), 0,
+     "Log"},
+    {NULL}  /* Sentinel */
+};
+
+/** Read double from PyObject
+    @param p PyObject
+    @return double
+*/
+double CTriaxialEllipsoidModel_readDouble(PyObject *p) {
+    if (PyFloat_Check(p)==1) {
+        return (double)(((PyFloatObject *)(p))->ob_fval);
+    } else if (PyInt_Check(p)==1) {
+        return (double)(((PyIntObject *)(p))->ob_ival);
+    } else if (PyLong_Check(p)==1) {
+        return (double)PyLong_AsLong(p);
+    } else {
+        return 0.0;
+    }
+}
+
+
+/**
+ * Function to call to evaluate model
+ * @param args: input q or [q,phi]
+ * @return: function value
+ */
+static PyObject * run(CTriaxialEllipsoidModel *self, PyObject *args) {
+	double q_value, phi_value;
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->axis_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_theta") );
+    self->model->semi_axisA = PyFloat_AsDouble( PyDict_GetItemString(self->params, "semi_axisA") );
+    self->model->semi_axisB = PyFloat_AsDouble( PyDict_GetItemString(self->params, "semi_axisB") );
+    self->model->semi_axisC = PyFloat_AsDouble( PyDict_GetItemString(self->params, "semi_axisC") );
+    self->model->axis_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_phi") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->contrast = PyFloat_AsDouble( PyDict_GetItemString(self->params, "contrast") );
+    // Read in dispersion parameters
+    PyObject* disp_dict;
+    DispersionVisitor* visitor = new DispersionVisitor();
+    disp_dict = PyDict_GetItemString(self->dispersion, "axis_theta");
+    self->model->axis_theta.dispersion->accept_as_destination(visitor, self->model->axis_theta.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "axis_phi");
+    self->model->axis_phi.dispersion->accept_as_destination(visitor, self->model->axis_phi.dispersion, disp_dict);
+
+	
+	// Get input and determine whether we have to supply a 1D or 2D return value.
+	if ( !PyArg_ParseTuple(args,"O",&pars) ) {
+	    PyErr_SetString(CTriaxialEllipsoidModelError, 
+	    	"CTriaxialEllipsoidModel.run expects a q value.");
+		return NULL;
+	}
+	  
+	// Check params
+	if( PyList_Check(pars)==1) {
+		
+		// Length of list should be 2 for I(q,phi)
+	    npars = PyList_GET_SIZE(pars); 
+	    if(npars!=2) {
+	    	PyErr_SetString(CTriaxialEllipsoidModelError, 
+	    		"CTriaxialEllipsoidModel.run expects a double or a list of dimension 2.");
+	    	return NULL;
+	    }
+	    // We have a vector q, get the q and phi values at which
+	    // to evaluate I(q,phi)
+	    q_value = CTriaxialEllipsoidModel_readDouble(PyList_GET_ITEM(pars,0));
+	    phi_value = CTriaxialEllipsoidModel_readDouble(PyList_GET_ITEM(pars,1));
+	    // Skip zero
+	    if (q_value==0) {
+	    	return Py_BuildValue("d",0.0);
+	    }
+		return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value));
+
+	} else {
+
+		// We have a scalar q, we will evaluate I(q)
+		q_value = CTriaxialEllipsoidModel_readDouble(pars);		
+		
+		return Py_BuildValue("d",(*(self->model))(q_value));
+	}	
+}
+
+/**
+ * Function to call to evaluate model in cartesian coordinates
+ * @param args: input q or [qx, qy]]
+ * @return: function value
+ */
+static PyObject * runXY(CTriaxialEllipsoidModel *self, PyObject *args) {
+	double qx_value, qy_value;
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->axis_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_theta") );
+    self->model->semi_axisA = PyFloat_AsDouble( PyDict_GetItemString(self->params, "semi_axisA") );
+    self->model->semi_axisB = PyFloat_AsDouble( PyDict_GetItemString(self->params, "semi_axisB") );
+    self->model->semi_axisC = PyFloat_AsDouble( PyDict_GetItemString(self->params, "semi_axisC") );
+    self->model->axis_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_phi") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->contrast = PyFloat_AsDouble( PyDict_GetItemString(self->params, "contrast") );
+    // Read in dispersion parameters
+    PyObject* disp_dict;
+    DispersionVisitor* visitor = new DispersionVisitor();
+    disp_dict = PyDict_GetItemString(self->dispersion, "axis_theta");
+    self->model->axis_theta.dispersion->accept_as_destination(visitor, self->model->axis_theta.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "axis_phi");
+    self->model->axis_phi.dispersion->accept_as_destination(visitor, self->model->axis_phi.dispersion, disp_dict);
+
+	
+	// Get input and determine whether we have to supply a 1D or 2D return value.
+	if ( !PyArg_ParseTuple(args,"O",&pars) ) {
+	    PyErr_SetString(CTriaxialEllipsoidModelError, 
+	    	"CTriaxialEllipsoidModel.run expects a q value.");
+		return NULL;
+	}
+	  
+	// Check params
+	if( PyList_Check(pars)==1) {
+		
+		// Length of list should be 2 for I(qx, qy))
+	    npars = PyList_GET_SIZE(pars); 
+	    if(npars!=2) {
+	    	PyErr_SetString(CTriaxialEllipsoidModelError, 
+	    		"CTriaxialEllipsoidModel.run expects a double or a list of dimension 2.");
+	    	return NULL;
+	    }
+	    // We have a vector q, get the qx and qy values at which
+	    // to evaluate I(qx,qy)
+	    qx_value = CTriaxialEllipsoidModel_readDouble(PyList_GET_ITEM(pars,0));
+	    qy_value = CTriaxialEllipsoidModel_readDouble(PyList_GET_ITEM(pars,1));
+	    return Py_BuildValue("d",(*(self->model))(qx_value,qy_value));
+
+	} else {
+
+		// We have a scalar q, we will evaluate I(q)
+		qx_value = CTriaxialEllipsoidModel_readDouble(pars);		
+		
+		return Py_BuildValue("d",(*(self->model))(qx_value));
+	}	
+}
+
+static PyObject * reset(CTriaxialEllipsoidModel *self, PyObject *args) {
+    
+
+    return Py_BuildValue("d",0.0);
+}
+
+static PyObject * set_dispersion(CTriaxialEllipsoidModel *self, PyObject *args) {
+	PyObject * disp;
+	const char * par_name;
+
+	if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
+	    PyErr_SetString(CTriaxialEllipsoidModelError,
+	    	"CTriaxialEllipsoidModel.set_dispersion expects a DispersionModel object.");
+		return NULL;
+	}
+	void *temp = PyCObject_AsVoidPtr(disp);
+	DispersionModel * dispersion = static_cast<DispersionModel *>(temp);
+
+
+	// Ugliness necessary to go from python to C
+	    // TODO: refactor this
+    if (!strcmp(par_name, "axis_theta")) {
+        self->model->axis_theta.dispersion = dispersion;
+    } else    if (!strcmp(par_name, "axis_phi")) {
+        self->model->axis_phi.dispersion = dispersion;
+    } else {
+	    PyErr_SetString(CTriaxialEllipsoidModelError,
+	    	"CTriaxialEllipsoidModel.set_dispersion expects a valid parameter name.");
+		return NULL;
+	}
+
+	DispersionVisitor* visitor = new DispersionVisitor();
+	PyObject * disp_dict = PyDict_New();
+	dispersion->accept_as_source(visitor, dispersion, disp_dict);
+	PyDict_SetItemString(self->dispersion, par_name, disp_dict);
+    return Py_BuildValue("i",1);
+}
+
+
+static PyMethodDef CTriaxialEllipsoidModel_methods[] = {
+    {"run",      (PyCFunction)run     , METH_VARARGS,
+      "Evaluate the model at a given Q or Q, phi"},
+    {"runXY",      (PyCFunction)runXY     , METH_VARARGS,
+      "Evaluate the model at a given Q or Qx, Qy"},
+    {"reset",    (PyCFunction)reset   , METH_VARARGS,
+      "Reset pair correlation"},
+    {"set_dispersion",      (PyCFunction)set_dispersion     , METH_VARARGS,
+      "Set the dispersion model for a given parameter"},
+   {NULL}
+};
+
+static PyTypeObject CTriaxialEllipsoidModelType = {
+    PyObject_HEAD_INIT(NULL)
+    0,                         /*ob_size*/
+    "CTriaxialEllipsoidModel",             /*tp_name*/
+    sizeof(CTriaxialEllipsoidModel),             /*tp_basicsize*/
+    0,                         /*tp_itemsize*/
+    (destructor)CTriaxialEllipsoidModel_dealloc, /*tp_dealloc*/
+    0,                         /*tp_print*/
+    0,                         /*tp_getattr*/
+    0,                         /*tp_setattr*/
+    0,                         /*tp_compare*/
+    0,                         /*tp_repr*/
+    0,                         /*tp_as_number*/
+    0,                         /*tp_as_sequence*/
+    0,                         /*tp_as_mapping*/
+    0,                         /*tp_hash */
+    0,                         /*tp_call*/
+    0,                         /*tp_str*/
+    0,                         /*tp_getattro*/
+    0,                         /*tp_setattro*/
+    0,                         /*tp_as_buffer*/
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+    "CTriaxialEllipsoidModel objects",           /* tp_doc */
+    0,		               /* tp_traverse */
+    0,		               /* tp_clear */
+    0,		               /* tp_richcompare */
+    0,		               /* tp_weaklistoffset */
+    0,		               /* tp_iter */
+    0,		               /* tp_iternext */
+    CTriaxialEllipsoidModel_methods,             /* tp_methods */
+    CTriaxialEllipsoidModel_members,             /* tp_members */
+    0,                         /* tp_getset */
+    0,                         /* tp_base */
+    0,                         /* tp_dict */
+    0,                         /* tp_descr_get */
+    0,                         /* tp_descr_set */
+    0,                         /* tp_dictoffset */
+    (initproc)CTriaxialEllipsoidModel_init,      /* tp_init */
+    0,                         /* tp_alloc */
+    CTriaxialEllipsoidModel_new,                 /* tp_new */
+};
+
+
+static PyMethodDef module_methods[] = {
+    {NULL} 
+};
+
+/**
+ * Function used to add the model class to a module
+ * @param module: module to add the class to
+ */ 
+void addCTriaxialEllipsoidModel(PyObject *module) {
+	PyObject *d;
+	
+    if (PyType_Ready(&CTriaxialEllipsoidModelType) < 0)
+        return;
+
+    Py_INCREF(&CTriaxialEllipsoidModelType);
+    PyModule_AddObject(module, "CTriaxialEllipsoidModel", (PyObject *)&CTriaxialEllipsoidModelType);
+    
+    d = PyModule_GetDict(module);
+    CTriaxialEllipsoidModelError = PyErr_NewException("CTriaxialEllipsoidModel.error", NULL, NULL);
+    PyDict_SetItemString(d, "CTriaxialEllipsoidModelError", CTriaxialEllipsoidModelError);
+}
+
Index: sansmodels/src/sans/models/c_models/c_models.cpp
===================================================================
--- sansmodels/src/sans/models/c_models/c_models.cpp	(revision 8a487138bf42fe6104144ee6073b5989aa12bcd6)
+++ sansmodels/src/sans/models/c_models/c_models.cpp	(revision 50686972861f70ebff2c64a50118cfb6b905253a)
@@ -21,4 +21,7 @@
 void addCEllipsoidModel(PyObject *module);
 void addCEllipticalCylinderModel(PyObject *module);
+void addCTriaxialEllipsoidModel(PyObject *module);
+void addCFlexibleCylinderModel(PyObject *module);
+void addCStackedDisksModel(PyObject *module);
 
 extern "C" {
@@ -161,4 +164,7 @@
 	addCDiamCylFunc(m);
 	addCEllipticalCylinderModel(m);
+	addCTriaxialEllipsoidModel(m);
+	addCFlexibleCylinderModel(m);
+	addCStackedDisksModel(m);
 	addDisperser(m);
 	addCGaussian(m);
Index: sansmodels/src/sans/models/c_models/flexiblecylinder.cpp
===================================================================
--- sansmodels/src/sans/models/c_models/flexiblecylinder.cpp	(revision 50686972861f70ebff2c64a50118cfb6b905253a)
+++ sansmodels/src/sans/models/c_models/flexiblecylinder.cpp	(revision 50686972861f70ebff2c64a50118cfb6b905253a)
@@ -0,0 +1,186 @@
+/**
+	This software was developed by the University of Tennessee as part of the
+	Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
+	project funded by the US National Science Foundation.
+
+	If you use DANSE applications to do scientific research that leads to
+	publication, we ask that you acknowledge the use of the software with the
+	following sentence:
+
+	"This work benefited from DANSE software developed under NSF award DMR-0520547."
+
+	copyright 2008, University of Tennessee
+ */
+
+/**
+ * Scattering model classes
+ * The classes use the IGOR library found in
+ *   sansmodels/src/libigor
+ *
+ *	TODO: refactor so that we pull in the old sansmodels.c_extensions
+ *	TODO: add 2d 
+ */
+
+#include <math.h>
+#include "models.hh"
+#include "parameters.hh"
+#include <stdio.h>
+using namespace std;
+
+extern "C" {
+	#include "libCylinder.h"
+	#include "flexible_cylinder.h"
+}
+
+FlexibleCylinderModel :: FlexibleCylinderModel() {
+	scale      = Parameter(1.0);
+	length     = Parameter(1000.0, true);
+	length.set_min(0.0);
+	kuhn_length = Parameter(100.0, true);
+	kuhn_length.set_min(0.0);
+	radius  = Parameter(20.0, true);
+	radius.set_min(0.0);
+	contrast   = Parameter(5.3e-6);
+	background = Parameter(0.0001);
+	axis_theta  = Parameter(0.0, true);
+	axis_phi    = Parameter(0.0, true);
+}
+
+/**
+ * Function to evaluate 1D scattering function
+ * The NIST IGOR library is used for the actual calculation.
+ * @param q: q-value
+ * @return: function value
+ */
+double FlexibleCylinderModel :: operator()(double q) {
+	double dp[5];
+
+	// Fill parameter array for IGOR library
+	// Add the background after averaging
+	dp[0] = scale();
+	dp[1] = length();
+	dp[2] = kuhn_length();
+	dp[3] = radius();
+	dp[4] = contrast();
+	dp[5] = background();
+
+	// Get the dispersion points for the length
+	vector<WeightPoint> weights_length;
+	length.get_weights(weights_length);
+
+	// Get the dispersion points for the radius
+	vector<WeightPoint> weights_radius;
+	radius.get_weights(weights_radius);
+
+	// Perform the computation, with all weight points
+	double sum = 0.0;
+	double norm = 0.0;
+
+	// Loop over semi axis A weight points
+	for(int i=0; i< (int)weights_length.size(); i++) {
+		dp[1] = weights_length[i].value;
+
+		// Loop over semi axis B weight points
+		for(int j=0; j< (int)weights_radius.size(); j++) {
+			dp[2] = weights_radius[j].value;
+
+			sum += weights_length[i].weight
+				* weights_radius[j].weight * FlexExclVolCyl(dp, q);
+			norm += weights_length[i].weight
+					* weights_radius[j].weight;
+		}
+	}
+	return sum/norm + background();
+}
+
+/**
+ * Function to evaluate 2D scattering function
+ * @param q_x: value of Q along x
+ * @param q_y: value of Q along y
+ * @return: function value
+ */
+double FlexibleCylinderModel :: operator()(double qx, double qy) {
+	FlexibleCylinderParameters dp;
+	// Fill parameter array
+	dp.scale      = scale();
+	dp.length     = length();
+	dp.kuhn_length= kuhn_length();
+	dp.radius     = radius();
+	dp.contrast   = contrast();
+	dp.background = background();
+	dp.axis_theta  = axis_theta();
+	dp.axis_phi    = axis_phi();
+
+	// Get the dispersion points for the length
+	vector<WeightPoint> weights_length;
+	length.get_weights(weights_length);
+
+	// Get the dispersion points for the radius
+	vector<WeightPoint> weights_radius;
+	radius.get_weights(weights_radius);
+
+	// Get angular averaging for theta
+	vector<WeightPoint> weights_theta;
+	axis_theta.get_weights(weights_theta);
+
+	// Get angular averaging for phi
+	vector<WeightPoint> weights_phi;
+	axis_phi.get_weights(weights_phi);
+
+	// Perform the computation, with all weight points
+	double sum = 0.0;
+	double norm = 0.0;
+
+	// Loop over length weight points
+	for(int i=0; i< (int)weights_length.size(); i++) {
+		dp.length = weights_length[i].value;
+
+		// Loop over radius weight points
+		for(int j=0; j< (int)weights_radius.size(); j++) {
+			dp.radius = weights_radius[j].value;
+
+				// Average over theta distribution
+				for(int k=0; k< (int)weights_theta.size(); k++) {
+					dp.axis_theta = weights_theta[k].value;
+
+					// Average over phi distribution
+					for(int l=0; l <(int)weights_phi.size(); l++) {
+						dp.axis_phi = weights_phi[l].value;
+
+						double _ptvalue = weights_length[i].weight
+							* weights_radius[j].weight
+							* weights_theta[k].weight
+							* weights_phi[l].weight
+							* flexible_cylinder_analytical_2DXY(&dp, qx, qy);
+						if (weights_theta.size()>1) {
+							_ptvalue *= sin(weights_theta[k].value);
+						}
+						sum += _ptvalue;
+
+						norm += weights_length[i].weight
+							* weights_radius[j].weight
+							* weights_theta[k].weight
+							* weights_phi[l].weight;
+				}
+			}
+		}
+	}
+	// Averaging in theta needs an extra normalization
+	// factor to account for the sin(theta) term in the
+	// integration (see documentation).
+	if (weights_theta.size()>1) norm = norm / asin(1.0);
+	return sum/norm + background();
+}
+
+/**
+ * Function to evaluate 2D scattering function
+ * @param pars: parameters of the triaxial ellipsoid
+ * @param q: q-value
+ * @param phi: angle phi
+ * @return: function value
+ */
+double FlexibleCylinderModel :: evaluate_rphi(double q, double phi) {
+	double qx = q*cos(phi);
+	double qy = q*sin(phi);
+	return (*this).operator()(qx, qy);
+}
Index: sansmodels/src/sans/models/c_models/models.hh
===================================================================
--- sansmodels/src/sans/models/c_models/models.hh	(revision 8a487138bf42fe6104144ee6073b5989aa12bcd6)
+++ sansmodels/src/sans/models/c_models/models.hh	(revision 50686972861f70ebff2c64a50118cfb6b905253a)
@@ -267,3 +267,69 @@
 };
 
+class TriaxialEllipsoidModel{
+public:
+	// Model parameters
+	Parameter scale;
+	Parameter semi_axisA;
+	Parameter semi_axisB;
+	Parameter semi_axisC;
+	Parameter contrast;
+	Parameter background;
+	Parameter axis_theta;
+	Parameter axis_phi;
+	
+	// Constructor
+	TriaxialEllipsoidModel();
+
+	// Operators to get I(Q)
+	double operator()(double q);
+	double operator()(double qx, double qy);
+	double evaluate_rphi(double q, double phi);
+};
+
+class FlexibleCylinderModel{
+public:
+	// Model parameters
+	Parameter scale;
+	Parameter length;
+	Parameter kuhn_length;
+	Parameter radius;
+	Parameter contrast;
+	Parameter background;
+	Parameter axis_theta;
+	Parameter axis_phi;
+	
+	// Constructor
+	FlexibleCylinderModel();
+
+	// Operators to get I(Q)
+	double operator()(double q);
+	double operator()(double qx, double qy);
+	double evaluate_rphi(double q, double phi);
+};
+
+class StackedDisksModel{
+public:
+	// Model parameters
+	Parameter scale;
+	Parameter length;
+	Parameter radius;
+	Parameter thickness;
+	Parameter core_sld;
+	Parameter layer_sld;
+	Parameter solvent_sld;
+	Parameter nlayers;
+	Parameter spacing;
+	Parameter background;
+	Parameter axis_theta;
+	Parameter axis_phi;
+	
+	// Constructor
+	StackedDisksModel();
+
+	// Operators to get I(Q)
+	double operator()(double q);
+	double operator()(double qx, double qy);
+	double evaluate_rphi(double q, double phi);
+};
 #endif
Index: sansmodels/src/sans/models/c_models/stackeddisks.cpp
===================================================================
--- sansmodels/src/sans/models/c_models/stackeddisks.cpp	(revision 50686972861f70ebff2c64a50118cfb6b905253a)
+++ sansmodels/src/sans/models/c_models/stackeddisks.cpp	(revision 50686972861f70ebff2c64a50118cfb6b905253a)
@@ -0,0 +1,217 @@
+/**
+	This software was developed by the University of Tennessee as part of the
+	Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
+	project funded by the US National Science Foundation.
+
+	If you use DANSE applications to do scientific research that leads to
+	publication, we ask that you acknowledge the use of the software with the
+	following sentence:
+
+	"This work benefited from DANSE software developed under NSF award DMR-0520547."
+
+	copyright 2008, University of Tennessee
+ */
+
+/**
+ * Scattering model classes
+ * The classes use the IGOR library found in
+ *   sansmodels/src/libigor
+ *
+ *	TODO: refactor so that we pull in the old sansmodels.c_extensions
+ *	TODO: add 2d 
+ */
+
+#include <math.h>
+#include "models.hh"
+#include "parameters.hh"
+#include <stdio.h>
+using namespace std;
+
+extern "C" {
+	#include "libCylinder.h"
+	#include "stacked_disks.h"
+}
+
+StackedDisksModel :: StackedDisksModel() {
+	scale      = Parameter(1.0);
+	radius     = Parameter(3000.0, true);
+	radius.set_min(0.0);
+	length     = Parameter(10.0, true);
+	length.set_min(0.0);
+	thickness     = Parameter(15.0);
+	thickness.set_min(0.0);
+	core_sld = Parameter(4.0e-6);
+	layer_sld  = Parameter(-4.0e-7);
+	solvent_sld  = Parameter(5.0e-6);
+	nlayers   = Parameter(1);
+	spacing   = Parameter(0);
+	background = Parameter(0.001);
+	axis_theta  = Parameter(0.0, true);
+	axis_phi    = Parameter(0.0, true);
+}
+
+/**
+ * Function to evaluate 1D scattering function
+ * The NIST IGOR library is used for the actual calculation.
+ * @param q: q-value
+ * @return: function value
+ */
+double StackedDisksModel :: operator()(double q) {
+	double dp[10];
+
+	// Fill parameter array for IGOR library
+	// Add the background after averaging
+	dp[0] = scale();
+	dp[1] = radius();
+	dp[2] = length();
+	dp[3] = thickness();
+	dp[4] = core_sld();
+	dp[5] = layer_sld();
+	dp[6] = solvent_sld();
+	dp[7] = nlayers();
+	dp[8] = spacing();
+	dp[9] = background();
+
+	// Get the dispersion points for the length
+	vector<WeightPoint> weights_length;
+	length.get_weights(weights_length);
+
+	// Get the dispersion points for the radius
+	vector<WeightPoint> weights_radius;
+	radius.get_weights(weights_radius);
+
+	// Get the dispersion points for the thickness
+	vector<WeightPoint> weights_thickness;
+	thickness.get_weights(weights_thickness);
+
+	// Perform the computation, with all weight points
+	double sum = 0.0;
+	double norm = 0.0;
+
+	// Loop over length weight points
+	for(int i=0; i< (int)weights_length.size(); i++) {
+		dp[1] = weights_length[i].value;
+
+		// Loop over radius weight points
+		for(int j=0; j< (int)weights_radius.size(); j++) {
+			dp[2] = weights_radius[j].value;
+
+			// Loop over thickness weight points
+			for(int k=0; k< (int)weights_radius.size(); k++) {
+				dp[3] = weights_radius[k].value;
+
+				sum += weights_length[i].weight
+					* weights_radius[j].weight * weights_thickness[k].weight* StackedDiscs(dp, q);
+				norm += weights_length[i].weight
+					* weights_radius[j].weight* weights_thickness[k].weight;
+			}
+		}
+	}
+	return sum/norm + background();
+}
+
+/**
+ * Function to evaluate 2D scattering function
+ * @param q_x: value of Q along x
+ * @param q_y: value of Q along y
+ * @return: function value
+ */
+double StackedDisksModel :: operator()(double qx, double qy) {
+	StackedDisksParameters dp;
+	// Fill parameter array
+	dp.scale      = scale();
+	dp.length     = length();
+	dp.radius	  = radius();
+	dp.thickness  = thickness();
+	dp.core_sld   = core_sld();
+	dp.layer_sld  = layer_sld();
+	dp.solvent_sld= solvent_sld();
+	dp.nlayers	  = nlayers();
+	dp.spacing    = spacing();
+	dp.background = background();
+	dp.axis_theta = axis_theta();
+	dp.axis_phi   = axis_phi();
+
+	// Get the dispersion points for the length
+	vector<WeightPoint> weights_length;
+	length.get_weights(weights_length);
+
+	// Get the dispersion points for the radius
+	vector<WeightPoint> weights_radius;
+	radius.get_weights(weights_radius);
+
+	// Get the dispersion points for the thickness
+	vector<WeightPoint> weights_thickness;
+	thickness.get_weights(weights_thickness);
+
+	// Get angular averaging for theta
+	vector<WeightPoint> weights_theta;
+	axis_theta.get_weights(weights_theta);
+
+	// Get angular averaging for phi
+	vector<WeightPoint> weights_phi;
+	axis_phi.get_weights(weights_phi);
+
+	// Perform the computation, with all weight points
+	double sum = 0.0;
+	double norm = 0.0;
+
+	// Loop over length weight points
+	for(int i=0; i< (int)weights_length.size(); i++) {
+		dp.length = weights_length[i].value;
+
+		// Loop over radius weight points
+		for(int j=0; j< (int)weights_radius.size(); j++) {
+			dp.radius = weights_radius[j].value;
+
+				// Loop over thickness weight points
+				for(int k=0; k< (int)weights_thickness.size(); k++) {
+				dp.thickness = weights_thickness[k].value;
+
+					for(int l=0; l< (int)weights_theta.size(); l++) {
+					dp.axis_theta = weights_theta[l].value;
+
+						// Average over phi distribution
+						for(int m=0; m <(int)weights_phi.size(); m++) {
+							dp.axis_phi = weights_phi[m].value;
+
+							double _ptvalue = weights_length[i].weight
+								* weights_radius[j].weight
+								* weights_thickness[k].weight
+								* weights_theta[l].weight
+								* weights_phi[m].weight
+								* stacked_disks_analytical_2DXY(&dp, qx, qy);
+							if (weights_theta.size()>1) {
+								_ptvalue *= sin(weights_theta[l].value);
+							}
+							sum += _ptvalue;
+
+							norm += weights_length[i].weight
+								* weights_radius[j].weight
+								* weights_thickness[k].weight
+								* weights_theta[l].weight
+								* weights_phi[m].weight;
+						}
+				}
+			}
+		}
+	}
+	// Averaging in theta needs an extra normalization
+	// factor to account for the sin(theta) term in the
+	// integration (see documentation).
+	if (weights_theta.size()>1) norm = norm / asin(1.0);
+	return sum/norm + background();
+}
+
+/**
+ * Function to evaluate 2D scattering function
+ * @param pars: parameters of the triaxial ellipsoid
+ * @param q: q-value
+ * @param phi: angle phi
+ * @return: function value
+ */
+double StackedDisksModel :: evaluate_rphi(double q, double phi) {
+	double qx = q*cos(phi);
+	double qy = q*sin(phi);
+	return (*this).operator()(qx, qy);
+}
Index: sansmodels/src/sans/models/c_models/triaxialellipsoid.cpp
===================================================================
--- sansmodels/src/sans/models/c_models/triaxialellipsoid.cpp	(revision 50686972861f70ebff2c64a50118cfb6b905253a)
+++ sansmodels/src/sans/models/c_models/triaxialellipsoid.cpp	(revision 50686972861f70ebff2c64a50118cfb6b905253a)
@@ -0,0 +1,206 @@
+/**
+	This software was developed by the University of Tennessee as part of the
+	Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
+	project funded by the US National Science Foundation.
+
+	If you use DANSE applications to do scientific research that leads to
+	publication, we ask that you acknowledge the use of the software with the
+	following sentence:
+
+	"This work benefited from DANSE software developed under NSF award DMR-0520547."
+
+	copyright 2008, University of Tennessee
+ */
+
+/**
+ * Scattering model classes
+ * The classes use the IGOR library found in
+ *   sansmodels/src/libigor
+ *
+ *	TODO: refactor so that we pull in the old sansmodels.c_extensions
+ */
+
+#include <math.h>
+#include "models.hh"
+#include "parameters.hh"
+#include <stdio.h>
+using namespace std;
+
+extern "C" {
+	#include "libCylinder.h"
+	#include "triaxial_ellipsoid.h"
+}
+
+TriaxialEllipsoidModel :: TriaxialEllipsoidModel() {
+	scale      = Parameter(1.0);
+	semi_axisA     = Parameter(20.0, true);
+	semi_axisA.set_min(0.0);
+	semi_axisB     = Parameter(20.0, true);
+	semi_axisB.set_min(0.0);
+	semi_axisC  = Parameter(400.0, true);
+	semi_axisC.set_min(0.0);
+	contrast   = Parameter(5.3e-6);
+	background = Parameter(0.0);
+	axis_theta  = Parameter(0.0, true);
+	axis_phi    = Parameter(0.0, true);
+}
+
+/**
+ * Function to evaluate 1D scattering function
+ * The NIST IGOR library is used for the actual calculation.
+ * @param q: q-value
+ * @return: function value
+ */
+double TriaxialEllipsoidModel :: operator()(double q) {
+	double dp[5];
+
+	// Fill parameter array for IGOR library
+	// Add the background after averaging
+	dp[0] = scale();
+	dp[1] = semi_axisA();
+	dp[2] = semi_axisB();
+	dp[3] = semi_axisC();
+	dp[4] = contrast();
+	dp[5] = background();
+
+	// Get the dispersion points for the semi axis A
+	vector<WeightPoint> weights_semi_axisA;
+	semi_axisA.get_weights(weights_semi_axisA);
+
+	// Get the dispersion points for the semi axis B
+	vector<WeightPoint> weights_semi_axisB;
+	semi_axisB.get_weights(weights_semi_axisB);
+
+	// Get the dispersion points for the semi axis C
+	vector<WeightPoint> weights_semi_axisC;
+	semi_axisC.get_weights(weights_semi_axisC);
+
+	// Perform the computation, with all weight points
+	double sum = 0.0;
+	double norm = 0.0;
+
+	// Loop over semi axis A weight points
+	for(int i=0; i< (int)weights_semi_axisA.size(); i++) {
+		dp[1] = weights_semi_axisA[i].value;
+
+		// Loop over semi axis B weight points
+		for(int j=0; j< (int)weights_semi_axisB.size(); j++) {
+			dp[2] = weights_semi_axisB[j].value;
+
+			// Loop over semi axis C weight points
+			for(int k=0; k< (int)weights_semi_axisC.size(); k++) {
+				dp[3] = weights_semi_axisC[k].value;
+
+				sum += weights_semi_axisA[i].weight
+					* weights_semi_axisB[j].weight * weights_semi_axisC[k].weight* TriaxialEllipsoid(dp, q);
+				norm += weights_semi_axisA[i].weight
+					* weights_semi_axisB[j].weight * weights_semi_axisC[k].weight;
+			}
+		}
+	}
+	return sum/norm + background();
+}
+
+/**
+ * Function to evaluate 2D scattering function
+ * @param q_x: value of Q along x
+ * @param q_y: value of Q along y
+ * @return: function value
+ */
+double TriaxialEllipsoidModel :: operator()(double qx, double qy) {
+	TriaxialEllipsoidParameters dp;
+	// Fill parameter array
+	dp.scale      = scale();
+	dp.semi_axisA   = semi_axisA();
+	dp.semi_axisB     = semi_axisB();
+	dp.semi_axisC     = semi_axisC();
+	dp.contrast   = contrast();
+	dp.background = 0.0;
+	dp.axis_theta  = axis_theta();
+	dp.axis_phi    = axis_phi();
+
+	// Get the dispersion points for the semi_axis A
+	vector<WeightPoint> weights_semi_axisA;
+	semi_axisA.get_weights(weights_semi_axisA);
+
+	// Get the dispersion points for the semi_axis B
+	vector<WeightPoint> weights_semi_axisB;
+	semi_axisB.get_weights(weights_semi_axisB);
+
+	// Get the dispersion points for the semi_axis C
+	vector<WeightPoint> weights_semi_axisC;
+	semi_axisC.get_weights(weights_semi_axisC);
+
+	// Get angular averaging for theta
+	vector<WeightPoint> weights_theta;
+	axis_theta.get_weights(weights_theta);
+
+	// Get angular averaging for phi
+	vector<WeightPoint> weights_phi;
+	axis_phi.get_weights(weights_phi);
+
+	// Perform the computation, with all weight points
+	double sum = 0.0;
+	double norm = 0.0;
+
+	// Loop over semi axis A weight points
+	for(int i=0; i< (int)weights_semi_axisA.size(); i++) {
+		dp.semi_axisA = weights_semi_axisA[i].value;
+
+		// Loop over semi axis B weight points
+		for(int j=0; j< (int)weights_semi_axisB.size(); j++) {
+			dp.semi_axisB = weights_semi_axisB[j].value;
+
+			// Loop over semi axis C weight points
+			for(int k=0; k < (int)weights_semi_axisC.size(); k++) {
+			dp.semi_axisC = weights_semi_axisC[k].value;
+
+				// Average over theta distribution
+				for(int l=0; l< (int)weights_theta.size(); l++) {
+					dp.axis_theta = weights_theta[l].value;
+
+					// Average over phi distribution
+					for(int m=0; m <(int)weights_phi.size(); m++) {
+						dp.axis_phi = weights_phi[m].value;
+
+						double _ptvalue = weights_semi_axisA[i].weight
+							* weights_semi_axisB[j].weight
+							* weights_semi_axisC[k].weight
+							* weights_theta[l].weight
+							* weights_phi[m].weight
+							* triaxial_ellipsoid_analytical_2DXY(&dp, qx, qy);
+						if (weights_theta.size()>1) {
+							_ptvalue *= sin(weights_theta[k].value);
+						}
+						sum += _ptvalue;
+
+						norm += weights_semi_axisA[i].weight
+							* weights_semi_axisB[j].weight
+							* weights_semi_axisC[k].weight
+							* weights_theta[l].weight
+							* weights_phi[m].weight;
+					}
+
+				}
+			}
+		}
+	}
+	// Averaging in theta needs an extra normalization
+	// factor to account for the sin(theta) term in the
+	// integration (see documentation).
+	if (weights_theta.size()>1) norm = norm / asin(1.0);
+	return sum/norm + background();
+}
+
+/**
+ * Function to evaluate 2D scattering function
+ * @param pars: parameters of the triaxial ellipsoid
+ * @param q: q-value
+ * @param phi: angle phi
+ * @return: function value
+ */
+double TriaxialEllipsoidModel :: evaluate_rphi(double q, double phi) {
+	double qx = q*cos(phi);
+	double qy = q*sin(phi);
+	return (*this).operator()(qx, qy);
+}
