[e096270] | 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 | /** COnionModel |
---|
| 16 | * |
---|
| 17 | * C extension |
---|
| 18 | * |
---|
| 19 | * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY |
---|
| 20 | * DO NOT MODIFY THIS FILE, MODIFY onion.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 "onion.h" |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | #include "models.hh" |
---|
| 39 | #include "dispersion_visitor.hh" |
---|
| 40 | |
---|
| 41 | /// Error object for raised exceptions |
---|
| 42 | static PyObject * COnionModelError = 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 | OnionModel * model; |
---|
| 54 | /// Log for unit testing |
---|
| 55 | PyObject * log; |
---|
| 56 | } COnionModel; |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | static void |
---|
| 60 | COnionModel_dealloc(COnionModel* 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 | |
---|
| 71 | static PyObject * |
---|
| 72 | COnionModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
---|
| 73 | { |
---|
| 74 | COnionModel *self; |
---|
| 75 | |
---|
| 76 | self = (COnionModel *)type->tp_alloc(type, 0); |
---|
| 77 | |
---|
| 78 | return (PyObject *)self; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | static int |
---|
| 82 | COnionModel_init(COnionModel *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 OnionModel(); |
---|
| 90 | |
---|
| 91 | // Initialize parameter dictionary |
---|
[35aface] | 92 | PyDict_SetItemString(self->params,"thick_shell4",Py_BuildValue("d",50.000000000000)); |
---|
| 93 | PyDict_SetItemString(self->params,"thick_shell5",Py_BuildValue("d",50.000000000000)); |
---|
| 94 | PyDict_SetItemString(self->params,"thick_shell9",Py_BuildValue("d",50.000000000000)); |
---|
| 95 | PyDict_SetItemString(self->params,"thick_shell7",Py_BuildValue("d",50.000000000000)); |
---|
[fbd09fa0] | 96 | PyDict_SetItemString(self->params,"sld_core0",Py_BuildValue("d",0.000001000000)); |
---|
| 97 | PyDict_SetItemString(self->params,"rad_core0",Py_BuildValue("d",200.000000000000)); |
---|
[35aface] | 98 | PyDict_SetItemString(self->params,"A_shell10",Py_BuildValue("d",1.000000000000)); |
---|
| 99 | PyDict_SetItemString(self->params,"thick_shell1",Py_BuildValue("d",50.000000000000)); |
---|
| 100 | PyDict_SetItemString(self->params,"func_shell4",Py_BuildValue("d",2.000000000000)); |
---|
| 101 | PyDict_SetItemString(self->params,"func_shell5",Py_BuildValue("d",2.000000000000)); |
---|
| 102 | PyDict_SetItemString(self->params,"func_shell6",Py_BuildValue("d",2.000000000000)); |
---|
| 103 | PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",1.000000000000)); |
---|
| 104 | PyDict_SetItemString(self->params,"func_shell1",Py_BuildValue("d",2.000000000000)); |
---|
| 105 | PyDict_SetItemString(self->params,"thick_shell10",Py_BuildValue("d",50.000000000000)); |
---|
| 106 | PyDict_SetItemString(self->params,"func_shell3",Py_BuildValue("d",2.000000000000)); |
---|
| 107 | PyDict_SetItemString(self->params,"func_shell8",Py_BuildValue("d",2.000000000000)); |
---|
| 108 | PyDict_SetItemString(self->params,"func_shell9",Py_BuildValue("d",2.000000000000)); |
---|
| 109 | PyDict_SetItemString(self->params,"sld_in_shell5",Py_BuildValue("d",0.000003700000)); |
---|
| 110 | PyDict_SetItemString(self->params,"func_shell10",Py_BuildValue("d",2.000000000000)); |
---|
| 111 | PyDict_SetItemString(self->params,"sld_in_shell4",Py_BuildValue("d",0.000003200000)); |
---|
| 112 | PyDict_SetItemString(self->params,"sld_in_shell7",Py_BuildValue("d",0.000004700000)); |
---|
| 113 | PyDict_SetItemString(self->params,"sld_out_shell9",Py_BuildValue("d",0.000006000000)); |
---|
| 114 | PyDict_SetItemString(self->params,"sld_out_shell8",Py_BuildValue("d",0.000005500000)); |
---|
| 115 | PyDict_SetItemString(self->params,"thick_shell6",Py_BuildValue("d",50.000000000000)); |
---|
| 116 | PyDict_SetItemString(self->params,"sld_out_shell2",Py_BuildValue("d",0.000002500000)); |
---|
| 117 | PyDict_SetItemString(self->params,"sld_in_shell9",Py_BuildValue("d",0.000005700000)); |
---|
| 118 | PyDict_SetItemString(self->params,"sld_in_shell8",Py_BuildValue("d",0.000005200000)); |
---|
| 119 | PyDict_SetItemString(self->params,"thick_shell2",Py_BuildValue("d",50.000000000000)); |
---|
[fbd09fa0] | 120 | PyDict_SetItemString(self->params,"thick_shell3",Py_BuildValue("d",50.000000000000)); |
---|
[35aface] | 121 | PyDict_SetItemString(self->params,"sld_out_shell1",Py_BuildValue("d",0.000002000000)); |
---|
[fbd09fa0] | 122 | PyDict_SetItemString(self->params,"sld_out_shell5",Py_BuildValue("d",0.000004000000)); |
---|
[35aface] | 123 | PyDict_SetItemString(self->params,"sld_out_shell3",Py_BuildValue("d",0.000003000000)); |
---|
| 124 | PyDict_SetItemString(self->params,"sld_in_shell6",Py_BuildValue("d",0.000004200000)); |
---|
[fbd09fa0] | 125 | PyDict_SetItemString(self->params,"sld_in_shell1",Py_BuildValue("d",0.000001700000)); |
---|
[35aface] | 126 | PyDict_SetItemString(self->params,"sld_out_shell4",Py_BuildValue("d",0.000003500000)); |
---|
| 127 | PyDict_SetItemString(self->params,"sld_in_shell3",Py_BuildValue("d",0.000002700000)); |
---|
| 128 | PyDict_SetItemString(self->params,"sld_out_shell6",Py_BuildValue("d",0.000004500000)); |
---|
| 129 | PyDict_SetItemString(self->params,"func_shell7",Py_BuildValue("d",2.000000000000)); |
---|
| 130 | PyDict_SetItemString(self->params,"sld_out_shell7",Py_BuildValue("d",0.000005000000)); |
---|
| 131 | PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.000000000000)); |
---|
| 132 | PyDict_SetItemString(self->params,"n_shells",Py_BuildValue("d",1.000000000000)); |
---|
| 133 | PyDict_SetItemString(self->params,"sld_in_shell2",Py_BuildValue("d",0.000002200000)); |
---|
| 134 | PyDict_SetItemString(self->params,"sld_solv",Py_BuildValue("d",0.000006400000)); |
---|
| 135 | PyDict_SetItemString(self->params,"func_shell2",Py_BuildValue("d",2.000000000000)); |
---|
| 136 | PyDict_SetItemString(self->params,"thick_shell8",Py_BuildValue("d",50.000000000000)); |
---|
| 137 | PyDict_SetItemString(self->params,"sld_out_shell10",Py_BuildValue("d",0.000006200000)); |
---|
| 138 | PyDict_SetItemString(self->params,"sld_in_shell10",Py_BuildValue("d",0.000006000000)); |
---|
| 139 | PyDict_SetItemString(self->params,"A_shell8",Py_BuildValue("d",1.000000000000)); |
---|
| 140 | PyDict_SetItemString(self->params,"A_shell9",Py_BuildValue("d",1.000000000000)); |
---|
| 141 | PyDict_SetItemString(self->params,"A_shell6",Py_BuildValue("d",1.000000000000)); |
---|
| 142 | PyDict_SetItemString(self->params,"A_shell7",Py_BuildValue("d",1.000000000000)); |
---|
| 143 | PyDict_SetItemString(self->params,"A_shell4",Py_BuildValue("d",1.000000000000)); |
---|
| 144 | PyDict_SetItemString(self->params,"A_shell5",Py_BuildValue("d",1.000000000000)); |
---|
| 145 | PyDict_SetItemString(self->params,"A_shell2",Py_BuildValue("d",1.000000000000)); |
---|
| 146 | PyDict_SetItemString(self->params,"A_shell3",Py_BuildValue("d",1.000000000000)); |
---|
| 147 | PyDict_SetItemString(self->params,"A_shell1",Py_BuildValue("d",1.000000000000)); |
---|
[e096270] | 148 | // Initialize dispersion / averaging parameter dict |
---|
| 149 | DispersionVisitor* visitor = new DispersionVisitor(); |
---|
| 150 | PyObject * disp_dict; |
---|
| 151 | disp_dict = PyDict_New(); |
---|
[fbd09fa0] | 152 | self->model->rad_core0.dispersion->accept_as_source(visitor, self->model->rad_core0.dispersion, disp_dict); |
---|
| 153 | PyDict_SetItemString(self->dispersion, "rad_core0", disp_dict); |
---|
[e096270] | 154 | disp_dict = PyDict_New(); |
---|
| 155 | self->model->thick_shell1.dispersion->accept_as_source(visitor, self->model->thick_shell1.dispersion, disp_dict); |
---|
| 156 | PyDict_SetItemString(self->dispersion, "thick_shell1", disp_dict); |
---|
| 157 | disp_dict = PyDict_New(); |
---|
| 158 | self->model->thick_shell2.dispersion->accept_as_source(visitor, self->model->thick_shell2.dispersion, disp_dict); |
---|
| 159 | PyDict_SetItemString(self->dispersion, "thick_shell2", disp_dict); |
---|
| 160 | disp_dict = PyDict_New(); |
---|
| 161 | self->model->thick_shell3.dispersion->accept_as_source(visitor, self->model->thick_shell3.dispersion, disp_dict); |
---|
| 162 | PyDict_SetItemString(self->dispersion, "thick_shell3", disp_dict); |
---|
| 163 | disp_dict = PyDict_New(); |
---|
| 164 | self->model->thick_shell4.dispersion->accept_as_source(visitor, self->model->thick_shell4.dispersion, disp_dict); |
---|
| 165 | PyDict_SetItemString(self->dispersion, "thick_shell4", disp_dict); |
---|
| 166 | disp_dict = PyDict_New(); |
---|
| 167 | self->model->thick_shell5.dispersion->accept_as_source(visitor, self->model->thick_shell5.dispersion, disp_dict); |
---|
| 168 | PyDict_SetItemString(self->dispersion, "thick_shell5", disp_dict); |
---|
| 169 | disp_dict = PyDict_New(); |
---|
| 170 | self->model->thick_shell6.dispersion->accept_as_source(visitor, self->model->thick_shell6.dispersion, disp_dict); |
---|
| 171 | PyDict_SetItemString(self->dispersion, "thick_shell6", disp_dict); |
---|
| 172 | disp_dict = PyDict_New(); |
---|
| 173 | self->model->thick_shell7.dispersion->accept_as_source(visitor, self->model->thick_shell7.dispersion, disp_dict); |
---|
| 174 | PyDict_SetItemString(self->dispersion, "thick_shell7", disp_dict); |
---|
| 175 | disp_dict = PyDict_New(); |
---|
| 176 | self->model->thick_shell8.dispersion->accept_as_source(visitor, self->model->thick_shell8.dispersion, disp_dict); |
---|
| 177 | PyDict_SetItemString(self->dispersion, "thick_shell8", disp_dict); |
---|
| 178 | disp_dict = PyDict_New(); |
---|
| 179 | self->model->thick_shell9.dispersion->accept_as_source(visitor, self->model->thick_shell9.dispersion, disp_dict); |
---|
| 180 | PyDict_SetItemString(self->dispersion, "thick_shell9", disp_dict); |
---|
| 181 | disp_dict = PyDict_New(); |
---|
| 182 | self->model->thick_shell10.dispersion->accept_as_source(visitor, self->model->thick_shell10.dispersion, disp_dict); |
---|
| 183 | PyDict_SetItemString(self->dispersion, "thick_shell10", disp_dict); |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | |
---|
| 187 | // Create empty log |
---|
| 188 | self->log = PyDict_New(); |
---|
| 189 | |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | } |
---|
| 193 | return 0; |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | static PyMemberDef COnionModel_members[] = { |
---|
| 197 | {"params", T_OBJECT, offsetof(COnionModel, params), 0, |
---|
| 198 | "Parameters"}, |
---|
| 199 | {"dispersion", T_OBJECT, offsetof(COnionModel, dispersion), 0, |
---|
| 200 | "Dispersion parameters"}, |
---|
| 201 | {"log", T_OBJECT, offsetof(COnionModel, log), 0, |
---|
| 202 | "Log"}, |
---|
| 203 | {NULL} /* Sentinel */ |
---|
| 204 | }; |
---|
| 205 | |
---|
| 206 | /** Read double from PyObject |
---|
| 207 | @param p PyObject |
---|
| 208 | @return double |
---|
| 209 | */ |
---|
| 210 | double COnionModel_readDouble(PyObject *p) { |
---|
| 211 | if (PyFloat_Check(p)==1) { |
---|
| 212 | return (double)(((PyFloatObject *)(p))->ob_fval); |
---|
| 213 | } else if (PyInt_Check(p)==1) { |
---|
| 214 | return (double)(((PyIntObject *)(p))->ob_ival); |
---|
| 215 | } else if (PyLong_Check(p)==1) { |
---|
| 216 | return (double)PyLong_AsLong(p); |
---|
| 217 | } else { |
---|
| 218 | return 0.0; |
---|
| 219 | } |
---|
| 220 | } |
---|
| 221 | /** |
---|
| 222 | * Function to call to evaluate model |
---|
| 223 | * @param args: input numpy array q[] |
---|
| 224 | * @return: numpy array object |
---|
| 225 | */ |
---|
| 226 | |
---|
| 227 | static PyObject *evaluateOneDim(OnionModel* model, PyArrayObject *q){ |
---|
| 228 | PyArrayObject *result; |
---|
| 229 | |
---|
| 230 | // Check validity of array q , q must be of dimension 1, an array of double |
---|
| 231 | if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE) |
---|
| 232 | { |
---|
| 233 | //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; |
---|
| 234 | //PyErr_SetString(PyExc_ValueError , message); |
---|
| 235 | return NULL; |
---|
| 236 | } |
---|
| 237 | result = (PyArrayObject *)PyArray_FromDims(q->nd, (int *)(q->dimensions), |
---|
| 238 | PyArray_DOUBLE); |
---|
| 239 | if (result == NULL) { |
---|
| 240 | const char * message= "Could not create result "; |
---|
| 241 | PyErr_SetString(PyExc_RuntimeError , message); |
---|
| 242 | return NULL; |
---|
| 243 | } |
---|
| 244 | for (int i = 0; i < q->dimensions[0]; i++){ |
---|
| 245 | double q_value = *(double *)(q->data + i*q->strides[0]); |
---|
| 246 | double *result_value = (double *)(result->data + i*result->strides[0]); |
---|
| 247 | *result_value =(*model)(q_value); |
---|
| 248 | } |
---|
| 249 | return PyArray_Return(result); |
---|
| 250 | } |
---|
| 251 | |
---|
| 252 | /** |
---|
| 253 | * Function to call to evaluate model |
---|
| 254 | * @param args: input numpy array [x[],y[]] |
---|
| 255 | * @return: numpy array object |
---|
| 256 | */ |
---|
| 257 | static PyObject * evaluateTwoDimXY( OnionModel* model, |
---|
| 258 | PyArrayObject *x, PyArrayObject *y) |
---|
| 259 | { |
---|
| 260 | PyArrayObject *result; |
---|
| 261 | int i,j, x_len, y_len, dims[1]; |
---|
| 262 | //check validity of input vectors |
---|
| 263 | if (x->nd != 1 || x->descr->type_num != PyArray_DOUBLE |
---|
| 264 | || y->nd != 1 || y->descr->type_num != PyArray_DOUBLE |
---|
| 265 | || y->dimensions[0] != x->dimensions[0]){ |
---|
| 266 | const char * message= "evaluateTwoDimXY expect 2 numpy arrays"; |
---|
| 267 | PyErr_SetString(PyExc_ValueError , message); |
---|
| 268 | return NULL; |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | if (PyArray_Check(x) && PyArray_Check(y)) { |
---|
| 272 | |
---|
| 273 | x_len = dims[0]= x->dimensions[0]; |
---|
| 274 | y_len = dims[0]= y->dimensions[0]; |
---|
| 275 | |
---|
| 276 | // Make a new double matrix of same dims |
---|
| 277 | result=(PyArrayObject *) PyArray_FromDims(1,dims,NPY_DOUBLE); |
---|
| 278 | if (result == NULL){ |
---|
| 279 | const char * message= "Could not create result "; |
---|
| 280 | PyErr_SetString(PyExc_RuntimeError , message); |
---|
| 281 | return NULL; |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | /* Do the calculation. */ |
---|
| 285 | for ( i=0; i< x_len; i++) { |
---|
| 286 | double x_value = *(double *)(x->data + i*x->strides[0]); |
---|
| 287 | double y_value = *(double *)(y->data + i*y->strides[0]); |
---|
| 288 | double *result_value = (double *)(result->data + |
---|
| 289 | i*result->strides[0]); |
---|
| 290 | *result_value = (*model)(x_value, y_value); |
---|
| 291 | } |
---|
| 292 | return PyArray_Return(result); |
---|
| 293 | |
---|
| 294 | }else{ |
---|
| 295 | PyErr_SetString(COnionModelError, |
---|
| 296 | "COnionModel.evaluateTwoDimXY couldn't run."); |
---|
| 297 | return NULL; |
---|
| 298 | } |
---|
| 299 | } |
---|
| 300 | /** |
---|
| 301 | * evalDistribution function evaluate a model function with input vector |
---|
| 302 | * @param args: input q as vector or [qx, qy] where qx, qy are vectors |
---|
| 303 | * |
---|
| 304 | */ |
---|
| 305 | static PyObject * evalDistribution(COnionModel *self, PyObject *args){ |
---|
| 306 | PyObject *qx, *qy; |
---|
| 307 | PyArrayObject * pars; |
---|
| 308 | int npars ,mpars; |
---|
| 309 | |
---|
| 310 | // Get parameters |
---|
| 311 | |
---|
| 312 | // Reader parameter dictionary |
---|
| 313 | self->model->thick_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell4") ); |
---|
| 314 | self->model->thick_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell5") ); |
---|
| 315 | self->model->thick_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell9") ); |
---|
| 316 | self->model->thick_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell7") ); |
---|
[fbd09fa0] | 317 | self->model->sld_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_core0") ); |
---|
| 318 | self->model->rad_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "rad_core0") ); |
---|
[e096270] | 319 | self->model->A_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell10") ); |
---|
| 320 | self->model->thick_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell1") ); |
---|
| 321 | self->model->func_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell4") ); |
---|
| 322 | self->model->func_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell5") ); |
---|
| 323 | self->model->func_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell6") ); |
---|
| 324 | self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") ); |
---|
| 325 | self->model->func_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell1") ); |
---|
| 326 | self->model->thick_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell10") ); |
---|
| 327 | self->model->func_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell3") ); |
---|
| 328 | self->model->func_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell8") ); |
---|
| 329 | self->model->func_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell9") ); |
---|
| 330 | self->model->sld_in_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell5") ); |
---|
| 331 | self->model->func_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell10") ); |
---|
| 332 | self->model->sld_in_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell4") ); |
---|
| 333 | self->model->sld_in_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell7") ); |
---|
| 334 | self->model->sld_out_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell9") ); |
---|
| 335 | self->model->sld_out_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell8") ); |
---|
| 336 | self->model->thick_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell6") ); |
---|
| 337 | self->model->sld_out_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell2") ); |
---|
| 338 | self->model->sld_in_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell9") ); |
---|
| 339 | self->model->sld_in_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell8") ); |
---|
| 340 | self->model->thick_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell2") ); |
---|
[fbd09fa0] | 341 | self->model->thick_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell3") ); |
---|
[e096270] | 342 | self->model->sld_out_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell1") ); |
---|
[fbd09fa0] | 343 | self->model->sld_out_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell5") ); |
---|
[e096270] | 344 | self->model->sld_out_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell3") ); |
---|
| 345 | self->model->sld_in_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell6") ); |
---|
[fbd09fa0] | 346 | self->model->sld_in_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell1") ); |
---|
[e096270] | 347 | self->model->sld_out_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell4") ); |
---|
| 348 | self->model->sld_in_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell3") ); |
---|
| 349 | self->model->sld_out_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell6") ); |
---|
| 350 | self->model->func_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell7") ); |
---|
| 351 | self->model->sld_out_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell7") ); |
---|
| 352 | self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") ); |
---|
| 353 | self->model->n_shells = PyFloat_AsDouble( PyDict_GetItemString(self->params, "n_shells") ); |
---|
| 354 | self->model->sld_in_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell2") ); |
---|
| 355 | self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") ); |
---|
| 356 | self->model->func_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell2") ); |
---|
| 357 | self->model->thick_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell8") ); |
---|
| 358 | self->model->sld_out_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell10") ); |
---|
| 359 | self->model->sld_in_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell10") ); |
---|
| 360 | self->model->A_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell8") ); |
---|
| 361 | self->model->A_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell9") ); |
---|
| 362 | self->model->A_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell6") ); |
---|
| 363 | self->model->A_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell7") ); |
---|
| 364 | self->model->A_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell4") ); |
---|
| 365 | self->model->A_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell5") ); |
---|
| 366 | self->model->A_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell2") ); |
---|
| 367 | self->model->A_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell3") ); |
---|
| 368 | self->model->A_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell1") ); |
---|
| 369 | // Read in dispersion parameters |
---|
| 370 | PyObject* disp_dict; |
---|
| 371 | DispersionVisitor* visitor = new DispersionVisitor(); |
---|
[fbd09fa0] | 372 | disp_dict = PyDict_GetItemString(self->dispersion, "rad_core0"); |
---|
| 373 | self->model->rad_core0.dispersion->accept_as_destination(visitor, self->model->rad_core0.dispersion, disp_dict); |
---|
[e096270] | 374 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell1"); |
---|
| 375 | self->model->thick_shell1.dispersion->accept_as_destination(visitor, self->model->thick_shell1.dispersion, disp_dict); |
---|
| 376 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell2"); |
---|
| 377 | self->model->thick_shell2.dispersion->accept_as_destination(visitor, self->model->thick_shell2.dispersion, disp_dict); |
---|
| 378 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell3"); |
---|
| 379 | self->model->thick_shell3.dispersion->accept_as_destination(visitor, self->model->thick_shell3.dispersion, disp_dict); |
---|
| 380 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell4"); |
---|
| 381 | self->model->thick_shell4.dispersion->accept_as_destination(visitor, self->model->thick_shell4.dispersion, disp_dict); |
---|
| 382 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell5"); |
---|
| 383 | self->model->thick_shell5.dispersion->accept_as_destination(visitor, self->model->thick_shell5.dispersion, disp_dict); |
---|
| 384 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell6"); |
---|
| 385 | self->model->thick_shell6.dispersion->accept_as_destination(visitor, self->model->thick_shell6.dispersion, disp_dict); |
---|
| 386 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell7"); |
---|
| 387 | self->model->thick_shell7.dispersion->accept_as_destination(visitor, self->model->thick_shell7.dispersion, disp_dict); |
---|
| 388 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell8"); |
---|
| 389 | self->model->thick_shell8.dispersion->accept_as_destination(visitor, self->model->thick_shell8.dispersion, disp_dict); |
---|
| 390 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell9"); |
---|
| 391 | self->model->thick_shell9.dispersion->accept_as_destination(visitor, self->model->thick_shell9.dispersion, disp_dict); |
---|
| 392 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell10"); |
---|
| 393 | self->model->thick_shell10.dispersion->accept_as_destination(visitor, self->model->thick_shell10.dispersion, disp_dict); |
---|
| 394 | |
---|
| 395 | |
---|
| 396 | // Get input and determine whether we have to supply a 1D or 2D return value. |
---|
| 397 | if ( !PyArg_ParseTuple(args,"O",&pars) ) { |
---|
| 398 | PyErr_SetString(COnionModelError, |
---|
| 399 | "COnionModel.evalDistribution expects a q value."); |
---|
| 400 | return NULL; |
---|
| 401 | } |
---|
| 402 | // Check params |
---|
| 403 | |
---|
| 404 | if(PyArray_Check(pars)==1) { |
---|
| 405 | |
---|
| 406 | // Length of list should 1 or 2 |
---|
| 407 | npars = pars->nd; |
---|
| 408 | if(npars==1) { |
---|
| 409 | // input is a numpy array |
---|
| 410 | if (PyArray_Check(pars)) { |
---|
| 411 | return evaluateOneDim(self->model, (PyArrayObject*)pars); |
---|
| 412 | } |
---|
| 413 | }else{ |
---|
| 414 | PyErr_SetString(COnionModelError, |
---|
| 415 | "COnionModel.evalDistribution expect numpy array of one dimension."); |
---|
| 416 | return NULL; |
---|
| 417 | } |
---|
| 418 | }else if( PyList_Check(pars)==1) { |
---|
| 419 | // Length of list should be 2 for I(qx,qy) |
---|
| 420 | mpars = PyList_GET_SIZE(pars); |
---|
| 421 | if(mpars!=2) { |
---|
| 422 | PyErr_SetString(COnionModelError, |
---|
| 423 | "COnionModel.evalDistribution expects a list of dimension 2."); |
---|
| 424 | return NULL; |
---|
| 425 | } |
---|
| 426 | qx = PyList_GET_ITEM(pars,0); |
---|
| 427 | qy = PyList_GET_ITEM(pars,1); |
---|
| 428 | if (PyArray_Check(qx) && PyArray_Check(qy)) { |
---|
| 429 | return evaluateTwoDimXY(self->model, (PyArrayObject*)qx, |
---|
| 430 | (PyArrayObject*)qy); |
---|
| 431 | }else{ |
---|
| 432 | PyErr_SetString(COnionModelError, |
---|
| 433 | "COnionModel.evalDistribution expect 2 numpy arrays in list."); |
---|
| 434 | return NULL; |
---|
| 435 | } |
---|
| 436 | } |
---|
| 437 | PyErr_SetString(COnionModelError, |
---|
| 438 | "COnionModel.evalDistribution couln't be run."); |
---|
| 439 | return NULL; |
---|
| 440 | |
---|
| 441 | } |
---|
| 442 | |
---|
| 443 | /** |
---|
| 444 | * Function to call to evaluate model |
---|
| 445 | * @param args: input q or [q,phi] |
---|
| 446 | * @return: function value |
---|
| 447 | */ |
---|
| 448 | static PyObject * run(COnionModel *self, PyObject *args) { |
---|
| 449 | double q_value, phi_value; |
---|
| 450 | PyObject* pars; |
---|
| 451 | int npars; |
---|
| 452 | |
---|
| 453 | // Get parameters |
---|
| 454 | |
---|
| 455 | // Reader parameter dictionary |
---|
| 456 | self->model->thick_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell4") ); |
---|
| 457 | self->model->thick_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell5") ); |
---|
| 458 | self->model->thick_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell9") ); |
---|
| 459 | self->model->thick_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell7") ); |
---|
[fbd09fa0] | 460 | self->model->sld_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_core0") ); |
---|
| 461 | self->model->rad_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "rad_core0") ); |
---|
[e096270] | 462 | self->model->A_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell10") ); |
---|
| 463 | self->model->thick_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell1") ); |
---|
| 464 | self->model->func_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell4") ); |
---|
| 465 | self->model->func_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell5") ); |
---|
| 466 | self->model->func_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell6") ); |
---|
| 467 | self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") ); |
---|
| 468 | self->model->func_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell1") ); |
---|
| 469 | self->model->thick_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell10") ); |
---|
| 470 | self->model->func_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell3") ); |
---|
| 471 | self->model->func_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell8") ); |
---|
| 472 | self->model->func_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell9") ); |
---|
| 473 | self->model->sld_in_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell5") ); |
---|
| 474 | self->model->func_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell10") ); |
---|
| 475 | self->model->sld_in_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell4") ); |
---|
| 476 | self->model->sld_in_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell7") ); |
---|
| 477 | self->model->sld_out_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell9") ); |
---|
| 478 | self->model->sld_out_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell8") ); |
---|
| 479 | self->model->thick_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell6") ); |
---|
| 480 | self->model->sld_out_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell2") ); |
---|
| 481 | self->model->sld_in_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell9") ); |
---|
| 482 | self->model->sld_in_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell8") ); |
---|
| 483 | self->model->thick_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell2") ); |
---|
[fbd09fa0] | 484 | self->model->thick_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell3") ); |
---|
[e096270] | 485 | self->model->sld_out_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell1") ); |
---|
[fbd09fa0] | 486 | self->model->sld_out_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell5") ); |
---|
[e096270] | 487 | self->model->sld_out_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell3") ); |
---|
| 488 | self->model->sld_in_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell6") ); |
---|
[fbd09fa0] | 489 | self->model->sld_in_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell1") ); |
---|
[e096270] | 490 | self->model->sld_out_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell4") ); |
---|
| 491 | self->model->sld_in_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell3") ); |
---|
| 492 | self->model->sld_out_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell6") ); |
---|
| 493 | self->model->func_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell7") ); |
---|
| 494 | self->model->sld_out_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell7") ); |
---|
| 495 | self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") ); |
---|
| 496 | self->model->n_shells = PyFloat_AsDouble( PyDict_GetItemString(self->params, "n_shells") ); |
---|
| 497 | self->model->sld_in_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell2") ); |
---|
| 498 | self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") ); |
---|
| 499 | self->model->func_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell2") ); |
---|
| 500 | self->model->thick_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell8") ); |
---|
| 501 | self->model->sld_out_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell10") ); |
---|
| 502 | self->model->sld_in_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell10") ); |
---|
| 503 | self->model->A_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell8") ); |
---|
| 504 | self->model->A_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell9") ); |
---|
| 505 | self->model->A_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell6") ); |
---|
| 506 | self->model->A_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell7") ); |
---|
| 507 | self->model->A_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell4") ); |
---|
| 508 | self->model->A_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell5") ); |
---|
| 509 | self->model->A_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell2") ); |
---|
| 510 | self->model->A_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell3") ); |
---|
| 511 | self->model->A_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell1") ); |
---|
| 512 | // Read in dispersion parameters |
---|
| 513 | PyObject* disp_dict; |
---|
| 514 | DispersionVisitor* visitor = new DispersionVisitor(); |
---|
[fbd09fa0] | 515 | disp_dict = PyDict_GetItemString(self->dispersion, "rad_core0"); |
---|
| 516 | self->model->rad_core0.dispersion->accept_as_destination(visitor, self->model->rad_core0.dispersion, disp_dict); |
---|
[e096270] | 517 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell1"); |
---|
| 518 | self->model->thick_shell1.dispersion->accept_as_destination(visitor, self->model->thick_shell1.dispersion, disp_dict); |
---|
| 519 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell2"); |
---|
| 520 | self->model->thick_shell2.dispersion->accept_as_destination(visitor, self->model->thick_shell2.dispersion, disp_dict); |
---|
| 521 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell3"); |
---|
| 522 | self->model->thick_shell3.dispersion->accept_as_destination(visitor, self->model->thick_shell3.dispersion, disp_dict); |
---|
| 523 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell4"); |
---|
| 524 | self->model->thick_shell4.dispersion->accept_as_destination(visitor, self->model->thick_shell4.dispersion, disp_dict); |
---|
| 525 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell5"); |
---|
| 526 | self->model->thick_shell5.dispersion->accept_as_destination(visitor, self->model->thick_shell5.dispersion, disp_dict); |
---|
| 527 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell6"); |
---|
| 528 | self->model->thick_shell6.dispersion->accept_as_destination(visitor, self->model->thick_shell6.dispersion, disp_dict); |
---|
| 529 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell7"); |
---|
| 530 | self->model->thick_shell7.dispersion->accept_as_destination(visitor, self->model->thick_shell7.dispersion, disp_dict); |
---|
| 531 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell8"); |
---|
| 532 | self->model->thick_shell8.dispersion->accept_as_destination(visitor, self->model->thick_shell8.dispersion, disp_dict); |
---|
| 533 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell9"); |
---|
| 534 | self->model->thick_shell9.dispersion->accept_as_destination(visitor, self->model->thick_shell9.dispersion, disp_dict); |
---|
| 535 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell10"); |
---|
| 536 | self->model->thick_shell10.dispersion->accept_as_destination(visitor, self->model->thick_shell10.dispersion, disp_dict); |
---|
| 537 | |
---|
| 538 | |
---|
| 539 | // Get input and determine whether we have to supply a 1D or 2D return value. |
---|
| 540 | if ( !PyArg_ParseTuple(args,"O",&pars) ) { |
---|
| 541 | PyErr_SetString(COnionModelError, |
---|
| 542 | "COnionModel.run expects a q value."); |
---|
| 543 | return NULL; |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | // Check params |
---|
| 547 | if( PyList_Check(pars)==1) { |
---|
| 548 | |
---|
| 549 | // Length of list should be 2 for I(q,phi) |
---|
| 550 | npars = PyList_GET_SIZE(pars); |
---|
| 551 | if(npars!=2) { |
---|
| 552 | PyErr_SetString(COnionModelError, |
---|
| 553 | "COnionModel.run expects a double or a list of dimension 2."); |
---|
| 554 | return NULL; |
---|
| 555 | } |
---|
| 556 | // We have a vector q, get the q and phi values at which |
---|
| 557 | // to evaluate I(q,phi) |
---|
| 558 | q_value = COnionModel_readDouble(PyList_GET_ITEM(pars,0)); |
---|
| 559 | phi_value = COnionModel_readDouble(PyList_GET_ITEM(pars,1)); |
---|
| 560 | // Skip zero |
---|
| 561 | if (q_value==0) { |
---|
| 562 | return Py_BuildValue("d",0.0); |
---|
| 563 | } |
---|
| 564 | return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value)); |
---|
| 565 | |
---|
| 566 | } else { |
---|
| 567 | |
---|
| 568 | // We have a scalar q, we will evaluate I(q) |
---|
| 569 | q_value = COnionModel_readDouble(pars); |
---|
| 570 | |
---|
| 571 | return Py_BuildValue("d",(*(self->model))(q_value)); |
---|
| 572 | } |
---|
| 573 | } |
---|
| 574 | /** |
---|
| 575 | * Function to call to calculate_ER |
---|
| 576 | * @return: effective radius value |
---|
| 577 | */ |
---|
| 578 | static PyObject * calculate_ER(COnionModel *self) { |
---|
| 579 | |
---|
| 580 | PyObject* pars; |
---|
| 581 | int npars; |
---|
| 582 | |
---|
| 583 | // Get parameters |
---|
| 584 | |
---|
| 585 | // Reader parameter dictionary |
---|
| 586 | self->model->thick_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell4") ); |
---|
| 587 | self->model->thick_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell5") ); |
---|
| 588 | self->model->thick_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell9") ); |
---|
| 589 | self->model->thick_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell7") ); |
---|
[fbd09fa0] | 590 | self->model->sld_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_core0") ); |
---|
| 591 | self->model->rad_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "rad_core0") ); |
---|
[e096270] | 592 | self->model->A_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell10") ); |
---|
| 593 | self->model->thick_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell1") ); |
---|
| 594 | self->model->func_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell4") ); |
---|
| 595 | self->model->func_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell5") ); |
---|
| 596 | self->model->func_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell6") ); |
---|
| 597 | self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") ); |
---|
| 598 | self->model->func_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell1") ); |
---|
| 599 | self->model->thick_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell10") ); |
---|
| 600 | self->model->func_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell3") ); |
---|
| 601 | self->model->func_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell8") ); |
---|
| 602 | self->model->func_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell9") ); |
---|
| 603 | self->model->sld_in_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell5") ); |
---|
| 604 | self->model->func_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell10") ); |
---|
| 605 | self->model->sld_in_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell4") ); |
---|
| 606 | self->model->sld_in_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell7") ); |
---|
| 607 | self->model->sld_out_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell9") ); |
---|
| 608 | self->model->sld_out_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell8") ); |
---|
| 609 | self->model->thick_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell6") ); |
---|
| 610 | self->model->sld_out_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell2") ); |
---|
| 611 | self->model->sld_in_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell9") ); |
---|
| 612 | self->model->sld_in_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell8") ); |
---|
| 613 | self->model->thick_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell2") ); |
---|
[fbd09fa0] | 614 | self->model->thick_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell3") ); |
---|
[e096270] | 615 | self->model->sld_out_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell1") ); |
---|
[fbd09fa0] | 616 | self->model->sld_out_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell5") ); |
---|
[e096270] | 617 | self->model->sld_out_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell3") ); |
---|
| 618 | self->model->sld_in_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell6") ); |
---|
[fbd09fa0] | 619 | self->model->sld_in_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell1") ); |
---|
[e096270] | 620 | self->model->sld_out_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell4") ); |
---|
| 621 | self->model->sld_in_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell3") ); |
---|
| 622 | self->model->sld_out_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell6") ); |
---|
| 623 | self->model->func_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell7") ); |
---|
| 624 | self->model->sld_out_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell7") ); |
---|
| 625 | self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") ); |
---|
| 626 | self->model->n_shells = PyFloat_AsDouble( PyDict_GetItemString(self->params, "n_shells") ); |
---|
| 627 | self->model->sld_in_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell2") ); |
---|
| 628 | self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") ); |
---|
| 629 | self->model->func_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell2") ); |
---|
| 630 | self->model->thick_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell8") ); |
---|
| 631 | self->model->sld_out_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell10") ); |
---|
| 632 | self->model->sld_in_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell10") ); |
---|
| 633 | self->model->A_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell8") ); |
---|
| 634 | self->model->A_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell9") ); |
---|
| 635 | self->model->A_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell6") ); |
---|
| 636 | self->model->A_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell7") ); |
---|
| 637 | self->model->A_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell4") ); |
---|
| 638 | self->model->A_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell5") ); |
---|
| 639 | self->model->A_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell2") ); |
---|
| 640 | self->model->A_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell3") ); |
---|
| 641 | self->model->A_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell1") ); |
---|
| 642 | // Read in dispersion parameters |
---|
| 643 | PyObject* disp_dict; |
---|
| 644 | DispersionVisitor* visitor = new DispersionVisitor(); |
---|
[fbd09fa0] | 645 | disp_dict = PyDict_GetItemString(self->dispersion, "rad_core0"); |
---|
| 646 | self->model->rad_core0.dispersion->accept_as_destination(visitor, self->model->rad_core0.dispersion, disp_dict); |
---|
[e096270] | 647 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell1"); |
---|
| 648 | self->model->thick_shell1.dispersion->accept_as_destination(visitor, self->model->thick_shell1.dispersion, disp_dict); |
---|
| 649 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell2"); |
---|
| 650 | self->model->thick_shell2.dispersion->accept_as_destination(visitor, self->model->thick_shell2.dispersion, disp_dict); |
---|
| 651 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell3"); |
---|
| 652 | self->model->thick_shell3.dispersion->accept_as_destination(visitor, self->model->thick_shell3.dispersion, disp_dict); |
---|
| 653 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell4"); |
---|
| 654 | self->model->thick_shell4.dispersion->accept_as_destination(visitor, self->model->thick_shell4.dispersion, disp_dict); |
---|
| 655 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell5"); |
---|
| 656 | self->model->thick_shell5.dispersion->accept_as_destination(visitor, self->model->thick_shell5.dispersion, disp_dict); |
---|
| 657 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell6"); |
---|
| 658 | self->model->thick_shell6.dispersion->accept_as_destination(visitor, self->model->thick_shell6.dispersion, disp_dict); |
---|
| 659 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell7"); |
---|
| 660 | self->model->thick_shell7.dispersion->accept_as_destination(visitor, self->model->thick_shell7.dispersion, disp_dict); |
---|
| 661 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell8"); |
---|
| 662 | self->model->thick_shell8.dispersion->accept_as_destination(visitor, self->model->thick_shell8.dispersion, disp_dict); |
---|
| 663 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell9"); |
---|
| 664 | self->model->thick_shell9.dispersion->accept_as_destination(visitor, self->model->thick_shell9.dispersion, disp_dict); |
---|
| 665 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell10"); |
---|
| 666 | self->model->thick_shell10.dispersion->accept_as_destination(visitor, self->model->thick_shell10.dispersion, disp_dict); |
---|
| 667 | |
---|
| 668 | |
---|
| 669 | return Py_BuildValue("d",(*(self->model)).calculate_ER()); |
---|
| 670 | |
---|
| 671 | } |
---|
| 672 | /** |
---|
| 673 | * Function to call to evaluate model in cartesian coordinates |
---|
| 674 | * @param args: input q or [qx, qy]] |
---|
| 675 | * @return: function value |
---|
| 676 | */ |
---|
| 677 | static PyObject * runXY(COnionModel *self, PyObject *args) { |
---|
| 678 | double qx_value, qy_value; |
---|
| 679 | PyObject* pars; |
---|
| 680 | int npars; |
---|
| 681 | |
---|
| 682 | // Get parameters |
---|
| 683 | |
---|
| 684 | // Reader parameter dictionary |
---|
| 685 | self->model->thick_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell4") ); |
---|
| 686 | self->model->thick_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell5") ); |
---|
| 687 | self->model->thick_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell9") ); |
---|
| 688 | self->model->thick_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell7") ); |
---|
[fbd09fa0] | 689 | self->model->sld_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_core0") ); |
---|
| 690 | self->model->rad_core0 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "rad_core0") ); |
---|
[e096270] | 691 | self->model->A_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell10") ); |
---|
| 692 | self->model->thick_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell1") ); |
---|
| 693 | self->model->func_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell4") ); |
---|
| 694 | self->model->func_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell5") ); |
---|
| 695 | self->model->func_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell6") ); |
---|
| 696 | self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") ); |
---|
| 697 | self->model->func_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell1") ); |
---|
| 698 | self->model->thick_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell10") ); |
---|
| 699 | self->model->func_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell3") ); |
---|
| 700 | self->model->func_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell8") ); |
---|
| 701 | self->model->func_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell9") ); |
---|
| 702 | self->model->sld_in_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell5") ); |
---|
| 703 | self->model->func_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell10") ); |
---|
| 704 | self->model->sld_in_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell4") ); |
---|
| 705 | self->model->sld_in_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell7") ); |
---|
| 706 | self->model->sld_out_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell9") ); |
---|
| 707 | self->model->sld_out_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell8") ); |
---|
| 708 | self->model->thick_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell6") ); |
---|
| 709 | self->model->sld_out_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell2") ); |
---|
| 710 | self->model->sld_in_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell9") ); |
---|
| 711 | self->model->sld_in_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell8") ); |
---|
| 712 | self->model->thick_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell2") ); |
---|
[fbd09fa0] | 713 | self->model->thick_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell3") ); |
---|
[e096270] | 714 | self->model->sld_out_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell1") ); |
---|
[fbd09fa0] | 715 | self->model->sld_out_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell5") ); |
---|
[e096270] | 716 | self->model->sld_out_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell3") ); |
---|
| 717 | self->model->sld_in_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell6") ); |
---|
[fbd09fa0] | 718 | self->model->sld_in_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell1") ); |
---|
[e096270] | 719 | self->model->sld_out_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell4") ); |
---|
| 720 | self->model->sld_in_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell3") ); |
---|
| 721 | self->model->sld_out_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell6") ); |
---|
| 722 | self->model->func_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell7") ); |
---|
| 723 | self->model->sld_out_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell7") ); |
---|
| 724 | self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") ); |
---|
| 725 | self->model->n_shells = PyFloat_AsDouble( PyDict_GetItemString(self->params, "n_shells") ); |
---|
| 726 | self->model->sld_in_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell2") ); |
---|
| 727 | self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") ); |
---|
| 728 | self->model->func_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "func_shell2") ); |
---|
| 729 | self->model->thick_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_shell8") ); |
---|
| 730 | self->model->sld_out_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_out_shell10") ); |
---|
| 731 | self->model->sld_in_shell10 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_in_shell10") ); |
---|
| 732 | self->model->A_shell8 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell8") ); |
---|
| 733 | self->model->A_shell9 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell9") ); |
---|
| 734 | self->model->A_shell6 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell6") ); |
---|
| 735 | self->model->A_shell7 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell7") ); |
---|
| 736 | self->model->A_shell4 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell4") ); |
---|
| 737 | self->model->A_shell5 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell5") ); |
---|
| 738 | self->model->A_shell2 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell2") ); |
---|
| 739 | self->model->A_shell3 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell3") ); |
---|
| 740 | self->model->A_shell1 = PyFloat_AsDouble( PyDict_GetItemString(self->params, "A_shell1") ); |
---|
| 741 | // Read in dispersion parameters |
---|
| 742 | PyObject* disp_dict; |
---|
| 743 | DispersionVisitor* visitor = new DispersionVisitor(); |
---|
[fbd09fa0] | 744 | disp_dict = PyDict_GetItemString(self->dispersion, "rad_core0"); |
---|
| 745 | self->model->rad_core0.dispersion->accept_as_destination(visitor, self->model->rad_core0.dispersion, disp_dict); |
---|
[e096270] | 746 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell1"); |
---|
| 747 | self->model->thick_shell1.dispersion->accept_as_destination(visitor, self->model->thick_shell1.dispersion, disp_dict); |
---|
| 748 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell2"); |
---|
| 749 | self->model->thick_shell2.dispersion->accept_as_destination(visitor, self->model->thick_shell2.dispersion, disp_dict); |
---|
| 750 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell3"); |
---|
| 751 | self->model->thick_shell3.dispersion->accept_as_destination(visitor, self->model->thick_shell3.dispersion, disp_dict); |
---|
| 752 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell4"); |
---|
| 753 | self->model->thick_shell4.dispersion->accept_as_destination(visitor, self->model->thick_shell4.dispersion, disp_dict); |
---|
| 754 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell5"); |
---|
| 755 | self->model->thick_shell5.dispersion->accept_as_destination(visitor, self->model->thick_shell5.dispersion, disp_dict); |
---|
| 756 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell6"); |
---|
| 757 | self->model->thick_shell6.dispersion->accept_as_destination(visitor, self->model->thick_shell6.dispersion, disp_dict); |
---|
| 758 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell7"); |
---|
| 759 | self->model->thick_shell7.dispersion->accept_as_destination(visitor, self->model->thick_shell7.dispersion, disp_dict); |
---|
| 760 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell8"); |
---|
| 761 | self->model->thick_shell8.dispersion->accept_as_destination(visitor, self->model->thick_shell8.dispersion, disp_dict); |
---|
| 762 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell9"); |
---|
| 763 | self->model->thick_shell9.dispersion->accept_as_destination(visitor, self->model->thick_shell9.dispersion, disp_dict); |
---|
| 764 | disp_dict = PyDict_GetItemString(self->dispersion, "thick_shell10"); |
---|
| 765 | self->model->thick_shell10.dispersion->accept_as_destination(visitor, self->model->thick_shell10.dispersion, disp_dict); |
---|
| 766 | |
---|
| 767 | |
---|
| 768 | // Get input and determine whether we have to supply a 1D or 2D return value. |
---|
| 769 | if ( !PyArg_ParseTuple(args,"O",&pars) ) { |
---|
| 770 | PyErr_SetString(COnionModelError, |
---|
| 771 | "COnionModel.run expects a q value."); |
---|
| 772 | return NULL; |
---|
| 773 | } |
---|
| 774 | |
---|
| 775 | // Check params |
---|
| 776 | if( PyList_Check(pars)==1) { |
---|
| 777 | |
---|
| 778 | // Length of list should be 2 for I(qx, qy)) |
---|
| 779 | npars = PyList_GET_SIZE(pars); |
---|
| 780 | if(npars!=2) { |
---|
| 781 | PyErr_SetString(COnionModelError, |
---|
| 782 | "COnionModel.run expects a double or a list of dimension 2."); |
---|
| 783 | return NULL; |
---|
| 784 | } |
---|
| 785 | // We have a vector q, get the qx and qy values at which |
---|
| 786 | // to evaluate I(qx,qy) |
---|
| 787 | qx_value = COnionModel_readDouble(PyList_GET_ITEM(pars,0)); |
---|
| 788 | qy_value = COnionModel_readDouble(PyList_GET_ITEM(pars,1)); |
---|
| 789 | return Py_BuildValue("d",(*(self->model))(qx_value,qy_value)); |
---|
| 790 | |
---|
| 791 | } else { |
---|
| 792 | |
---|
| 793 | // We have a scalar q, we will evaluate I(q) |
---|
| 794 | qx_value = COnionModel_readDouble(pars); |
---|
| 795 | |
---|
| 796 | return Py_BuildValue("d",(*(self->model))(qx_value)); |
---|
| 797 | } |
---|
| 798 | } |
---|
| 799 | |
---|
| 800 | static PyObject * reset(COnionModel *self, PyObject *args) { |
---|
| 801 | |
---|
| 802 | |
---|
| 803 | return Py_BuildValue("d",0.0); |
---|
| 804 | } |
---|
| 805 | |
---|
| 806 | static PyObject * set_dispersion(COnionModel *self, PyObject *args) { |
---|
| 807 | PyObject * disp; |
---|
| 808 | const char * par_name; |
---|
| 809 | |
---|
| 810 | if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) { |
---|
| 811 | PyErr_SetString(COnionModelError, |
---|
| 812 | "COnionModel.set_dispersion expects a DispersionModel object."); |
---|
| 813 | return NULL; |
---|
| 814 | } |
---|
| 815 | void *temp = PyCObject_AsVoidPtr(disp); |
---|
| 816 | DispersionModel * dispersion = static_cast<DispersionModel *>(temp); |
---|
| 817 | |
---|
| 818 | |
---|
| 819 | // Ugliness necessary to go from python to C |
---|
| 820 | // TODO: refactor this |
---|
[fbd09fa0] | 821 | if (!strcmp(par_name, "rad_core0")) { |
---|
| 822 | self->model->rad_core0.dispersion = dispersion; |
---|
[e096270] | 823 | } else if (!strcmp(par_name, "thick_shell1")) { |
---|
| 824 | self->model->thick_shell1.dispersion = dispersion; |
---|
| 825 | } else if (!strcmp(par_name, "thick_shell2")) { |
---|
| 826 | self->model->thick_shell2.dispersion = dispersion; |
---|
| 827 | } else if (!strcmp(par_name, "thick_shell3")) { |
---|
| 828 | self->model->thick_shell3.dispersion = dispersion; |
---|
| 829 | } else if (!strcmp(par_name, "thick_shell4")) { |
---|
| 830 | self->model->thick_shell4.dispersion = dispersion; |
---|
| 831 | } else if (!strcmp(par_name, "thick_shell5")) { |
---|
| 832 | self->model->thick_shell5.dispersion = dispersion; |
---|
| 833 | } else if (!strcmp(par_name, "thick_shell6")) { |
---|
| 834 | self->model->thick_shell6.dispersion = dispersion; |
---|
| 835 | } else if (!strcmp(par_name, "thick_shell7")) { |
---|
| 836 | self->model->thick_shell7.dispersion = dispersion; |
---|
| 837 | } else if (!strcmp(par_name, "thick_shell8")) { |
---|
| 838 | self->model->thick_shell8.dispersion = dispersion; |
---|
| 839 | } else if (!strcmp(par_name, "thick_shell9")) { |
---|
| 840 | self->model->thick_shell9.dispersion = dispersion; |
---|
| 841 | } else if (!strcmp(par_name, "thick_shell10")) { |
---|
| 842 | self->model->thick_shell10.dispersion = dispersion; |
---|
| 843 | } else { |
---|
| 844 | PyErr_SetString(COnionModelError, |
---|
| 845 | "COnionModel.set_dispersion expects a valid parameter name."); |
---|
| 846 | return NULL; |
---|
| 847 | } |
---|
| 848 | |
---|
| 849 | DispersionVisitor* visitor = new DispersionVisitor(); |
---|
| 850 | PyObject * disp_dict = PyDict_New(); |
---|
| 851 | dispersion->accept_as_source(visitor, dispersion, disp_dict); |
---|
| 852 | PyDict_SetItemString(self->dispersion, par_name, disp_dict); |
---|
| 853 | return Py_BuildValue("i",1); |
---|
| 854 | } |
---|
| 855 | |
---|
| 856 | |
---|
| 857 | static PyMethodDef COnionModel_methods[] = { |
---|
| 858 | {"run", (PyCFunction)run , METH_VARARGS, |
---|
| 859 | "Evaluate the model at a given Q or Q, phi"}, |
---|
| 860 | {"runXY", (PyCFunction)runXY , METH_VARARGS, |
---|
| 861 | "Evaluate the model at a given Q or Qx, Qy"}, |
---|
| 862 | {"calculate_ER", (PyCFunction)calculate_ER , METH_VARARGS, |
---|
| 863 | "Evaluate the model at a given Q or Q, phi"}, |
---|
| 864 | |
---|
| 865 | {"evalDistribution", (PyCFunction)evalDistribution , METH_VARARGS, |
---|
| 866 | "Evaluate the model at a given Q or Qx, Qy vector "}, |
---|
| 867 | {"reset", (PyCFunction)reset , METH_VARARGS, |
---|
| 868 | "Reset pair correlation"}, |
---|
| 869 | {"set_dispersion", (PyCFunction)set_dispersion , METH_VARARGS, |
---|
| 870 | "Set the dispersion model for a given parameter"}, |
---|
| 871 | {NULL} |
---|
| 872 | }; |
---|
| 873 | |
---|
| 874 | static PyTypeObject COnionModelType = { |
---|
| 875 | PyObject_HEAD_INIT(NULL) |
---|
| 876 | 0, /*ob_size*/ |
---|
| 877 | "COnionModel", /*tp_name*/ |
---|
| 878 | sizeof(COnionModel), /*tp_basicsize*/ |
---|
| 879 | 0, /*tp_itemsize*/ |
---|
| 880 | (destructor)COnionModel_dealloc, /*tp_dealloc*/ |
---|
| 881 | 0, /*tp_print*/ |
---|
| 882 | 0, /*tp_getattr*/ |
---|
| 883 | 0, /*tp_setattr*/ |
---|
| 884 | 0, /*tp_compare*/ |
---|
| 885 | 0, /*tp_repr*/ |
---|
| 886 | 0, /*tp_as_number*/ |
---|
| 887 | 0, /*tp_as_sequence*/ |
---|
| 888 | 0, /*tp_as_mapping*/ |
---|
| 889 | 0, /*tp_hash */ |
---|
| 890 | 0, /*tp_call*/ |
---|
| 891 | 0, /*tp_str*/ |
---|
| 892 | 0, /*tp_getattro*/ |
---|
| 893 | 0, /*tp_setattro*/ |
---|
| 894 | 0, /*tp_as_buffer*/ |
---|
| 895 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ |
---|
| 896 | "COnionModel objects", /* tp_doc */ |
---|
| 897 | 0, /* tp_traverse */ |
---|
| 898 | 0, /* tp_clear */ |
---|
| 899 | 0, /* tp_richcompare */ |
---|
| 900 | 0, /* tp_weaklistoffset */ |
---|
| 901 | 0, /* tp_iter */ |
---|
| 902 | 0, /* tp_iternext */ |
---|
| 903 | COnionModel_methods, /* tp_methods */ |
---|
| 904 | COnionModel_members, /* tp_members */ |
---|
| 905 | 0, /* tp_getset */ |
---|
| 906 | 0, /* tp_base */ |
---|
| 907 | 0, /* tp_dict */ |
---|
| 908 | 0, /* tp_descr_get */ |
---|
| 909 | 0, /* tp_descr_set */ |
---|
| 910 | 0, /* tp_dictoffset */ |
---|
| 911 | (initproc)COnionModel_init, /* tp_init */ |
---|
| 912 | 0, /* tp_alloc */ |
---|
| 913 | COnionModel_new, /* tp_new */ |
---|
| 914 | }; |
---|
| 915 | |
---|
| 916 | |
---|
| 917 | //static PyMethodDef module_methods[] = { |
---|
| 918 | // {NULL} |
---|
| 919 | //}; |
---|
| 920 | |
---|
| 921 | /** |
---|
| 922 | * Function used to add the model class to a module |
---|
| 923 | * @param module: module to add the class to |
---|
| 924 | */ |
---|
| 925 | void addCOnionModel(PyObject *module) { |
---|
| 926 | PyObject *d; |
---|
| 927 | |
---|
| 928 | if (PyType_Ready(&COnionModelType) < 0) |
---|
| 929 | return; |
---|
| 930 | |
---|
| 931 | Py_INCREF(&COnionModelType); |
---|
| 932 | PyModule_AddObject(module, "COnionModel", (PyObject *)&COnionModelType); |
---|
| 933 | |
---|
| 934 | d = PyModule_GetDict(module); |
---|
| 935 | COnionModelError = PyErr_NewException("COnionModel.error", NULL, NULL); |
---|
| 936 | PyDict_SetItemString(d, "COnionModelError", COnionModelError); |
---|
| 937 | } |
---|
| 938 | |
---|