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