source: sasview/sansmodels/src/c_models/c_models.cpp @ 20efe7b

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 20efe7b was 3764dbd7, checked in by Jae Cho <jhjcho@…>, 13 years ago

raspberry model

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