source: sasview/src/sans/models/c_extension/python_wrapper/generated/CCoreFourShellModel.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: 42.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/** CCoreFourShellModel
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\corefourshell.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 "corefourshell.h"
39#include "dispersion_visitor.hh"
40
41/// Error object for raised exceptions
42static PyObject * CCoreFourShellModelError = 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    CoreFourShellModel * model;
54    /// Log for unit testing
55    PyObject * log;
56} CCoreFourShellModel;
57
58
59static void
60CCoreFourShellModel_dealloc(CCoreFourShellModel* 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 *
72CCoreFourShellModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
73{
74    CCoreFourShellModel *self;
75   
76    self = (CCoreFourShellModel *)type->tp_alloc(type, 0);
77   
78    return (PyObject *)self;
79}
80
81static int
82CCoreFourShellModel_init(CCoreFourShellModel *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 CoreFourShellModel();
91
92        // Initialize parameter dictionary
93        PyDict_SetItemString(self->params,"sld_core0",Py_BuildValue("d",0.000006400000));
94        PyDict_SetItemString(self->params,"Up_frac_i",Py_BuildValue("d",0.500000000000));
95        PyDict_SetItemString(self->params,"Up_frac_f",Py_BuildValue("d",0.500000000000));
96        PyDict_SetItemString(self->params,"rad_core0",Py_BuildValue("d",60.000000000000));
97        PyDict_SetItemString(self->params,"sld_shell3",Py_BuildValue("d",0.000003000000));
98        PyDict_SetItemString(self->params,"Up_theta",Py_BuildValue("d",0.000000000000));
99        PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",1.000000000000));
100        PyDict_SetItemString(self->params,"thick_shell3",Py_BuildValue("d",10.000000000000));
101        PyDict_SetItemString(self->params,"M_phi_core0",Py_BuildValue("d",0.000000000000));
102        PyDict_SetItemString(self->params,"M_phi_solv",Py_BuildValue("d",0.000000000000));
103        PyDict_SetItemString(self->params,"M0_sld_core0",Py_BuildValue("d",0.000000000000));
104        PyDict_SetItemString(self->params,"thick_shell4",Py_BuildValue("d",10.000000000000));
105        PyDict_SetItemString(self->params,"sld_shell4",Py_BuildValue("d",0.000004000000));
106        PyDict_SetItemString(self->params,"sld_shell2",Py_BuildValue("d",0.000002000000));
107        PyDict_SetItemString(self->params,"thick_shell1",Py_BuildValue("d",10.000000000000));
108        PyDict_SetItemString(self->params,"thick_shell2",Py_BuildValue("d",10.000000000000));
109        PyDict_SetItemString(self->params,"sld_shell1",Py_BuildValue("d",0.000001000000));
110        PyDict_SetItemString(self->params,"M_theta_core0",Py_BuildValue("d",0.000000000000));
111        PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.001000000000));
112        PyDict_SetItemString(self->params,"M0_sld_solv",Py_BuildValue("d",0.000000000000));
113        PyDict_SetItemString(self->params,"M_theta_shell3",Py_BuildValue("d",0.000000000000));
114        PyDict_SetItemString(self->params,"M_theta_shell2",Py_BuildValue("d",0.000000000000));
115        PyDict_SetItemString(self->params,"M_theta_shell1",Py_BuildValue("d",0.000000000000));
116        PyDict_SetItemString(self->params,"sld_solv",Py_BuildValue("d",0.000006400000));
117        PyDict_SetItemString(self->params,"M_theta_shell4",Py_BuildValue("d",0.000000000000));
118        PyDict_SetItemString(self->params,"M_phi_shell2",Py_BuildValue("d",0.000000000000));
119        PyDict_SetItemString(self->params,"M_phi_shell3",Py_BuildValue("d",0.000000000000));
120        PyDict_SetItemString(self->params,"M_phi_shell1",Py_BuildValue("d",0.000000000000));
121        PyDict_SetItemString(self->params,"M_phi_shell4",Py_BuildValue("d",0.000000000000));
122        PyDict_SetItemString(self->params,"M0_sld_shell4",Py_BuildValue("d",0.000000000000));
123        PyDict_SetItemString(self->params,"M0_sld_shell3",Py_BuildValue("d",0.000000000000));
124        PyDict_SetItemString(self->params,"M0_sld_shell2",Py_BuildValue("d",0.000000000000));
125        PyDict_SetItemString(self->params,"M0_sld_shell1",Py_BuildValue("d",0.000000000000));
126        PyDict_SetItemString(self->params,"M_theta_solv",Py_BuildValue("d",0.000000000000));
127        // Initialize dispersion / averaging parameter dict
128        DispersionVisitor* visitor = new DispersionVisitor();
129        PyObject * disp_dict;
130        disp_dict = PyDict_New();
131        self->model->rad_core0.dispersion->accept_as_source(visitor, self->model->rad_core0.dispersion, disp_dict);
132        PyDict_SetItemString(self->dispersion, "rad_core0", disp_dict);
133        disp_dict = PyDict_New();
134        self->model->thick_shell1.dispersion->accept_as_source(visitor, self->model->thick_shell1.dispersion, disp_dict);
135        PyDict_SetItemString(self->dispersion, "thick_shell1", disp_dict);
136        disp_dict = PyDict_New();
137        self->model->thick_shell2.dispersion->accept_as_source(visitor, self->model->thick_shell2.dispersion, disp_dict);
138        PyDict_SetItemString(self->dispersion, "thick_shell2", disp_dict);
139        disp_dict = PyDict_New();
140        self->model->thick_shell3.dispersion->accept_as_source(visitor, self->model->thick_shell3.dispersion, disp_dict);
141        PyDict_SetItemString(self->dispersion, "thick_shell3", disp_dict);
142        disp_dict = PyDict_New();
143        self->model->thick_shell4.dispersion->accept_as_source(visitor, self->model->thick_shell4.dispersion, disp_dict);
144        PyDict_SetItemString(self->dispersion, "thick_shell4", disp_dict);
145
146
147         
148        // Create empty log
149        self->log = PyDict_New();
150       
151       
152
153    }
154    return 0;
155}
156
157static char name_params[] = "params";
158static char def_params[] = "Parameters";
159static char name_dispersion[] = "dispersion";
160static char def_dispersion[] = "Dispersion parameters";
161static char name_log[] = "log";
162static char def_log[] = "Log";
163
164static PyMemberDef CCoreFourShellModel_members[] = {
165    {name_params, T_OBJECT, offsetof(CCoreFourShellModel, params), 0, def_params},
166        {name_dispersion, T_OBJECT, offsetof(CCoreFourShellModel, dispersion), 0, def_dispersion},     
167    {name_log, T_OBJECT, offsetof(CCoreFourShellModel, log), 0, def_log},
168    {NULL}  /* Sentinel */
169};
170
171/** Read double from PyObject
172    @param p PyObject
173    @return double
174*/
175double CCoreFourShellModel_readDouble(PyObject *p) {
176    if (PyFloat_Check(p)==1) {
177        return (double)(((PyFloatObject *)(p))->ob_fval);
178    } else if (PyInt_Check(p)==1) {
179        return (double)(((PyIntObject *)(p))->ob_ival);
180    } else if (PyLong_Check(p)==1) {
181        return (double)PyLong_AsLong(p);
182    } else {
183        return 0.0;
184    }
185}
186/**
187 * Function to call to evaluate model
188 * @param args: input numpy array q[]
189 * @return: numpy array object
190 */
191 
192static PyObject *evaluateOneDim(CoreFourShellModel* model, PyArrayObject *q){
193    PyArrayObject *result;
194   
195    // Check validity of array q , q must be of dimension 1, an array of double
196    if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE)
197    {
198        //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num;
199        //PyErr_SetString(PyExc_ValueError , message);
200        return NULL;
201    }
202    result = (PyArrayObject *)PyArray_FromDims(q->nd, (int *)(q->dimensions), PyArray_DOUBLE);
203        if (result == NULL) {
204        const char * message= "Could not create result ";
205        PyErr_SetString(PyExc_RuntimeError , message);
206                return NULL;
207        }
208#pragma omp parallel for
209         for (int i = 0; i < q->dimensions[0]; i++){
210      double q_value  = *(double *)(q->data + i*q->strides[0]);
211      double *result_value = (double *)(result->data + i*result->strides[0]);
212      *result_value =(*model)(q_value);
213        }
214    return PyArray_Return(result); 
215 }
216
217 /**
218 * Function to call to evaluate model
219 * @param args: input numpy array  [x[],y[]]
220 * @return: numpy array object
221 */
222 static PyObject * evaluateTwoDimXY( CoreFourShellModel* model, 
223                              PyArrayObject *x, PyArrayObject *y)
224 {
225    PyArrayObject *result;
226    int x_len, y_len, dims[1];
227    //check validity of input vectors
228    if (x->nd != 1 || x->descr->type_num != PyArray_DOUBLE
229        || y->nd != 1 || y->descr->type_num != PyArray_DOUBLE
230        || y->dimensions[0] != x->dimensions[0]){
231        const char * message= "evaluateTwoDimXY  expect 2 numpy arrays";
232        PyErr_SetString(PyExc_ValueError , message); 
233        return NULL;
234    }
235   
236        if (PyArray_Check(x) && PyArray_Check(y)) {
237               
238            x_len = dims[0]= x->dimensions[0];
239        y_len = dims[0]= y->dimensions[0];
240           
241            // Make a new double matrix of same dims
242        result=(PyArrayObject *) PyArray_FromDims(1,dims,NPY_DOUBLE);
243        if (result == NULL){
244            const char * message= "Could not create result ";
245        PyErr_SetString(PyExc_RuntimeError , message);
246            return NULL;
247            }
248       
249        /* Do the calculation. */
250#pragma omp parallel for
251        for (int i=0; i< x_len; i++) {
252            double x_value = *(double *)(x->data + i*x->strides[0]);
253                    double y_value = *(double *)(y->data + i*y->strides[0]);
254                        double *result_value = (double *)(result->data +
255                              i*result->strides[0]);
256                        *result_value = (*model)(x_value, y_value);
257        }           
258        return PyArray_Return(result); 
259       
260        }else{
261                    PyErr_SetString(CCoreFourShellModelError, 
262                   "CCoreFourShellModel.evaluateTwoDimXY couldn't run.");
263                return NULL;
264                }       
265}
266/**
267 *  evalDistribution function evaluate a model function with input vector
268 *  @param args: input q as vector or [qx, qy] where qx, qy are vectors
269 *
270 */ 
271static PyObject * evalDistribution(CCoreFourShellModel *self, PyObject *args){
272        PyObject *qx, *qy;
273        PyArrayObject * pars;
274        int npars ,mpars;
275       
276        // Get parameters
277       
278            // Reader parameter dictionary
279    self->model->sld_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_core0") );
280    self->model->Up_frac_i = PyFloat_AsDouble( PyDict_GetItemString(self->params, "Up_frac_i") );
281    self->model->Up_frac_f = PyFloat_AsDouble( PyDict_GetItemString(self->params, "Up_frac_f") );
282    self->model->rad_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "rad_core0") );
283    self->model->sld_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell3") );
284    self->model->Up_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "Up_theta") );
285    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
286    self->model->thick_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell3") );
287    self->model->M_phi_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_core0") );
288    self->model->M_phi_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_solv") );
289    self->model->M0_sld_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_core0") );
290    self->model->thick_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell4") );
291    self->model->sld_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell4") );
292    self->model->sld_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell2") );
293    self->model->thick_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell1") );
294    self->model->thick_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell2") );
295    self->model->sld_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell1") );
296    self->model->M_theta_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_core0") );
297    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
298    self->model->M0_sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_solv") );
299    self->model->M_theta_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell3") );
300    self->model->M_theta_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell2") );
301    self->model->M_theta_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell1") );
302    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
303    self->model->M_theta_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell4") );
304    self->model->M_phi_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell2") );
305    self->model->M_phi_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell3") );
306    self->model->M_phi_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell1") );
307    self->model->M_phi_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell4") );
308    self->model->M0_sld_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell4") );
309    self->model->M0_sld_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell3") );
310    self->model->M0_sld_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell2") );
311    self->model->M0_sld_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell1") );
312    self->model->M_theta_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_solv") );
313    // Read in dispersion parameters
314    PyObject* disp_dict;
315    DispersionVisitor* visitor = new DispersionVisitor();
316    disp_dict = PyDict_GetItemString(self->dispersion, "rad_core0");
317    self->model->rad_core0.dispersion->accept_as_destination(visitor, self->model->rad_core0.dispersion, disp_dict);
318    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell1");
319    self->model->thick_shell1.dispersion->accept_as_destination(visitor, self->model->thick_shell1.dispersion, disp_dict);
320    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell2");
321    self->model->thick_shell2.dispersion->accept_as_destination(visitor, self->model->thick_shell2.dispersion, disp_dict);
322    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell3");
323    self->model->thick_shell3.dispersion->accept_as_destination(visitor, self->model->thick_shell3.dispersion, disp_dict);
324    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell4");
325    self->model->thick_shell4.dispersion->accept_as_destination(visitor, self->model->thick_shell4.dispersion, disp_dict);
326
327       
328        // Get input and determine whether we have to supply a 1D or 2D return value.
329        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
330            PyErr_SetString(CCoreFourShellModelError, 
331                "CCoreFourShellModel.evalDistribution expects a q value.");
332                return NULL;
333        }
334    // Check params
335       
336    if(PyArray_Check(pars)==1) {
337               
338            // Length of list should 1 or 2
339            npars = pars->nd; 
340            if(npars==1) {
341                // input is a numpy array
342                if (PyArray_Check(pars)) {
343                        return evaluateOneDim(self->model, (PyArrayObject*)pars); 
344                    }
345                }else{
346                    PyErr_SetString(CCoreFourShellModelError, 
347                   "CCoreFourShellModel.evalDistribution expect numpy array of one dimension.");
348                return NULL;
349                }
350    }else if( PyList_Check(pars)==1) {
351        // Length of list should be 2 for I(qx,qy)
352            mpars = PyList_GET_SIZE(pars); 
353            if(mpars!=2) {
354                PyErr_SetString(CCoreFourShellModelError, 
355                        "CCoreFourShellModel.evalDistribution expects a list of dimension 2.");
356                return NULL;
357            }
358             qx = PyList_GET_ITEM(pars,0);
359             qy = PyList_GET_ITEM(pars,1);
360             if (PyArray_Check(qx) && PyArray_Check(qy)) {
361                 return evaluateTwoDimXY(self->model, (PyArrayObject*)qx,
362                           (PyArrayObject*)qy);
363                 }else{
364                    PyErr_SetString(CCoreFourShellModelError, 
365                   "CCoreFourShellModel.evalDistribution expect 2 numpy arrays in list.");
366                return NULL;
367             }
368        }
369        PyErr_SetString(CCoreFourShellModelError, 
370                   "CCoreFourShellModel.evalDistribution couln't be run.");
371        return NULL;
372       
373}
374
375/**
376 * Function to call to evaluate model
377 * @param args: input q or [q,phi]
378 * @return: function value
379 */
380static PyObject * run(CCoreFourShellModel *self, PyObject *args) {
381        double q_value, phi_value;
382        PyObject* pars;
383        int npars;
384       
385        // Get parameters
386       
387            // Reader parameter dictionary
388    self->model->sld_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_core0") );
389    self->model->Up_frac_i = PyFloat_AsDouble( PyDict_GetItemString(self->params, "Up_frac_i") );
390    self->model->Up_frac_f = PyFloat_AsDouble( PyDict_GetItemString(self->params, "Up_frac_f") );
391    self->model->rad_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "rad_core0") );
392    self->model->sld_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell3") );
393    self->model->Up_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "Up_theta") );
394    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
395    self->model->thick_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell3") );
396    self->model->M_phi_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_core0") );
397    self->model->M_phi_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_solv") );
398    self->model->M0_sld_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_core0") );
399    self->model->thick_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell4") );
400    self->model->sld_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell4") );
401    self->model->sld_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell2") );
402    self->model->thick_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell1") );
403    self->model->thick_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell2") );
404    self->model->sld_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell1") );
405    self->model->M_theta_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_core0") );
406    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
407    self->model->M0_sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_solv") );
408    self->model->M_theta_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell3") );
409    self->model->M_theta_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell2") );
410    self->model->M_theta_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell1") );
411    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
412    self->model->M_theta_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell4") );
413    self->model->M_phi_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell2") );
414    self->model->M_phi_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell3") );
415    self->model->M_phi_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell1") );
416    self->model->M_phi_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell4") );
417    self->model->M0_sld_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell4") );
418    self->model->M0_sld_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell3") );
419    self->model->M0_sld_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell2") );
420    self->model->M0_sld_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell1") );
421    self->model->M_theta_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_solv") );
422    // Read in dispersion parameters
423    PyObject* disp_dict;
424    DispersionVisitor* visitor = new DispersionVisitor();
425    disp_dict = PyDict_GetItemString(self->dispersion, "rad_core0");
426    self->model->rad_core0.dispersion->accept_as_destination(visitor, self->model->rad_core0.dispersion, disp_dict);
427    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell1");
428    self->model->thick_shell1.dispersion->accept_as_destination(visitor, self->model->thick_shell1.dispersion, disp_dict);
429    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell2");
430    self->model->thick_shell2.dispersion->accept_as_destination(visitor, self->model->thick_shell2.dispersion, disp_dict);
431    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell3");
432    self->model->thick_shell3.dispersion->accept_as_destination(visitor, self->model->thick_shell3.dispersion, disp_dict);
433    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell4");
434    self->model->thick_shell4.dispersion->accept_as_destination(visitor, self->model->thick_shell4.dispersion, disp_dict);
435
436       
437        // Get input and determine whether we have to supply a 1D or 2D return value.
438        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
439            PyErr_SetString(CCoreFourShellModelError, 
440                "CCoreFourShellModel.run expects a q value.");
441                return NULL;
442        }
443         
444        // Check params
445        if( PyList_Check(pars)==1) {
446               
447                // Length of list should be 2 for I(q,phi)
448            npars = PyList_GET_SIZE(pars); 
449            if(npars!=2) {
450                PyErr_SetString(CCoreFourShellModelError, 
451                        "CCoreFourShellModel.run expects a double or a list of dimension 2.");
452                return NULL;
453            }
454            // We have a vector q, get the q and phi values at which
455            // to evaluate I(q,phi)
456            q_value = CCoreFourShellModel_readDouble(PyList_GET_ITEM(pars,0));
457            phi_value = CCoreFourShellModel_readDouble(PyList_GET_ITEM(pars,1));
458            // Skip zero
459            if (q_value==0) {
460                return Py_BuildValue("d",0.0);
461            }
462                return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value));
463
464        } else {
465
466                // We have a scalar q, we will evaluate I(q)
467                q_value = CCoreFourShellModel_readDouble(pars);         
468               
469                return Py_BuildValue("d",(*(self->model))(q_value));
470        }       
471}
472/**
473 * Function to call to calculate_ER
474 * @return: effective radius value
475 */
476static PyObject * calculate_ER(CCoreFourShellModel *self) {
477
478        // Get parameters
479       
480            // Reader parameter dictionary
481    self->model->sld_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_core0") );
482    self->model->Up_frac_i = PyFloat_AsDouble( PyDict_GetItemString(self->params, "Up_frac_i") );
483    self->model->Up_frac_f = PyFloat_AsDouble( PyDict_GetItemString(self->params, "Up_frac_f") );
484    self->model->rad_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "rad_core0") );
485    self->model->sld_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell3") );
486    self->model->Up_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "Up_theta") );
487    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
488    self->model->thick_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell3") );
489    self->model->M_phi_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_core0") );
490    self->model->M_phi_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_solv") );
491    self->model->M0_sld_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_core0") );
492    self->model->thick_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell4") );
493    self->model->sld_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell4") );
494    self->model->sld_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell2") );
495    self->model->thick_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell1") );
496    self->model->thick_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell2") );
497    self->model->sld_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell1") );
498    self->model->M_theta_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_core0") );
499    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
500    self->model->M0_sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_solv") );
501    self->model->M_theta_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell3") );
502    self->model->M_theta_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell2") );
503    self->model->M_theta_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell1") );
504    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
505    self->model->M_theta_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell4") );
506    self->model->M_phi_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell2") );
507    self->model->M_phi_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell3") );
508    self->model->M_phi_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell1") );
509    self->model->M_phi_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell4") );
510    self->model->M0_sld_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell4") );
511    self->model->M0_sld_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell3") );
512    self->model->M0_sld_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell2") );
513    self->model->M0_sld_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell1") );
514    self->model->M_theta_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_solv") );
515    // Read in dispersion parameters
516    PyObject* disp_dict;
517    DispersionVisitor* visitor = new DispersionVisitor();
518    disp_dict = PyDict_GetItemString(self->dispersion, "rad_core0");
519    self->model->rad_core0.dispersion->accept_as_destination(visitor, self->model->rad_core0.dispersion, disp_dict);
520    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell1");
521    self->model->thick_shell1.dispersion->accept_as_destination(visitor, self->model->thick_shell1.dispersion, disp_dict);
522    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell2");
523    self->model->thick_shell2.dispersion->accept_as_destination(visitor, self->model->thick_shell2.dispersion, disp_dict);
524    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell3");
525    self->model->thick_shell3.dispersion->accept_as_destination(visitor, self->model->thick_shell3.dispersion, disp_dict);
526    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell4");
527    self->model->thick_shell4.dispersion->accept_as_destination(visitor, self->model->thick_shell4.dispersion, disp_dict);
528
529               
530        return Py_BuildValue("d",(*(self->model)).calculate_ER());
531
532}
533/**
534 * Function to call to cal the ratio shell volume/ total volume
535 * @return: the ratio shell volume/ total volume
536 */
537static PyObject * calculate_VR(CCoreFourShellModel *self) {
538
539        // Get parameters
540       
541            // Reader parameter dictionary
542    self->model->sld_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_core0") );
543    self->model->Up_frac_i = PyFloat_AsDouble( PyDict_GetItemString(self->params, "Up_frac_i") );
544    self->model->Up_frac_f = PyFloat_AsDouble( PyDict_GetItemString(self->params, "Up_frac_f") );
545    self->model->rad_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "rad_core0") );
546    self->model->sld_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell3") );
547    self->model->Up_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "Up_theta") );
548    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
549    self->model->thick_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell3") );
550    self->model->M_phi_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_core0") );
551    self->model->M_phi_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_solv") );
552    self->model->M0_sld_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_core0") );
553    self->model->thick_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell4") );
554    self->model->sld_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell4") );
555    self->model->sld_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell2") );
556    self->model->thick_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell1") );
557    self->model->thick_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell2") );
558    self->model->sld_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell1") );
559    self->model->M_theta_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_core0") );
560    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
561    self->model->M0_sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_solv") );
562    self->model->M_theta_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell3") );
563    self->model->M_theta_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell2") );
564    self->model->M_theta_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell1") );
565    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
566    self->model->M_theta_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell4") );
567    self->model->M_phi_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell2") );
568    self->model->M_phi_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell3") );
569    self->model->M_phi_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell1") );
570    self->model->M_phi_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell4") );
571    self->model->M0_sld_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell4") );
572    self->model->M0_sld_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell3") );
573    self->model->M0_sld_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell2") );
574    self->model->M0_sld_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell1") );
575    self->model->M_theta_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_solv") );
576    // Read in dispersion parameters
577    PyObject* disp_dict;
578    DispersionVisitor* visitor = new DispersionVisitor();
579    disp_dict = PyDict_GetItemString(self->dispersion, "rad_core0");
580    self->model->rad_core0.dispersion->accept_as_destination(visitor, self->model->rad_core0.dispersion, disp_dict);
581    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell1");
582    self->model->thick_shell1.dispersion->accept_as_destination(visitor, self->model->thick_shell1.dispersion, disp_dict);
583    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell2");
584    self->model->thick_shell2.dispersion->accept_as_destination(visitor, self->model->thick_shell2.dispersion, disp_dict);
585    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell3");
586    self->model->thick_shell3.dispersion->accept_as_destination(visitor, self->model->thick_shell3.dispersion, disp_dict);
587    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell4");
588    self->model->thick_shell4.dispersion->accept_as_destination(visitor, self->model->thick_shell4.dispersion, disp_dict);
589
590               
591        return Py_BuildValue("d",(*(self->model)).calculate_VR());
592
593}
594/**
595 * Function to call to evaluate model in cartesian coordinates
596 * @param args: input q or [qx, qy]]
597 * @return: function value
598 */
599static PyObject * runXY(CCoreFourShellModel *self, PyObject *args) {
600        double qx_value, qy_value;
601        PyObject* pars;
602        int npars;
603       
604        // Get parameters
605       
606            // Reader parameter dictionary
607    self->model->sld_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_core0") );
608    self->model->Up_frac_i = PyFloat_AsDouble( PyDict_GetItemString(self->params, "Up_frac_i") );
609    self->model->Up_frac_f = PyFloat_AsDouble( PyDict_GetItemString(self->params, "Up_frac_f") );
610    self->model->rad_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "rad_core0") );
611    self->model->sld_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell3") );
612    self->model->Up_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "Up_theta") );
613    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
614    self->model->thick_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell3") );
615    self->model->M_phi_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_core0") );
616    self->model->M_phi_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_solv") );
617    self->model->M0_sld_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_core0") );
618    self->model->thick_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell4") );
619    self->model->sld_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell4") );
620    self->model->sld_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell2") );
621    self->model->thick_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell1") );
622    self->model->thick_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell2") );
623    self->model->sld_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_shell1") );
624    self->model->M_theta_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_core0") );
625    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
626    self->model->M0_sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_solv") );
627    self->model->M_theta_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell3") );
628    self->model->M_theta_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell2") );
629    self->model->M_theta_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell1") );
630    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
631    self->model->M_theta_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_shell4") );
632    self->model->M_phi_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell2") );
633    self->model->M_phi_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell3") );
634    self->model->M_phi_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell1") );
635    self->model->M_phi_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_phi_shell4") );
636    self->model->M0_sld_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell4") );
637    self->model->M0_sld_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell3") );
638    self->model->M0_sld_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell2") );
639    self->model->M0_sld_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M0_sld_shell1") );
640    self->model->M_theta_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "M_theta_solv") );
641    // Read in dispersion parameters
642    PyObject* disp_dict;
643    DispersionVisitor* visitor = new DispersionVisitor();
644    disp_dict = PyDict_GetItemString(self->dispersion, "rad_core0");
645    self->model->rad_core0.dispersion->accept_as_destination(visitor, self->model->rad_core0.dispersion, disp_dict);
646    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell1");
647    self->model->thick_shell1.dispersion->accept_as_destination(visitor, self->model->thick_shell1.dispersion, disp_dict);
648    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell2");
649    self->model->thick_shell2.dispersion->accept_as_destination(visitor, self->model->thick_shell2.dispersion, disp_dict);
650    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell3");
651    self->model->thick_shell3.dispersion->accept_as_destination(visitor, self->model->thick_shell3.dispersion, disp_dict);
652    disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell4");
653    self->model->thick_shell4.dispersion->accept_as_destination(visitor, self->model->thick_shell4.dispersion, disp_dict);
654
655       
656        // Get input and determine whether we have to supply a 1D or 2D return value.
657        if ( !PyArg_ParseTuple(args,"O",&pars) ) {
658            PyErr_SetString(CCoreFourShellModelError, 
659                "CCoreFourShellModel.run expects a q value.");
660                return NULL;
661        }
662         
663        // Check params
664        if( PyList_Check(pars)==1) {
665               
666                // Length of list should be 2 for I(qx, qy))
667            npars = PyList_GET_SIZE(pars); 
668            if(npars!=2) {
669                PyErr_SetString(CCoreFourShellModelError, 
670                        "CCoreFourShellModel.run expects a double or a list of dimension 2.");
671                return NULL;
672            }
673            // We have a vector q, get the qx and qy values at which
674            // to evaluate I(qx,qy)
675            qx_value = CCoreFourShellModel_readDouble(PyList_GET_ITEM(pars,0));
676            qy_value = CCoreFourShellModel_readDouble(PyList_GET_ITEM(pars,1));
677            return Py_BuildValue("d",(*(self->model))(qx_value,qy_value));
678
679        } else {
680
681                // We have a scalar q, we will evaluate I(q)
682                qx_value = CCoreFourShellModel_readDouble(pars);               
683               
684                return Py_BuildValue("d",(*(self->model))(qx_value));
685        }       
686}
687
688static PyObject * reset(CCoreFourShellModel *self, PyObject *args) {
689   
690
691    return Py_BuildValue("d",0.0);
692}
693
694static PyObject * set_dispersion(CCoreFourShellModel *self, PyObject *args) {
695        PyObject * disp;
696        const char * par_name;
697
698        if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
699            PyErr_SetString(CCoreFourShellModelError,
700                "CCoreFourShellModel.set_dispersion expects a DispersionModel object.");
701                return NULL;
702        }
703        void *temp = PyCObject_AsVoidPtr(disp);
704        DispersionModel * dispersion = static_cast<DispersionModel *>(temp);
705
706
707        // Ugliness necessary to go from python to C
708            // TODO: refactor this
709    if (!strcmp(par_name, "rad_core0")) {
710        self->model->rad_core0.dispersion = dispersion;
711    } else    if (!strcmp(par_name, "thick_shell1")) {
712        self->model->thick_shell1.dispersion = dispersion;
713    } else    if (!strcmp(par_name, "thick_shell2")) {
714        self->model->thick_shell2.dispersion = dispersion;
715    } else    if (!strcmp(par_name, "thick_shell3")) {
716        self->model->thick_shell3.dispersion = dispersion;
717    } else    if (!strcmp(par_name, "thick_shell4")) {
718        self->model->thick_shell4.dispersion = dispersion;
719    } else {
720            PyErr_SetString(CCoreFourShellModelError,
721                "CCoreFourShellModel.set_dispersion expects a valid parameter name.");
722                return NULL;
723        }
724
725        DispersionVisitor* visitor = new DispersionVisitor();
726        PyObject * disp_dict = PyDict_New();
727        dispersion->accept_as_source(visitor, dispersion, disp_dict);
728        PyDict_SetItemString(self->dispersion, par_name, disp_dict);
729    return Py_BuildValue("i",1);
730}
731
732
733static PyMethodDef CCoreFourShellModel_methods[] = {
734    {"run",      (PyCFunction)run     , METH_VARARGS,
735      "Evaluate the model at a given Q or Q, phi"},
736    {"runXY",      (PyCFunction)runXY     , METH_VARARGS,
737      "Evaluate the model at a given Q or Qx, Qy"},
738    {"calculate_ER",      (PyCFunction)calculate_ER     , METH_VARARGS,
739      "Evaluate the model at a given Q or Q, phi"},
740    {"calculate_VR",      (PyCFunction)calculate_VR     , METH_VARARGS,
741      "Evaluate VR"},   
742    {"evalDistribution",  (PyCFunction)evalDistribution , METH_VARARGS,
743      "Evaluate the model at a given Q or Qx, Qy vector "},
744    {"reset",    (PyCFunction)reset   , METH_VARARGS,
745      "Reset pair correlation"},
746    {"set_dispersion",      (PyCFunction)set_dispersion     , METH_VARARGS,
747      "Set the dispersion model for a given parameter"},
748   {NULL}
749};
750
751static PyTypeObject CCoreFourShellModelType = {
752    PyObject_HEAD_INIT(NULL)
753    0,                         /*ob_size*/
754    "CCoreFourShellModel",             /*tp_name*/
755    sizeof(CCoreFourShellModel),             /*tp_basicsize*/
756    0,                         /*tp_itemsize*/
757    (destructor)CCoreFourShellModel_dealloc, /*tp_dealloc*/
758    0,                         /*tp_print*/
759    0,                         /*tp_getattr*/
760    0,                         /*tp_setattr*/
761    0,                         /*tp_compare*/
762    0,                         /*tp_repr*/
763    0,                         /*tp_as_number*/
764    0,                         /*tp_as_sequence*/
765    0,                         /*tp_as_mapping*/
766    0,                         /*tp_hash */
767    0,                         /*tp_call*/
768    0,                         /*tp_str*/
769    0,                         /*tp_getattro*/
770    0,                         /*tp_setattro*/
771    0,                         /*tp_as_buffer*/
772    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
773    "CCoreFourShellModel objects",           /* tp_doc */
774    0,                         /* tp_traverse */
775    0,                         /* tp_clear */
776    0,                         /* tp_richcompare */
777    0,                         /* tp_weaklistoffset */
778    0,                         /* tp_iter */
779    0,                         /* tp_iternext */
780    CCoreFourShellModel_methods,             /* tp_methods */
781    CCoreFourShellModel_members,             /* tp_members */
782    0,                         /* tp_getset */
783    0,                         /* tp_base */
784    0,                         /* tp_dict */
785    0,                         /* tp_descr_get */
786    0,                         /* tp_descr_set */
787    0,                         /* tp_dictoffset */
788    (initproc)CCoreFourShellModel_init,      /* tp_init */
789    0,                         /* tp_alloc */
790    CCoreFourShellModel_new,                 /* tp_new */
791};
792
793
794//static PyMethodDef module_methods[] = {
795//    {NULL}
796//};
797
798/**
799 * Function used to add the model class to a module
800 * @param module: module to add the class to
801 */ 
802void addCCoreFourShellModel(PyObject *module) {
803        PyObject *d;
804       
805    if (PyType_Ready(&CCoreFourShellModelType) < 0)
806        return;
807
808    Py_INCREF(&CCoreFourShellModelType);
809    PyModule_AddObject(module, "CCoreFourShellModel", (PyObject *)&CCoreFourShellModelType);
810   
811    d = PyModule_GetDict(module);
812    static char error_name[] = "CCoreFourShellModel.error";
813    CCoreFourShellModelError = PyErr_NewException(error_name, NULL, NULL);
814    PyDict_SetItemString(d, "CCoreFourShellModelError", CCoreFourShellModelError);
815}
816
Note: See TracBrowser for help on using the repository browser.