[af03ddd] | 1 | /** c_models |
---|
| 2 | * |
---|
| 3 | * Module containing all SANS model extensions |
---|
| 4 | * |
---|
| 5 | * @author M.Doucet / UTK |
---|
| 6 | */ |
---|
| 7 | #include <Python.h> |
---|
| 8 | #include <parameters.hh> |
---|
[812b901] | 9 | #define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sans |
---|
| 10 | #include "arrayobject.h" |
---|
| 11 | |
---|
[af03ddd] | 12 | |
---|
| 13 | void addCCylinderModel(PyObject *module); |
---|
[fbd09fa0] | 14 | void addCBarBellModel(PyObject *module); |
---|
| 15 | void addCCappedCylinderModel(PyObject *module); |
---|
[27a0771] | 16 | void addCTriaxialEllipsoidModel(PyObject *module); |
---|
[8a48713] | 17 | void addCParallelepipedModel(PyObject *module); |
---|
[18f2ca1] | 18 | void addCCSParallelepipedModel(PyObject *module); |
---|
[0f5bc9f] | 19 | void addCSphereModel(PyObject *module); |
---|
[96d19c6] | 20 | void addCSphereSLDModel(PyObject *module); |
---|
[e096270] | 21 | void addCOnionModel(PyObject *module); |
---|
[d9547e7] | 22 | void addCLinearPearlsModel(PyObject *module); |
---|
[8c8cb05] | 23 | void addCPearlNecklaceModel(PyObject *module); |
---|
[35aface] | 24 | void addCReflModel(PyObject *module); |
---|
[96656e3] | 25 | void addCReflAdvModel(PyObject *module); |
---|
[c724ccd] | 26 | void addCFuzzySphereModel(PyObject *module); |
---|
[25579e8] | 27 | void addCHardsphereStructure(PyObject *module); |
---|
| 28 | void addCStickyHSStructure(PyObject *module); |
---|
[94a3f8f] | 29 | void addCSCCrystalModel(PyObject *module); |
---|
[d5b6a9d] | 30 | void addCFCCrystalModel(PyObject *module); |
---|
| 31 | void addCBCCrystalModel(PyObject *module); |
---|
[25579e8] | 32 | void addCSquareWellStructure(PyObject *module); |
---|
| 33 | void addCHayterMSAStructure(PyObject *module); |
---|
[0f5bc9f] | 34 | void addCCoreShellModel(PyObject *module); |
---|
[7289627] | 35 | void addCCore2ndMomentModel(PyObject *module); |
---|
[c724ccd] | 36 | void addCCoreFourShellModel(PyObject *module); |
---|
[0f5bc9f] | 37 | void addCCoreShellCylinderModel(PyObject *module); |
---|
[543d1bd] | 38 | void addCCoreShellBicelleModel(PyObject *module); |
---|
[0f5bc9f] | 39 | void addCEllipsoidModel(PyObject *module); |
---|
| 40 | void addCEllipticalCylinderModel(PyObject *module); |
---|
[5068697] | 41 | void addCTriaxialEllipsoidModel(PyObject *module); |
---|
| 42 | void addCFlexibleCylinderModel(PyObject *module); |
---|
[c724ccd] | 43 | void addCFlexCylEllipXModel(PyObject *module); |
---|
[5068697] | 44 | void addCStackedDisksModel(PyObject *module); |
---|
[27a0771] | 45 | void addCLamellarPSModel(PyObject *module); |
---|
| 46 | void addCLamellarPSHGModel(PyObject *module); |
---|
[fbd09fa0] | 47 | void addCLamellarPCrystalModel(PyObject *module); |
---|
[eddff027] | 48 | void addCCoreShellEllipsoidModel(PyObject *module); |
---|
[5eb9154] | 49 | void addCDiamEllipFunc(PyObject *module); |
---|
| 50 | void addCDiamCylFunc(PyObject *module); |
---|
[96d19c6] | 51 | void addCSLDCalFunc(PyObject *module); |
---|
[5eb9154] | 52 | |
---|
[34c3020] | 53 | void addCLamellarModel(PyObject *module); |
---|
| 54 | void addCLamellarFFHGModel(PyObject *module); |
---|
[27fea3f] | 55 | void addCHollowCylinderModel(PyObject *module); |
---|
[3d25331f] | 56 | void addCMultiShellModel(PyObject *module); |
---|
| 57 | void addCVesicleModel(PyObject *module); |
---|
| 58 | void addCBinaryHSModel(PyObject *module); |
---|
[35aface] | 59 | void addCRPAModel(PyObject *module); |
---|
[c724ccd] | 60 | void addCFractalModel(PyObject *module); |
---|
[08648c0] | 61 | void addCMassSurfaceFractal(PyObject *module); |
---|
| 62 | void addCSurfaceFractalModel(PyObject *module); |
---|
| 63 | void addCMassFractalModel(PyObject *module); |
---|
[c724ccd] | 64 | void addCPoly_GaussCoil(PyObject *module); |
---|
[27a0771] | 65 | |
---|
[0f5bc9f] | 66 | |
---|
[af03ddd] | 67 | extern "C" { |
---|
[fd080830] | 68 | void addDisperser(PyObject *module); |
---|
[af03ddd] | 69 | } |
---|
[82c11d3] | 70 | void addCLorentzian(PyObject *module); |
---|
[20d91bd] | 71 | void addCSchulz(PyObject *module); |
---|
[101065a] | 72 | void addCGaussian(PyObject *module); |
---|
| 73 | void addCLogNormal(PyObject *module); |
---|
[af03ddd] | 74 | |
---|
| 75 | /** |
---|
| 76 | * Delete a dispersion model object |
---|
| 77 | */ |
---|
| 78 | void del_dispersion_model(void *ptr){ |
---|
[fd080830] | 79 | DispersionModel * disp = static_cast<DispersionModel *>(ptr); |
---|
| 80 | delete disp; |
---|
| 81 | return; |
---|
[af03ddd] | 82 | } |
---|
| 83 | |
---|
| 84 | /** |
---|
| 85 | * Create a dispersion model as a python object |
---|
| 86 | */ |
---|
| 87 | PyObject * new_dispersion_model(PyObject *, PyObject *args) { |
---|
[fd080830] | 88 | DispersionModel *disp = new DispersionModel(); |
---|
| 89 | return PyCObject_FromVoidPtr(disp, del_dispersion_model); |
---|
[af03ddd] | 90 | } |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | /** |
---|
[eba9885] | 94 | * Delete a lognormal dispersion model object |
---|
| 95 | */ |
---|
| 96 | void del_lognormal_dispersion(void *ptr){ |
---|
[fd080830] | 97 | LogNormalDispersion * disp = static_cast<LogNormalDispersion *>(ptr); |
---|
| 98 | delete disp; |
---|
| 99 | return; |
---|
[eba9885] | 100 | } |
---|
| 101 | |
---|
| 102 | /** |
---|
| 103 | * Create a lognormal dispersion model as a python object |
---|
| 104 | */ |
---|
| 105 | PyObject * new_lognormal_dispersion(PyObject *, PyObject *args) { |
---|
[fd080830] | 106 | LogNormalDispersion *disp = new LogNormalDispersion(); |
---|
| 107 | return PyCObject_FromVoidPtr(disp, del_lognormal_dispersion); |
---|
[eba9885] | 108 | } |
---|
| 109 | |
---|
| 110 | /** |
---|
[af03ddd] | 111 | * Delete a gaussian dispersion model object |
---|
| 112 | */ |
---|
| 113 | void del_gaussian_dispersion(void *ptr){ |
---|
[fd080830] | 114 | GaussianDispersion * disp = static_cast<GaussianDispersion *>(ptr); |
---|
| 115 | delete disp; |
---|
| 116 | return; |
---|
[af03ddd] | 117 | } |
---|
| 118 | |
---|
| 119 | /** |
---|
| 120 | * Create a gaussian dispersion model as a python object |
---|
| 121 | */ |
---|
| 122 | PyObject * new_gaussian_dispersion(PyObject *, PyObject *args) { |
---|
[fd080830] | 123 | GaussianDispersion *disp = new GaussianDispersion(); |
---|
| 124 | return PyCObject_FromVoidPtr(disp, del_gaussian_dispersion); |
---|
[af03ddd] | 125 | } |
---|
| 126 | |
---|
[8dc02d8b] | 127 | |
---|
| 128 | /** |
---|
| 129 | * Delete a rectangle dispersion model object |
---|
| 130 | */ |
---|
| 131 | void del_rectangle_dispersion(void *ptr){ |
---|
[fd080830] | 132 | RectangleDispersion * disp = static_cast<RectangleDispersion *>(ptr); |
---|
| 133 | delete disp; |
---|
| 134 | return; |
---|
[8dc02d8b] | 135 | } |
---|
| 136 | |
---|
| 137 | /** |
---|
| 138 | * Create a rectangle dispersion model as a python object |
---|
| 139 | */ |
---|
| 140 | PyObject * new_rectangle_dispersion(PyObject *, PyObject *args) { |
---|
[fd080830] | 141 | RectangleDispersion *disp = new RectangleDispersion(); |
---|
| 142 | return PyCObject_FromVoidPtr(disp, del_rectangle_dispersion); |
---|
[8dc02d8b] | 143 | } |
---|
| 144 | |
---|
| 145 | |
---|
[af03ddd] | 146 | /** |
---|
[eba9885] | 147 | * Delete a schulz dispersion model object |
---|
| 148 | */ |
---|
| 149 | void del_schulz_dispersion(void *ptr){ |
---|
[fd080830] | 150 | SchulzDispersion * disp = static_cast<SchulzDispersion *>(ptr); |
---|
| 151 | delete disp; |
---|
| 152 | return; |
---|
[eba9885] | 153 | } |
---|
| 154 | /** |
---|
| 155 | * Create a schulz dispersion model as a python object |
---|
| 156 | */ |
---|
| 157 | PyObject * new_schulz_dispersion(PyObject *, PyObject *args) { |
---|
[fd080830] | 158 | SchulzDispersion *disp = new SchulzDispersion(); |
---|
| 159 | return PyCObject_FromVoidPtr(disp, del_schulz_dispersion); |
---|
[eba9885] | 160 | } |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | /** |
---|
[af03ddd] | 164 | * Delete an array dispersion model object |
---|
| 165 | */ |
---|
| 166 | void del_array_dispersion(void *ptr){ |
---|
[fd080830] | 167 | ArrayDispersion * disp = static_cast<ArrayDispersion *>(ptr); |
---|
| 168 | delete disp; |
---|
| 169 | return; |
---|
[af03ddd] | 170 | } |
---|
| 171 | |
---|
| 172 | /** |
---|
| 173 | * Create an array dispersion model as a python object |
---|
| 174 | */ |
---|
| 175 | PyObject * new_array_dispersion(PyObject *, PyObject *args) { |
---|
[fd080830] | 176 | ArrayDispersion *disp = new ArrayDispersion(); |
---|
| 177 | return PyCObject_FromVoidPtr(disp, del_array_dispersion); |
---|
[af03ddd] | 178 | } |
---|
| 179 | |
---|
| 180 | #define INVECTOR(obj,buf,len) \ |
---|
| 181 | do { \ |
---|
[fd080830] | 182 | int err = PyObject_AsReadBuffer(obj, (const void **)(&buf), &len); \ |
---|
| 183 | if (err < 0) return NULL; \ |
---|
| 184 | len /= sizeof(*buf); \ |
---|
[af03ddd] | 185 | } while (0) |
---|
| 186 | |
---|
| 187 | /** |
---|
| 188 | * Sets weights from a numpy array |
---|
| 189 | */ |
---|
| 190 | PyObject * set_weights(PyObject *, PyObject *args) { |
---|
[fd080830] | 191 | PyObject *val_obj; |
---|
| 192 | PyObject *wei_obj; |
---|
| 193 | PyObject *disp; |
---|
| 194 | Py_ssize_t nval; |
---|
| 195 | Py_ssize_t nwei; |
---|
| 196 | double *values; |
---|
| 197 | double *weights; |
---|
| 198 | //int i; |
---|
| 199 | |
---|
| 200 | if (!PyArg_ParseTuple(args, "OOO", &disp, &val_obj, &wei_obj)) return NULL; |
---|
| 201 | INVECTOR(val_obj, values, nval); |
---|
| 202 | INVECTOR(wei_obj, weights, nwei); |
---|
| 203 | |
---|
| 204 | // Sanity check |
---|
| 205 | if(nval!=nwei) return NULL; |
---|
| 206 | |
---|
| 207 | // Set the array pointers |
---|
| 208 | void *temp = PyCObject_AsVoidPtr(disp); |
---|
| 209 | DispersionModel * dispersion = static_cast<DispersionModel *>(temp); |
---|
| 210 | dispersion->set_weights(nval, values, weights); |
---|
| 211 | |
---|
| 212 | return Py_BuildValue("i",1); |
---|
[af03ddd] | 213 | } |
---|
| 214 | |
---|
| 215 | |
---|
| 216 | |
---|
| 217 | /** |
---|
| 218 | * Define empty module |
---|
| 219 | */ |
---|
| 220 | static PyMethodDef module_methods[] = { |
---|
[fd080830] | 221 | {"new_dispersion_model", (PyCFunction)new_dispersion_model , METH_VARARGS, |
---|
| 222 | "Create a new DispersionModel object"}, |
---|
| 223 | {"new_gaussian_model", (PyCFunction)new_gaussian_dispersion, METH_VARARGS, |
---|
| 224 | "Create a new GaussianDispersion object"}, |
---|
| 225 | {"new_rectangle_model", (PyCFunction)new_rectangle_dispersion, METH_VARARGS, |
---|
| 226 | "Create a new RectangleDispersion object"}, |
---|
| 227 | {"new_lognormal_model", (PyCFunction)new_lognormal_dispersion, METH_VARARGS, |
---|
| 228 | "Create a new LogNormalDispersion object"}, |
---|
| 229 | {"new_schulz_model", (PyCFunction)new_schulz_dispersion, METH_VARARGS, |
---|
| 230 | "Create a new SchulzDispersion object"}, |
---|
| 231 | {"new_array_model", (PyCFunction)new_array_dispersion , METH_VARARGS, |
---|
| 232 | "Create a new ArrayDispersion object"}, |
---|
| 233 | {"set_dispersion_weights",(PyCFunction)set_weights , METH_VARARGS, |
---|
| 234 | "Create the dispersion weight arrays for an Array Dispersion object"}, |
---|
| 235 | {NULL} |
---|
[af03ddd] | 236 | }; |
---|
| 237 | |
---|
| 238 | |
---|
| 239 | #ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ |
---|
| 240 | #define PyMODINIT_FUNC void |
---|
| 241 | #endif |
---|
| 242 | PyMODINIT_FUNC |
---|
| 243 | initc_models(void) |
---|
| 244 | { |
---|
[fd080830] | 245 | PyObject* m; |
---|
| 246 | |
---|
| 247 | m = Py_InitModule3("c_models", module_methods, |
---|
| 248 | "C extension module for SANS scattering models."); |
---|
| 249 | import_array(); |
---|
| 250 | |
---|
| 251 | addCCylinderModel(m); |
---|
| 252 | addCBarBellModel(m); |
---|
| 253 | addCCappedCylinderModel(m); |
---|
| 254 | addCParallelepipedModel(m); |
---|
| 255 | addCCSParallelepipedModel(m); |
---|
| 256 | addCCoreShellCylinderModel(m); |
---|
[543d1bd] | 257 | addCCoreShellBicelleModel(m); |
---|
[fd080830] | 258 | addCCoreShellModel(m); |
---|
| 259 | addCCoreFourShellModel(m); |
---|
[7289627] | 260 | addCCore2ndMomentModel(m); |
---|
[fd080830] | 261 | addCEllipsoidModel(m); |
---|
| 262 | addCSphereModel(m); |
---|
| 263 | addCSphereSLDModel(m); |
---|
| 264 | addCOnionModel(m); |
---|
| 265 | addCReflModel(m); |
---|
| 266 | addCReflAdvModel(m); |
---|
| 267 | addCFuzzySphereModel(m); |
---|
| 268 | addCHardsphereStructure(m); |
---|
| 269 | addCStickyHSStructure(m); |
---|
| 270 | addCSCCrystalModel(m); |
---|
| 271 | addCFCCrystalModel(m); |
---|
| 272 | addCBCCrystalModel(m); |
---|
| 273 | addCSquareWellStructure(m); |
---|
| 274 | addCHayterMSAStructure(m); |
---|
| 275 | addCEllipticalCylinderModel(m); |
---|
| 276 | addCTriaxialEllipsoidModel(m); |
---|
| 277 | addCFlexibleCylinderModel(m); |
---|
| 278 | addCFlexCylEllipXModel(m); |
---|
| 279 | addCStackedDisksModel(m); |
---|
| 280 | addCLamellarPSModel(m); |
---|
| 281 | addCLamellarPSHGModel(m); |
---|
| 282 | addCLamellarPCrystalModel(m); |
---|
| 283 | addCCoreShellEllipsoidModel(m); |
---|
| 284 | addCDiamEllipFunc(m); |
---|
| 285 | addCDiamCylFunc(m); |
---|
| 286 | addCSLDCalFunc(m); |
---|
[d9547e7] | 287 | addCLinearPearlsModel(m); |
---|
[fd080830] | 288 | addCPearlNecklaceModel(m); |
---|
| 289 | addCLamellarModel(m); |
---|
| 290 | addCLamellarFFHGModel(m); |
---|
| 291 | addCHollowCylinderModel(m); |
---|
| 292 | addCMultiShellModel(m); |
---|
| 293 | addCBinaryHSModel(m); |
---|
| 294 | addDisperser(m); |
---|
| 295 | addCGaussian(m); |
---|
| 296 | addCSchulz(m); |
---|
| 297 | addCLogNormal(m); |
---|
| 298 | addCLorentzian(m); |
---|
| 299 | addCVesicleModel(m); |
---|
| 300 | addCPoly_GaussCoil(m); |
---|
| 301 | addCRPAModel(m); |
---|
| 302 | addCFractalModel(m); |
---|
[08648c0] | 303 | addCMassSurfaceFractal(m); |
---|
| 304 | addCMassFractalModel(m); |
---|
| 305 | addCSurfaceFractalModel(m); |
---|
[af03ddd] | 306 | } |
---|