source: sasview/sansmodels/src/sans/models/c_models/CStackedDisksModel.cpp @ e0a8a3c

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 e0a8a3c was e0a8a3c, checked in by Gervaise Alina <gervyh@…>, 15 years ago

change the orientation of models

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