source: sasview/sansmodels/src/sans/models/c_models/CPearlNecklaceModel.cpp @ 0da56f5

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 0da56f5 was 463eb76e, checked in by Jae Cho <jhjcho@…>, 13 years ago

implementation of pearlneckclace model: need utest and doc

  • Property mode set to 100644
File size: 22.5 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/** CPearlNecklaceModel
16 *
17 * C extension
18 *
19 * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY
20 *          DO NOT MODIFY THIS FILE, MODIFY pearlnecklace.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 "pearlnecklace.h"
36}
37
38#include "models.hh"
39#include "dispersion_visitor.hh"
40
41/// Error object for raised exceptions
42static PyObject * CPearlNecklaceModelError = 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    PearlNecklaceModel * model;
54    /// Log for unit testing
55    PyObject * log;
56} CPearlNecklaceModel;
57
58
59static void
60CPearlNecklaceModel_dealloc(CPearlNecklaceModel* 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 *
72CPearlNecklaceModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
73{
74    CPearlNecklaceModel *self;
75   
76    self = (CPearlNecklaceModel *)type->tp_alloc(type, 0);
77   
78    return (PyObject *)self;
79}
80
81static int
82CPearlNecklaceModel_init(CPearlNecklaceModel *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 PearlNecklaceModel();
90       
91        // Initialize parameter dictionary
92        PyDict_SetItemString(self->params,"num_pearls",Py_BuildValue("d",3.000000000000));
93        PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",1.000000000000));
94        PyDict_SetItemString(self->params,"thick_string",Py_BuildValue("d",2.500000000000));
95        PyDict_SetItemString(self->params,"sld_string",Py_BuildValue("d",0.000001000000));
96        PyDict_SetItemString(self->params,"edge_separation",Py_BuildValue("d",350.000000000000));
97        PyDict_SetItemString(self->params,"sld_pearl",Py_BuildValue("d",0.000001000000));
98        PyDict_SetItemString(self->params,"radius",Py_BuildValue("d",80.000000000000));
99        PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.000000000000));
100        PyDict_SetItemString(self->params,"sld_solv",Py_BuildValue("d",0.000006300000));
101        // Initialize dispersion / averaging parameter dict
102        DispersionVisitor* visitor = new DispersionVisitor();
103        PyObject * disp_dict;
104        disp_dict = PyDict_New();
105        self->model->radius.dispersion->accept_as_source(visitor, self->model->radius.dispersion, disp_dict);
106        PyDict_SetItemString(self->dispersion, "radius", disp_dict);
107        disp_dict = PyDict_New();
108        self->model->edge_separation.dispersion->accept_as_source(visitor, self->model->edge_separation.dispersion, disp_dict);
109        PyDict_SetItemString(self->dispersion, "edge_separation", 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 CPearlNecklaceModel_members[] = {
123    {"params", T_OBJECT, offsetof(CPearlNecklaceModel, params), 0,
124     "Parameters"},
125        {"dispersion", T_OBJECT, offsetof(CPearlNecklaceModel, dispersion), 0,
126          "Dispersion parameters"},     
127    {"log", T_OBJECT, offsetof(CPearlNecklaceModel, log), 0,
128     "Log"},
129    {NULL}  /* Sentinel */
130};
131
132/** Read double from PyObject
133    @param p PyObject
134    @return double
135*/
136double CPearlNecklaceModel_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}
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(PearlNecklaceModel* 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 }
177
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( PearlNecklaceModel* model, 
184                              PyArrayObject *x, PyArrayObject *y)
185 {
186    PyArrayObject *result;
187    int i,j, x_len, y_len, dims[1];
188    //check validity of input vectors
189    if (x->nd != 1 || x->descr->type_num != PyArray_DOUBLE
190        || y->nd != 1 || y->descr->type_num != PyArray_DOUBLE
191        || y->dimensions[0] != 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)) {
198               
199            x_len = dims[0]= x->dimensions[0];
200        y_len = dims[0]= y->dimensions[0];
201           
202            // Make a new double matrix of same dims
203        result=(PyArrayObject *) PyArray_FromDims(1,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. */
211        for ( i=0; i< x_len; i++) {
212            double x_value = *(double *)(x->data + i*x->strides[0]);
213                    double y_value = *(double *)(y->data + i*y->strides[0]);
214                        double *result_value = (double *)(result->data +
215                              i*result->strides[0]);
216                        *result_value = (*model)(x_value, y_value);
217        }           
218        return PyArray_Return(result); 
219       
220        }else{
221                    PyErr_SetString(CPearlNecklaceModelError, 
222                   "CPearlNecklaceModel.evaluateTwoDimXY couldn't run.");
223                return NULL;
224                }       
225}
226/**
227 *  evalDistribution function evaluate a model function with input vector
228 *  @param args: input q as vector or [qx, qy] where qx, qy are vectors
229 *
230 */ 
231static PyObject * evalDistribution(CPearlNecklaceModel *self, PyObject *args){
232        PyObject *qx, *qy;
233        PyArrayObject * pars;
234        int npars ,mpars;
235       
236        // Get parameters
237       
238            // Reader parameter dictionary
239    self->model->num_pearls = PyFloat_AsDouble( PyDict_GetItemString(self->params, "num_pearls") );
240    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
241    self->model->thick_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_string") );
242    self->model->sld_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_string") );
243    self->model->edge_separation = PyFloat_AsDouble( PyDict_GetItemString(self->params, "edge_separation") );
244    self->model->sld_pearl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_pearl") );
245    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
246    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
247    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
248    // Read in dispersion parameters
249    PyObject* disp_dict;
250    DispersionVisitor* visitor = new DispersionVisitor();
251    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
252    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
253    disp_dict = PyDict_GetItemString(self->dispersion, "edge_separation");
254    self->model->edge_separation.dispersion->accept_as_destination(visitor, self->model->edge_separation.dispersion, disp_dict);
255
256       
257        // Get input and determine whether we have to supply a 1D or 2D return value.
258        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
259            PyErr_SetString(CPearlNecklaceModelError, 
260                "CPearlNecklaceModel.evalDistribution expects a q value.");
261                return NULL;
262        }
263    // Check params
264       
265    if(PyArray_Check(pars)==1) {
266               
267            // Length of list should 1 or 2
268            npars = pars->nd; 
269            if(npars==1) {
270                // input is a numpy array
271                if (PyArray_Check(pars)) {
272                        return evaluateOneDim(self->model, (PyArrayObject*)pars); 
273                    }
274                }else{
275                    PyErr_SetString(CPearlNecklaceModelError, 
276                   "CPearlNecklaceModel.evalDistribution expect numpy array of one dimension.");
277                return NULL;
278                }
279    }else if( PyList_Check(pars)==1) {
280        // Length of list should be 2 for I(qx,qy)
281            mpars = PyList_GET_SIZE(pars); 
282            if(mpars!=2) {
283                PyErr_SetString(CPearlNecklaceModelError, 
284                        "CPearlNecklaceModel.evalDistribution expects a list of dimension 2.");
285                return NULL;
286            }
287             qx = PyList_GET_ITEM(pars,0);
288             qy = PyList_GET_ITEM(pars,1);
289             if (PyArray_Check(qx) && PyArray_Check(qy)) {
290                 return evaluateTwoDimXY(self->model, (PyArrayObject*)qx,
291                           (PyArrayObject*)qy);
292                 }else{
293                    PyErr_SetString(CPearlNecklaceModelError, 
294                   "CPearlNecklaceModel.evalDistribution expect 2 numpy arrays in list.");
295                return NULL;
296             }
297        }
298        PyErr_SetString(CPearlNecklaceModelError, 
299                   "CPearlNecklaceModel.evalDistribution couln't be run.");
300        return NULL;
301       
302}
303
304/**
305 * Function to call to evaluate model
306 * @param args: input q or [q,phi]
307 * @return: function value
308 */
309static PyObject * run(CPearlNecklaceModel *self, PyObject *args) {
310        double q_value, phi_value;
311        PyObject* pars;
312        int npars;
313       
314        // Get parameters
315       
316            // Reader parameter dictionary
317    self->model->num_pearls = PyFloat_AsDouble( PyDict_GetItemString(self->params, "num_pearls") );
318    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
319    self->model->thick_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_string") );
320    self->model->sld_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_string") );
321    self->model->edge_separation = PyFloat_AsDouble( PyDict_GetItemString(self->params, "edge_separation") );
322    self->model->sld_pearl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_pearl") );
323    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
324    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
325    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
326    // Read in dispersion parameters
327    PyObject* disp_dict;
328    DispersionVisitor* visitor = new DispersionVisitor();
329    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
330    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
331    disp_dict = PyDict_GetItemString(self->dispersion, "edge_separation");
332    self->model->edge_separation.dispersion->accept_as_destination(visitor, self->model->edge_separation.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(CPearlNecklaceModelError, 
338                "CPearlNecklaceModel.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(CPearlNecklaceModelError, 
349                        "CPearlNecklaceModel.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 = CPearlNecklaceModel_readDouble(PyList_GET_ITEM(pars,0));
355            phi_value = CPearlNecklaceModel_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 = CPearlNecklaceModel_readDouble(pars);         
366               
367                return Py_BuildValue("d",(*(self->model))(q_value));
368        }       
369}
370/**
371 * Function to call to calculate_ER
372 * @return: effective radius value
373 */
374static PyObject * calculate_ER(CPearlNecklaceModel *self) {
375
376        PyObject* pars;
377        int npars;
378       
379        // Get parameters
380       
381            // Reader parameter dictionary
382    self->model->num_pearls = PyFloat_AsDouble( PyDict_GetItemString(self->params, "num_pearls") );
383    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
384    self->model->thick_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_string") );
385    self->model->sld_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_string") );
386    self->model->edge_separation = PyFloat_AsDouble( PyDict_GetItemString(self->params, "edge_separation") );
387    self->model->sld_pearl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_pearl") );
388    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
389    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
390    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
391    // Read in dispersion parameters
392    PyObject* disp_dict;
393    DispersionVisitor* visitor = new DispersionVisitor();
394    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
395    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
396    disp_dict = PyDict_GetItemString(self->dispersion, "edge_separation");
397    self->model->edge_separation.dispersion->accept_as_destination(visitor, self->model->edge_separation.dispersion, disp_dict);
398
399               
400        return Py_BuildValue("d",(*(self->model)).calculate_ER());
401
402}
403/**
404 * Function to call to evaluate model in cartesian coordinates
405 * @param args: input q or [qx, qy]]
406 * @return: function value
407 */
408static PyObject * runXY(CPearlNecklaceModel *self, PyObject *args) {
409        double qx_value, qy_value;
410        PyObject* pars;
411        int npars;
412       
413        // Get parameters
414       
415            // Reader parameter dictionary
416    self->model->num_pearls = PyFloat_AsDouble( PyDict_GetItemString(self->params, "num_pearls") );
417    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
418    self->model->thick_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_string") );
419    self->model->sld_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_string") );
420    self->model->edge_separation = PyFloat_AsDouble( PyDict_GetItemString(self->params, "edge_separation") );
421    self->model->sld_pearl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_pearl") );
422    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
423    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
424    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
425    // Read in dispersion parameters
426    PyObject* disp_dict;
427    DispersionVisitor* visitor = new DispersionVisitor();
428    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
429    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
430    disp_dict = PyDict_GetItemString(self->dispersion, "edge_separation");
431    self->model->edge_separation.dispersion->accept_as_destination(visitor, self->model->edge_separation.dispersion, disp_dict);
432
433       
434        // Get input and determine whether we have to supply a 1D or 2D return value.
435        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
436            PyErr_SetString(CPearlNecklaceModelError, 
437                "CPearlNecklaceModel.run expects a q value.");
438                return NULL;
439        }
440         
441        // Check params
442        if( PyList_Check(pars)==1) {
443               
444                // Length of list should be 2 for I(qx, qy))
445            npars = PyList_GET_SIZE(pars); 
446            if(npars!=2) {
447                PyErr_SetString(CPearlNecklaceModelError, 
448                        "CPearlNecklaceModel.run expects a double or a list of dimension 2.");
449                return NULL;
450            }
451            // We have a vector q, get the qx and qy values at which
452            // to evaluate I(qx,qy)
453            qx_value = CPearlNecklaceModel_readDouble(PyList_GET_ITEM(pars,0));
454            qy_value = CPearlNecklaceModel_readDouble(PyList_GET_ITEM(pars,1));
455            return Py_BuildValue("d",(*(self->model))(qx_value,qy_value));
456
457        } else {
458
459                // We have a scalar q, we will evaluate I(q)
460                qx_value = CPearlNecklaceModel_readDouble(pars);               
461               
462                return Py_BuildValue("d",(*(self->model))(qx_value));
463        }       
464}
465
466static PyObject * reset(CPearlNecklaceModel *self, PyObject *args) {
467   
468
469    return Py_BuildValue("d",0.0);
470}
471
472static PyObject * set_dispersion(CPearlNecklaceModel *self, PyObject *args) {
473        PyObject * disp;
474        const char * par_name;
475
476        if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
477            PyErr_SetString(CPearlNecklaceModelError,
478                "CPearlNecklaceModel.set_dispersion expects a DispersionModel object.");
479                return NULL;
480        }
481        void *temp = PyCObject_AsVoidPtr(disp);
482        DispersionModel * dispersion = static_cast<DispersionModel *>(temp);
483
484
485        // Ugliness necessary to go from python to C
486            // TODO: refactor this
487    if (!strcmp(par_name, "radius")) {
488        self->model->radius.dispersion = dispersion;
489    } else    if (!strcmp(par_name, "edge_separation")) {
490        self->model->edge_separation.dispersion = dispersion;
491    } else {
492            PyErr_SetString(CPearlNecklaceModelError,
493                "CPearlNecklaceModel.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 CPearlNecklaceModel_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"},
510    {"calculate_ER",      (PyCFunction)calculate_ER     , METH_VARARGS,
511      "Evaluate the model at a given Q or Q, phi"},
512     
513    {"evalDistribution",  (PyCFunction)evalDistribution , METH_VARARGS,
514      "Evaluate the model at a given Q or Qx, Qy vector "},
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 CPearlNecklaceModelType = {
523    PyObject_HEAD_INIT(NULL)
524    0,                         /*ob_size*/
525    "CPearlNecklaceModel",             /*tp_name*/
526    sizeof(CPearlNecklaceModel),             /*tp_basicsize*/
527    0,                         /*tp_itemsize*/
528    (destructor)CPearlNecklaceModel_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    "CPearlNecklaceModel 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    CPearlNecklaceModel_methods,             /* tp_methods */
552    CPearlNecklaceModel_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)CPearlNecklaceModel_init,      /* tp_init */
560    0,                         /* tp_alloc */
561    CPearlNecklaceModel_new,                 /* tp_new */
562};
563
564
565//static PyMethodDef module_methods[] = {
566//    {NULL}
567//};
568
569/**
570 * Function used to add the model class to a module
571 * @param module: module to add the class to
572 */ 
573void addCPearlNecklaceModel(PyObject *module) {
574        PyObject *d;
575       
576    if (PyType_Ready(&CPearlNecklaceModelType) < 0)
577        return;
578
579    Py_INCREF(&CPearlNecklaceModelType);
580    PyModule_AddObject(module, "CPearlNecklaceModel", (PyObject *)&CPearlNecklaceModelType);
581   
582    d = PyModule_GetDict(module);
583    CPearlNecklaceModelError = PyErr_NewException("CPearlNecklaceModel.error", NULL, NULL);
584    PyDict_SetItemString(d, "CPearlNecklaceModelError", CPearlNecklaceModelError);
585}
586
Note: See TracBrowser for help on using the repository browser.