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

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 27953d1 was 975ec8e, checked in by Jae Cho <jhjcho@…>, 15 years ago

working on 2D models. Still need smore corrections and unit tests.

  • Property mode set to 100644
File size: 24.3 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            x_len = dims[0]= x->dimensions[0];
207        y_len = dims[1]= y->dimensions[1];
208           
209            // Make a new double matrix of same dims
210        result=(PyArrayObject *) PyArray_FromDims(2,dims,NPY_DOUBLE);
211        if (result == NULL){
212            const char * message= "Could not create result ";
213        PyErr_SetString(PyExc_RuntimeError , message);
214            return NULL;
215            }
216       
217        /* Do the calculation. */
218        for ( i=0; i< x_len; i++) {
219            for ( j=0; j< y_len; j++) {
220                double x_value = *(double *)(x->data + i*x->strides[0]);
221                    double y_value = *(double *)(y->data + j*y->strides[1]);
222                        double *result_value = (double *)(result->data +
223                              i*result->strides[0] + j*result->strides[1]);
224                        *result_value = (*model)(x_value, y_value);
225            }           
226        }
227        return PyArray_Return(result); 
228       
229        }else{
230                    PyErr_SetString(CStackedDisksModelError, 
231                   "CStackedDisksModel.evaluateTwoDimXY couldn't run.");
232                return NULL;
233                }       
234}
235/**
236 *  evalDistribution function evaluate a model function with input vector
237 *  @param args: input q as vector or [qx, qy] where qx, qy are vectors
238 *
239 */ 
240static PyObject * evalDistribution(CStackedDisksModel *self, PyObject *args){
241        PyObject *qx, *qy;
242        PyArrayObject * pars;
243        int npars ,mpars;
244       
245        // Get parameters
246       
247            // Reader parameter dictionary
248    self->model->core_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "core_sld") );
249    self->model->core_thick = PyFloat_AsDouble( PyDict_GetItemString(self->params, "core_thick") );
250    self->model->layer_thick = PyFloat_AsDouble( PyDict_GetItemString(self->params, "layer_thick") );
251    self->model->axis_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_theta") );
252    self->model->layer_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "layer_sld") );
253    self->model->axis_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_phi") );
254    self->model->solvent_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "solvent_sld") );
255    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
256    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
257    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
258    self->model->sigma_d = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sigma_d") );
259    self->model->n_stacking = PyFloat_AsDouble( PyDict_GetItemString(self->params, "n_stacking") );
260    // Read in dispersion parameters
261    PyObject* disp_dict;
262    DispersionVisitor* visitor = new DispersionVisitor();
263    disp_dict = PyDict_GetItemString(self->dispersion, "core_thick");
264    self->model->core_thick.dispersion->accept_as_destination(visitor, self->model->core_thick.dispersion, disp_dict);
265    disp_dict = PyDict_GetItemString(self->dispersion, "layer_thick");
266    self->model->layer_thick.dispersion->accept_as_destination(visitor, self->model->layer_thick.dispersion, disp_dict);
267    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
268    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
269    disp_dict = PyDict_GetItemString(self->dispersion, "axis_theta");
270    self->model->axis_theta.dispersion->accept_as_destination(visitor, self->model->axis_theta.dispersion, disp_dict);
271    disp_dict = PyDict_GetItemString(self->dispersion, "axis_phi");
272    self->model->axis_phi.dispersion->accept_as_destination(visitor, self->model->axis_phi.dispersion, disp_dict);
273
274       
275        // Get input and determine whether we have to supply a 1D or 2D return value.
276        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
277            PyErr_SetString(CStackedDisksModelError, 
278                "CStackedDisksModel.evalDistribution expects a q value.");
279                return NULL;
280        }
281    // Check params
282       
283    if(PyArray_Check(pars)==1) {
284               
285            // Length of list should 1 or 2
286            npars = pars->nd; 
287            if(npars==1) {
288                // input is a numpy array
289                if (PyArray_Check(pars)) {
290                        return evaluateOneDim(self->model, (PyArrayObject*)pars); 
291                    }
292                }else{
293                    PyErr_SetString(CStackedDisksModelError, 
294                   "CStackedDisksModel.evalDistribution expect numpy array of one dimension.");
295                return NULL;
296                }
297    }else if( PyList_Check(pars)==1) {
298        // Length of list should be 2 for I(qx,qy)
299            mpars = PyList_GET_SIZE(pars); 
300            if(mpars!=2) {
301                PyErr_SetString(CStackedDisksModelError, 
302                        "CStackedDisksModel.evalDistribution expects a list of dimension 2.");
303                return NULL;
304            }
305             qx = PyList_GET_ITEM(pars,0);
306             qy = PyList_GET_ITEM(pars,1);
307             if (PyArray_Check(qx) && PyArray_Check(qy)) {
308                 return evaluateTwoDimXY(self->model, (PyArrayObject*)qx,
309                           (PyArrayObject*)qy);
310                 }else{
311                    PyErr_SetString(CStackedDisksModelError, 
312                   "CStackedDisksModel.evalDistribution expect 2 numpy arrays in list.");
313                return NULL;
314             }
315        }else{
316            PyErr_SetString(CStackedDisksModelError, 
317                   "CStackedDisksModel.evalDistribution couln't be run.");
318            return NULL;
319        }
320}
321
322/**
323 * Function to call to evaluate model
324 * @param args: input q or [q,phi]
325 * @return: function value
326 */
327static PyObject * run(CStackedDisksModel *self, PyObject *args) {
328        double q_value, phi_value;
329        PyObject* pars;
330        int npars;
331       
332        // Get parameters
333       
334            // Reader parameter dictionary
335    self->model->core_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "core_sld") );
336    self->model->core_thick = PyFloat_AsDouble( PyDict_GetItemString(self->params, "core_thick") );
337    self->model->layer_thick = PyFloat_AsDouble( PyDict_GetItemString(self->params, "layer_thick") );
338    self->model->axis_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_theta") );
339    self->model->layer_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "layer_sld") );
340    self->model->axis_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_phi") );
341    self->model->solvent_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "solvent_sld") );
342    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
343    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
344    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
345    self->model->sigma_d = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sigma_d") );
346    self->model->n_stacking = PyFloat_AsDouble( PyDict_GetItemString(self->params, "n_stacking") );
347    // Read in dispersion parameters
348    PyObject* disp_dict;
349    DispersionVisitor* visitor = new DispersionVisitor();
350    disp_dict = PyDict_GetItemString(self->dispersion, "core_thick");
351    self->model->core_thick.dispersion->accept_as_destination(visitor, self->model->core_thick.dispersion, disp_dict);
352    disp_dict = PyDict_GetItemString(self->dispersion, "layer_thick");
353    self->model->layer_thick.dispersion->accept_as_destination(visitor, self->model->layer_thick.dispersion, disp_dict);
354    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
355    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
356    disp_dict = PyDict_GetItemString(self->dispersion, "axis_theta");
357    self->model->axis_theta.dispersion->accept_as_destination(visitor, self->model->axis_theta.dispersion, disp_dict);
358    disp_dict = PyDict_GetItemString(self->dispersion, "axis_phi");
359    self->model->axis_phi.dispersion->accept_as_destination(visitor, self->model->axis_phi.dispersion, disp_dict);
360
361       
362        // Get input and determine whether we have to supply a 1D or 2D return value.
363        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
364            PyErr_SetString(CStackedDisksModelError, 
365                "CStackedDisksModel.run expects a q value.");
366                return NULL;
367        }
368         
369        // Check params
370        if( PyList_Check(pars)==1) {
371               
372                // Length of list should be 2 for I(q,phi)
373            npars = PyList_GET_SIZE(pars); 
374            if(npars!=2) {
375                PyErr_SetString(CStackedDisksModelError, 
376                        "CStackedDisksModel.run expects a double or a list of dimension 2.");
377                return NULL;
378            }
379            // We have a vector q, get the q and phi values at which
380            // to evaluate I(q,phi)
381            q_value = CStackedDisksModel_readDouble(PyList_GET_ITEM(pars,0));
382            phi_value = CStackedDisksModel_readDouble(PyList_GET_ITEM(pars,1));
383            // Skip zero
384            if (q_value==0) {
385                return Py_BuildValue("d",0.0);
386            }
387                return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value));
388
389        } else {
390
391                // We have a scalar q, we will evaluate I(q)
392                q_value = CStackedDisksModel_readDouble(pars);         
393               
394                return Py_BuildValue("d",(*(self->model))(q_value));
395        }       
396}
397
398/**
399 * Function to call to evaluate model in cartesian coordinates
400 * @param args: input q or [qx, qy]]
401 * @return: function value
402 */
403static PyObject * runXY(CStackedDisksModel *self, PyObject *args) {
404        double qx_value, qy_value;
405        PyObject* pars;
406        int npars;
407       
408        // Get parameters
409       
410            // Reader parameter dictionary
411    self->model->core_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "core_sld") );
412    self->model->core_thick = PyFloat_AsDouble( PyDict_GetItemString(self->params, "core_thick") );
413    self->model->layer_thick = PyFloat_AsDouble( PyDict_GetItemString(self->params, "layer_thick") );
414    self->model->axis_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_theta") );
415    self->model->layer_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "layer_sld") );
416    self->model->axis_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_phi") );
417    self->model->solvent_sld = PyFloat_AsDouble( PyDict_GetItemString(self->params, "solvent_sld") );
418    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
419    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
420    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
421    self->model->sigma_d = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sigma_d") );
422    self->model->n_stacking = PyFloat_AsDouble( PyDict_GetItemString(self->params, "n_stacking") );
423    // Read in dispersion parameters
424    PyObject* disp_dict;
425    DispersionVisitor* visitor = new DispersionVisitor();
426    disp_dict = PyDict_GetItemString(self->dispersion, "core_thick");
427    self->model->core_thick.dispersion->accept_as_destination(visitor, self->model->core_thick.dispersion, disp_dict);
428    disp_dict = PyDict_GetItemString(self->dispersion, "layer_thick");
429    self->model->layer_thick.dispersion->accept_as_destination(visitor, self->model->layer_thick.dispersion, disp_dict);
430    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
431    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
432    disp_dict = PyDict_GetItemString(self->dispersion, "axis_theta");
433    self->model->axis_theta.dispersion->accept_as_destination(visitor, self->model->axis_theta.dispersion, disp_dict);
434    disp_dict = PyDict_GetItemString(self->dispersion, "axis_phi");
435    self->model->axis_phi.dispersion->accept_as_destination(visitor, self->model->axis_phi.dispersion, disp_dict);
436
437       
438        // Get input and determine whether we have to supply a 1D or 2D return value.
439        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
440            PyErr_SetString(CStackedDisksModelError, 
441                "CStackedDisksModel.run expects a q value.");
442                return NULL;
443        }
444         
445        // Check params
446        if( PyList_Check(pars)==1) {
447               
448                // Length of list should be 2 for I(qx, qy))
449            npars = PyList_GET_SIZE(pars); 
450            if(npars!=2) {
451                PyErr_SetString(CStackedDisksModelError, 
452                        "CStackedDisksModel.run expects a double or a list of dimension 2.");
453                return NULL;
454            }
455            // We have a vector q, get the qx and qy values at which
456            // to evaluate I(qx,qy)
457            qx_value = CStackedDisksModel_readDouble(PyList_GET_ITEM(pars,0));
458            qy_value = CStackedDisksModel_readDouble(PyList_GET_ITEM(pars,1));
459            return Py_BuildValue("d",(*(self->model))(qx_value,qy_value));
460
461        } else {
462
463                // We have a scalar q, we will evaluate I(q)
464                qx_value = CStackedDisksModel_readDouble(pars);         
465               
466                return Py_BuildValue("d",(*(self->model))(qx_value));
467        }       
468}
469
470static PyObject * reset(CStackedDisksModel *self, PyObject *args) {
471   
472
473    return Py_BuildValue("d",0.0);
474}
475
476static PyObject * set_dispersion(CStackedDisksModel *self, PyObject *args) {
477        PyObject * disp;
478        const char * par_name;
479
480        if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
481            PyErr_SetString(CStackedDisksModelError,
482                "CStackedDisksModel.set_dispersion expects a DispersionModel object.");
483                return NULL;
484        }
485        void *temp = PyCObject_AsVoidPtr(disp);
486        DispersionModel * dispersion = static_cast<DispersionModel *>(temp);
487
488
489        // Ugliness necessary to go from python to C
490            // TODO: refactor this
491    if (!strcmp(par_name, "core_thick")) {
492        self->model->core_thick.dispersion = dispersion;
493    } else    if (!strcmp(par_name, "layer_thick")) {
494        self->model->layer_thick.dispersion = dispersion;
495    } else    if (!strcmp(par_name, "radius")) {
496        self->model->radius.dispersion = dispersion;
497    } else    if (!strcmp(par_name, "axis_theta")) {
498        self->model->axis_theta.dispersion = dispersion;
499    } else    if (!strcmp(par_name, "axis_phi")) {
500        self->model->axis_phi.dispersion = dispersion;
501    } else {
502            PyErr_SetString(CStackedDisksModelError,
503                "CStackedDisksModel.set_dispersion expects a valid parameter name.");
504                return NULL;
505        }
506
507        DispersionVisitor* visitor = new DispersionVisitor();
508        PyObject * disp_dict = PyDict_New();
509        dispersion->accept_as_source(visitor, dispersion, disp_dict);
510        PyDict_SetItemString(self->dispersion, par_name, disp_dict);
511    return Py_BuildValue("i",1);
512}
513
514
515static PyMethodDef CStackedDisksModel_methods[] = {
516    {"run",      (PyCFunction)run     , METH_VARARGS,
517      "Evaluate the model at a given Q or Q, phi"},
518    {"runXY",      (PyCFunction)runXY     , METH_VARARGS,
519      "Evaluate the model at a given Q or Qx, Qy"},
520     
521    {"evalDistribution",  (PyCFunction)evalDistribution , METH_VARARGS,
522      "Evaluate the model at a given Q or Qx, Qy vector "},
523    {"reset",    (PyCFunction)reset   , METH_VARARGS,
524      "Reset pair correlation"},
525    {"set_dispersion",      (PyCFunction)set_dispersion     , METH_VARARGS,
526      "Set the dispersion model for a given parameter"},
527   {NULL}
528};
529
530static PyTypeObject CStackedDisksModelType = {
531    PyObject_HEAD_INIT(NULL)
532    0,                         /*ob_size*/
533    "CStackedDisksModel",             /*tp_name*/
534    sizeof(CStackedDisksModel),             /*tp_basicsize*/
535    0,                         /*tp_itemsize*/
536    (destructor)CStackedDisksModel_dealloc, /*tp_dealloc*/
537    0,                         /*tp_print*/
538    0,                         /*tp_getattr*/
539    0,                         /*tp_setattr*/
540    0,                         /*tp_compare*/
541    0,                         /*tp_repr*/
542    0,                         /*tp_as_number*/
543    0,                         /*tp_as_sequence*/
544    0,                         /*tp_as_mapping*/
545    0,                         /*tp_hash */
546    0,                         /*tp_call*/
547    0,                         /*tp_str*/
548    0,                         /*tp_getattro*/
549    0,                         /*tp_setattro*/
550    0,                         /*tp_as_buffer*/
551    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
552    "CStackedDisksModel objects",           /* tp_doc */
553    0,                         /* tp_traverse */
554    0,                         /* tp_clear */
555    0,                         /* tp_richcompare */
556    0,                         /* tp_weaklistoffset */
557    0,                         /* tp_iter */
558    0,                         /* tp_iternext */
559    CStackedDisksModel_methods,             /* tp_methods */
560    CStackedDisksModel_members,             /* tp_members */
561    0,                         /* tp_getset */
562    0,                         /* tp_base */
563    0,                         /* tp_dict */
564    0,                         /* tp_descr_get */
565    0,                         /* tp_descr_set */
566    0,                         /* tp_dictoffset */
567    (initproc)CStackedDisksModel_init,      /* tp_init */
568    0,                         /* tp_alloc */
569    CStackedDisksModel_new,                 /* tp_new */
570};
571
572
573//static PyMethodDef module_methods[] = {
574//    {NULL}
575//};
576
577/**
578 * Function used to add the model class to a module
579 * @param module: module to add the class to
580 */ 
581void addCStackedDisksModel(PyObject *module) {
582        PyObject *d;
583       
584    if (PyType_Ready(&CStackedDisksModelType) < 0)
585        return;
586
587    Py_INCREF(&CStackedDisksModelType);
588    PyModule_AddObject(module, "CStackedDisksModel", (PyObject *)&CStackedDisksModelType);
589   
590    d = PyModule_GetDict(module);
591    CStackedDisksModelError = PyErr_NewException("CStackedDisksModel.error", NULL, NULL);
592    PyDict_SetItemString(d, "CStackedDisksModelError", CStackedDisksModelError);
593}
594
Note: See TracBrowser for help on using the repository browser.