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