source: sasview/sansmodels/src/c_models/c_models.cpp @ 6d4df13

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 6d4df13 was 431c9e0, checked in by ajj, 12 years ago

Adding parts of cephes math library to provide bessel functions on all platforms.

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