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