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