source: sasview/sansmodels/src/c_models/c_models.cpp @ 2d52cf0

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 2d52cf0 was 08648c0, checked in by Jae Cho <jhjcho@…>, 13 years ago

more s king's fractal models: todo: doc, test

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