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