source: sasview/src/sans/models/c_extension/python_wrapper/generated/CPearlNecklaceModel.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: 24.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/** CPearlNecklaceModel
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\pearlnecklace.h
21 *          AND RE-RUN THE GENERATOR SCRIPT
22 *
23 */
24#define NO_IMPORT_ARRAY
25#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sans
26 
27extern "C" {
28#include <Python.h>
29#include <arrayobject.h>
30#include "structmember.h"
31#include <stdio.h>
32#include <stdlib.h>
33#include <math.h>
34#include <time.h>
35
36}
37
38#include "pearlnecklace.h"
39#include "dispersion_visitor.hh"
40
41/// Error object for raised exceptions
42static PyObject * CPearlNecklaceModelError = NULL;
43
44
45// Class definition
46typedef struct {
47    PyObject_HEAD
48    /// Parameters
49    PyObject * params;
50    /// Dispersion parameters
51    PyObject * dispersion;
52    /// Underlying model object
53    PearlNecklaceModel * model;
54    /// Log for unit testing
55    PyObject * log;
56} CPearlNecklaceModel;
57
58
59static void
60CPearlNecklaceModel_dealloc(CPearlNecklaceModel* self)
61{
62    Py_DECREF(self->params);
63    Py_DECREF(self->dispersion);
64    Py_DECREF(self->log);
65    delete self->model;
66    self->ob_type->tp_free((PyObject*)self);
67   
68
69}
70
71static PyObject *
72CPearlNecklaceModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
73{
74    CPearlNecklaceModel *self;
75   
76    self = (CPearlNecklaceModel *)type->tp_alloc(type, 0);
77   
78    return (PyObject *)self;
79}
80
81static int
82CPearlNecklaceModel_init(CPearlNecklaceModel *self, PyObject *args, PyObject *kwds)
83{
84    if (self != NULL) {
85       
86        // Create parameters
87        self->params = PyDict_New();
88        self->dispersion = PyDict_New();
89
90        self->model = new PearlNecklaceModel();
91
92        // Initialize parameter dictionary
93        PyDict_SetItemString(self->params,"num_pearls",Py_BuildValue("d",3.000000000000));
94        PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",1.000000000000));
95        PyDict_SetItemString(self->params,"thick_string",Py_BuildValue("d",2.500000000000));
96        PyDict_SetItemString(self->params,"sld_string",Py_BuildValue("d",0.000001000000));
97        PyDict_SetItemString(self->params,"edge_separation",Py_BuildValue("d",350.000000000000));
98        PyDict_SetItemString(self->params,"sld_pearl",Py_BuildValue("d",0.000001000000));
99        PyDict_SetItemString(self->params,"radius",Py_BuildValue("d",80.000000000000));
100        PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.000000000000));
101        PyDict_SetItemString(self->params,"sld_solv",Py_BuildValue("d",0.000006300000));
102        // Initialize dispersion / averaging parameter dict
103        DispersionVisitor* visitor = new DispersionVisitor();
104        PyObject * disp_dict;
105        disp_dict = PyDict_New();
106        self->model->radius.dispersion->accept_as_source(visitor, self->model->radius.dispersion, disp_dict);
107        PyDict_SetItemString(self->dispersion, "radius", disp_dict);
108        disp_dict = PyDict_New();
109        self->model->edge_separation.dispersion->accept_as_source(visitor, self->model->edge_separation.dispersion, disp_dict);
110        PyDict_SetItemString(self->dispersion, "edge_separation", disp_dict);
111
112
113         
114        // Create empty log
115        self->log = PyDict_New();
116       
117       
118
119    }
120    return 0;
121}
122
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
130static PyMemberDef CPearlNecklaceModel_members[] = {
131    {name_params, T_OBJECT, offsetof(CPearlNecklaceModel, params), 0, def_params},
132        {name_dispersion, T_OBJECT, offsetof(CPearlNecklaceModel, dispersion), 0, def_dispersion},     
133    {name_log, T_OBJECT, offsetof(CPearlNecklaceModel, log), 0, def_log},
134    {NULL}  /* Sentinel */
135};
136
137/** Read double from PyObject
138    @param p PyObject
139    @return double
140*/
141double CPearlNecklaceModel_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}
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(PearlNecklaceModel* 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), PyArray_DOUBLE);
169        if (result == NULL) {
170        const char * message= "Could not create result ";
171        PyErr_SetString(PyExc_RuntimeError , message);
172                return NULL;
173        }
174#pragma omp parallel for
175         for (int i = 0; i < q->dimensions[0]; i++){
176      double q_value  = *(double *)(q->data + i*q->strides[0]);
177      double *result_value = (double *)(result->data + i*result->strides[0]);
178      *result_value =(*model)(q_value);
179        }
180    return PyArray_Return(result); 
181 }
182
183 /**
184 * Function to call to evaluate model
185 * @param args: input numpy array  [x[],y[]]
186 * @return: numpy array object
187 */
188 static PyObject * evaluateTwoDimXY( PearlNecklaceModel* model, 
189                              PyArrayObject *x, PyArrayObject *y)
190 {
191    PyArrayObject *result;
192    int x_len, y_len, dims[1];
193    //check validity of input vectors
194    if (x->nd != 1 || x->descr->type_num != PyArray_DOUBLE
195        || y->nd != 1 || y->descr->type_num != PyArray_DOUBLE
196        || y->dimensions[0] != x->dimensions[0]){
197        const char * message= "evaluateTwoDimXY  expect 2 numpy arrays";
198        PyErr_SetString(PyExc_ValueError , message); 
199        return NULL;
200    }
201   
202        if (PyArray_Check(x) && PyArray_Check(y)) {
203               
204            x_len = dims[0]= x->dimensions[0];
205        y_len = dims[0]= y->dimensions[0];
206           
207            // Make a new double matrix of same dims
208        result=(PyArrayObject *) PyArray_FromDims(1,dims,NPY_DOUBLE);
209        if (result == NULL){
210            const char * message= "Could not create result ";
211        PyErr_SetString(PyExc_RuntimeError , message);
212            return NULL;
213            }
214       
215        /* Do the calculation. */
216#pragma omp parallel for
217        for (int i=0; i< x_len; i++) {
218            double x_value = *(double *)(x->data + i*x->strides[0]);
219                    double y_value = *(double *)(y->data + i*y->strides[0]);
220                        double *result_value = (double *)(result->data +
221                              i*result->strides[0]);
222                        *result_value = (*model)(x_value, y_value);
223        }           
224        return PyArray_Return(result); 
225       
226        }else{
227                    PyErr_SetString(CPearlNecklaceModelError, 
228                   "CPearlNecklaceModel.evaluateTwoDimXY couldn't run.");
229                return NULL;
230                }       
231}
232/**
233 *  evalDistribution function evaluate a model function with input vector
234 *  @param args: input q as vector or [qx, qy] where qx, qy are vectors
235 *
236 */ 
237static PyObject * evalDistribution(CPearlNecklaceModel *self, PyObject *args){
238        PyObject *qx, *qy;
239        PyArrayObject * pars;
240        int npars ,mpars;
241       
242        // Get parameters
243       
244            // Reader parameter dictionary
245    self->model->num_pearls = PyFloat_AsDouble( PyDict_GetItemString(self->params, "num_pearls") );
246    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
247    self->model->thick_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_string") );
248    self->model->sld_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_string") );
249    self->model->edge_separation = PyFloat_AsDouble( PyDict_GetItemString(self->params, "edge_separation") );
250    self->model->sld_pearl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_pearl") );
251    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
252    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
253    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
254    // Read in dispersion parameters
255    PyObject* disp_dict;
256    DispersionVisitor* visitor = new DispersionVisitor();
257    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
258    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
259    disp_dict = PyDict_GetItemString(self->dispersion, "edge_separation");
260    self->model->edge_separation.dispersion->accept_as_destination(visitor, self->model->edge_separation.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(CPearlNecklaceModelError, 
266                "CPearlNecklaceModel.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(CPearlNecklaceModelError, 
282                   "CPearlNecklaceModel.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(CPearlNecklaceModelError, 
290                        "CPearlNecklaceModel.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(CPearlNecklaceModelError, 
300                   "CPearlNecklaceModel.evalDistribution expect 2 numpy arrays in list.");
301                return NULL;
302             }
303        }
304        PyErr_SetString(CPearlNecklaceModelError, 
305                   "CPearlNecklaceModel.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(CPearlNecklaceModel *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->num_pearls = PyFloat_AsDouble( PyDict_GetItemString(self->params, "num_pearls") );
324    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
325    self->model->thick_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_string") );
326    self->model->sld_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_string") );
327    self->model->edge_separation = PyFloat_AsDouble( PyDict_GetItemString(self->params, "edge_separation") );
328    self->model->sld_pearl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_pearl") );
329    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
330    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
331    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
332    // Read in dispersion parameters
333    PyObject* disp_dict;
334    DispersionVisitor* visitor = new DispersionVisitor();
335    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
336    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
337    disp_dict = PyDict_GetItemString(self->dispersion, "edge_separation");
338    self->model->edge_separation.dispersion->accept_as_destination(visitor, self->model->edge_separation.dispersion, disp_dict);
339
340       
341        // Get input and determine whether we have to supply a 1D or 2D return value.
342        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
343            PyErr_SetString(CPearlNecklaceModelError, 
344                "CPearlNecklaceModel.run expects a q value.");
345                return NULL;
346        }
347         
348        // Check params
349        if( PyList_Check(pars)==1) {
350               
351                // Length of list should be 2 for I(q,phi)
352            npars = PyList_GET_SIZE(pars); 
353            if(npars!=2) {
354                PyErr_SetString(CPearlNecklaceModelError, 
355                        "CPearlNecklaceModel.run expects a double or a list of dimension 2.");
356                return NULL;
357            }
358            // We have a vector q, get the q and phi values at which
359            // to evaluate I(q,phi)
360            q_value = CPearlNecklaceModel_readDouble(PyList_GET_ITEM(pars,0));
361            phi_value = CPearlNecklaceModel_readDouble(PyList_GET_ITEM(pars,1));
362            // Skip zero
363            if (q_value==0) {
364                return Py_BuildValue("d",0.0);
365            }
366                return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value));
367
368        } else {
369
370                // We have a scalar q, we will evaluate I(q)
371                q_value = CPearlNecklaceModel_readDouble(pars);         
372               
373                return Py_BuildValue("d",(*(self->model))(q_value));
374        }       
375}
376/**
377 * Function to call to calculate_ER
378 * @return: effective radius value
379 */
380static PyObject * calculate_ER(CPearlNecklaceModel *self) {
381
382        // Get parameters
383       
384            // Reader parameter dictionary
385    self->model->num_pearls = PyFloat_AsDouble( PyDict_GetItemString(self->params, "num_pearls") );
386    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
387    self->model->thick_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_string") );
388    self->model->sld_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_string") );
389    self->model->edge_separation = PyFloat_AsDouble( PyDict_GetItemString(self->params, "edge_separation") );
390    self->model->sld_pearl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_pearl") );
391    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
392    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
393    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
394    // Read in dispersion parameters
395    PyObject* disp_dict;
396    DispersionVisitor* visitor = new DispersionVisitor();
397    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
398    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
399    disp_dict = PyDict_GetItemString(self->dispersion, "edge_separation");
400    self->model->edge_separation.dispersion->accept_as_destination(visitor, self->model->edge_separation.dispersion, disp_dict);
401
402               
403        return Py_BuildValue("d",(*(self->model)).calculate_ER());
404
405}
406/**
407 * Function to call to cal the ratio shell volume/ total volume
408 * @return: the ratio shell volume/ total volume
409 */
410static PyObject * calculate_VR(CPearlNecklaceModel *self) {
411
412        // Get parameters
413       
414            // Reader parameter dictionary
415    self->model->num_pearls = PyFloat_AsDouble( PyDict_GetItemString(self->params, "num_pearls") );
416    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
417    self->model->thick_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_string") );
418    self->model->sld_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_string") );
419    self->model->edge_separation = PyFloat_AsDouble( PyDict_GetItemString(self->params, "edge_separation") );
420    self->model->sld_pearl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_pearl") );
421    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
422    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
423    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
424    // Read in dispersion parameters
425    PyObject* disp_dict;
426    DispersionVisitor* visitor = new DispersionVisitor();
427    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
428    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
429    disp_dict = PyDict_GetItemString(self->dispersion, "edge_separation");
430    self->model->edge_separation.dispersion->accept_as_destination(visitor, self->model->edge_separation.dispersion, disp_dict);
431
432               
433        return Py_BuildValue("d",(*(self->model)).calculate_VR());
434
435}
436/**
437 * Function to call to evaluate model in cartesian coordinates
438 * @param args: input q or [qx, qy]]
439 * @return: function value
440 */
441static PyObject * runXY(CPearlNecklaceModel *self, PyObject *args) {
442        double qx_value, qy_value;
443        PyObject* pars;
444        int npars;
445       
446        // Get parameters
447       
448            // Reader parameter dictionary
449    self->model->num_pearls = PyFloat_AsDouble( PyDict_GetItemString(self->params, "num_pearls") );
450    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
451    self->model->thick_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_string") );
452    self->model->sld_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_string") );
453    self->model->edge_separation = PyFloat_AsDouble( PyDict_GetItemString(self->params, "edge_separation") );
454    self->model->sld_pearl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_pearl") );
455    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
456    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
457    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
458    // Read in dispersion parameters
459    PyObject* disp_dict;
460    DispersionVisitor* visitor = new DispersionVisitor();
461    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
462    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
463    disp_dict = PyDict_GetItemString(self->dispersion, "edge_separation");
464    self->model->edge_separation.dispersion->accept_as_destination(visitor, self->model->edge_separation.dispersion, disp_dict);
465
466       
467        // Get input and determine whether we have to supply a 1D or 2D return value.
468        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
469            PyErr_SetString(CPearlNecklaceModelError, 
470                "CPearlNecklaceModel.run expects a q value.");
471                return NULL;
472        }
473         
474        // Check params
475        if( PyList_Check(pars)==1) {
476               
477                // Length of list should be 2 for I(qx, qy))
478            npars = PyList_GET_SIZE(pars); 
479            if(npars!=2) {
480                PyErr_SetString(CPearlNecklaceModelError, 
481                        "CPearlNecklaceModel.run expects a double or a list of dimension 2.");
482                return NULL;
483            }
484            // We have a vector q, get the qx and qy values at which
485            // to evaluate I(qx,qy)
486            qx_value = CPearlNecklaceModel_readDouble(PyList_GET_ITEM(pars,0));
487            qy_value = CPearlNecklaceModel_readDouble(PyList_GET_ITEM(pars,1));
488            return Py_BuildValue("d",(*(self->model))(qx_value,qy_value));
489
490        } else {
491
492                // We have a scalar q, we will evaluate I(q)
493                qx_value = CPearlNecklaceModel_readDouble(pars);               
494               
495                return Py_BuildValue("d",(*(self->model))(qx_value));
496        }       
497}
498
499static PyObject * reset(CPearlNecklaceModel *self, PyObject *args) {
500   
501
502    return Py_BuildValue("d",0.0);
503}
504
505static PyObject * set_dispersion(CPearlNecklaceModel *self, PyObject *args) {
506        PyObject * disp;
507        const char * par_name;
508
509        if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
510            PyErr_SetString(CPearlNecklaceModelError,
511                "CPearlNecklaceModel.set_dispersion expects a DispersionModel object.");
512                return NULL;
513        }
514        void *temp = PyCObject_AsVoidPtr(disp);
515        DispersionModel * dispersion = static_cast<DispersionModel *>(temp);
516
517
518        // Ugliness necessary to go from python to C
519            // TODO: refactor this
520    if (!strcmp(par_name, "radius")) {
521        self->model->radius.dispersion = dispersion;
522    } else    if (!strcmp(par_name, "edge_separation")) {
523        self->model->edge_separation.dispersion = dispersion;
524    } else {
525            PyErr_SetString(CPearlNecklaceModelError,
526                "CPearlNecklaceModel.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 CPearlNecklaceModel_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 CPearlNecklaceModelType = {
557    PyObject_HEAD_INIT(NULL)
558    0,                         /*ob_size*/
559    "CPearlNecklaceModel",             /*tp_name*/
560    sizeof(CPearlNecklaceModel),             /*tp_basicsize*/
561    0,                         /*tp_itemsize*/
562    (destructor)CPearlNecklaceModel_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    "CPearlNecklaceModel 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    CPearlNecklaceModel_methods,             /* tp_methods */
586    CPearlNecklaceModel_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)CPearlNecklaceModel_init,      /* tp_init */
594    0,                         /* tp_alloc */
595    CPearlNecklaceModel_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 addCPearlNecklaceModel(PyObject *module) {
608        PyObject *d;
609       
610    if (PyType_Ready(&CPearlNecklaceModelType) < 0)
611        return;
612
613    Py_INCREF(&CPearlNecklaceModelType);
614    PyModule_AddObject(module, "CPearlNecklaceModel", (PyObject *)&CPearlNecklaceModelType);
615   
616    d = PyModule_GetDict(module);
617    static char error_name[] = "CPearlNecklaceModel.error";
618    CPearlNecklaceModelError = PyErr_NewException(error_name, NULL, NULL);
619    PyDict_SetItemString(d, "CPearlNecklaceModelError", CPearlNecklaceModelError);
620}
621
Note: See TracBrowser for help on using the repository browser.