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

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 87fbc60 was 4d09267, checked in by Jae Cho <jhjcho@…>, 16 years ago

Added 2nd virial coeff. functions

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