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

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 a4cd162 was 35aface, checked in by Jae Cho <jhjcho@…>, 14 years ago

addede new models and attr. non_fittable

  • Property mode set to 100644
File size: 22.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/** 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 PyMemberDef CFlexibleCylinderModel_members[] = {
124    {"params", T_OBJECT, offsetof(CFlexibleCylinderModel, params), 0,
125     "Parameters"},
126        {"dispersion", T_OBJECT, offsetof(CFlexibleCylinderModel, dispersion), 0,
127          "Dispersion parameters"},     
128    {"log", T_OBJECT, offsetof(CFlexibleCylinderModel, log), 0,
129     "Log"},
130    {NULL}  /* Sentinel */
131};
132
133/** Read double from PyObject
134    @param p PyObject
135    @return double
136*/
137double CFlexibleCylinderModel_readDouble(PyObject *p) {
138    if (PyFloat_Check(p)==1) {
139        return (double)(((PyFloatObject *)(p))->ob_fval);
140    } else if (PyInt_Check(p)==1) {
141        return (double)(((PyIntObject *)(p))->ob_ival);
142    } else if (PyLong_Check(p)==1) {
143        return (double)PyLong_AsLong(p);
144    } else {
145        return 0.0;
146    }
147}
148/**
149 * Function to call to evaluate model
150 * @param args: input numpy array q[]
151 * @return: numpy array object
152 */
153 
154static PyObject *evaluateOneDim(FlexibleCylinderModel* model, PyArrayObject *q){
155    PyArrayObject *result;
156   
157    // Check validity of array q , q must be of dimension 1, an array of double
158    if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE)
159    {
160        //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num;
161        //PyErr_SetString(PyExc_ValueError , message);
162        return NULL;
163    }
164    result = (PyArrayObject *)PyArray_FromDims(q->nd, (int *)(q->dimensions), 
165                                                                                  PyArray_DOUBLE);
166        if (result == NULL) {
167        const char * message= "Could not create result ";
168        PyErr_SetString(PyExc_RuntimeError , message);
169                return NULL;
170        }
171         for (int i = 0; i < q->dimensions[0]; i++){
172      double q_value  = *(double *)(q->data + i*q->strides[0]);
173      double *result_value = (double *)(result->data + i*result->strides[0]);
174      *result_value =(*model)(q_value);
175        }
176    return PyArray_Return(result); 
177 }
178
179 /**
180 * Function to call to evaluate model
181 * @param args: input numpy array  [x[],y[]]
182 * @return: numpy array object
183 */
184 static PyObject * evaluateTwoDimXY( FlexibleCylinderModel* model, 
185                              PyArrayObject *x, PyArrayObject *y)
186 {
187    PyArrayObject *result;
188    int i,j, x_len, y_len, dims[1];
189    //check validity of input vectors
190    if (x->nd != 1 || x->descr->type_num != PyArray_DOUBLE
191        || y->nd != 1 || y->descr->type_num != PyArray_DOUBLE
192        || y->dimensions[0] != x->dimensions[0]){
193        const char * message= "evaluateTwoDimXY  expect 2 numpy arrays";
194        PyErr_SetString(PyExc_ValueError , message); 
195        return NULL;
196    }
197   
198        if (PyArray_Check(x) && PyArray_Check(y)) {
199               
200            x_len = dims[0]= x->dimensions[0];
201        y_len = dims[0]= y->dimensions[0];
202           
203            // Make a new double matrix of same dims
204        result=(PyArrayObject *) PyArray_FromDims(1,dims,NPY_DOUBLE);
205        if (result == NULL){
206            const char * message= "Could not create result ";
207        PyErr_SetString(PyExc_RuntimeError , message);
208            return NULL;
209            }
210       
211        /* Do the calculation. */
212        for ( i=0; i< x_len; i++) {
213            double x_value = *(double *)(x->data + i*x->strides[0]);
214                    double y_value = *(double *)(y->data + i*y->strides[0]);
215                        double *result_value = (double *)(result->data +
216                              i*result->strides[0]);
217                        *result_value = (*model)(x_value, y_value);
218        }           
219        return PyArray_Return(result); 
220       
221        }else{
222                    PyErr_SetString(CFlexibleCylinderModelError, 
223                   "CFlexibleCylinderModel.evaluateTwoDimXY couldn't run.");
224                return NULL;
225                }       
226}
227/**
228 *  evalDistribution function evaluate a model function with input vector
229 *  @param args: input q as vector or [qx, qy] where qx, qy are vectors
230 *
231 */ 
232static PyObject * evalDistribution(CFlexibleCylinderModel *self, PyObject *args){
233        PyObject *qx, *qy;
234        PyArrayObject * pars;
235        int npars ,mpars;
236       
237        // Get parameters
238       
239            // Reader parameter dictionary
240    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
241    self->model->sldCyl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldCyl") );
242    self->model->length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "length") );
243    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
244    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
245    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
246    self->model->kuhn_length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "kuhn_length") );
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        }
299        PyErr_SetString(CFlexibleCylinderModelError, 
300                   "CFlexibleCylinderModel.evalDistribution couln't be run.");
301        return NULL;
302       
303}
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->sldCyl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldCyl") );
320    self->model->length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "length") );
321    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
322    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
323    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
324    self->model->kuhn_length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "kuhn_length") );
325    // Read in dispersion parameters
326    PyObject* disp_dict;
327    DispersionVisitor* visitor = new DispersionVisitor();
328    disp_dict = PyDict_GetItemString(self->dispersion, "length");
329    self->model->length.dispersion->accept_as_destination(visitor, self->model->length.dispersion, disp_dict);
330    disp_dict = PyDict_GetItemString(self->dispersion, "kuhn_length");
331    self->model->kuhn_length.dispersion->accept_as_destination(visitor, self->model->kuhn_length.dispersion, disp_dict);
332    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
333    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
334
335       
336        // Get input and determine whether we have to supply a 1D or 2D return value.
337        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
338            PyErr_SetString(CFlexibleCylinderModelError, 
339                "CFlexibleCylinderModel.run expects a q value.");
340                return NULL;
341        }
342         
343        // Check params
344        if( PyList_Check(pars)==1) {
345               
346                // Length of list should be 2 for I(q,phi)
347            npars = PyList_GET_SIZE(pars); 
348            if(npars!=2) {
349                PyErr_SetString(CFlexibleCylinderModelError, 
350                        "CFlexibleCylinderModel.run expects a double or a list of dimension 2.");
351                return NULL;
352            }
353            // We have a vector q, get the q and phi values at which
354            // to evaluate I(q,phi)
355            q_value = CFlexibleCylinderModel_readDouble(PyList_GET_ITEM(pars,0));
356            phi_value = CFlexibleCylinderModel_readDouble(PyList_GET_ITEM(pars,1));
357            // Skip zero
358            if (q_value==0) {
359                return Py_BuildValue("d",0.0);
360            }
361                return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value));
362
363        } else {
364
365                // We have a scalar q, we will evaluate I(q)
366                q_value = CFlexibleCylinderModel_readDouble(pars);             
367               
368                return Py_BuildValue("d",(*(self->model))(q_value));
369        }       
370}
371/**
372 * Function to call to calculate_ER
373 * @return: effective radius value
374 */
375static PyObject * calculate_ER(CFlexibleCylinderModel *self) {
376
377        PyObject* pars;
378        int npars;
379       
380        // Get parameters
381       
382            // Reader parameter dictionary
383    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
384    self->model->sldCyl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldCyl") );
385    self->model->length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "length") );
386    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
387    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
388    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
389    self->model->kuhn_length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "kuhn_length") );
390    // Read in dispersion parameters
391    PyObject* disp_dict;
392    DispersionVisitor* visitor = new DispersionVisitor();
393    disp_dict = PyDict_GetItemString(self->dispersion, "length");
394    self->model->length.dispersion->accept_as_destination(visitor, self->model->length.dispersion, disp_dict);
395    disp_dict = PyDict_GetItemString(self->dispersion, "kuhn_length");
396    self->model->kuhn_length.dispersion->accept_as_destination(visitor, self->model->kuhn_length.dispersion, disp_dict);
397    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
398    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
399
400               
401        return Py_BuildValue("d",(*(self->model)).calculate_ER());
402
403}
404/**
405 * Function to call to evaluate model in cartesian coordinates
406 * @param args: input q or [qx, qy]]
407 * @return: function value
408 */
409static PyObject * runXY(CFlexibleCylinderModel *self, PyObject *args) {
410        double qx_value, qy_value;
411        PyObject* pars;
412        int npars;
413       
414        // Get parameters
415       
416            // Reader parameter dictionary
417    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
418    self->model->sldCyl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldCyl") );
419    self->model->length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "length") );
420    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
421    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
422    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
423    self->model->kuhn_length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "kuhn_length") );
424    // Read in dispersion parameters
425    PyObject* disp_dict;
426    DispersionVisitor* visitor = new DispersionVisitor();
427    disp_dict = PyDict_GetItemString(self->dispersion, "length");
428    self->model->length.dispersion->accept_as_destination(visitor, self->model->length.dispersion, disp_dict);
429    disp_dict = PyDict_GetItemString(self->dispersion, "kuhn_length");
430    self->model->kuhn_length.dispersion->accept_as_destination(visitor, self->model->kuhn_length.dispersion, disp_dict);
431    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
432    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
433
434       
435        // Get input and determine whether we have to supply a 1D or 2D return value.
436        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
437            PyErr_SetString(CFlexibleCylinderModelError, 
438                "CFlexibleCylinderModel.run expects a q value.");
439                return NULL;
440        }
441         
442        // Check params
443        if( PyList_Check(pars)==1) {
444               
445                // Length of list should be 2 for I(qx, qy))
446            npars = PyList_GET_SIZE(pars); 
447            if(npars!=2) {
448                PyErr_SetString(CFlexibleCylinderModelError, 
449                        "CFlexibleCylinderModel.run expects a double or a list of dimension 2.");
450                return NULL;
451            }
452            // We have a vector q, get the qx and qy values at which
453            // to evaluate I(qx,qy)
454            qx_value = CFlexibleCylinderModel_readDouble(PyList_GET_ITEM(pars,0));
455            qy_value = CFlexibleCylinderModel_readDouble(PyList_GET_ITEM(pars,1));
456            return Py_BuildValue("d",(*(self->model))(qx_value,qy_value));
457
458        } else {
459
460                // We have a scalar q, we will evaluate I(q)
461                qx_value = CFlexibleCylinderModel_readDouble(pars);             
462               
463                return Py_BuildValue("d",(*(self->model))(qx_value));
464        }       
465}
466
467static PyObject * reset(CFlexibleCylinderModel *self, PyObject *args) {
468   
469
470    return Py_BuildValue("d",0.0);
471}
472
473static PyObject * set_dispersion(CFlexibleCylinderModel *self, PyObject *args) {
474        PyObject * disp;
475        const char * par_name;
476
477        if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
478            PyErr_SetString(CFlexibleCylinderModelError,
479                "CFlexibleCylinderModel.set_dispersion expects a DispersionModel object.");
480                return NULL;
481        }
482        void *temp = PyCObject_AsVoidPtr(disp);
483        DispersionModel * dispersion = static_cast<DispersionModel *>(temp);
484
485
486        // Ugliness necessary to go from python to C
487            // TODO: refactor this
488    if (!strcmp(par_name, "length")) {
489        self->model->length.dispersion = dispersion;
490    } else    if (!strcmp(par_name, "kuhn_length")) {
491        self->model->kuhn_length.dispersion = dispersion;
492    } else    if (!strcmp(par_name, "radius")) {
493        self->model->radius.dispersion = dispersion;
494    } else {
495            PyErr_SetString(CFlexibleCylinderModelError,
496                "CFlexibleCylinderModel.set_dispersion expects a valid parameter name.");
497                return NULL;
498        }
499
500        DispersionVisitor* visitor = new DispersionVisitor();
501        PyObject * disp_dict = PyDict_New();
502        dispersion->accept_as_source(visitor, dispersion, disp_dict);
503        PyDict_SetItemString(self->dispersion, par_name, disp_dict);
504    return Py_BuildValue("i",1);
505}
506
507
508static PyMethodDef CFlexibleCylinderModel_methods[] = {
509    {"run",      (PyCFunction)run     , METH_VARARGS,
510      "Evaluate the model at a given Q or Q, phi"},
511    {"runXY",      (PyCFunction)runXY     , METH_VARARGS,
512      "Evaluate the model at a given Q or Qx, Qy"},
513    {"calculate_ER",      (PyCFunction)calculate_ER     , METH_VARARGS,
514      "Evaluate the model at a given Q or Q, phi"},
515     
516    {"evalDistribution",  (PyCFunction)evalDistribution , METH_VARARGS,
517      "Evaluate the model at a given Q or Qx, Qy vector "},
518    {"reset",    (PyCFunction)reset   , METH_VARARGS,
519      "Reset pair correlation"},
520    {"set_dispersion",      (PyCFunction)set_dispersion     , METH_VARARGS,
521      "Set the dispersion model for a given parameter"},
522   {NULL}
523};
524
525static PyTypeObject CFlexibleCylinderModelType = {
526    PyObject_HEAD_INIT(NULL)
527    0,                         /*ob_size*/
528    "CFlexibleCylinderModel",             /*tp_name*/
529    sizeof(CFlexibleCylinderModel),             /*tp_basicsize*/
530    0,                         /*tp_itemsize*/
531    (destructor)CFlexibleCylinderModel_dealloc, /*tp_dealloc*/
532    0,                         /*tp_print*/
533    0,                         /*tp_getattr*/
534    0,                         /*tp_setattr*/
535    0,                         /*tp_compare*/
536    0,                         /*tp_repr*/
537    0,                         /*tp_as_number*/
538    0,                         /*tp_as_sequence*/
539    0,                         /*tp_as_mapping*/
540    0,                         /*tp_hash */
541    0,                         /*tp_call*/
542    0,                         /*tp_str*/
543    0,                         /*tp_getattro*/
544    0,                         /*tp_setattro*/
545    0,                         /*tp_as_buffer*/
546    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
547    "CFlexibleCylinderModel objects",           /* tp_doc */
548    0,                         /* tp_traverse */
549    0,                         /* tp_clear */
550    0,                         /* tp_richcompare */
551    0,                         /* tp_weaklistoffset */
552    0,                         /* tp_iter */
553    0,                         /* tp_iternext */
554    CFlexibleCylinderModel_methods,             /* tp_methods */
555    CFlexibleCylinderModel_members,             /* tp_members */
556    0,                         /* tp_getset */
557    0,                         /* tp_base */
558    0,                         /* tp_dict */
559    0,                         /* tp_descr_get */
560    0,                         /* tp_descr_set */
561    0,                         /* tp_dictoffset */
562    (initproc)CFlexibleCylinderModel_init,      /* tp_init */
563    0,                         /* tp_alloc */
564    CFlexibleCylinderModel_new,                 /* tp_new */
565};
566
567
568//static PyMethodDef module_methods[] = {
569//    {NULL}
570//};
571
572/**
573 * Function used to add the model class to a module
574 * @param module: module to add the class to
575 */ 
576void addCFlexibleCylinderModel(PyObject *module) {
577        PyObject *d;
578       
579    if (PyType_Ready(&CFlexibleCylinderModelType) < 0)
580        return;
581
582    Py_INCREF(&CFlexibleCylinderModelType);
583    PyModule_AddObject(module, "CFlexibleCylinderModel", (PyObject *)&CFlexibleCylinderModelType);
584   
585    d = PyModule_GetDict(module);
586    CFlexibleCylinderModelError = PyErr_NewException("CFlexibleCylinderModel.error", NULL, NULL);
587    PyDict_SetItemString(d, "CFlexibleCylinderModelError", CFlexibleCylinderModelError);
588}
589
Note: See TracBrowser for help on using the repository browser.