source: sasview/sansmodels/src/sans/models/c_models/CLamellarPSHGModel.cpp @ 2605da22

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 2605da22 was 2605da22, checked in by Mathieu Doucet <doucetm@…>, 12 years ago

Re #4 Still a few more warnings

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