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

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 b1c3295 was b1c3295, checked in by Mathieu Doucet <doucetm@…>, 12 years ago

Re #4 This should clean up a whole bunch of C++ warnings.

  • Property mode set to 100644
File size: 22.7 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/** 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 */
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 "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{
62    Py_DECREF(self->params);
63    Py_DECREF(self->dispersion);
64    Py_DECREF(self->log);
65    delete self->model;
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.000000000000));
93        PyDict_SetItemString(self->params,"sldCyl",Py_BuildValue("d",0.000001000000));
94        PyDict_SetItemString(self->params,"length",Py_BuildValue("d",1000.000000000000));
95        PyDict_SetItemString(self->params,"sldSolv",Py_BuildValue("d",0.000006300000));
96        PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.000100000000));
97        PyDict_SetItemString(self->params,"radius",Py_BuildValue("d",20.000000000000));
98        PyDict_SetItemString(self->params,"kuhn_length",Py_BuildValue("d",100.000000000000));
99        // Initialize dispersion / averaging parameter dict
100        DispersionVisitor* visitor = new DispersionVisitor();
101        PyObject * disp_dict;
102        disp_dict = PyDict_New();
103        self->model->length.dispersion->accept_as_source(visitor, self->model->length.dispersion, disp_dict);
104        PyDict_SetItemString(self->dispersion, "length", disp_dict);
105        disp_dict = PyDict_New();
106        self->model->kuhn_length.dispersion->accept_as_source(visitor, self->model->kuhn_length.dispersion, disp_dict);
107        PyDict_SetItemString(self->dispersion, "kuhn_length", disp_dict);
108        disp_dict = PyDict_New();
109        self->model->radius.dispersion->accept_as_source(visitor, self->model->radius.dispersion, disp_dict);
110        PyDict_SetItemString(self->dispersion, "radius", disp_dict);
111
112
113         
114        // Create empty log
115        self->log = PyDict_New();
116       
117       
118
119    }
120    return 0;
121}
122
123static char name_params[] = "params";
124static char def_params[] = "Parameters";
125static char name_dispersion[] = "dispersion";
126static char def_dispersion[] = "Dispersion parameters";
127static char name_log[] = "log";
128static char def_log[] = "Log";
129
130static PyMemberDef CFlexibleCylinderModel_members[] = {
131    {name_params, T_OBJECT, offsetof(CFlexibleCylinderModel, params), 0, def_params},
132        {name_dispersion, T_OBJECT, offsetof(CFlexibleCylinderModel, dispersion), 0, def_dispersion},     
133    {name_log, T_OBJECT, offsetof(CFlexibleCylinderModel, log), 0, def_log},
134    {NULL}  /* Sentinel */
135};
136
137/** Read double from PyObject
138    @param p PyObject
139    @return double
140*/
141double CFlexibleCylinderModel_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(FlexibleCylinderModel* 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 /**
184 * Function to call to evaluate model
185 * @param args: input numpy array  [x[],y[]]
186 * @return: numpy array object
187 */
188 static PyObject * evaluateTwoDimXY( FlexibleCylinderModel* model, 
189                              PyArrayObject *x, PyArrayObject *y)
190 {
191    PyArrayObject *result;
192    int i,j, x_len, y_len, dims[1];
193    //check validity of input vectors
194    if (x->nd != 1 || x->descr->type_num != PyArray_DOUBLE
195        || y->nd != 1 || y->descr->type_num != PyArray_DOUBLE
196        || y->dimensions[0] != x->dimensions[0]){
197        const char * message= "evaluateTwoDimXY  expect 2 numpy arrays";
198        PyErr_SetString(PyExc_ValueError , message); 
199        return NULL;
200    }
201   
202        if (PyArray_Check(x) && PyArray_Check(y)) {
203               
204            x_len = dims[0]= x->dimensions[0];
205        y_len = dims[0]= y->dimensions[0];
206           
207            // Make a new double matrix of same dims
208        result=(PyArrayObject *) PyArray_FromDims(1,dims,NPY_DOUBLE);
209        if (result == NULL){
210            const char * message= "Could not create result ";
211        PyErr_SetString(PyExc_RuntimeError , message);
212            return NULL;
213            }
214       
215        /* Do the calculation. */
216        for ( i=0; i< x_len; i++) {
217            double x_value = *(double *)(x->data + i*x->strides[0]);
218                    double y_value = *(double *)(y->data + i*y->strides[0]);
219                        double *result_value = (double *)(result->data +
220                              i*result->strides[0]);
221                        *result_value = (*model)(x_value, y_value);
222        }           
223        return PyArray_Return(result); 
224       
225        }else{
226                    PyErr_SetString(CFlexibleCylinderModelError, 
227                   "CFlexibleCylinderModel.evaluateTwoDimXY couldn't run.");
228                return NULL;
229                }       
230}
231/**
232 *  evalDistribution function evaluate a model function with input vector
233 *  @param args: input q as vector or [qx, qy] where qx, qy are vectors
234 *
235 */ 
236static PyObject * evalDistribution(CFlexibleCylinderModel *self, PyObject *args){
237        PyObject *qx, *qy;
238        PyArrayObject * pars;
239        int npars ,mpars;
240       
241        // Get parameters
242       
243            // Reader parameter dictionary
244    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
245    self->model->sldCyl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldCyl") );
246    self->model->length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "length") );
247    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
248    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
249    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
250    self->model->kuhn_length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "kuhn_length") );
251    // Read in dispersion parameters
252    PyObject* disp_dict;
253    DispersionVisitor* visitor = new DispersionVisitor();
254    disp_dict = PyDict_GetItemString(self->dispersion, "length");
255    self->model->length.dispersion->accept_as_destination(visitor, self->model->length.dispersion, disp_dict);
256    disp_dict = PyDict_GetItemString(self->dispersion, "kuhn_length");
257    self->model->kuhn_length.dispersion->accept_as_destination(visitor, self->model->kuhn_length.dispersion, disp_dict);
258    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
259    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
260
261       
262        // Get input and determine whether we have to supply a 1D or 2D return value.
263        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
264            PyErr_SetString(CFlexibleCylinderModelError, 
265                "CFlexibleCylinderModel.evalDistribution expects a q value.");
266                return NULL;
267        }
268    // Check params
269       
270    if(PyArray_Check(pars)==1) {
271               
272            // Length of list should 1 or 2
273            npars = pars->nd; 
274            if(npars==1) {
275                // input is a numpy array
276                if (PyArray_Check(pars)) {
277                        return evaluateOneDim(self->model, (PyArrayObject*)pars); 
278                    }
279                }else{
280                    PyErr_SetString(CFlexibleCylinderModelError, 
281                   "CFlexibleCylinderModel.evalDistribution expect numpy array of one dimension.");
282                return NULL;
283                }
284    }else if( PyList_Check(pars)==1) {
285        // Length of list should be 2 for I(qx,qy)
286            mpars = PyList_GET_SIZE(pars); 
287            if(mpars!=2) {
288                PyErr_SetString(CFlexibleCylinderModelError, 
289                        "CFlexibleCylinderModel.evalDistribution expects a list of dimension 2.");
290                return NULL;
291            }
292             qx = PyList_GET_ITEM(pars,0);
293             qy = PyList_GET_ITEM(pars,1);
294             if (PyArray_Check(qx) && PyArray_Check(qy)) {
295                 return evaluateTwoDimXY(self->model, (PyArrayObject*)qx,
296                           (PyArrayObject*)qy);
297                 }else{
298                    PyErr_SetString(CFlexibleCylinderModelError, 
299                   "CFlexibleCylinderModel.evalDistribution expect 2 numpy arrays in list.");
300                return NULL;
301             }
302        }
303        PyErr_SetString(CFlexibleCylinderModelError, 
304                   "CFlexibleCylinderModel.evalDistribution couln't be run.");
305        return NULL;
306       
307}
308
309/**
310 * Function to call to evaluate model
311 * @param args: input q or [q,phi]
312 * @return: function value
313 */
314static PyObject * run(CFlexibleCylinderModel *self, PyObject *args) {
315        double q_value, phi_value;
316        PyObject* pars;
317        int npars;
318       
319        // Get parameters
320       
321            // Reader parameter dictionary
322    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
323    self->model->sldCyl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldCyl") );
324    self->model->length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "length") );
325    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
326    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
327    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
328    self->model->kuhn_length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "kuhn_length") );
329    // Read in dispersion parameters
330    PyObject* disp_dict;
331    DispersionVisitor* visitor = new DispersionVisitor();
332    disp_dict = PyDict_GetItemString(self->dispersion, "length");
333    self->model->length.dispersion->accept_as_destination(visitor, self->model->length.dispersion, disp_dict);
334    disp_dict = PyDict_GetItemString(self->dispersion, "kuhn_length");
335    self->model->kuhn_length.dispersion->accept_as_destination(visitor, self->model->kuhn_length.dispersion, disp_dict);
336    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
337    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
338
339       
340        // Get input and determine whether we have to supply a 1D or 2D return value.
341        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
342            PyErr_SetString(CFlexibleCylinderModelError, 
343                "CFlexibleCylinderModel.run expects a q value.");
344                return NULL;
345        }
346         
347        // Check params
348        if( PyList_Check(pars)==1) {
349               
350                // Length of list should be 2 for I(q,phi)
351            npars = PyList_GET_SIZE(pars); 
352            if(npars!=2) {
353                PyErr_SetString(CFlexibleCylinderModelError, 
354                        "CFlexibleCylinderModel.run expects a double or a list of dimension 2.");
355                return NULL;
356            }
357            // We have a vector q, get the q and phi values at which
358            // to evaluate I(q,phi)
359            q_value = CFlexibleCylinderModel_readDouble(PyList_GET_ITEM(pars,0));
360            phi_value = CFlexibleCylinderModel_readDouble(PyList_GET_ITEM(pars,1));
361            // Skip zero
362            if (q_value==0) {
363                return Py_BuildValue("d",0.0);
364            }
365                return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value));
366
367        } else {
368
369                // We have a scalar q, we will evaluate I(q)
370                q_value = CFlexibleCylinderModel_readDouble(pars);             
371               
372                return Py_BuildValue("d",(*(self->model))(q_value));
373        }       
374}
375/**
376 * Function to call to calculate_ER
377 * @return: effective radius value
378 */
379static PyObject * calculate_ER(CFlexibleCylinderModel *self) {
380
381        PyObject* pars;
382        int npars;
383       
384        // Get parameters
385       
386            // Reader parameter dictionary
387    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
388    self->model->sldCyl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldCyl") );
389    self->model->length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "length") );
390    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
391    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
392    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
393    self->model->kuhn_length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "kuhn_length") );
394    // Read in dispersion parameters
395    PyObject* disp_dict;
396    DispersionVisitor* visitor = new DispersionVisitor();
397    disp_dict = PyDict_GetItemString(self->dispersion, "length");
398    self->model->length.dispersion->accept_as_destination(visitor, self->model->length.dispersion, disp_dict);
399    disp_dict = PyDict_GetItemString(self->dispersion, "kuhn_length");
400    self->model->kuhn_length.dispersion->accept_as_destination(visitor, self->model->kuhn_length.dispersion, disp_dict);
401    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
402    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
403
404               
405        return Py_BuildValue("d",(*(self->model)).calculate_ER());
406
407}
408/**
409 * Function to call to evaluate model in cartesian coordinates
410 * @param args: input q or [qx, qy]]
411 * @return: function value
412 */
413static PyObject * runXY(CFlexibleCylinderModel *self, PyObject *args) {
414        double qx_value, qy_value;
415        PyObject* pars;
416        int npars;
417       
418        // Get parameters
419       
420            // Reader parameter dictionary
421    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
422    self->model->sldCyl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldCyl") );
423    self->model->length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "length") );
424    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
425    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
426    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
427    self->model->kuhn_length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "kuhn_length") );
428    // Read in dispersion parameters
429    PyObject* disp_dict;
430    DispersionVisitor* visitor = new DispersionVisitor();
431    disp_dict = PyDict_GetItemString(self->dispersion, "length");
432    self->model->length.dispersion->accept_as_destination(visitor, self->model->length.dispersion, disp_dict);
433    disp_dict = PyDict_GetItemString(self->dispersion, "kuhn_length");
434    self->model->kuhn_length.dispersion->accept_as_destination(visitor, self->model->kuhn_length.dispersion, disp_dict);
435    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
436    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
437
438       
439        // Get input and determine whether we have to supply a 1D or 2D return value.
440        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
441            PyErr_SetString(CFlexibleCylinderModelError, 
442                "CFlexibleCylinderModel.run expects a q value.");
443                return NULL;
444        }
445         
446        // Check params
447        if( PyList_Check(pars)==1) {
448               
449                // Length of list should be 2 for I(qx, qy))
450            npars = PyList_GET_SIZE(pars); 
451            if(npars!=2) {
452                PyErr_SetString(CFlexibleCylinderModelError, 
453                        "CFlexibleCylinderModel.run expects a double or a list of dimension 2.");
454                return NULL;
455            }
456            // We have a vector q, get the qx and qy values at which
457            // to evaluate I(qx,qy)
458            qx_value = CFlexibleCylinderModel_readDouble(PyList_GET_ITEM(pars,0));
459            qy_value = CFlexibleCylinderModel_readDouble(PyList_GET_ITEM(pars,1));
460            return Py_BuildValue("d",(*(self->model))(qx_value,qy_value));
461
462        } else {
463
464                // We have a scalar q, we will evaluate I(q)
465                qx_value = CFlexibleCylinderModel_readDouble(pars);             
466               
467                return Py_BuildValue("d",(*(self->model))(qx_value));
468        }       
469}
470
471static PyObject * reset(CFlexibleCylinderModel *self, PyObject *args) {
472   
473
474    return Py_BuildValue("d",0.0);
475}
476
477static PyObject * set_dispersion(CFlexibleCylinderModel *self, PyObject *args) {
478        PyObject * disp;
479        const char * par_name;
480
481        if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
482            PyErr_SetString(CFlexibleCylinderModelError,
483                "CFlexibleCylinderModel.set_dispersion expects a DispersionModel object.");
484                return NULL;
485        }
486        void *temp = PyCObject_AsVoidPtr(disp);
487        DispersionModel * dispersion = static_cast<DispersionModel *>(temp);
488
489
490        // Ugliness necessary to go from python to C
491            // TODO: refactor this
492    if (!strcmp(par_name, "length")) {
493        self->model->length.dispersion = dispersion;
494    } else    if (!strcmp(par_name, "kuhn_length")) {
495        self->model->kuhn_length.dispersion = dispersion;
496    } else    if (!strcmp(par_name, "radius")) {
497        self->model->radius.dispersion = dispersion;
498    } else {
499            PyErr_SetString(CFlexibleCylinderModelError,
500                "CFlexibleCylinderModel.set_dispersion expects a valid parameter name.");
501                return NULL;
502        }
503
504        DispersionVisitor* visitor = new DispersionVisitor();
505        PyObject * disp_dict = PyDict_New();
506        dispersion->accept_as_source(visitor, dispersion, disp_dict);
507        PyDict_SetItemString(self->dispersion, par_name, disp_dict);
508    return Py_BuildValue("i",1);
509}
510
511
512static PyMethodDef CFlexibleCylinderModel_methods[] = {
513    {"run",      (PyCFunction)run     , METH_VARARGS,
514      "Evaluate the model at a given Q or Q, phi"},
515    {"runXY",      (PyCFunction)runXY     , METH_VARARGS,
516      "Evaluate the model at a given Q or Qx, Qy"},
517    {"calculate_ER",      (PyCFunction)calculate_ER     , METH_VARARGS,
518      "Evaluate the model at a given Q or Q, phi"},
519     
520    {"evalDistribution",  (PyCFunction)evalDistribution , METH_VARARGS,
521      "Evaluate the model at a given Q or Qx, Qy vector "},
522    {"reset",    (PyCFunction)reset   , METH_VARARGS,
523      "Reset pair correlation"},
524    {"set_dispersion",      (PyCFunction)set_dispersion     , METH_VARARGS,
525      "Set the dispersion model for a given parameter"},
526   {NULL}
527};
528
529static PyTypeObject CFlexibleCylinderModelType = {
530    PyObject_HEAD_INIT(NULL)
531    0,                         /*ob_size*/
532    "CFlexibleCylinderModel",             /*tp_name*/
533    sizeof(CFlexibleCylinderModel),             /*tp_basicsize*/
534    0,                         /*tp_itemsize*/
535    (destructor)CFlexibleCylinderModel_dealloc, /*tp_dealloc*/
536    0,                         /*tp_print*/
537    0,                         /*tp_getattr*/
538    0,                         /*tp_setattr*/
539    0,                         /*tp_compare*/
540    0,                         /*tp_repr*/
541    0,                         /*tp_as_number*/
542    0,                         /*tp_as_sequence*/
543    0,                         /*tp_as_mapping*/
544    0,                         /*tp_hash */
545    0,                         /*tp_call*/
546    0,                         /*tp_str*/
547    0,                         /*tp_getattro*/
548    0,                         /*tp_setattro*/
549    0,                         /*tp_as_buffer*/
550    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
551    "CFlexibleCylinderModel objects",           /* tp_doc */
552    0,                         /* tp_traverse */
553    0,                         /* tp_clear */
554    0,                         /* tp_richcompare */
555    0,                         /* tp_weaklistoffset */
556    0,                         /* tp_iter */
557    0,                         /* tp_iternext */
558    CFlexibleCylinderModel_methods,             /* tp_methods */
559    CFlexibleCylinderModel_members,             /* tp_members */
560    0,                         /* tp_getset */
561    0,                         /* tp_base */
562    0,                         /* tp_dict */
563    0,                         /* tp_descr_get */
564    0,                         /* tp_descr_set */
565    0,                         /* tp_dictoffset */
566    (initproc)CFlexibleCylinderModel_init,      /* tp_init */
567    0,                         /* tp_alloc */
568    CFlexibleCylinderModel_new,                 /* tp_new */
569};
570
571
572//static PyMethodDef module_methods[] = {
573//    {NULL}
574//};
575
576/**
577 * Function used to add the model class to a module
578 * @param module: module to add the class to
579 */ 
580void addCFlexibleCylinderModel(PyObject *module) {
581        PyObject *d;
582       
583    if (PyType_Ready(&CFlexibleCylinderModelType) < 0)
584        return;
585
586    Py_INCREF(&CFlexibleCylinderModelType);
587    PyModule_AddObject(module, "CFlexibleCylinderModel", (PyObject *)&CFlexibleCylinderModelType);
588   
589    d = PyModule_GetDict(module);
590    CFlexibleCylinderModelError = PyErr_NewException("CFlexibleCylinderModel.error", NULL, NULL);
591    PyDict_SetItemString(d, "CFlexibleCylinderModelError", CFlexibleCylinderModelError);
592}
593
Note: See TracBrowser for help on using the repository browser.