[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> |
---|
| 9 | |
---|
| 10 | void addCCylinderModel(PyObject *module); |
---|
[27a0771] | 11 | void addCTriaxialEllipsoidModel(PyObject *module); |
---|
[8a48713] | 12 | void addCParallelepipedModel(PyObject *module); |
---|
[0f5bc9f] | 13 | void addCSphereModel(PyObject *module); |
---|
[25579e8] | 14 | void addCHardsphereStructure(PyObject *module); |
---|
| 15 | void addCStickyHSStructure(PyObject *module); |
---|
| 16 | void addCSquareWellStructure(PyObject *module); |
---|
| 17 | void addCHayterMSAStructure(PyObject *module); |
---|
[4d09267] | 18 | void addCDiamEllipFunc(PyObject *module); |
---|
| 19 | void addCDiamCylFunc(PyObject *module); |
---|
[0f5bc9f] | 20 | void addCCoreShellModel(PyObject *module); |
---|
| 21 | void addCCoreShellCylinderModel(PyObject *module); |
---|
| 22 | void addCEllipsoidModel(PyObject *module); |
---|
| 23 | void addCEllipticalCylinderModel(PyObject *module); |
---|
[5068697] | 24 | void addCTriaxialEllipsoidModel(PyObject *module); |
---|
| 25 | void addCFlexibleCylinderModel(PyObject *module); |
---|
| 26 | void addCStackedDisksModel(PyObject *module); |
---|
[27a0771] | 27 | void addCLamellarPSModel(PyObject *module); |
---|
| 28 | void addCLamellarPSHGModel(PyObject *module); |
---|
| 29 | void addCOblateModel(PyObject *module); |
---|
| 30 | void addCProlateModel(PyObject *module); |
---|
[34c3020] | 31 | void addCLamellarModel(PyObject *module); |
---|
| 32 | void addCLamellarFFHGModel(PyObject *module); |
---|
[27a0771] | 33 | |
---|
[0f5bc9f] | 34 | |
---|
[af03ddd] | 35 | extern "C" { |
---|
[0f5bc9f] | 36 | //void addCCoreShellCylinderModel(PyObject *module); |
---|
| 37 | //void addCCoreShellModel(PyObject *module); |
---|
| 38 | //void addCEllipsoidModel(PyObject *module); |
---|
| 39 | //void addCEllipticalCylinderModel(PyObject *module); |
---|
[af03ddd] | 40 | void addDisperser(PyObject *module); |
---|
| 41 | void addCGaussian(PyObject *module); |
---|
| 42 | void addCLorentzian(PyObject *module); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | /** |
---|
| 46 | * Delete a dispersion model object |
---|
| 47 | */ |
---|
| 48 | void del_dispersion_model(void *ptr){ |
---|
| 49 | DispersionModel * disp = static_cast<DispersionModel *>(ptr); |
---|
| 50 | delete disp; |
---|
| 51 | return; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | /** |
---|
| 55 | * Create a dispersion model as a python object |
---|
| 56 | */ |
---|
| 57 | PyObject * new_dispersion_model(PyObject *, PyObject *args) { |
---|
| 58 | DispersionModel *disp = new DispersionModel(); |
---|
| 59 | return PyCObject_FromVoidPtr(disp, del_dispersion_model); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | * Delete a gaussian dispersion model object |
---|
| 65 | */ |
---|
| 66 | void del_gaussian_dispersion(void *ptr){ |
---|
| 67 | GaussianDispersion * disp = static_cast<GaussianDispersion *>(ptr); |
---|
| 68 | delete disp; |
---|
| 69 | return; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | /** |
---|
| 73 | * Create a gaussian dispersion model as a python object |
---|
| 74 | */ |
---|
| 75 | PyObject * new_gaussian_dispersion(PyObject *, PyObject *args) { |
---|
| 76 | GaussianDispersion *disp = new GaussianDispersion(); |
---|
| 77 | return PyCObject_FromVoidPtr(disp, del_gaussian_dispersion); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | /** |
---|
| 81 | * Delete an array dispersion model object |
---|
| 82 | */ |
---|
| 83 | void del_array_dispersion(void *ptr){ |
---|
| 84 | ArrayDispersion * disp = static_cast<ArrayDispersion *>(ptr); |
---|
| 85 | delete disp; |
---|
| 86 | return; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | /** |
---|
| 90 | * Create an array dispersion model as a python object |
---|
| 91 | */ |
---|
| 92 | PyObject * new_array_dispersion(PyObject *, PyObject *args) { |
---|
| 93 | ArrayDispersion *disp = new ArrayDispersion(); |
---|
| 94 | return PyCObject_FromVoidPtr(disp, del_array_dispersion); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | #define INVECTOR(obj,buf,len) \ |
---|
| 98 | do { \ |
---|
| 99 | int err = PyObject_AsReadBuffer(obj, (const void **)(&buf), &len); \ |
---|
| 100 | if (err < 0) return NULL; \ |
---|
| 101 | len /= sizeof(*buf); \ |
---|
| 102 | } while (0) |
---|
| 103 | |
---|
| 104 | /** |
---|
| 105 | * Sets weights from a numpy array |
---|
| 106 | */ |
---|
| 107 | PyObject * set_weights(PyObject *, PyObject *args) { |
---|
| 108 | PyObject *val_obj; |
---|
| 109 | PyObject *wei_obj; |
---|
| 110 | PyObject *disp; |
---|
| 111 | Py_ssize_t nval; |
---|
| 112 | Py_ssize_t nwei; |
---|
| 113 | double *values; |
---|
| 114 | double *weights; |
---|
| 115 | int i; |
---|
| 116 | |
---|
| 117 | if (!PyArg_ParseTuple(args, "OOO", &disp, &val_obj, &wei_obj)) return NULL; |
---|
| 118 | INVECTOR(val_obj, values, nval); |
---|
| 119 | INVECTOR(wei_obj, weights, nwei); |
---|
| 120 | |
---|
| 121 | // Sanity check |
---|
| 122 | if(nval!=nwei) return NULL; |
---|
| 123 | |
---|
| 124 | // Set the array pointers |
---|
| 125 | void *temp = PyCObject_AsVoidPtr(disp); |
---|
| 126 | DispersionModel * dispersion = static_cast<DispersionModel *>(temp); |
---|
| 127 | dispersion->set_weights(nval, values, weights); |
---|
| 128 | |
---|
| 129 | return Py_BuildValue("i",1); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | /** |
---|
| 135 | * Define empty module |
---|
| 136 | */ |
---|
| 137 | static PyMethodDef module_methods[] = { |
---|
| 138 | {"new_dispersion_model", (PyCFunction)new_dispersion_model , METH_VARARGS, |
---|
| 139 | "Create a new DispersionModel object"}, |
---|
| 140 | {"new_gaussian_model", (PyCFunction)new_gaussian_dispersion, METH_VARARGS, |
---|
| 141 | "Create a new GaussianDispersion object"}, |
---|
| 142 | {"new_array_model", (PyCFunction)new_array_dispersion , METH_VARARGS, |
---|
| 143 | "Create a new ArrayDispersion object"}, |
---|
| 144 | {"set_dispersion_weights",(PyCFunction)set_weights , METH_VARARGS, |
---|
| 145 | "Create the dispersion weight arrays for an Array Dispersion object"}, |
---|
| 146 | {NULL} |
---|
| 147 | }; |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | #ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ |
---|
| 151 | #define PyMODINIT_FUNC void |
---|
| 152 | #endif |
---|
| 153 | PyMODINIT_FUNC |
---|
| 154 | initc_models(void) |
---|
| 155 | { |
---|
| 156 | PyObject* m; |
---|
| 157 | |
---|
| 158 | m = Py_InitModule3("c_models", module_methods, |
---|
| 159 | "C extension module for SANS scattering models."); |
---|
| 160 | |
---|
| 161 | addCCylinderModel(m); |
---|
[8a48713] | 162 | addCParallelepipedModel(m); |
---|
[af03ddd] | 163 | addCCoreShellCylinderModel(m); |
---|
| 164 | addCCoreShellModel(m); |
---|
| 165 | addCEllipsoidModel(m); |
---|
| 166 | addCSphereModel(m); |
---|
[25579e8] | 167 | addCHardsphereStructure(m); |
---|
| 168 | addCStickyHSStructure(m); |
---|
| 169 | addCSquareWellStructure(m); |
---|
| 170 | addCHayterMSAStructure(m); |
---|
[4d09267] | 171 | addCDiamEllipFunc(m); |
---|
| 172 | addCDiamCylFunc(m); |
---|
[af03ddd] | 173 | addCEllipticalCylinderModel(m); |
---|
[5068697] | 174 | addCTriaxialEllipsoidModel(m); |
---|
| 175 | addCFlexibleCylinderModel(m); |
---|
| 176 | addCStackedDisksModel(m); |
---|
[27a0771] | 177 | addCLamellarPSModel(m); |
---|
| 178 | addCLamellarPSHGModel(m); |
---|
| 179 | addCOblateModel(m); |
---|
| 180 | addCProlateModel(m); |
---|
[34c3020] | 181 | addCLamellarModel(m); |
---|
| 182 | addCLamellarFFHGModel(m); |
---|
[af03ddd] | 183 | addDisperser(m); |
---|
| 184 | addCGaussian(m); |
---|
| 185 | addCLorentzian(m); |
---|
| 186 | |
---|
| 187 | } |
---|