source: sasview/sansmodels/src/sans/models/c_models/CCoreShellCylinderModel.cpp @ e0a8a3c

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

change the orientation of models

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