source: sasview/src/sans/models/c_extension/python_wrapper/generated/CRaspBerryModel.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: 23.0 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/** CRaspBerryModel
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\raspberry.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 "raspberry.h"
39#include "dispersion_visitor.hh"
40
41/// Error object for raised exceptions
42static PyObject * CRaspBerryModelError = 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    RaspBerryModel * model;
54    /// Log for unit testing
55    PyObject * log;
56} CRaspBerryModel;
57
58
59static void
60CRaspBerryModel_dealloc(CRaspBerryModel* 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 *
72CRaspBerryModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
73{
74    CRaspBerryModel *self;
75   
76    self = (CRaspBerryModel *)type->tp_alloc(type, 0);
77   
78    return (PyObject *)self;
79}
80
81static int
82CRaspBerryModel_init(CRaspBerryModel *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 RaspBerryModel();
91
92        // Initialize parameter dictionary
93        PyDict_SetItemString(self->params,"volf_Ssph",Py_BuildValue("d",0.005000000000));
94        PyDict_SetItemString(self->params,"sld_Ssph",Py_BuildValue("d",0.000003500000));
95        PyDict_SetItemString(self->params,"radius_Ssph",Py_BuildValue("d",100.000000000000));
96        PyDict_SetItemString(self->params,"delta_Ssph",Py_BuildValue("d",0.000000000000));
97        PyDict_SetItemString(self->params,"radius_Lsph",Py_BuildValue("d",5000.000000000000));
98        PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.000000000000));
99        PyDict_SetItemString(self->params,"surfrac_Ssph",Py_BuildValue("d",0.400000000000));
100        PyDict_SetItemString(self->params,"sld_Lsph",Py_BuildValue("d",-0.000000400000));
101        PyDict_SetItemString(self->params,"volf_Lsph",Py_BuildValue("d",0.050000000000));
102        PyDict_SetItemString(self->params,"sld_solv",Py_BuildValue("d",0.000006300000));
103        // Initialize dispersion / averaging parameter dict
104        DispersionVisitor* visitor = new DispersionVisitor();
105        PyObject * disp_dict;
106        disp_dict = PyDict_New();
107        self->model->radius_Lsph.dispersion->accept_as_source(visitor, self->model->radius_Lsph.dispersion, disp_dict);
108        PyDict_SetItemString(self->dispersion, "radius_Lsph", disp_dict);
109
110
111         
112        // Create empty log
113        self->log = PyDict_New();
114       
115       
116
117    }
118    return 0;
119}
120
121static char name_params[] = "params";
122static char def_params[] = "Parameters";
123static char name_dispersion[] = "dispersion";
124static char def_dispersion[] = "Dispersion parameters";
125static char name_log[] = "log";
126static char def_log[] = "Log";
127
128static PyMemberDef CRaspBerryModel_members[] = {
129    {name_params, T_OBJECT, offsetof(CRaspBerryModel, params), 0, def_params},
130        {name_dispersion, T_OBJECT, offsetof(CRaspBerryModel, dispersion), 0, def_dispersion},     
131    {name_log, T_OBJECT, offsetof(CRaspBerryModel, log), 0, def_log},
132    {NULL}  /* Sentinel */
133};
134
135/** Read double from PyObject
136    @param p PyObject
137    @return double
138*/
139double CRaspBerryModel_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(RaspBerryModel* 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), PyArray_DOUBLE);
167        if (result == NULL) {
168        const char * message= "Could not create result ";
169        PyErr_SetString(PyExc_RuntimeError , message);
170                return NULL;
171        }
172#pragma omp parallel for
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( RaspBerryModel* model, 
187                              PyArrayObject *x, PyArrayObject *y)
188 {
189    PyArrayObject *result;
190    int x_len, y_len, dims[1];
191    //check validity of input vectors
192    if (x->nd != 1 || x->descr->type_num != PyArray_DOUBLE
193        || y->nd != 1 || y->descr->type_num != PyArray_DOUBLE
194        || y->dimensions[0] != 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               
202            x_len = dims[0]= x->dimensions[0];
203        y_len = dims[0]= y->dimensions[0];
204           
205            // Make a new double matrix of same dims
206        result=(PyArrayObject *) PyArray_FromDims(1,dims,NPY_DOUBLE);
207        if (result == NULL){
208            const char * message= "Could not create result ";
209        PyErr_SetString(PyExc_RuntimeError , message);
210            return NULL;
211            }
212       
213        /* Do the calculation. */
214#pragma omp parallel for
215        for (int i=0; i< x_len; i++) {
216            double x_value = *(double *)(x->data + i*x->strides[0]);
217                    double y_value = *(double *)(y->data + i*y->strides[0]);
218                        double *result_value = (double *)(result->data +
219                              i*result->strides[0]);
220                        *result_value = (*model)(x_value, y_value);
221        }           
222        return PyArray_Return(result); 
223       
224        }else{
225                    PyErr_SetString(CRaspBerryModelError, 
226                   "CRaspBerryModel.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(CRaspBerryModel *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->volf_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "volf_Ssph") );
244    self->model->sld_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_Ssph") );
245    self->model->radius_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius_Ssph") );
246    self->model->delta_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "delta_Ssph") );
247    self->model->radius_Lsph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius_Lsph") );
248    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
249    self->model->surfrac_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "surfrac_Ssph") );
250    self->model->sld_Lsph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_Lsph") );
251    self->model->volf_Lsph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "volf_Lsph") );
252    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
253    // Read in dispersion parameters
254    PyObject* disp_dict;
255    DispersionVisitor* visitor = new DispersionVisitor();
256    disp_dict = PyDict_GetItemString(self->dispersion, "radius_Lsph");
257    self->model->radius_Lsph.dispersion->accept_as_destination(visitor, self->model->radius_Lsph.dispersion, disp_dict);
258
259       
260        // Get input and determine whether we have to supply a 1D or 2D return value.
261        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
262            PyErr_SetString(CRaspBerryModelError, 
263                "CRaspBerryModel.evalDistribution expects a q value.");
264                return NULL;
265        }
266    // Check params
267       
268    if(PyArray_Check(pars)==1) {
269               
270            // Length of list should 1 or 2
271            npars = pars->nd; 
272            if(npars==1) {
273                // input is a numpy array
274                if (PyArray_Check(pars)) {
275                        return evaluateOneDim(self->model, (PyArrayObject*)pars); 
276                    }
277                }else{
278                    PyErr_SetString(CRaspBerryModelError, 
279                   "CRaspBerryModel.evalDistribution expect numpy array of one dimension.");
280                return NULL;
281                }
282    }else if( PyList_Check(pars)==1) {
283        // Length of list should be 2 for I(qx,qy)
284            mpars = PyList_GET_SIZE(pars); 
285            if(mpars!=2) {
286                PyErr_SetString(CRaspBerryModelError, 
287                        "CRaspBerryModel.evalDistribution expects a list of dimension 2.");
288                return NULL;
289            }
290             qx = PyList_GET_ITEM(pars,0);
291             qy = PyList_GET_ITEM(pars,1);
292             if (PyArray_Check(qx) && PyArray_Check(qy)) {
293                 return evaluateTwoDimXY(self->model, (PyArrayObject*)qx,
294                           (PyArrayObject*)qy);
295                 }else{
296                    PyErr_SetString(CRaspBerryModelError, 
297                   "CRaspBerryModel.evalDistribution expect 2 numpy arrays in list.");
298                return NULL;
299             }
300        }
301        PyErr_SetString(CRaspBerryModelError, 
302                   "CRaspBerryModel.evalDistribution couln't be run.");
303        return NULL;
304       
305}
306
307/**
308 * Function to call to evaluate model
309 * @param args: input q or [q,phi]
310 * @return: function value
311 */
312static PyObject * run(CRaspBerryModel *self, PyObject *args) {
313        double q_value, phi_value;
314        PyObject* pars;
315        int npars;
316       
317        // Get parameters
318       
319            // Reader parameter dictionary
320    self->model->volf_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "volf_Ssph") );
321    self->model->sld_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_Ssph") );
322    self->model->radius_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius_Ssph") );
323    self->model->delta_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "delta_Ssph") );
324    self->model->radius_Lsph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius_Lsph") );
325    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
326    self->model->surfrac_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "surfrac_Ssph") );
327    self->model->sld_Lsph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_Lsph") );
328    self->model->volf_Lsph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "volf_Lsph") );
329    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
330    // Read in dispersion parameters
331    PyObject* disp_dict;
332    DispersionVisitor* visitor = new DispersionVisitor();
333    disp_dict = PyDict_GetItemString(self->dispersion, "radius_Lsph");
334    self->model->radius_Lsph.dispersion->accept_as_destination(visitor, self->model->radius_Lsph.dispersion, disp_dict);
335
336       
337        // Get input and determine whether we have to supply a 1D or 2D return value.
338        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
339            PyErr_SetString(CRaspBerryModelError, 
340                "CRaspBerryModel.run expects a q value.");
341                return NULL;
342        }
343         
344        // Check params
345        if( PyList_Check(pars)==1) {
346               
347                // Length of list should be 2 for I(q,phi)
348            npars = PyList_GET_SIZE(pars); 
349            if(npars!=2) {
350                PyErr_SetString(CRaspBerryModelError, 
351                        "CRaspBerryModel.run expects a double or a list of dimension 2.");
352                return NULL;
353            }
354            // We have a vector q, get the q and phi values at which
355            // to evaluate I(q,phi)
356            q_value = CRaspBerryModel_readDouble(PyList_GET_ITEM(pars,0));
357            phi_value = CRaspBerryModel_readDouble(PyList_GET_ITEM(pars,1));
358            // Skip zero
359            if (q_value==0) {
360                return Py_BuildValue("d",0.0);
361            }
362                return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value));
363
364        } else {
365
366                // We have a scalar q, we will evaluate I(q)
367                q_value = CRaspBerryModel_readDouble(pars);             
368               
369                return Py_BuildValue("d",(*(self->model))(q_value));
370        }       
371}
372/**
373 * Function to call to calculate_ER
374 * @return: effective radius value
375 */
376static PyObject * calculate_ER(CRaspBerryModel *self) {
377
378        // Get parameters
379       
380            // Reader parameter dictionary
381    self->model->volf_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "volf_Ssph") );
382    self->model->sld_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_Ssph") );
383    self->model->radius_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius_Ssph") );
384    self->model->delta_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "delta_Ssph") );
385    self->model->radius_Lsph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius_Lsph") );
386    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
387    self->model->surfrac_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "surfrac_Ssph") );
388    self->model->sld_Lsph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_Lsph") );
389    self->model->volf_Lsph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "volf_Lsph") );
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_Lsph");
395    self->model->radius_Lsph.dispersion->accept_as_destination(visitor, self->model->radius_Lsph.dispersion, disp_dict);
396
397               
398        return Py_BuildValue("d",(*(self->model)).calculate_ER());
399
400}
401/**
402 * Function to call to cal the ratio shell volume/ total volume
403 * @return: the ratio shell volume/ total volume
404 */
405static PyObject * calculate_VR(CRaspBerryModel *self) {
406
407        // Get parameters
408       
409            // Reader parameter dictionary
410    self->model->volf_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "volf_Ssph") );
411    self->model->sld_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_Ssph") );
412    self->model->radius_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius_Ssph") );
413    self->model->delta_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "delta_Ssph") );
414    self->model->radius_Lsph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius_Lsph") );
415    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
416    self->model->surfrac_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "surfrac_Ssph") );
417    self->model->sld_Lsph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_Lsph") );
418    self->model->volf_Lsph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "volf_Lsph") );
419    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
420    // Read in dispersion parameters
421    PyObject* disp_dict;
422    DispersionVisitor* visitor = new DispersionVisitor();
423    disp_dict = PyDict_GetItemString(self->dispersion, "radius_Lsph");
424    self->model->radius_Lsph.dispersion->accept_as_destination(visitor, self->model->radius_Lsph.dispersion, disp_dict);
425
426               
427        return Py_BuildValue("d",(*(self->model)).calculate_VR());
428
429}
430/**
431 * Function to call to evaluate model in cartesian coordinates
432 * @param args: input q or [qx, qy]]
433 * @return: function value
434 */
435static PyObject * runXY(CRaspBerryModel *self, PyObject *args) {
436        double qx_value, qy_value;
437        PyObject* pars;
438        int npars;
439       
440        // Get parameters
441       
442            // Reader parameter dictionary
443    self->model->volf_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "volf_Ssph") );
444    self->model->sld_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_Ssph") );
445    self->model->radius_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius_Ssph") );
446    self->model->delta_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "delta_Ssph") );
447    self->model->radius_Lsph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius_Lsph") );
448    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
449    self->model->surfrac_Ssph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "surfrac_Ssph") );
450    self->model->sld_Lsph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_Lsph") );
451    self->model->volf_Lsph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "volf_Lsph") );
452    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
453    // Read in dispersion parameters
454    PyObject* disp_dict;
455    DispersionVisitor* visitor = new DispersionVisitor();
456    disp_dict = PyDict_GetItemString(self->dispersion, "radius_Lsph");
457    self->model->radius_Lsph.dispersion->accept_as_destination(visitor, self->model->radius_Lsph.dispersion, disp_dict);
458
459       
460        // Get input and determine whether we have to supply a 1D or 2D return value.
461        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
462            PyErr_SetString(CRaspBerryModelError, 
463                "CRaspBerryModel.run expects a q value.");
464                return NULL;
465        }
466         
467        // Check params
468        if( PyList_Check(pars)==1) {
469               
470                // Length of list should be 2 for I(qx, qy))
471            npars = PyList_GET_SIZE(pars); 
472            if(npars!=2) {
473                PyErr_SetString(CRaspBerryModelError, 
474                        "CRaspBerryModel.run expects a double or a list of dimension 2.");
475                return NULL;
476            }
477            // We have a vector q, get the qx and qy values at which
478            // to evaluate I(qx,qy)
479            qx_value = CRaspBerryModel_readDouble(PyList_GET_ITEM(pars,0));
480            qy_value = CRaspBerryModel_readDouble(PyList_GET_ITEM(pars,1));
481            return Py_BuildValue("d",(*(self->model))(qx_value,qy_value));
482
483        } else {
484
485                // We have a scalar q, we will evaluate I(q)
486                qx_value = CRaspBerryModel_readDouble(pars);           
487               
488                return Py_BuildValue("d",(*(self->model))(qx_value));
489        }       
490}
491
492static PyObject * reset(CRaspBerryModel *self, PyObject *args) {
493   
494
495    return Py_BuildValue("d",0.0);
496}
497
498static PyObject * set_dispersion(CRaspBerryModel *self, PyObject *args) {
499        PyObject * disp;
500        const char * par_name;
501
502        if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
503            PyErr_SetString(CRaspBerryModelError,
504                "CRaspBerryModel.set_dispersion expects a DispersionModel object.");
505                return NULL;
506        }
507        void *temp = PyCObject_AsVoidPtr(disp);
508        DispersionModel * dispersion = static_cast<DispersionModel *>(temp);
509
510
511        // Ugliness necessary to go from python to C
512            // TODO: refactor this
513    if (!strcmp(par_name, "radius_Lsph")) {
514        self->model->radius_Lsph.dispersion = dispersion;
515    } else {
516            PyErr_SetString(CRaspBerryModelError,
517                "CRaspBerryModel.set_dispersion expects a valid parameter name.");
518                return NULL;
519        }
520
521        DispersionVisitor* visitor = new DispersionVisitor();
522        PyObject * disp_dict = PyDict_New();
523        dispersion->accept_as_source(visitor, dispersion, disp_dict);
524        PyDict_SetItemString(self->dispersion, par_name, disp_dict);
525    return Py_BuildValue("i",1);
526}
527
528
529static PyMethodDef CRaspBerryModel_methods[] = {
530    {"run",      (PyCFunction)run     , METH_VARARGS,
531      "Evaluate the model at a given Q or Q, phi"},
532    {"runXY",      (PyCFunction)runXY     , METH_VARARGS,
533      "Evaluate the model at a given Q or Qx, Qy"},
534    {"calculate_ER",      (PyCFunction)calculate_ER     , METH_VARARGS,
535      "Evaluate the model at a given Q or Q, phi"},
536    {"calculate_VR",      (PyCFunction)calculate_VR     , METH_VARARGS,
537      "Evaluate VR"},   
538    {"evalDistribution",  (PyCFunction)evalDistribution , METH_VARARGS,
539      "Evaluate the model at a given Q or Qx, Qy vector "},
540    {"reset",    (PyCFunction)reset   , METH_VARARGS,
541      "Reset pair correlation"},
542    {"set_dispersion",      (PyCFunction)set_dispersion     , METH_VARARGS,
543      "Set the dispersion model for a given parameter"},
544   {NULL}
545};
546
547static PyTypeObject CRaspBerryModelType = {
548    PyObject_HEAD_INIT(NULL)
549    0,                         /*ob_size*/
550    "CRaspBerryModel",             /*tp_name*/
551    sizeof(CRaspBerryModel),             /*tp_basicsize*/
552    0,                         /*tp_itemsize*/
553    (destructor)CRaspBerryModel_dealloc, /*tp_dealloc*/
554    0,                         /*tp_print*/
555    0,                         /*tp_getattr*/
556    0,                         /*tp_setattr*/
557    0,                         /*tp_compare*/
558    0,                         /*tp_repr*/
559    0,                         /*tp_as_number*/
560    0,                         /*tp_as_sequence*/
561    0,                         /*tp_as_mapping*/
562    0,                         /*tp_hash */
563    0,                         /*tp_call*/
564    0,                         /*tp_str*/
565    0,                         /*tp_getattro*/
566    0,                         /*tp_setattro*/
567    0,                         /*tp_as_buffer*/
568    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
569    "CRaspBerryModel objects",           /* tp_doc */
570    0,                         /* tp_traverse */
571    0,                         /* tp_clear */
572    0,                         /* tp_richcompare */
573    0,                         /* tp_weaklistoffset */
574    0,                         /* tp_iter */
575    0,                         /* tp_iternext */
576    CRaspBerryModel_methods,             /* tp_methods */
577    CRaspBerryModel_members,             /* tp_members */
578    0,                         /* tp_getset */
579    0,                         /* tp_base */
580    0,                         /* tp_dict */
581    0,                         /* tp_descr_get */
582    0,                         /* tp_descr_set */
583    0,                         /* tp_dictoffset */
584    (initproc)CRaspBerryModel_init,      /* tp_init */
585    0,                         /* tp_alloc */
586    CRaspBerryModel_new,                 /* tp_new */
587};
588
589
590//static PyMethodDef module_methods[] = {
591//    {NULL}
592//};
593
594/**
595 * Function used to add the model class to a module
596 * @param module: module to add the class to
597 */ 
598void addCRaspBerryModel(PyObject *module) {
599        PyObject *d;
600       
601    if (PyType_Ready(&CRaspBerryModelType) < 0)
602        return;
603
604    Py_INCREF(&CRaspBerryModelType);
605    PyModule_AddObject(module, "CRaspBerryModel", (PyObject *)&CRaspBerryModelType);
606   
607    d = PyModule_GetDict(module);
608    static char error_name[] = "CRaspBerryModel.error";
609    CRaspBerryModelError = PyErr_NewException(error_name, NULL, NULL);
610    PyDict_SetItemString(d, "CRaspBerryModelError", CRaspBerryModelError);
611}
612
Note: See TracBrowser for help on using the repository browser.