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