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

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 f41b4c3 was 8a48713, checked in by Gervaise Alina <gervyh@…>, 15 years ago

implement 1D for parallelepiped model

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