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

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 01de557 was 0b082f3, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

Re #7 Enable openmp for all models

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