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