source: sasview/sansmodels/src/sans/models/c_models/CFlexibleCylinderModel.cpp @ 2e38ebb

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 2e38ebb was 71e2de7, checked in by Gervaise Alina <gervyh@…>, 15 years ago

change destructor for models

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