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