source: sasview/sansmodels/src/sans/models/c_models/CParallelepipedModel.cpp @ 2cb89e7

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 2cb89e7 was 2cb89e7, checked in by Jae Cho <jhjcho@…>, 15 years ago

Changed the def. of lengths of sides for 2D,thus consistent w/ 1D. And shortened the names.

  • 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/** CParallelepipedModel
16 *
17 * C extension
18 *
19 * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY
20 *          DO NOT MODIFY THIS FILE, MODIFY parallelepiped.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 "parallelepiped.h"
36}
37
38#include "models.hh"
39#include "dispersion_visitor.hh"
40
41/// Error object for raised exceptions
42static PyObject * CParallelepipedModelError = 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    ParallelepipedModel * model;
54    /// Log for unit testing
55    PyObject * log;
56} CParallelepipedModel;
57
58
59static void
60CParallelepipedModel_dealloc(CParallelepipedModel* self)
61{
62    self->ob_type->tp_free((PyObject*)self);
63   
64
65}
66
67static PyObject *
68CParallelepipedModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
69{
70    CParallelepipedModel *self;
71   
72    self = (CParallelepipedModel *)type->tp_alloc(type, 0);
73   
74    return (PyObject *)self;
75}
76
77static int
78CParallelepipedModel_init(CParallelepipedModel *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 ParallelepipedModel();
86       
87        // Initialize parameter dictionary
88        PyDict_SetItemString(self->params,"short_a",Py_BuildValue("d",35.000000));
89        PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",1.000000));
90        PyDict_SetItemString(self->params,"long_b",Py_BuildValue("d",75.000000));
91        PyDict_SetItemString(self->params,"longer_c",Py_BuildValue("d",400.000000));
92        PyDict_SetItemString(self->params,"parallel_psi",Py_BuildValue("d",0.000000));
93        PyDict_SetItemString(self->params,"parallel_phi",Py_BuildValue("d",0.000000));
94        PyDict_SetItemString(self->params,"parallel_theta",Py_BuildValue("d",0.000000));
95        PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.000000));
96        PyDict_SetItemString(self->params,"contrast",Py_BuildValue("d",0.000005));
97        // Initialize dispersion / averaging parameter dict
98        DispersionVisitor* visitor = new DispersionVisitor();
99        PyObject * disp_dict;
100        disp_dict = PyDict_New();
101        self->model->short_a.dispersion->accept_as_source(visitor, self->model->short_a.dispersion, disp_dict);
102        PyDict_SetItemString(self->dispersion, "short_a", disp_dict);
103        disp_dict = PyDict_New();
104        self->model->long_b.dispersion->accept_as_source(visitor, self->model->long_b.dispersion, disp_dict);
105        PyDict_SetItemString(self->dispersion, "long_b", disp_dict);
106        disp_dict = PyDict_New();
107        self->model->longer_c.dispersion->accept_as_source(visitor, self->model->longer_c.dispersion, disp_dict);
108        PyDict_SetItemString(self->dispersion, "longer_c", disp_dict);
109        disp_dict = PyDict_New();
110        self->model->parallel_phi.dispersion->accept_as_source(visitor, self->model->parallel_phi.dispersion, disp_dict);
111        PyDict_SetItemString(self->dispersion, "parallel_phi", disp_dict);
112        disp_dict = PyDict_New();
113        self->model->parallel_psi.dispersion->accept_as_source(visitor, self->model->parallel_psi.dispersion, disp_dict);
114        PyDict_SetItemString(self->dispersion, "parallel_psi", disp_dict);
115        disp_dict = PyDict_New();
116        self->model->parallel_theta.dispersion->accept_as_source(visitor, self->model->parallel_theta.dispersion, disp_dict);
117        PyDict_SetItemString(self->dispersion, "parallel_theta", 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 CParallelepipedModel_members[] = {
131    {"params", T_OBJECT, offsetof(CParallelepipedModel, params), 0,
132     "Parameters"},
133        {"dispersion", T_OBJECT, offsetof(CParallelepipedModel, dispersion), 0,
134          "Dispersion parameters"},     
135    {"log", T_OBJECT, offsetof(CParallelepipedModel, log), 0,
136     "Log"},
137    {NULL}  /* Sentinel */
138};
139
140/** Read double from PyObject
141    @param p PyObject
142    @return double
143*/
144double CParallelepipedModel_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(ParallelepipedModel* 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( ParallelepipedModel* 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(CParallelepipedModelError, 
231                   "CParallelepipedModel.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(CParallelepipedModel *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->short_a = PyFloat_AsDouble( PyDict_GetItemString(self->params, "short_a") );
249    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
250    self->model->long_b = PyFloat_AsDouble( PyDict_GetItemString(self->params, "long_b") );
251    self->model->longer_c = PyFloat_AsDouble( PyDict_GetItemString(self->params, "longer_c") );
252    self->model->parallel_psi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "parallel_psi") );
253    self->model->parallel_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "parallel_phi") );
254    self->model->parallel_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "parallel_theta") );
255    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
256    self->model->contrast = PyFloat_AsDouble( PyDict_GetItemString(self->params, "contrast") );
257    // Read in dispersion parameters
258    PyObject* disp_dict;
259    DispersionVisitor* visitor = new DispersionVisitor();
260    disp_dict = PyDict_GetItemString(self->dispersion, "short_a");
261    self->model->short_a.dispersion->accept_as_destination(visitor, self->model->short_a.dispersion, disp_dict);
262    disp_dict = PyDict_GetItemString(self->dispersion, "long_b");
263    self->model->long_b.dispersion->accept_as_destination(visitor, self->model->long_b.dispersion, disp_dict);
264    disp_dict = PyDict_GetItemString(self->dispersion, "longer_c");
265    self->model->longer_c.dispersion->accept_as_destination(visitor, self->model->longer_c.dispersion, disp_dict);
266    disp_dict = PyDict_GetItemString(self->dispersion, "parallel_phi");
267    self->model->parallel_phi.dispersion->accept_as_destination(visitor, self->model->parallel_phi.dispersion, disp_dict);
268    disp_dict = PyDict_GetItemString(self->dispersion, "parallel_psi");
269    self->model->parallel_psi.dispersion->accept_as_destination(visitor, self->model->parallel_psi.dispersion, disp_dict);
270    disp_dict = PyDict_GetItemString(self->dispersion, "parallel_theta");
271    self->model->parallel_theta.dispersion->accept_as_destination(visitor, self->model->parallel_theta.dispersion, disp_dict);
272
273       
274        // Get input and determine whether we have to supply a 1D or 2D return value.
275        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
276            PyErr_SetString(CParallelepipedModelError, 
277                "CParallelepipedModel.evalDistribution expects a q value.");
278                return NULL;
279        }
280    // Check params
281       
282    if(PyArray_Check(pars)==1) {
283               
284            // Length of list should 1 or 2
285            npars = pars->nd; 
286            if(npars==1) {
287                // input is a numpy array
288                if (PyArray_Check(pars)) {
289                        return evaluateOneDim(self->model, (PyArrayObject*)pars); 
290                    }
291                }else{
292                    PyErr_SetString(CParallelepipedModelError, 
293                   "CParallelepipedModel.evalDistribution expect numpy array of one dimension.");
294                return NULL;
295                }
296    }else if( PyList_Check(pars)==1) {
297        // Length of list should be 2 for I(qx,qy)
298            mpars = PyList_GET_SIZE(pars); 
299            if(mpars!=2) {
300                PyErr_SetString(CParallelepipedModelError, 
301                        "CParallelepipedModel.evalDistribution expects a list of dimension 2.");
302                return NULL;
303            }
304             qx = PyList_GET_ITEM(pars,0);
305             qy = PyList_GET_ITEM(pars,1);
306             if (PyArray_Check(qx) && PyArray_Check(qy)) {
307                 return evaluateTwoDimXY(self->model, (PyArrayObject*)qx,
308                           (PyArrayObject*)qy);
309                 }else{
310                    PyErr_SetString(CParallelepipedModelError, 
311                   "CParallelepipedModel.evalDistribution expect 2 numpy arrays in list.");
312                return NULL;
313             }
314        }else{
315            PyErr_SetString(CParallelepipedModelError, 
316                   "CParallelepipedModel.evalDistribution couln't be run.");
317            return NULL;
318        }
319}
320
321/**
322 * Function to call to evaluate model
323 * @param args: input q or [q,phi]
324 * @return: function value
325 */
326static PyObject * run(CParallelepipedModel *self, PyObject *args) {
327        double q_value, phi_value;
328        PyObject* pars;
329        int npars;
330       
331        // Get parameters
332       
333            // Reader parameter dictionary
334    self->model->short_a = PyFloat_AsDouble( PyDict_GetItemString(self->params, "short_a") );
335    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
336    self->model->long_b = PyFloat_AsDouble( PyDict_GetItemString(self->params, "long_b") );
337    self->model->longer_c = PyFloat_AsDouble( PyDict_GetItemString(self->params, "longer_c") );
338    self->model->parallel_psi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "parallel_psi") );
339    self->model->parallel_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "parallel_phi") );
340    self->model->parallel_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "parallel_theta") );
341    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
342    self->model->contrast = PyFloat_AsDouble( PyDict_GetItemString(self->params, "contrast") );
343    // Read in dispersion parameters
344    PyObject* disp_dict;
345    DispersionVisitor* visitor = new DispersionVisitor();
346    disp_dict = PyDict_GetItemString(self->dispersion, "short_a");
347    self->model->short_a.dispersion->accept_as_destination(visitor, self->model->short_a.dispersion, disp_dict);
348    disp_dict = PyDict_GetItemString(self->dispersion, "long_b");
349    self->model->long_b.dispersion->accept_as_destination(visitor, self->model->long_b.dispersion, disp_dict);
350    disp_dict = PyDict_GetItemString(self->dispersion, "longer_c");
351    self->model->longer_c.dispersion->accept_as_destination(visitor, self->model->longer_c.dispersion, disp_dict);
352    disp_dict = PyDict_GetItemString(self->dispersion, "parallel_phi");
353    self->model->parallel_phi.dispersion->accept_as_destination(visitor, self->model->parallel_phi.dispersion, disp_dict);
354    disp_dict = PyDict_GetItemString(self->dispersion, "parallel_psi");
355    self->model->parallel_psi.dispersion->accept_as_destination(visitor, self->model->parallel_psi.dispersion, disp_dict);
356    disp_dict = PyDict_GetItemString(self->dispersion, "parallel_theta");
357    self->model->parallel_theta.dispersion->accept_as_destination(visitor, self->model->parallel_theta.dispersion, disp_dict);
358
359       
360        // Get input and determine whether we have to supply a 1D or 2D return value.
361        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
362            PyErr_SetString(CParallelepipedModelError, 
363                "CParallelepipedModel.run expects a q value.");
364                return NULL;
365        }
366         
367        // Check params
368        if( PyList_Check(pars)==1) {
369               
370                // Length of list should be 2 for I(q,phi)
371            npars = PyList_GET_SIZE(pars); 
372            if(npars!=2) {
373                PyErr_SetString(CParallelepipedModelError, 
374                        "CParallelepipedModel.run expects a double or a list of dimension 2.");
375                return NULL;
376            }
377            // We have a vector q, get the q and phi values at which
378            // to evaluate I(q,phi)
379            q_value = CParallelepipedModel_readDouble(PyList_GET_ITEM(pars,0));
380            phi_value = CParallelepipedModel_readDouble(PyList_GET_ITEM(pars,1));
381            // Skip zero
382            if (q_value==0) {
383                return Py_BuildValue("d",0.0);
384            }
385                return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value));
386
387        } else {
388
389                // We have a scalar q, we will evaluate I(q)
390                q_value = CParallelepipedModel_readDouble(pars);               
391               
392                return Py_BuildValue("d",(*(self->model))(q_value));
393        }       
394}
395
396/**
397 * Function to call to evaluate model in cartesian coordinates
398 * @param args: input q or [qx, qy]]
399 * @return: function value
400 */
401static PyObject * runXY(CParallelepipedModel *self, PyObject *args) {
402        double qx_value, qy_value;
403        PyObject* pars;
404        int npars;
405       
406        // Get parameters
407       
408            // Reader parameter dictionary
409    self->model->short_a = PyFloat_AsDouble( PyDict_GetItemString(self->params, "short_a") );
410    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
411    self->model->long_b = PyFloat_AsDouble( PyDict_GetItemString(self->params, "long_b") );
412    self->model->longer_c = PyFloat_AsDouble( PyDict_GetItemString(self->params, "longer_c") );
413    self->model->parallel_psi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "parallel_psi") );
414    self->model->parallel_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "parallel_phi") );
415    self->model->parallel_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "parallel_theta") );
416    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
417    self->model->contrast = PyFloat_AsDouble( PyDict_GetItemString(self->params, "contrast") );
418    // Read in dispersion parameters
419    PyObject* disp_dict;
420    DispersionVisitor* visitor = new DispersionVisitor();
421    disp_dict = PyDict_GetItemString(self->dispersion, "short_a");
422    self->model->short_a.dispersion->accept_as_destination(visitor, self->model->short_a.dispersion, disp_dict);
423    disp_dict = PyDict_GetItemString(self->dispersion, "long_b");
424    self->model->long_b.dispersion->accept_as_destination(visitor, self->model->long_b.dispersion, disp_dict);
425    disp_dict = PyDict_GetItemString(self->dispersion, "longer_c");
426    self->model->longer_c.dispersion->accept_as_destination(visitor, self->model->longer_c.dispersion, disp_dict);
427    disp_dict = PyDict_GetItemString(self->dispersion, "parallel_phi");
428    self->model->parallel_phi.dispersion->accept_as_destination(visitor, self->model->parallel_phi.dispersion, disp_dict);
429    disp_dict = PyDict_GetItemString(self->dispersion, "parallel_psi");
430    self->model->parallel_psi.dispersion->accept_as_destination(visitor, self->model->parallel_psi.dispersion, disp_dict);
431    disp_dict = PyDict_GetItemString(self->dispersion, "parallel_theta");
432    self->model->parallel_theta.dispersion->accept_as_destination(visitor, self->model->parallel_theta.dispersion, disp_dict);
433
434       
435        // Get input and determine whether we have to supply a 1D or 2D return value.
436        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
437            PyErr_SetString(CParallelepipedModelError, 
438                "CParallelepipedModel.run expects a q value.");
439                return NULL;
440        }
441         
442        // Check params
443        if( PyList_Check(pars)==1) {
444               
445                // Length of list should be 2 for I(qx, qy))
446            npars = PyList_GET_SIZE(pars); 
447            if(npars!=2) {
448                PyErr_SetString(CParallelepipedModelError, 
449                        "CParallelepipedModel.run expects a double or a list of dimension 2.");
450                return NULL;
451            }
452            // We have a vector q, get the qx and qy values at which
453            // to evaluate I(qx,qy)
454            qx_value = CParallelepipedModel_readDouble(PyList_GET_ITEM(pars,0));
455            qy_value = CParallelepipedModel_readDouble(PyList_GET_ITEM(pars,1));
456            return Py_BuildValue("d",(*(self->model))(qx_value,qy_value));
457
458        } else {
459
460                // We have a scalar q, we will evaluate I(q)
461                qx_value = CParallelepipedModel_readDouble(pars);               
462               
463                return Py_BuildValue("d",(*(self->model))(qx_value));
464        }       
465}
466
467static PyObject * reset(CParallelepipedModel *self, PyObject *args) {
468   
469
470    return Py_BuildValue("d",0.0);
471}
472
473static PyObject * set_dispersion(CParallelepipedModel *self, PyObject *args) {
474        PyObject * disp;
475        const char * par_name;
476
477        if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
478            PyErr_SetString(CParallelepipedModelError,
479                "CParallelepipedModel.set_dispersion expects a DispersionModel object.");
480                return NULL;
481        }
482        void *temp = PyCObject_AsVoidPtr(disp);
483        DispersionModel * dispersion = static_cast<DispersionModel *>(temp);
484
485
486        // Ugliness necessary to go from python to C
487            // TODO: refactor this
488    if (!strcmp(par_name, "short_a")) {
489        self->model->short_a.dispersion = dispersion;
490    } else    if (!strcmp(par_name, "long_b")) {
491        self->model->long_b.dispersion = dispersion;
492    } else    if (!strcmp(par_name, "longer_c")) {
493        self->model->longer_c.dispersion = dispersion;
494    } else    if (!strcmp(par_name, "parallel_phi")) {
495        self->model->parallel_phi.dispersion = dispersion;
496    } else    if (!strcmp(par_name, "parallel_psi")) {
497        self->model->parallel_psi.dispersion = dispersion;
498    } else    if (!strcmp(par_name, "parallel_theta")) {
499        self->model->parallel_theta.dispersion = dispersion;
500    } else {
501            PyErr_SetString(CParallelepipedModelError,
502                "CParallelepipedModel.set_dispersion expects a valid parameter name.");
503                return NULL;
504        }
505
506        DispersionVisitor* visitor = new DispersionVisitor();
507        PyObject * disp_dict = PyDict_New();
508        dispersion->accept_as_source(visitor, dispersion, disp_dict);
509        PyDict_SetItemString(self->dispersion, par_name, disp_dict);
510    return Py_BuildValue("i",1);
511}
512
513
514static PyMethodDef CParallelepipedModel_methods[] = {
515    {"run",      (PyCFunction)run     , METH_VARARGS,
516      "Evaluate the model at a given Q or Q, phi"},
517    {"runXY",      (PyCFunction)runXY     , METH_VARARGS,
518      "Evaluate the model at a given Q or Qx, Qy"},
519     
520    {"evalDistribution",  (PyCFunction)evalDistribution , METH_VARARGS,
521      "Evaluate the model at a given Q or Qx, Qy vector "},
522    {"reset",    (PyCFunction)reset   , METH_VARARGS,
523      "Reset pair correlation"},
524    {"set_dispersion",      (PyCFunction)set_dispersion     , METH_VARARGS,
525      "Set the dispersion model for a given parameter"},
526   {NULL}
527};
528
529static PyTypeObject CParallelepipedModelType = {
530    PyObject_HEAD_INIT(NULL)
531    0,                         /*ob_size*/
532    "CParallelepipedModel",             /*tp_name*/
533    sizeof(CParallelepipedModel),             /*tp_basicsize*/
534    0,                         /*tp_itemsize*/
535    (destructor)CParallelepipedModel_dealloc, /*tp_dealloc*/
536    0,                         /*tp_print*/
537    0,                         /*tp_getattr*/
538    0,                         /*tp_setattr*/
539    0,                         /*tp_compare*/
540    0,                         /*tp_repr*/
541    0,                         /*tp_as_number*/
542    0,                         /*tp_as_sequence*/
543    0,                         /*tp_as_mapping*/
544    0,                         /*tp_hash */
545    0,                         /*tp_call*/
546    0,                         /*tp_str*/
547    0,                         /*tp_getattro*/
548    0,                         /*tp_setattro*/
549    0,                         /*tp_as_buffer*/
550    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
551    "CParallelepipedModel objects",           /* tp_doc */
552    0,                         /* tp_traverse */
553    0,                         /* tp_clear */
554    0,                         /* tp_richcompare */
555    0,                         /* tp_weaklistoffset */
556    0,                         /* tp_iter */
557    0,                         /* tp_iternext */
558    CParallelepipedModel_methods,             /* tp_methods */
559    CParallelepipedModel_members,             /* tp_members */
560    0,                         /* tp_getset */
561    0,                         /* tp_base */
562    0,                         /* tp_dict */
563    0,                         /* tp_descr_get */
564    0,                         /* tp_descr_set */
565    0,                         /* tp_dictoffset */
566    (initproc)CParallelepipedModel_init,      /* tp_init */
567    0,                         /* tp_alloc */
568    CParallelepipedModel_new,                 /* tp_new */
569};
570
571
572//static PyMethodDef module_methods[] = {
573//    {NULL}
574//};
575
576/**
577 * Function used to add the model class to a module
578 * @param module: module to add the class to
579 */ 
580void addCParallelepipedModel(PyObject *module) {
581        PyObject *d;
582       
583    if (PyType_Ready(&CParallelepipedModelType) < 0)
584        return;
585
586    Py_INCREF(&CParallelepipedModelType);
587    PyModule_AddObject(module, "CParallelepipedModel", (PyObject *)&CParallelepipedModelType);
588   
589    d = PyModule_GetDict(module);
590    CParallelepipedModelError = PyErr_NewException("CParallelepipedModel.error", NULL, NULL);
591    PyDict_SetItemString(d, "CParallelepipedModelError", CParallelepipedModelError);
592}
593
Note: See TracBrowser for help on using the repository browser.