source: sasview/src/sans/models/c_extension/python_wrapper/generated/CTeubnerStreyModel.cpp @ 400155b

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 400155b was 400155b, checked in by gonzalezm, 9 years ago

Implementing request from ticket 261 - default number of bins in Annulus [Phi View] is now 36 and the first bin is now centered at 0 degrees

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