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