source: sasview/sansmodels/src/c_models/c_models.cpp @ 530cc84

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 530cc84 was fd080830, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

cleanup

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