[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); |
---|
[8c8cb05] | 22 | void addCPearlNecklaceModel(PyObject *module); |
---|
[35aface] | 23 | void addCReflModel(PyObject *module); |
---|
[96656e3] | 24 | void addCReflAdvModel(PyObject *module); |
---|
[c724ccd] | 25 | void addCFuzzySphereModel(PyObject *module); |
---|
[25579e8] | 26 | void addCHardsphereStructure(PyObject *module); |
---|
| 27 | void addCStickyHSStructure(PyObject *module); |
---|
[94a3f8f] | 28 | void addCSCCrystalModel(PyObject *module); |
---|
[d5b6a9d] | 29 | void addCFCCrystalModel(PyObject *module); |
---|
| 30 | void addCBCCrystalModel(PyObject *module); |
---|
[25579e8] | 31 | void addCSquareWellStructure(PyObject *module); |
---|
| 32 | void addCHayterMSAStructure(PyObject *module); |
---|
[0f5bc9f] | 33 | void addCCoreShellModel(PyObject *module); |
---|
[c724ccd] | 34 | void addCCoreFourShellModel(PyObject *module); |
---|
[0f5bc9f] | 35 | void addCCoreShellCylinderModel(PyObject *module); |
---|
| 36 | void addCEllipsoidModel(PyObject *module); |
---|
| 37 | void addCEllipticalCylinderModel(PyObject *module); |
---|
[5068697] | 38 | void addCTriaxialEllipsoidModel(PyObject *module); |
---|
| 39 | void addCFlexibleCylinderModel(PyObject *module); |
---|
[c724ccd] | 40 | void addCFlexCylEllipXModel(PyObject *module); |
---|
[5068697] | 41 | void addCStackedDisksModel(PyObject *module); |
---|
[27a0771] | 42 | void addCLamellarPSModel(PyObject *module); |
---|
| 43 | void addCLamellarPSHGModel(PyObject *module); |
---|
[fbd09fa0] | 44 | void addCLamellarPCrystalModel(PyObject *module); |
---|
[eddff027] | 45 | void addCCoreShellEllipsoidModel(PyObject *module); |
---|
[5eb9154] | 46 | void addCDiamEllipFunc(PyObject *module); |
---|
| 47 | void addCDiamCylFunc(PyObject *module); |
---|
[96d19c6] | 48 | void addCSLDCalFunc(PyObject *module); |
---|
[5eb9154] | 49 | |
---|
| 50 | //void addCOblateModel(PyObject *module); |
---|
| 51 | //void addCProlateModel(PyObject *module); |
---|
[34c3020] | 52 | void addCLamellarModel(PyObject *module); |
---|
| 53 | void addCLamellarFFHGModel(PyObject *module); |
---|
[27fea3f] | 54 | void addCHollowCylinderModel(PyObject *module); |
---|
[3d25331f] | 55 | void addCMultiShellModel(PyObject *module); |
---|
| 56 | void addCVesicleModel(PyObject *module); |
---|
| 57 | void addCBinaryHSModel(PyObject *module); |
---|
[35aface] | 58 | void addCRPAModel(PyObject *module); |
---|
[c724ccd] | 59 | void addCFractalModel(PyObject *module); |
---|
| 60 | void addCPoly_GaussCoil(PyObject *module); |
---|
[27a0771] | 61 | |
---|
[0f5bc9f] | 62 | |
---|
[af03ddd] | 63 | extern "C" { |
---|
[0f5bc9f] | 64 | //void addCCoreShellCylinderModel(PyObject *module); |
---|
| 65 | //void addCCoreShellModel(PyObject *module); |
---|
| 66 | //void addCEllipsoidModel(PyObject *module); |
---|
| 67 | //void addCEllipticalCylinderModel(PyObject *module); |
---|
[af03ddd] | 68 | void addDisperser(PyObject *module); |
---|
| 69 | void addCGaussian(PyObject *module); |
---|
| 70 | void addCLorentzian(PyObject *module); |
---|
[eba9885] | 71 | void addCLogNormal(PyObject *module); |
---|
| 72 | void addCSchulz(PyObject *module); |
---|
[af03ddd] | 73 | } |
---|
| 74 | |
---|
| 75 | /** |
---|
| 76 | * Delete a dispersion model object |
---|
| 77 | */ |
---|
| 78 | void del_dispersion_model(void *ptr){ |
---|
| 79 | DispersionModel * disp = static_cast<DispersionModel *>(ptr); |
---|
| 80 | delete disp; |
---|
| 81 | return; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | /** |
---|
| 85 | * Create a dispersion model as a python object |
---|
| 86 | */ |
---|
| 87 | PyObject * new_dispersion_model(PyObject *, PyObject *args) { |
---|
| 88 | DispersionModel *disp = new DispersionModel(); |
---|
| 89 | return PyCObject_FromVoidPtr(disp, del_dispersion_model); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | /** |
---|
[eba9885] | 94 | * Delete a lognormal dispersion model object |
---|
| 95 | */ |
---|
| 96 | void del_lognormal_dispersion(void *ptr){ |
---|
| 97 | LogNormalDispersion * disp = static_cast<LogNormalDispersion *>(ptr); |
---|
| 98 | delete disp; |
---|
| 99 | return; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | /** |
---|
| 103 | * Create a lognormal dispersion model as a python object |
---|
| 104 | */ |
---|
| 105 | PyObject * new_lognormal_dispersion(PyObject *, PyObject *args) { |
---|
| 106 | LogNormalDispersion *disp = new LogNormalDispersion(); |
---|
| 107 | return PyCObject_FromVoidPtr(disp, del_lognormal_dispersion); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | /** |
---|
[af03ddd] | 111 | * Delete a gaussian dispersion model object |
---|
| 112 | */ |
---|
| 113 | void del_gaussian_dispersion(void *ptr){ |
---|
| 114 | GaussianDispersion * disp = static_cast<GaussianDispersion *>(ptr); |
---|
| 115 | delete disp; |
---|
| 116 | return; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | /** |
---|
| 120 | * Create a gaussian dispersion model as a python object |
---|
| 121 | */ |
---|
| 122 | PyObject * new_gaussian_dispersion(PyObject *, PyObject *args) { |
---|
| 123 | GaussianDispersion *disp = new GaussianDispersion(); |
---|
| 124 | return PyCObject_FromVoidPtr(disp, del_gaussian_dispersion); |
---|
| 125 | } |
---|
| 126 | |
---|
[8dc02d8b] | 127 | |
---|
| 128 | /** |
---|
| 129 | * Delete a rectangle dispersion model object |
---|
| 130 | */ |
---|
| 131 | void del_rectangle_dispersion(void *ptr){ |
---|
| 132 | RectangleDispersion * disp = static_cast<RectangleDispersion *>(ptr); |
---|
| 133 | delete disp; |
---|
| 134 | return; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | /** |
---|
| 138 | * Create a rectangle dispersion model as a python object |
---|
| 139 | */ |
---|
| 140 | PyObject * new_rectangle_dispersion(PyObject *, PyObject *args) { |
---|
| 141 | RectangleDispersion *disp = new RectangleDispersion(); |
---|
| 142 | return PyCObject_FromVoidPtr(disp, del_rectangle_dispersion); |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | |
---|
[af03ddd] | 146 | /** |
---|
[eba9885] | 147 | * Delete a schulz dispersion model object |
---|
| 148 | */ |
---|
| 149 | void del_schulz_dispersion(void *ptr){ |
---|
| 150 | SchulzDispersion * disp = static_cast<SchulzDispersion *>(ptr); |
---|
| 151 | delete disp; |
---|
| 152 | return; |
---|
| 153 | } |
---|
| 154 | /** |
---|
| 155 | * Create a schulz dispersion model as a python object |
---|
| 156 | */ |
---|
| 157 | PyObject * new_schulz_dispersion(PyObject *, PyObject *args) { |
---|
| 158 | SchulzDispersion *disp = new SchulzDispersion(); |
---|
| 159 | return PyCObject_FromVoidPtr(disp, del_schulz_dispersion); |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | /** |
---|
[af03ddd] | 164 | * Delete an array dispersion model object |
---|
| 165 | */ |
---|
| 166 | void del_array_dispersion(void *ptr){ |
---|
| 167 | ArrayDispersion * disp = static_cast<ArrayDispersion *>(ptr); |
---|
| 168 | delete disp; |
---|
| 169 | return; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | /** |
---|
| 173 | * Create an array dispersion model as a python object |
---|
| 174 | */ |
---|
| 175 | PyObject * new_array_dispersion(PyObject *, PyObject *args) { |
---|
| 176 | ArrayDispersion *disp = new ArrayDispersion(); |
---|
| 177 | return PyCObject_FromVoidPtr(disp, del_array_dispersion); |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | #define INVECTOR(obj,buf,len) \ |
---|
| 181 | do { \ |
---|
| 182 | int err = PyObject_AsReadBuffer(obj, (const void **)(&buf), &len); \ |
---|
| 183 | if (err < 0) return NULL; \ |
---|
| 184 | len /= sizeof(*buf); \ |
---|
| 185 | } while (0) |
---|
| 186 | |
---|
| 187 | /** |
---|
| 188 | * Sets weights from a numpy array |
---|
| 189 | */ |
---|
| 190 | PyObject * set_weights(PyObject *, PyObject *args) { |
---|
| 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; |
---|
[812b901] | 198 | //int i; |
---|
[af03ddd] | 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); |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | |
---|
| 216 | |
---|
| 217 | /** |
---|
| 218 | * Define empty module |
---|
| 219 | */ |
---|
| 220 | static PyMethodDef module_methods[] = { |
---|
| 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"}, |
---|
[8dc02d8b] | 225 | {"new_rectangle_model", (PyCFunction)new_rectangle_dispersion, METH_VARARGS, |
---|
| 226 | "Create a new RectangleDispersion object"}, |
---|
[eba9885] | 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"}, |
---|
[af03ddd] | 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} |
---|
| 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 | { |
---|
| 245 | PyObject* m; |
---|
| 246 | |
---|
| 247 | m = Py_InitModule3("c_models", module_methods, |
---|
| 248 | "C extension module for SANS scattering models."); |
---|
[812b901] | 249 | import_array(); |
---|
[af03ddd] | 250 | |
---|
| 251 | addCCylinderModel(m); |
---|
[fbd09fa0] | 252 | addCBarBellModel(m); |
---|
| 253 | addCCappedCylinderModel(m); |
---|
[8a48713] | 254 | addCParallelepipedModel(m); |
---|
[18f2ca1] | 255 | addCCSParallelepipedModel(m); |
---|
[af03ddd] | 256 | addCCoreShellCylinderModel(m); |
---|
| 257 | addCCoreShellModel(m); |
---|
[c724ccd] | 258 | addCCoreFourShellModel(m); |
---|
[af03ddd] | 259 | addCEllipsoidModel(m); |
---|
| 260 | addCSphereModel(m); |
---|
[96d19c6] | 261 | addCSphereSLDModel(m); |
---|
[e096270] | 262 | addCOnionModel(m); |
---|
[35aface] | 263 | addCReflModel(m); |
---|
[96656e3] | 264 | addCReflAdvModel(m); |
---|
[c724ccd] | 265 | addCFuzzySphereModel(m); |
---|
[25579e8] | 266 | addCHardsphereStructure(m); |
---|
| 267 | addCStickyHSStructure(m); |
---|
[94a3f8f] | 268 | addCSCCrystalModel(m); |
---|
[d5b6a9d] | 269 | addCFCCrystalModel(m); |
---|
| 270 | addCBCCrystalModel(m); |
---|
[25579e8] | 271 | addCSquareWellStructure(m); |
---|
| 272 | addCHayterMSAStructure(m); |
---|
[af03ddd] | 273 | addCEllipticalCylinderModel(m); |
---|
[5068697] | 274 | addCTriaxialEllipsoidModel(m); |
---|
| 275 | addCFlexibleCylinderModel(m); |
---|
[c724ccd] | 276 | addCFlexCylEllipXModel(m); |
---|
[5068697] | 277 | addCStackedDisksModel(m); |
---|
[27a0771] | 278 | addCLamellarPSModel(m); |
---|
| 279 | addCLamellarPSHGModel(m); |
---|
[fbd09fa0] | 280 | addCLamellarPCrystalModel(m); |
---|
[eddff027] | 281 | addCCoreShellEllipsoidModel(m); |
---|
[5eb9154] | 282 | addCDiamEllipFunc(m); |
---|
| 283 | addCDiamCylFunc(m); |
---|
[96d19c6] | 284 | addCSLDCalFunc(m); |
---|
[8c8cb05] | 285 | addCPearlNecklaceModel(m); |
---|
[34c3020] | 286 | addCLamellarModel(m); |
---|
| 287 | addCLamellarFFHGModel(m); |
---|
[27fea3f] | 288 | addCHollowCylinderModel(m); |
---|
[3d25331f] | 289 | addCMultiShellModel(m); |
---|
| 290 | addCBinaryHSModel(m); |
---|
[59b9b675] | 291 | addDisperser(m); |
---|
| 292 | addCGaussian(m); |
---|
| 293 | addCSchulz(m); |
---|
| 294 | addCLogNormal(m); |
---|
| 295 | addCLorentzian(m); |
---|
[3d25331f] | 296 | addCVesicleModel(m); |
---|
[c724ccd] | 297 | addCPoly_GaussCoil(m); |
---|
[35aface] | 298 | addCRPAModel(m); |
---|
[c724ccd] | 299 | addCFractalModel(m); |
---|
[af03ddd] | 300 | } |
---|