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