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