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

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 43ecc75f was c724ccd, checked in by Jae Cho <jhjcho@…>, 15 years ago

More models added and correction of Wrappergenerator on model parameter value precision

  • Property mode set to 100644
File size: 7.4 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>
[812b901]9#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sans
10#include "arrayobject.h"
11
[af03ddd]12
13void addCCylinderModel(PyObject *module);
[27a0771]14void addCTriaxialEllipsoidModel(PyObject *module);
[8a48713]15void addCParallelepipedModel(PyObject *module);
[0f5bc9f]16void addCSphereModel(PyObject *module);
[c724ccd]17void addCFuzzySphereModel(PyObject *module);
[25579e8]18void addCHardsphereStructure(PyObject *module);
19void addCStickyHSStructure(PyObject *module);
20void addCSquareWellStructure(PyObject *module);
21void addCHayterMSAStructure(PyObject *module);
[0f5bc9f]22void addCCoreShellModel(PyObject *module);
[c724ccd]23void addCCoreFourShellModel(PyObject *module);
[0f5bc9f]24void addCCoreShellCylinderModel(PyObject *module);
25void addCEllipsoidModel(PyObject *module);
26void addCEllipticalCylinderModel(PyObject *module);
[5068697]27void addCTriaxialEllipsoidModel(PyObject *module);
28void addCFlexibleCylinderModel(PyObject *module);
[c724ccd]29void addCFlexCylEllipXModel(PyObject *module);
[5068697]30void addCStackedDisksModel(PyObject *module);
[27a0771]31void addCLamellarPSModel(PyObject *module);
32void addCLamellarPSHGModel(PyObject *module);
[eddff027]33void addCCoreShellEllipsoidModel(PyObject *module);
[5eb9154]34void addCDiamEllipFunc(PyObject *module);
35void addCDiamCylFunc(PyObject *module);
36
37//void addCOblateModel(PyObject *module);
38//void addCProlateModel(PyObject *module);
[34c3020]39void addCLamellarModel(PyObject *module);
40void addCLamellarFFHGModel(PyObject *module);
[27fea3f]41void addCHollowCylinderModel(PyObject *module);
[3d25331f]42void addCMultiShellModel(PyObject *module);
43void addCVesicleModel(PyObject *module);
44void addCBinaryHSModel(PyObject *module);
[c724ccd]45//void addCPolymerExclVolModel(PyObject *module);
46void addCFractalModel(PyObject *module);
47void addCPoly_GaussCoil(PyObject *module);
[27a0771]48
[0f5bc9f]49
[af03ddd]50extern "C" {
[0f5bc9f]51        //void addCCoreShellCylinderModel(PyObject *module);
52        //void addCCoreShellModel(PyObject *module);
53        //void addCEllipsoidModel(PyObject *module);
54        //void addCEllipticalCylinderModel(PyObject *module);
[af03ddd]55        void addDisperser(PyObject *module);
56        void addCGaussian(PyObject *module);
57        void addCLorentzian(PyObject *module);
[eba9885]58        void addCLogNormal(PyObject *module);
59        void addCSchulz(PyObject *module);
[af03ddd]60}
61
62/**
63 * Delete a dispersion model object
64 */
65void del_dispersion_model(void *ptr){
66        DispersionModel * disp = static_cast<DispersionModel *>(ptr);
67        delete disp;
68        return;
69}
70
71/**
72 * Create a dispersion model as a python object
73 */
74PyObject * new_dispersion_model(PyObject *, PyObject *args) {
75        DispersionModel *disp = new DispersionModel();
76        return PyCObject_FromVoidPtr(disp, del_dispersion_model);
77}
78
79
80/**
[eba9885]81 * Delete a lognormal dispersion model object
82 */
83void del_lognormal_dispersion(void *ptr){
84        LogNormalDispersion * disp = static_cast<LogNormalDispersion *>(ptr);
85        delete disp;
86        return;
87}
88
89/**
90 * Create a lognormal dispersion model as a python object
91 */
92PyObject * new_lognormal_dispersion(PyObject *, PyObject *args) {
93        LogNormalDispersion *disp = new LogNormalDispersion();
94        return PyCObject_FromVoidPtr(disp, del_lognormal_dispersion);
95}
96
97/**
[af03ddd]98 * Delete a gaussian dispersion model object
99 */
100void del_gaussian_dispersion(void *ptr){
101        GaussianDispersion * disp = static_cast<GaussianDispersion *>(ptr);
102        delete disp;
103        return;
104}
105
106/**
107 * Create a gaussian dispersion model as a python object
108 */
109PyObject * new_gaussian_dispersion(PyObject *, PyObject *args) {
110        GaussianDispersion *disp = new GaussianDispersion();
111        return PyCObject_FromVoidPtr(disp, del_gaussian_dispersion);
112}
113
114/**
[eba9885]115 * Delete a schulz dispersion model object
116 */
117void del_schulz_dispersion(void *ptr){
118        SchulzDispersion * disp = static_cast<SchulzDispersion *>(ptr);
119        delete disp;
120        return;
121}
122/**
123 * Create a schulz dispersion model as a python object
124 */
125PyObject * new_schulz_dispersion(PyObject *, PyObject *args) {
126        SchulzDispersion *disp = new SchulzDispersion();
127        return PyCObject_FromVoidPtr(disp, del_schulz_dispersion);
128}
129
130
131/**
[af03ddd]132 * Delete an array dispersion model object
133 */
134void del_array_dispersion(void *ptr){
135        ArrayDispersion * disp = static_cast<ArrayDispersion *>(ptr);
136        delete disp;
137        return;
138}
139
140/**
141 * Create an array dispersion model as a python object
142 */
143PyObject * new_array_dispersion(PyObject *, PyObject *args) {
144        ArrayDispersion *disp = new ArrayDispersion();
145        return PyCObject_FromVoidPtr(disp, del_array_dispersion);
146}
147
148#define INVECTOR(obj,buf,len)                                                                           \
149    do { \
150        int err = PyObject_AsReadBuffer(obj, (const void **)(&buf), &len); \
151        if (err < 0) return NULL; \
152        len /= sizeof(*buf); \
153    } while (0)
154
155/**
156 * Sets weights from a numpy array
157 */
158PyObject * set_weights(PyObject *, PyObject *args) {
159        PyObject *val_obj;
160        PyObject *wei_obj;
161        PyObject *disp;
162        Py_ssize_t nval;
163        Py_ssize_t nwei;
164        double *values;
165        double *weights;
[812b901]166    //int i;
[af03ddd]167
168        if (!PyArg_ParseTuple(args, "OOO", &disp, &val_obj, &wei_obj)) return NULL;
169        INVECTOR(val_obj, values, nval);
170        INVECTOR(wei_obj, weights, nwei);
171
172        // Sanity check
173        if(nval!=nwei) return NULL;
174
175        // Set the array pointers
176        void *temp = PyCObject_AsVoidPtr(disp);
177        DispersionModel * dispersion = static_cast<DispersionModel *>(temp);
178        dispersion->set_weights(nval, values, weights);
179
180        return Py_BuildValue("i",1);
181}
182
183
184
185/**
186 * Define empty module
187 */
188static PyMethodDef module_methods[] = {
189        {"new_dispersion_model", (PyCFunction)new_dispersion_model     , METH_VARARGS,
190                  "Create a new DispersionModel object"},
191        {"new_gaussian_model",   (PyCFunction)new_gaussian_dispersion, METH_VARARGS,
192                  "Create a new GaussianDispersion object"},
[eba9885]193    {"new_lognormal_model",   (PyCFunction)new_lognormal_dispersion, METH_VARARGS,
194                  "Create a new LogNormalDispersion object"},
195    {"new_schulz_model",   (PyCFunction)new_schulz_dispersion, METH_VARARGS,
196                  "Create a new SchulzDispersion object"},
[af03ddd]197        {"new_array_model",      (PyCFunction)new_array_dispersion  , METH_VARARGS,
198                  "Create a new ArrayDispersion object"},
199        {"set_dispersion_weights",(PyCFunction)set_weights  , METH_VARARGS,
200                        "Create the dispersion weight arrays for an Array Dispersion object"},
201    {NULL}
202};
203
204
205#ifndef PyMODINIT_FUNC  /* declarations for DLL import/export */
206#define PyMODINIT_FUNC void
207#endif
208PyMODINIT_FUNC
209initc_models(void)
210{
211    PyObject* m;
212
213    m = Py_InitModule3("c_models", module_methods,
214                       "C extension module for SANS scattering models.");
[812b901]215        import_array();
[af03ddd]216
217        addCCylinderModel(m);
[8a48713]218        addCParallelepipedModel(m);
[af03ddd]219        addCCoreShellCylinderModel(m);
220        addCCoreShellModel(m);
[c724ccd]221        addCCoreFourShellModel(m);
[af03ddd]222        addCEllipsoidModel(m);
223        addCSphereModel(m);
[c724ccd]224        addCFuzzySphereModel(m);
[25579e8]225        addCHardsphereStructure(m);
226        addCStickyHSStructure(m);
227        addCSquareWellStructure(m);
228        addCHayterMSAStructure(m);
[af03ddd]229        addCEllipticalCylinderModel(m);
[5068697]230        addCTriaxialEllipsoidModel(m);
231        addCFlexibleCylinderModel(m);
[c724ccd]232        addCFlexCylEllipXModel(m);
[5068697]233        addCStackedDisksModel(m);
[27a0771]234        addCLamellarPSModel(m);
235        addCLamellarPSHGModel(m);
[eddff027]236        addCCoreShellEllipsoidModel(m);
[5eb9154]237        addCDiamEllipFunc(m);
238        addCDiamCylFunc(m);
239
240//      addCOblateModel(m);
241//      addCProlateModel(m);
[34c3020]242        addCLamellarModel(m);
243        addCLamellarFFHGModel(m);
[27fea3f]244        addCHollowCylinderModel(m);
[3d25331f]245        addCMultiShellModel(m);
246        addCBinaryHSModel(m);
[af03ddd]247        addDisperser(m);
248        addCGaussian(m);
[eba9885]249        addCSchulz(m);
250        addCLogNormal(m);
[af03ddd]251        addCLorentzian(m);
[3d25331f]252        addCVesicleModel(m);
[c724ccd]253        addCPoly_GaussCoil(m);
254        addCFractalModel(m);
255//      addCPolymerExclVolModel(m);
[af03ddd]256}
Note: See TracBrowser for help on using the repository browser.