source: sasview/sansmodels/src/c_models/c_models.cpp @ 1e73833

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 1e73833 was 543d1bd, checked in by Jae Cho <jhjcho@…>, 13 years ago

Added coreshellbicelle model

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