source: sasview/sansmodels/src/sans/models/c_models/COblateModel.cpp @ c451be9

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

change destructor for models

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