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