source: sasview/sansmodels/src/sans/models/c_models/c_models.cpp @ 0a518e4c

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 0a518e4c was 25579e8, checked in by Jae Cho <jhjcho@…>, 16 years ago

Enable structure factors

  • Property mode set to 100644
File size: 4.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
10void addCCylinderModel(PyObject *module);
11void addCSphereModel(PyObject *module);
12void addCHardsphereStructure(PyObject *module);
13void addCStickyHSStructure(PyObject *module);
14void addCSquareWellStructure(PyObject *module);
15void addCHayterMSAStructure(PyObject *module);
16void addCCoreShellModel(PyObject *module);
17void addCCoreShellCylinderModel(PyObject *module);
18void addCEllipsoidModel(PyObject *module);
19void addCEllipticalCylinderModel(PyObject *module);
20
21extern "C" {
22        //void addCCoreShellCylinderModel(PyObject *module);
23        //void addCCoreShellModel(PyObject *module);
24        //void addCEllipsoidModel(PyObject *module);
25        //void addCEllipticalCylinderModel(PyObject *module);
26        void addDisperser(PyObject *module);
27        void addCGaussian(PyObject *module);
28        void addCLorentzian(PyObject *module);
29}
30
31/**
32 * Delete a dispersion model object
33 */
34void del_dispersion_model(void *ptr){
35        DispersionModel * disp = static_cast<DispersionModel *>(ptr);
36        delete disp;
37        return;
38}
39
40/**
41 * Create a dispersion model as a python object
42 */
43PyObject * new_dispersion_model(PyObject *, PyObject *args) {
44        DispersionModel *disp = new DispersionModel();
45        return PyCObject_FromVoidPtr(disp, del_dispersion_model);
46}
47
48
49/**
50 * Delete a gaussian dispersion model object
51 */
52void del_gaussian_dispersion(void *ptr){
53        GaussianDispersion * disp = static_cast<GaussianDispersion *>(ptr);
54        delete disp;
55        return;
56}
57
58/**
59 * Create a gaussian dispersion model as a python object
60 */
61PyObject * new_gaussian_dispersion(PyObject *, PyObject *args) {
62        GaussianDispersion *disp = new GaussianDispersion();
63        return PyCObject_FromVoidPtr(disp, del_gaussian_dispersion);
64}
65
66/**
67 * Delete an array dispersion model object
68 */
69void del_array_dispersion(void *ptr){
70        ArrayDispersion * disp = static_cast<ArrayDispersion *>(ptr);
71        delete disp;
72        return;
73}
74
75/**
76 * Create an array dispersion model as a python object
77 */
78PyObject * new_array_dispersion(PyObject *, PyObject *args) {
79        ArrayDispersion *disp = new ArrayDispersion();
80        return PyCObject_FromVoidPtr(disp, del_array_dispersion);
81}
82
83#define INVECTOR(obj,buf,len)                                                                           \
84    do { \
85        int err = PyObject_AsReadBuffer(obj, (const void **)(&buf), &len); \
86        if (err < 0) return NULL; \
87        len /= sizeof(*buf); \
88    } while (0)
89
90/**
91 * Sets weights from a numpy array
92 */
93PyObject * set_weights(PyObject *, PyObject *args) {
94        PyObject *val_obj;
95        PyObject *wei_obj;
96        PyObject *disp;
97        Py_ssize_t nval;
98        Py_ssize_t nwei;
99        double *values;
100        double *weights;
101    int i;
102
103        if (!PyArg_ParseTuple(args, "OOO", &disp, &val_obj, &wei_obj)) return NULL;
104        INVECTOR(val_obj, values, nval);
105        INVECTOR(wei_obj, weights, nwei);
106
107        // Sanity check
108        if(nval!=nwei) return NULL;
109
110        // Set the array pointers
111        void *temp = PyCObject_AsVoidPtr(disp);
112        DispersionModel * dispersion = static_cast<DispersionModel *>(temp);
113        dispersion->set_weights(nval, values, weights);
114
115        return Py_BuildValue("i",1);
116}
117
118
119
120/**
121 * Define empty module
122 */
123static PyMethodDef module_methods[] = {
124        {"new_dispersion_model", (PyCFunction)new_dispersion_model     , METH_VARARGS,
125                  "Create a new DispersionModel object"},
126        {"new_gaussian_model",   (PyCFunction)new_gaussian_dispersion, METH_VARARGS,
127                  "Create a new GaussianDispersion object"},
128        {"new_array_model",      (PyCFunction)new_array_dispersion  , METH_VARARGS,
129                  "Create a new ArrayDispersion object"},
130        {"set_dispersion_weights",(PyCFunction)set_weights  , METH_VARARGS,
131                        "Create the dispersion weight arrays for an Array Dispersion object"},
132    {NULL}
133};
134
135
136#ifndef PyMODINIT_FUNC  /* declarations for DLL import/export */
137#define PyMODINIT_FUNC void
138#endif
139PyMODINIT_FUNC
140initc_models(void)
141{
142    PyObject* m;
143
144    m = Py_InitModule3("c_models", module_methods,
145                       "C extension module for SANS scattering models.");
146
147        addCCylinderModel(m);
148        addCCoreShellCylinderModel(m);
149        addCCoreShellModel(m);
150        addCEllipsoidModel(m);
151        addCSphereModel(m);
152        addCHardsphereStructure(m);
153        addCStickyHSStructure(m);
154        addCSquareWellStructure(m);
155        addCHayterMSAStructure(m);
156        addCEllipticalCylinderModel(m);
157        addDisperser(m);
158        addCGaussian(m);
159        addCLorentzian(m);
160
161}
Note: See TracBrowser for help on using the repository browser.