source: sasview/sansmodels/src/sans/models/c_models/CHollowCylinderModel.cpp @ 1d67243

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