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