source: sasview/sansmodels/src/sans/models/c_models/CStackedDisksModel.cpp @ cad821b

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since cad821b was 9bd69098, checked in by Jae Cho <jhjcho@…>, 15 years ago

recompiled all due to Alina's new eval(run) function

  • Property mode set to 100644
File size: 24.6 KB
Line 
1/**
2        This software was developed by the University of Tennessee as part of the
3        Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
4        project funded by the US National Science Foundation.
5
6        If you use DANSE applications to do scientific research that leads to
7        publication, we ask that you acknowledge the use of the software with the
8        following sentence:
9
10        "This work benefited from DANSE software developed under NSF award DMR-0520547."
11
12        copyright 2008, University of Tennessee
13 */
14
15/** CStackedDisksModel
16 *
17 * C extension
18 *
19 * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY
20 *          DO NOT MODIFY THIS FILE, MODIFY stacked_disks.h
21 *          AND RE-RUN THE GENERATOR SCRIPT
22 *
23 */
24#define NO_IMPORT_ARRAY
25#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sans
26 
27extern "C" {
28#include <Python.h>
29#include <arrayobject.h>
30#include "structmember.h"
31#include <stdio.h>
32#include <stdlib.h>
33#include <math.h>
34#include <time.h>
35#include "stacked_disks.h"
36}
37
38#include "models.hh"
39#include "dispersion_visitor.hh"
40
41/// Error object for raised exceptions
42static PyObject * CStackedDisksModelError = NULL;
43
44
45// Class definition
46typedef struct {
47    PyObject_HEAD
48    /// Parameters
49    PyObject * params;
50    /// Dispersion parameters
51    PyObject * dispersion;
52    /// Underlying model object
53    StackedDisksModel * model;
54    /// Log for unit testing
55    PyObject * log;
56} CStackedDisksModel;
57
58
59static void
60CStackedDisksModel_dealloc(CStackedDisksModel* self)
61{
62    self->ob_type->tp_free((PyObject*)self);
63   
64
65}
66
67static PyObject *
68CStackedDisksModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
69{
70    CStackedDisksModel *self;
71   
72    self = (CStackedDisksModel *)type->tp_alloc(type, 0);
73   
74    return (PyObject *)self;
75}
76
77static int
78CStackedDisksModel_init(CStackedDisksModel *self, PyObject *args, PyObject *kwds)
79{
80    if (self != NULL) {
81       
82        // Create parameters
83        self->params = PyDict_New();
84        self->dispersion = PyDict_New();
85        self->model = new StackedDisksModel();
86       
87        // Initialize parameter dictionary
88        PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",0.010000));
89        PyDict_SetItemString(self->params,"axis_theta",Py_BuildValue("d",1.000000));
90        PyDict_SetItemString(self->params,"spacing",Py_BuildValue("d",0.000000));
91        PyDict_SetItemString(self->params,"nlayers",Py_BuildValue("d",1.000000));
92        PyDict_SetItemString(self->params,"layer_sld",Py_BuildValue("d",-0.000000));
93        PyDict_SetItemString(self->params,"solvent_sld",Py_BuildValue("d",0.000005));
94        PyDict_SetItemString(self->params,"thickness",Py_BuildValue("d",15.000000));
95        PyDict_SetItemString(self->params,"axis_phi",Py_BuildValue("d",1.000000));
96        PyDict_SetItemString(self->params,"length",Py_BuildValue("d",10.000000));
97        PyDict_SetItemString(self->params,"core_sld",Py_BuildValue("d",0.000004));
98        PyDict_SetItemString(self->params,"radius",Py_BuildValue("d",3000.000000));
99        PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.001000));
100        // Initialize dispersion / averaging parameter dict
101        DispersionVisitor* visitor = new DispersionVisitor();
102        PyObject * disp_dict;
103        disp_dict = PyDict_New();
104        self->model->length.dispersion->accept_as_source(visitor, self->model->length.dispersion, disp_dict);
105        PyDict_SetItemString(self->dispersion, "length", disp_dict);
106        disp_dict = PyDict_New();
107        self->model->radius.dispersion->accept_as_source(visitor, self->model->radius.dispersion, disp_dict);
108        PyDict_SetItemString(self->dispersion, "radius", disp_dict);
109        disp_dict = PyDict_New();
110        self->model->axis_theta.dispersion->accept_as_source(visitor, self->model->axis_theta.dispersion, disp_dict);
111        PyDict_SetItemString(self->dispersion, "axis_theta", disp_dict);
112        disp_dict = PyDict_New();
113        self->model->axis_phi.dispersion->accept_as_source(visitor, self->model->axis_phi.dispersion, disp_dict);
114        PyDict_SetItemString(self->dispersion, "axis_phi", disp_dict);
115
116
117         
118        // Create empty log
119        self->log = PyDict_New();
120       
121       
122
123    }
124    return 0;
125}
126
127static PyMemberDef CStackedDisksModel_members[] = {
128    {"params", T_OBJECT, offsetof(CStackedDisksModel, params), 0,
129     "Parameters"},
130        {"dispersion", T_OBJECT, offsetof(CStackedDisksModel, dispersion), 0,
131          "Dispersion parameters"},     
132    {"log", T_OBJECT, offsetof(CStackedDisksModel, log), 0,
133     "Log"},
134    {NULL}  /* Sentinel */
135};
136
137/** Read double from PyObject
138    @param p PyObject
139    @return double
140*/
141double CStackedDisksModel_readDouble(PyObject *p) {
142    if (PyFloat_Check(p)==1) {
143        return (double)(((PyFloatObject *)(p))->ob_fval);
144    } else if (PyInt_Check(p)==1) {
145        return (double)(((PyIntObject *)(p))->ob_ival);
146    } else if (PyLong_Check(p)==1) {
147        return (double)PyLong_AsLong(p);
148    } else {
149        return 0.0;
150    }
151}
152/**
153 * Function to call to evaluate model
154 * @param args: input numpy array q[]
155 * @return: numpy array object
156 */
157 
158static PyObject *evaluateOneDim(StackedDisksModel* model, PyArrayObject *q){
159    PyArrayObject *result;
160   
161    // Check validity of array q , q must be of dimension 1, an array of double
162    if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE)
163    {
164        //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num;
165        //PyErr_SetString(PyExc_ValueError , message);
166        return NULL;
167    }
168    result = (PyArrayObject *)PyArray_FromDims(q->nd, (int *)(q->dimensions), 
169                                                                                  PyArray_DOUBLE);
170        if (result == NULL) {
171        const char * message= "Could not create result ";
172        PyErr_SetString(PyExc_RuntimeError , message);
173                return NULL;
174        }
175         for (int i = 0; i < q->dimensions[0]; i++){
176      double q_value  = *(double *)(q->data + i*q->strides[0]);
177      double *result_value = (double *)(result->data + i*result->strides[0]);
178      *result_value =(*model)(q_value);
179        }
180    return PyArray_Return(result); 
181 }
182/**
183 * Function to call to evaluate model
184 * @param args: input numpy array  [q[],phi[]]
185 * @return: numpy array object
186 */
187static PyObject * evaluateTwoDim( StackedDisksModel* model, 
188                              PyArrayObject *q, PyArrayObject *phi)
189 {
190    PyArrayObject *result;
191    //check validity of input vectors
192    if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE
193        || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE
194        || phi->dimensions[0] != q->dimensions[0]){
195     
196        //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num;
197        PyErr_SetString(PyExc_ValueError ,"wrong input"); 
198        return NULL;
199    }
200        result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE);
201
202        if (result == NULL){
203            const char * message= "Could not create result ";
204        PyErr_SetString(PyExc_RuntimeError , message);
205            return NULL;
206        }
207       
208    for (int i = 0; i < q->dimensions[0]; i++) {
209      double q_value = *(double *)(q->data + i*q->strides[0]);
210      double phi_value = *(double *)(phi->data + i*phi->strides[0]);
211      double *result_value = (double *)(result->data + i*result->strides[0]);
212      if (q_value == 0)
213          *result_value = 0.0;
214      else
215          *result_value = model->evaluate_rphi(q_value, phi_value);
216    }
217    return PyArray_Return(result); 
218 }
219 /**
220 * Function to call to evaluate model
221 * @param args: input numpy array  [x[],y[]]
222 * @return: numpy array object
223 */
224 static PyObject * evaluateTwoDimXY( StackedDisksModel* model, 
225                              PyArrayObject *x, PyArrayObject *y)
226 {
227    PyArrayObject *result;
228    int i,j, x_len, y_len, dims[2];
229    //check validity of input vectors
230    if (x->nd != 2 || x->descr->type_num != PyArray_DOUBLE
231        || y->nd != 2 || y->descr->type_num != PyArray_DOUBLE
232        || y->dimensions[1] != x->dimensions[0]){
233        const char * message= "evaluateTwoDimXY  expect 2 numpy arrays";
234        PyErr_SetString(PyExc_ValueError , message); 
235        return NULL;
236    }
237   
238        if (PyArray_Check(x) && PyArray_Check(y)) {
239            x_len = dims[0]= x->dimensions[0];
240        y_len = dims[1]= y->dimensions[1];
241           
242            // Make a new double matrix of same dims
243        result=(PyArrayObject *) PyArray_FromDims(2,dims,NPY_DOUBLE);
244        if (result == NULL){
245            const char * message= "Could not create result ";
246        PyErr_SetString(PyExc_RuntimeError , message);
247            return NULL;
248            }
249       
250        /* Do the calculation. */
251        for ( i=0; i< x_len; i++) {
252            for ( j=0; j< y_len; j++) {
253                double x_value = *(double *)(x->data + i*x->strides[0]);
254                    double y_value = *(double *)(y->data + j*y->strides[1]);
255                        double *result_value = (double *)(result->data +
256                              i*result->strides[0] + j*result->strides[1]);
257                        *result_value = (*model)(x_value, y_value);
258            }           
259        }
260        return PyArray_Return(result); 
261       
262        }else{
263                    PyErr_SetString(CStackedDisksModelError, 
264                   "CStackedDisksModel.evaluateTwoDimXY couldn't run.");
265                return NULL;
266                }       
267}
268/**
269 *  evalDistribution function evaluate a model function with input vector
270 *  @param args: input q as vector or [qx, qy] where qx, qy are vectors
271 *
272 */ 
273static PyObject * evalDistribution(CStackedDisksModel *self, PyObject *args){
274        PyObject *qx, *qy;
275        PyArrayObject * pars;
276        int npars ,mpars;
277       
278        // Get parameters
279       
280            // Reader parameter dictionary
281    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
282    self->model->axis_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_theta") );
283    self->model->spacing = PyFloat_AsDouble( PyDict_GetItemString(self->params, "spacing") );
284    self->model->nlayers = PyFloat_AsDouble( PyDict_GetItemString(self->params, "nlayers") );
285    self->model->layer_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "layer_sld") );
286    self->model->solvent_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "solvent_sld") );
287    self->model->thickness = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thickness") );
288    self->model->axis_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_phi") );
289    self->model->length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "length") );
290    self->model->core_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "core_sld") );
291    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
292    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
293    // Read in dispersion parameters
294    PyObject* disp_dict;
295    DispersionVisitor* visitor = new DispersionVisitor();
296    disp_dict = PyDict_GetItemString(self->dispersion, "length");
297    self->model->length.dispersion->accept_as_destination(visitor, self->model->length.dispersion, disp_dict);
298    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
299    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
300    disp_dict = PyDict_GetItemString(self->dispersion, "axis_theta");
301    self->model->axis_theta.dispersion->accept_as_destination(visitor, self->model->axis_theta.dispersion, disp_dict);
302    disp_dict = PyDict_GetItemString(self->dispersion, "axis_phi");
303    self->model->axis_phi.dispersion->accept_as_destination(visitor, self->model->axis_phi.dispersion, disp_dict);
304
305       
306        // Get input and determine whether we have to supply a 1D or 2D return value.
307        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
308            PyErr_SetString(CStackedDisksModelError, 
309                "CStackedDisksModel.evalDistribution expects a q value.");
310                return NULL;
311        }
312    // Check params
313       
314    if(PyArray_Check(pars)==1) {
315               
316            // Length of list should 1 or 2
317            npars = pars->nd; 
318            if(npars==1) {
319                // input is a numpy array
320                if (PyArray_Check(pars)) {
321                        return evaluateOneDim(self->model, (PyArrayObject*)pars); 
322                    }
323                }else{
324                    PyErr_SetString(CStackedDisksModelError, 
325                   "CStackedDisksModel.evalDistribution expect numpy array of one dimension.");
326                return NULL;
327                }
328    }else if( PyList_Check(pars)==1) {
329        // Length of list should be 2 for I(qx,qy)
330            mpars = PyList_GET_SIZE(pars); 
331            if(mpars!=2) {
332                PyErr_SetString(CStackedDisksModelError, 
333                        "CStackedDisksModel.evalDistribution expects a list of dimension 2.");
334                return NULL;
335            }
336             qx = PyList_GET_ITEM(pars,0);
337             qy = PyList_GET_ITEM(pars,1);
338             if (PyArray_Check(qx) && PyArray_Check(qy)) {
339                 return evaluateTwoDimXY(self->model, (PyArrayObject*)qx,
340                           (PyArrayObject*)qy);
341                 }else{
342                    PyErr_SetString(CStackedDisksModelError, 
343                   "CStackedDisksModel.evalDistribution expect 2 numpy arrays in list.");
344                return NULL;
345             }
346        }else{
347            PyErr_SetString(CStackedDisksModelError, 
348                   "CStackedDisksModel.evalDistribution couln't be run.");
349            return NULL;
350        }
351}
352
353/**
354 * Function to call to evaluate model
355 * @param args: input q or [q,phi]
356 * @return: function value
357 */
358static PyObject * run(CStackedDisksModel *self, PyObject *args) {
359        double q_value, phi_value;
360        PyObject* pars;
361        int npars;
362       
363        // Get parameters
364       
365            // Reader parameter dictionary
366    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
367    self->model->axis_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_theta") );
368    self->model->spacing = PyFloat_AsDouble( PyDict_GetItemString(self->params, "spacing") );
369    self->model->nlayers = PyFloat_AsDouble( PyDict_GetItemString(self->params, "nlayers") );
370    self->model->layer_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "layer_sld") );
371    self->model->solvent_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "solvent_sld") );
372    self->model->thickness = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thickness") );
373    self->model->axis_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_phi") );
374    self->model->length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "length") );
375    self->model->core_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "core_sld") );
376    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
377    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
378    // Read in dispersion parameters
379    PyObject* disp_dict;
380    DispersionVisitor* visitor = new DispersionVisitor();
381    disp_dict = PyDict_GetItemString(self->dispersion, "length");
382    self->model->length.dispersion->accept_as_destination(visitor, self->model->length.dispersion, disp_dict);
383    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
384    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
385    disp_dict = PyDict_GetItemString(self->dispersion, "axis_theta");
386    self->model->axis_theta.dispersion->accept_as_destination(visitor, self->model->axis_theta.dispersion, disp_dict);
387    disp_dict = PyDict_GetItemString(self->dispersion, "axis_phi");
388    self->model->axis_phi.dispersion->accept_as_destination(visitor, self->model->axis_phi.dispersion, disp_dict);
389
390       
391        // Get input and determine whether we have to supply a 1D or 2D return value.
392        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
393            PyErr_SetString(CStackedDisksModelError, 
394                "CStackedDisksModel.run expects a q value.");
395                return NULL;
396        }
397         
398        // Check params
399        if( PyList_Check(pars)==1) {
400               
401                // Length of list should be 2 for I(q,phi)
402            npars = PyList_GET_SIZE(pars); 
403            if(npars!=2) {
404                PyErr_SetString(CStackedDisksModelError, 
405                        "CStackedDisksModel.run expects a double or a list of dimension 2.");
406                return NULL;
407            }
408            // We have a vector q, get the q and phi values at which
409            // to evaluate I(q,phi)
410            q_value = CStackedDisksModel_readDouble(PyList_GET_ITEM(pars,0));
411            phi_value = CStackedDisksModel_readDouble(PyList_GET_ITEM(pars,1));
412            // Skip zero
413            if (q_value==0) {
414                return Py_BuildValue("d",0.0);
415            }
416                return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value));
417
418        } else {
419
420                // We have a scalar q, we will evaluate I(q)
421                q_value = CStackedDisksModel_readDouble(pars);         
422               
423                return Py_BuildValue("d",(*(self->model))(q_value));
424        }       
425}
426
427/**
428 * Function to call to evaluate model in cartesian coordinates
429 * @param args: input q or [qx, qy]]
430 * @return: function value
431 */
432static PyObject * runXY(CStackedDisksModel *self, PyObject *args) {
433        double qx_value, qy_value;
434        PyObject* pars;
435        int npars;
436       
437        // Get parameters
438       
439            // Reader parameter dictionary
440    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
441    self->model->axis_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_theta") );
442    self->model->spacing = PyFloat_AsDouble( PyDict_GetItemString(self->params, "spacing") );
443    self->model->nlayers = PyFloat_AsDouble( PyDict_GetItemString(self->params, "nlayers") );
444    self->model->layer_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "layer_sld") );
445    self->model->solvent_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "solvent_sld") );
446    self->model->thickness = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thickness") );
447    self->model->axis_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_phi") );
448    self->model->length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "length") );
449    self->model->core_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "core_sld") );
450    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
451    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
452    // Read in dispersion parameters
453    PyObject* disp_dict;
454    DispersionVisitor* visitor = new DispersionVisitor();
455    disp_dict = PyDict_GetItemString(self->dispersion, "length");
456    self->model->length.dispersion->accept_as_destination(visitor, self->model->length.dispersion, disp_dict);
457    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
458    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
459    disp_dict = PyDict_GetItemString(self->dispersion, "axis_theta");
460    self->model->axis_theta.dispersion->accept_as_destination(visitor, self->model->axis_theta.dispersion, disp_dict);
461    disp_dict = PyDict_GetItemString(self->dispersion, "axis_phi");
462    self->model->axis_phi.dispersion->accept_as_destination(visitor, self->model->axis_phi.dispersion, disp_dict);
463
464       
465        // Get input and determine whether we have to supply a 1D or 2D return value.
466        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
467            PyErr_SetString(CStackedDisksModelError, 
468                "CStackedDisksModel.run expects a q value.");
469                return NULL;
470        }
471         
472        // Check params
473        if( PyList_Check(pars)==1) {
474               
475                // Length of list should be 2 for I(qx, qy))
476            npars = PyList_GET_SIZE(pars); 
477            if(npars!=2) {
478                PyErr_SetString(CStackedDisksModelError, 
479                        "CStackedDisksModel.run expects a double or a list of dimension 2.");
480                return NULL;
481            }
482            // We have a vector q, get the qx and qy values at which
483            // to evaluate I(qx,qy)
484            qx_value = CStackedDisksModel_readDouble(PyList_GET_ITEM(pars,0));
485            qy_value = CStackedDisksModel_readDouble(PyList_GET_ITEM(pars,1));
486            return Py_BuildValue("d",(*(self->model))(qx_value,qy_value));
487
488        } else {
489
490                // We have a scalar q, we will evaluate I(q)
491                qx_value = CStackedDisksModel_readDouble(pars);         
492               
493                return Py_BuildValue("d",(*(self->model))(qx_value));
494        }       
495}
496
497static PyObject * reset(CStackedDisksModel *self, PyObject *args) {
498   
499
500    return Py_BuildValue("d",0.0);
501}
502
503static PyObject * set_dispersion(CStackedDisksModel *self, PyObject *args) {
504        PyObject * disp;
505        const char * par_name;
506
507        if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
508            PyErr_SetString(CStackedDisksModelError,
509                "CStackedDisksModel.set_dispersion expects a DispersionModel object.");
510                return NULL;
511        }
512        void *temp = PyCObject_AsVoidPtr(disp);
513        DispersionModel * dispersion = static_cast<DispersionModel *>(temp);
514
515
516        // Ugliness necessary to go from python to C
517            // TODO: refactor this
518    if (!strcmp(par_name, "length")) {
519        self->model->length.dispersion = dispersion;
520    } else    if (!strcmp(par_name, "radius")) {
521        self->model->radius.dispersion = dispersion;
522    } else    if (!strcmp(par_name, "axis_theta")) {
523        self->model->axis_theta.dispersion = dispersion;
524    } else    if (!strcmp(par_name, "axis_phi")) {
525        self->model->axis_phi.dispersion = dispersion;
526    } else {
527            PyErr_SetString(CStackedDisksModelError,
528                "CStackedDisksModel.set_dispersion expects a valid parameter name.");
529                return NULL;
530        }
531
532        DispersionVisitor* visitor = new DispersionVisitor();
533        PyObject * disp_dict = PyDict_New();
534        dispersion->accept_as_source(visitor, dispersion, disp_dict);
535        PyDict_SetItemString(self->dispersion, par_name, disp_dict);
536    return Py_BuildValue("i",1);
537}
538
539
540static PyMethodDef CStackedDisksModel_methods[] = {
541    {"run",      (PyCFunction)run     , METH_VARARGS,
542      "Evaluate the model at a given Q or Q, phi"},
543    {"runXY",      (PyCFunction)runXY     , METH_VARARGS,
544      "Evaluate the model at a given Q or Qx, Qy"},
545     
546    {"evalDistribution",  (PyCFunction)evalDistribution , METH_VARARGS,
547      "Evaluate the model at a given Q or Qx, Qy vector "},
548    {"reset",    (PyCFunction)reset   , METH_VARARGS,
549      "Reset pair correlation"},
550    {"set_dispersion",      (PyCFunction)set_dispersion     , METH_VARARGS,
551      "Set the dispersion model for a given parameter"},
552   {NULL}
553};
554
555static PyTypeObject CStackedDisksModelType = {
556    PyObject_HEAD_INIT(NULL)
557    0,                         /*ob_size*/
558    "CStackedDisksModel",             /*tp_name*/
559    sizeof(CStackedDisksModel),             /*tp_basicsize*/
560    0,                         /*tp_itemsize*/
561    (destructor)CStackedDisksModel_dealloc, /*tp_dealloc*/
562    0,                         /*tp_print*/
563    0,                         /*tp_getattr*/
564    0,                         /*tp_setattr*/
565    0,                         /*tp_compare*/
566    0,                         /*tp_repr*/
567    0,                         /*tp_as_number*/
568    0,                         /*tp_as_sequence*/
569    0,                         /*tp_as_mapping*/
570    0,                         /*tp_hash */
571    0,                         /*tp_call*/
572    0,                         /*tp_str*/
573    0,                         /*tp_getattro*/
574    0,                         /*tp_setattro*/
575    0,                         /*tp_as_buffer*/
576    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
577    "CStackedDisksModel objects",           /* tp_doc */
578    0,                         /* tp_traverse */
579    0,                         /* tp_clear */
580    0,                         /* tp_richcompare */
581    0,                         /* tp_weaklistoffset */
582    0,                         /* tp_iter */
583    0,                         /* tp_iternext */
584    CStackedDisksModel_methods,             /* tp_methods */
585    CStackedDisksModel_members,             /* tp_members */
586    0,                         /* tp_getset */
587    0,                         /* tp_base */
588    0,                         /* tp_dict */
589    0,                         /* tp_descr_get */
590    0,                         /* tp_descr_set */
591    0,                         /* tp_dictoffset */
592    (initproc)CStackedDisksModel_init,      /* tp_init */
593    0,                         /* tp_alloc */
594    CStackedDisksModel_new,                 /* tp_new */
595};
596
597
598//static PyMethodDef module_methods[] = {
599//    {NULL}
600//};
601
602/**
603 * Function used to add the model class to a module
604 * @param module: module to add the class to
605 */ 
606void addCStackedDisksModel(PyObject *module) {
607        PyObject *d;
608       
609    if (PyType_Ready(&CStackedDisksModelType) < 0)
610        return;
611
612    Py_INCREF(&CStackedDisksModelType);
613    PyModule_AddObject(module, "CStackedDisksModel", (PyObject *)&CStackedDisksModelType);
614   
615    d = PyModule_GetDict(module);
616    CStackedDisksModelError = PyErr_NewException("CStackedDisksModel.error", NULL, NULL);
617    PyDict_SetItemString(d, "CStackedDisksModelError", CStackedDisksModelError);
618}
619
Note: See TracBrowser for help on using the repository browser.