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