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

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

wrote unittest for all model untested , haven' test critial point error handling

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