Changeset c1c29b6 in sasview for sansmodels/src
- 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
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/LamellarPSModel.py
r9bd69098 rc1c29b6 35 35 spacing = 400.0 [A] 36 36 delta = 30.0 [A] 37 sigma = 0.1538 37 contrast = 5.3e-006 [1/A²] 39 38 n_plates = 20.0 … … 66 65 *Parameters: spacing = repeat spacing, 67 66 delta = bilayer thickness, 68 sigma = variation in bilayer thickness69 67 contrast = SLD_solvent - SLD_bilayer 70 68 n_plate = # of Lamellar plates … … 78 76 self.details['spacing'] = ['[A]', None, None] 79 77 self.details['delta'] = ['[A]', None, None] 80 self.details['sigma'] = ['', None, None]81 78 self.details['contrast'] = ['[1/A²]', None, None] 82 79 self.details['n_plates'] = ['', None, None] … … 85 82 86 83 ## fittable parameters 87 self.fixed=[' spacing.width']84 self.fixed=['delta.width', 'spacing.width'] 88 85 89 86 ## parameters with orientation -
sansmodels/src/sans/models/c_extensions/ellipsoid.h
r1ed3834 rc1c29b6 28 28 // </text> 29 29 //[FIXED]= <text> axis_phi.width; axis_theta.width;radius_a.width; 30 //radius_b.width; length.width; r_minor.width 31 // ,r_ratio.width</text>30 //radius_b.width; length.width; r_minor.width; 31 //r_ratio.width</text> 32 32 //[ORIENTATION_PARAMS]= axis_phi.width; axis_theta.width;axis_phi; axis_theta 33 33 -
sansmodels/src/sans/models/c_extensions/lamellar.c
r0cfeff4 rc1c29b6 6 6 #include "lamellar.h" 7 7 #include <math.h> 8 #include "libCylinder.h"8 //#include "libCylinder.h" 9 9 #include <stdio.h> 10 10 #include <stdlib.h> -
sansmodels/src/sans/models/c_extensions/lamellar.h
r975ec8e rc1c29b6 36 36 } LamellarParameters; 37 37 38 39 38 /// kernel 39 double lamellar_kernel(double dp[], double q); 40 40 /// 1D scattering function 41 41 double lamellar_analytical_1D(LamellarParameters *pars, double q); -
sansmodels/src/sans/models/c_extensions/lamellarPS.c
rb4679de rc1c29b6 10 10 #include <stdlib.h> 11 11 12 /*LamellarPS_kernel() was moved from libigor to get rid of polydipersity in del(thickness) that we provide from control panel. 13 /* LamellarPSX : calculates the form factor of a lamellar structure - with S(q) effects included 14 ------- 15 ------- resolution effects ARE NOT included, but only a CONSTANT default value, not the real q-dependent resolution!! 16 17 */ 18 double 19 LamellarPS_kernel(double dp[], double q) 20 { 21 double scale,dd,del,contr,NN,Cp,bkg; //local variables of coefficient wave 22 double inten, qval,Pq,Sq,alpha,temp,t1,t2,t3,dQ; 23 double Pi,Euler,dQDefault,fii; 24 int ii,NNint; 25 Euler = 0.5772156649; // Euler's constant 26 dQDefault = 0.0;//0.0025; //[=] 1/A, q-resolution, default value 27 dQ = dQDefault; 28 29 Pi = 4.0*atan(1.0); 30 qval = q; 31 32 scale = dp[0]; 33 dd = dp[1]; 34 del = dp[2]; 35 contr = dp[3]; 36 NN = trunc(dp[4]); //be sure that NN is an integer 37 Cp = dp[5]; 38 bkg = dp[6]; 39 40 Pq = 2.0*contr*contr/qval/qval*(1.0-cos(qval*del)); 41 42 NNint = (int)NN; //cast to an integer for the loop 43 ii=0; 44 Sq = 0.0; 45 for(ii=1;ii<(NNint-1);ii+=1) { 46 47 fii = (double)ii; //do I really need to do this? 48 49 temp = 0.0; 50 alpha = Cp/4.0/Pi/Pi*(log(Pi*ii) + Euler); 51 t1 = 2.0*dQ*dQ*dd*dd*alpha; 52 t2 = 2.0*qval*qval*dd*dd*alpha; 53 t3 = dQ*dQ*dd*dd*ii*ii; 54 55 temp = 1.0-ii/NN; 56 temp *= cos(dd*qval*ii/(1.0+t1)); 57 temp *= exp(-1.0*(t2 + t3)/(2.0*(1.0+t1)) ); 58 temp /= sqrt(1.0+t1); 59 60 Sq += temp; 61 } 62 63 Sq *= 2.0; 64 Sq += 1.0; 65 66 inten = 2.0*Pi*scale*Pq*Sq/(dd*qval*qval); 67 68 inten *= 1.0e8; // 1/A to 1/cm 69 70 return(inten+bkg); 71 } 12 72 13 73 /** … … 18 78 */ 19 79 double lamellarPS_analytical_1D(LamellarPSParameters *pars, double q) { 20 double dp[ 8];80 double dp[7]; 21 81 22 82 // Fill paramater array … … 24 84 dp[1] = pars->spacing; 25 85 dp[2] = pars->delta; 26 dp[3] = pars->sigma; 27 dp[4] = pars->contrast; 28 dp[5] = pars->n_plates; 29 dp[6] = pars->caille; 30 dp[7] = pars->background; 86 dp[3] = pars->contrast; 87 dp[4] = pars->n_plates; 88 dp[5] = pars->caille; 89 dp[6] = pars->background; 31 90 32 91 // Call library function to evaluate model 33 return LamellarPS (dp, q);92 return LamellarPS_kernel(dp, q); 34 93 } 35 94 /** -
sansmodels/src/sans/models/c_extensions/lamellarPS.h
r96b59384 rc1c29b6 7 7 /** Structure definition for concentrated lamellar form factor parameters 8 8 * [PYTHONCLASS] = LamellarPSModel 9 * [DISP_PARAMS] = spacing9 * [DISP_PARAMS] = delta, spacing 10 10 [DESCRIPTION] = <text>[Concentrated Lamellar Form Factor] Calculates the scattered 11 11 intensity from a lyotropic lamellar phase. … … 21 21 *Parameters: spacing = repeat spacing, 22 22 delta = bilayer thickness, 23 sigma = variation in bilayer thickness24 23 contrast = SLD_solvent - SLD_bilayer 25 24 n_plate = # of Lamellar plates … … 28 27 scale = scale factor 29 28 </text> 30 [FIXED]= spacing.width29 [FIXED]= <text>delta.width; spacing.width</text> 31 30 [ORIENTATION_PARAMS]= 32 31 … … 42 41 // [DEFAULT]=delta=30 [A] 43 42 double delta; 44 /// polydispersity of the bilayer thickness [A]45 // [DEFAULT]=sigma=0.1546 double sigma;47 43 /// Contrast [1/A²] 48 44 // [DEFAULT]=contrast=5.3e-6 [1/A²] … … 60 56 } LamellarPSParameters; 61 57 62 63 58 /// kernel 59 double LamellarPS_kernel(double dp[], double q); 64 60 /// 1D scattering function 65 61 double lamellarPS_analytical_1D(LamellarPSParameters *pars, double q); -
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.