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