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

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 1d67243 was 975ec8e, checked in by Jae Cho <jhjcho@…>, 15 years ago

working on 2D models. Still need smore corrections and unit tests.

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