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