source: sasview/sansmodels/src/sans/models/c_models/CLamellarPSHGModel.cpp @ 0b082f3

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 0b082f3 was 0b082f3, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

Re #7 Enable openmp for all models

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