Changeset c1c29b6 in sasview for sansmodels/src/sans/models/c_models
- Timestamp:
- Aug 21, 2009 12:34:33 PM (15 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 14c3887
- Parents:
- bda194e3
- Location:
- sansmodels/src/sans/models/c_models
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/c_models/CLamellarPSModel.cpp
r9bd69098 rc1c29b6 92 92 PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.000000)); 93 93 PyDict_SetItemString(self->params,"delta",Py_BuildValue("d",30.000000)); 94 PyDict_SetItemString(self->params,"sigma",Py_BuildValue("d",0.150000));95 94 PyDict_SetItemString(self->params,"contrast",Py_BuildValue("d",0.000005)); 96 95 // Initialize dispersion / averaging parameter dict 97 96 DispersionVisitor* visitor = new DispersionVisitor(); 98 97 PyObject * disp_dict; 98 disp_dict = PyDict_New(); 99 self->model->delta.dispersion->accept_as_source(visitor, self->model->delta.dispersion, disp_dict); 100 PyDict_SetItemString(self->dispersion, "delta", disp_dict); 99 101 disp_dict = PyDict_New(); 100 102 self->model->spacing.dispersion->accept_as_source(visitor, self->model->spacing.dispersion, disp_dict); … … 167 169 return PyArray_Return(result); 168 170 } 169 /** 170 * Function to call to evaluate model 171 * @param args: input numpy array [q[],phi[]] 172 * @return: numpy array object 173 */ 174 static PyObject * evaluateTwoDim( LamellarPSModel* model, 175 PyArrayObject *q, PyArrayObject *phi) 176 { 177 PyArrayObject *result; 178 //check validity of input vectors 179 if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE 180 || phi->nd != 1 || phi->descr->type_num != PyArray_DOUBLE 181 || phi->dimensions[0] != q->dimensions[0]){ 182 183 //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num; 184 PyErr_SetString(PyExc_ValueError ,"wrong input"); 185 return NULL; 186 } 187 result= (PyArrayObject *)PyArray_FromDims(q->nd,(int*)(q->dimensions), PyArray_DOUBLE); 188 189 if (result == NULL){ 190 const char * message= "Could not create result "; 191 PyErr_SetString(PyExc_RuntimeError , message); 192 return NULL; 193 } 194 195 for (int i = 0; i < q->dimensions[0]; i++) { 196 double q_value = *(double *)(q->data + i*q->strides[0]); 197 double phi_value = *(double *)(phi->data + i*phi->strides[0]); 198 double *result_value = (double *)(result->data + i*result->strides[0]); 199 if (q_value == 0) 200 *result_value = 0.0; 201 else 202 *result_value = model->evaluate_rphi(q_value, phi_value); 203 } 204 return PyArray_Return(result); 205 } 171 206 172 /** 207 173 * Function to call to evaluate model … … 272 238 self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") ); 273 239 self->model->delta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "delta") ); 274 self->model->sigma = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sigma") );275 240 self->model->contrast = PyFloat_AsDouble( PyDict_GetItemString(self->params, "contrast") ); 276 241 // Read in dispersion parameters 277 242 PyObject* disp_dict; 278 243 DispersionVisitor* visitor = new DispersionVisitor(); 244 disp_dict = PyDict_GetItemString(self->dispersion, "delta"); 245 self->model->delta.dispersion->accept_as_destination(visitor, self->model->delta.dispersion, disp_dict); 279 246 disp_dict = PyDict_GetItemString(self->dispersion, "spacing"); 280 247 self->model->spacing.dispersion->accept_as_destination(visitor, self->model->spacing.dispersion, disp_dict); … … 347 314 self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") ); 348 315 self->model->delta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "delta") ); 349 self->model->sigma = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sigma") );350 316 self->model->contrast = PyFloat_AsDouble( PyDict_GetItemString(self->params, "contrast") ); 351 317 // Read in dispersion parameters 352 318 PyObject* disp_dict; 353 319 DispersionVisitor* visitor = new DispersionVisitor(); 320 disp_dict = PyDict_GetItemString(self->dispersion, "delta"); 321 self->model->delta.dispersion->accept_as_destination(visitor, self->model->delta.dispersion, disp_dict); 354 322 disp_dict = PyDict_GetItemString(self->dispersion, "spacing"); 355 323 self->model->spacing.dispersion->accept_as_destination(visitor, self->model->spacing.dispersion, disp_dict); … … 411 379 self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") ); 412 380 self->model->delta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "delta") ); 413 self->model->sigma = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sigma") );414 381 self->model->contrast = PyFloat_AsDouble( PyDict_GetItemString(self->params, "contrast") ); 415 382 // Read in dispersion parameters 416 383 PyObject* disp_dict; 417 384 DispersionVisitor* visitor = new DispersionVisitor(); 385 disp_dict = PyDict_GetItemString(self->dispersion, "delta"); 386 self->model->delta.dispersion->accept_as_destination(visitor, self->model->delta.dispersion, disp_dict); 418 387 disp_dict = PyDict_GetItemString(self->dispersion, "spacing"); 419 388 self->model->spacing.dispersion->accept_as_destination(visitor, self->model->spacing.dispersion, disp_dict); … … 473 442 // Ugliness necessary to go from python to C 474 443 // TODO: refactor this 475 if (!strcmp(par_name, "spacing")) { 444 if (!strcmp(par_name, "delta")) { 445 self->model->delta.dispersion = dispersion; 446 } else if (!strcmp(par_name, "spacing")) { 476 447 self->model->spacing.dispersion = dispersion; 477 448 } else { -
sansmodels/src/sans/models/c_models/lamellar.cpp
r975ec8e rc1c29b6 28 28 29 29 extern "C" { 30 #include "libCylinder.h"30 // #include "libCylinder.h" 31 31 #include "lamellar.h" 32 32 } -
sansmodels/src/sans/models/c_models/lamellarPS.cpp
rb4679de rc1c29b6 39 39 delta = Parameter(30.0); 40 40 delta.set_min(0.0); 41 sigma = Parameter(0.15);42 sigma.set_min(0.0);43 41 contrast = Parameter(5.3e-6); 44 42 n_plates = Parameter(20.0); … … 55 53 */ 56 54 double LamellarPSModel :: operator()(double q) { 57 double dp[ 8];55 double dp[7]; 58 56 59 57 // Fill parameter array for IGOR library … … 62 60 dp[1] = spacing(); 63 61 dp[2] = delta(); 64 dp[3] = sigma(); 65 dp[4] = contrast(); 66 dp[5] = n_plates(); 67 dp[6] = caille(); 68 dp[7] = 0.0; 62 dp[3] = contrast(); 63 dp[4] = n_plates(); 64 dp[5] = caille(); 65 dp[6] = 0.0; 69 66 70 67 71 // Get the dispersion points for (delta) thickness68 // Get the dispersion points for spacing and delta (thickness) 72 69 vector<WeightPoint> weights_spacing; 73 70 spacing.get_weights(weights_spacing); 71 vector<WeightPoint> weights_delta; 72 delta.get_weights(weights_delta); 74 73 75 74 // Perform the computation, with all weight points … … 80 79 for(int i=0; i< (int)weights_spacing.size(); i++) { 81 80 dp[1] = weights_spacing[i].value; 81 for(int j=0; j< (int)weights_spacing.size(); j++) { 82 dp[2] = weights_delta[i].value; 82 83 83 sum += weights_spacing[i].weight * LamellarPS(dp, q);84 norm += weights_spacing[i].weight;85 84 sum += weights_spacing[i].weight * weights_delta[j].weight * LamellarPS_kernel(dp, q); 85 norm += weights_spacing[i].weight * weights_delta[j].weight; 86 } 86 87 } 87 88 return sum/norm + background(); … … 108 109 return (*this).operator()(q); 109 110 } 111 -
sansmodels/src/sans/models/c_models/models.hh
r8e36cdd rc1c29b6 20 20 #include "cylinder.h" 21 21 #include "parallelepiped.h" 22 #include "lamellarPS.h" 23 #include "lamellar.h" 22 24 } 23 25 … … 383 385 Parameter spacing; 384 386 Parameter delta; 385 Parameter sigma;386 387 Parameter contrast; 387 388 Parameter n_plates;
Note: See TracChangeset
for help on using the changeset viewer.