source: sasview/sansmodels/src/sans/models/c_models/CLamellarPSHGModel.cpp @ 4d270706

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

change destructor for models

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