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

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 d67fc8d was 5eb9154, checked in by Jae Cho <jhjcho@…>, 15 years ago

calculation of the effective radius are added

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