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