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

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 db08737 was e096270, checked in by Jae Cho <jhjcho@…>, 14 years ago

added a new model

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