source: sasview/sansmodels/src/sans/models/c_models/c_models.cpp @ 8bd764d

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 8bd764d was 8809e48, checked in by Mathieu Doucet <doucetm@…>, 16 years ago

Updated cloning

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