Changeset 7a8faf8 in sasview for sansmodels/src
- Timestamp:
- May 19, 2011 11:20:21 AM (14 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:
- d785914
- Parents:
- c0a690c
- Location:
- sansmodels/src/sans/models
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/SphereSLDModel.py
rc7a7e1b r7a8faf8 198 198 199 199 ## fittable parameters 200 self.fixed=[ ]200 self.fixed=['rad_core0.width', 'thick_inter0.width'] 201 201 202 202 ## non-fittable parameters -
sansmodels/src/sans/models/SphericalSLDModel.py
r4b3d25b r7a8faf8 76 76 """ 77 77 ##set dispersion from model 78 self.dispersion = {} 79 78 for name , value in self.model.dispersion.iteritems(): 79 80 nshell = -1 81 if name.split('_')[0] == 'thick': 82 while nshell<1: 83 nshell += 1 84 if name.split('_')[1] == 'inter%s' % str(nshell): 85 self.dispersion[name]= value 86 else: 87 continue 88 else: 89 self.dispersion[name]= value 80 90 81 91 def _set_params(self): … … 279 289 Helper function to setParam 280 290 """ 281 291 toks = name.split('.') 292 if len(toks)==2: 293 for item in self.dispersion.keys(): 294 if item.lower()==toks[0].lower(): 295 for par in self.dispersion[item]: 296 if par.lower() == toks[1].lower(): 297 self.dispersion[item][par] = value 298 return 282 299 # Look for standard parameter 283 300 for item in self.params.keys(): … … 293 310 Fill the self.fixed list with the model fixed list 294 311 """ 312 for item in self.model.fixed: 313 if item.split('.')[0] in self.params.keys(): 314 self.fixed.append(item) 315 316 self.fixed.sort() 295 317 pass 296 318 … … 339 361 :dispersion: dispersion object of type DispersionModel 340 362 """ 341 pass 363 value= None 364 try: 365 if parameter in self.model.dispersion.keys(): 366 value= self.model.set_dispersion(parameter, dispersion) 367 self._set_dispersion() 368 return value 369 except: 370 raise -
sansmodels/src/sans/models/c_extensions/spheresld.h
r0164899a r7a8faf8 6 6 */ 7 7 //[PYTHONCLASS] = SphereSLDModel 8 //[DISP_PARAMS] = thick_inter08 //[DISP_PARAMS] = rad_core0, thick_inter0 9 9 //[DESCRIPTION] =<text>Calculate neutron reflectivity using the Parratt iterative formula 10 10 // Parameters: … … 26 26 // from the bottom (substrate) to the top. 27 27 // </text> 28 //[FIXED]= <text> </text>28 //[FIXED]= <text>rad_core0.width; thick_inter0.width</text> 29 29 //[NON_FITTABLE_PARAMS]= <text>n_shells;func_inter0;func_inter1;func_inter2;func_inter3;func_inter4;func_inter5;func_inter5;func_inter7;func_inter8;func_inter9;func_inter10 </text> 30 30 //[ORIENTATION_PARAMS]= <text> </text> -
sansmodels/src/sans/models/c_models/CSphereSLDModel.cpp
r0164899a r7a8faf8 154 154 PyObject * disp_dict; 155 155 disp_dict = PyDict_New(); 156 self->model->rad_core0.dispersion->accept_as_source(visitor, self->model->rad_core0.dispersion, disp_dict); 157 PyDict_SetItemString(self->dispersion, "rad_core0", disp_dict); 158 disp_dict = PyDict_New(); 156 159 self->model->thick_inter0.dispersion->accept_as_source(visitor, self->model->thick_inter0.dispersion, disp_dict); 157 160 PyDict_SetItemString(self->dispersion, "thick_inter0", disp_dict); … … 348 351 PyObject* disp_dict; 349 352 DispersionVisitor* visitor = new DispersionVisitor(); 353 disp_dict = PyDict_GetItemString(self->dispersion, "rad_core0"); 354 self->model->rad_core0.dispersion->accept_as_destination(visitor, self->model->rad_core0.dispersion, disp_dict); 350 355 disp_dict = PyDict_GetItemString(self->dispersion, "thick_inter0"); 351 356 self->model->thick_inter0.dispersion->accept_as_destination(visitor, self->model->thick_inter0.dispersion, disp_dict); … … 475 480 PyObject* disp_dict; 476 481 DispersionVisitor* visitor = new DispersionVisitor(); 482 disp_dict = PyDict_GetItemString(self->dispersion, "rad_core0"); 483 self->model->rad_core0.dispersion->accept_as_destination(visitor, self->model->rad_core0.dispersion, disp_dict); 477 484 disp_dict = PyDict_GetItemString(self->dispersion, "thick_inter0"); 478 485 self->model->thick_inter0.dispersion->accept_as_destination(visitor, self->model->thick_inter0.dispersion, disp_dict); … … 589 596 PyObject* disp_dict; 590 597 DispersionVisitor* visitor = new DispersionVisitor(); 598 disp_dict = PyDict_GetItemString(self->dispersion, "rad_core0"); 599 self->model->rad_core0.dispersion->accept_as_destination(visitor, self->model->rad_core0.dispersion, disp_dict); 591 600 disp_dict = PyDict_GetItemString(self->dispersion, "thick_inter0"); 592 601 self->model->thick_inter0.dispersion->accept_as_destination(visitor, self->model->thick_inter0.dispersion, disp_dict); … … 672 681 PyObject* disp_dict; 673 682 DispersionVisitor* visitor = new DispersionVisitor(); 683 disp_dict = PyDict_GetItemString(self->dispersion, "rad_core0"); 684 self->model->rad_core0.dispersion->accept_as_destination(visitor, self->model->rad_core0.dispersion, disp_dict); 674 685 disp_dict = PyDict_GetItemString(self->dispersion, "thick_inter0"); 675 686 self->model->thick_inter0.dispersion->accept_as_destination(visitor, self->model->thick_inter0.dispersion, disp_dict); … … 729 740 // Ugliness necessary to go from python to C 730 741 // TODO: refactor this 731 if (!strcmp(par_name, "thick_inter0")) { 742 if (!strcmp(par_name, "rad_core0")) { 743 self->model->rad_core0.dispersion = dispersion; 744 } else if (!strcmp(par_name, "thick_inter0")) { 732 745 self->model->thick_inter0.dispersion = dispersion; 733 746 } else { -
sansmodels/src/sans/models/c_models/spheresld.cpp
r0164899a r7a8faf8 13 13 n_shells = Parameter(1.0); 14 14 scale = Parameter(1.0); 15 thick_inter0 = Parameter(1.0); 15 thick_inter0 = Parameter(1.0, true); 16 thick_inter0.set_min(0.0); 16 17 func_inter0 = Parameter(0); 17 18 sld_core0 = Parameter(2.07e-06); … … 80 81 npts_inter = Parameter(35.0); 81 82 nu_inter0 = Parameter(2.5); 82 rad_core0 = Parameter(60.0); 83 rad_core0 = Parameter(60.0, true); 84 rad_core0.set_min(0.0); 83 85 } 84 86 … … 98 100 dp[4] = sld_core0(); 99 101 dp[5] = sld_solv(); 100 dp[6] = background();102 dp[6] = 0.0; 101 103 102 104 dp[7] = sld_flat1(); … … 161 163 162 164 // No polydispersion supported in this model. 163 164 return sphere_sld_kernel(dp,q); 165 // Get the dispersion points for the radius 166 vector<WeightPoint> weights_rad_core0; 167 rad_core0.get_weights(weights_rad_core0); 168 vector<WeightPoint> weights_thick_inter0; 169 thick_inter0.get_weights(weights_thick_inter0); 170 // Perform the computation, with all weight points 171 double sum = 0.0; 172 double norm = 0.0; 173 double vol = 0.0; 174 175 // Loop over core weight points 176 for(int i=0; i<weights_rad_core0.size(); i++) { 177 dp[59] = weights_rad_core0[i].value; 178 // Loop over thick_inter0 weight points 179 for(int j=0; j<weights_thick_inter0.size(); j++) { 180 dp[2] = weights_thick_inter0[j].value; 181 182 //Un-normalize Sphere by volume 183 sum += weights_rad_core0[i].weight * weights_thick_inter0[j].weight 184 * sphere_sld_kernel(dp,q) * pow((weights_rad_core0[i].value + 185 weights_thick_inter0[j].value),3.0); 186 //Find average volume 187 vol += weights_rad_core0[i].weight * weights_thick_inter0[j].weight 188 * pow((weights_rad_core0[i].value+weights_thick_inter0[j].value),3.0); 189 190 norm += weights_rad_core0[i].weight * weights_thick_inter0[j].weight; 191 } 192 } 193 194 if (vol != 0.0 && norm != 0.0) { 195 //Re-normalize by avg volume 196 sum = sum/(vol/norm);} 197 198 return sum/norm + background(); 165 199 } 166 200 … … 225 259 dp.thick_inter10 = thick_inter10(); 226 260 227 double rad_out = dp.rad_core0 + dp.thick_inter0; 228 if (dp.n_shells > 0) 229 rad_out += dp.thick_flat1 + dp.thick_inter1; 230 if (dp.n_shells > 1) 231 rad_out += dp.thick_flat2 + dp.thick_inter2; 232 if (dp.n_shells > 2) 233 rad_out += dp.thick_flat3 + dp.thick_inter3; 234 if (dp.n_shells > 3) 235 rad_out += dp.thick_flat4 + dp.thick_inter4; 236 if (dp.n_shells > 4) 237 rad_out += dp.thick_flat5 + dp.thick_inter5; 238 if (dp.n_shells > 5) 239 rad_out += dp.thick_flat6 + dp.thick_inter6; 240 if (dp.n_shells > 6) 241 rad_out += dp.thick_flat7 + dp.thick_inter7; 242 if (dp.n_shells > 7) 243 rad_out += dp.thick_flat8 + dp.thick_inter8; 244 if (dp.n_shells > 8) 245 rad_out += dp.thick_flat9 + dp.thick_inter9; 246 if (dp.n_shells > 9) 247 rad_out += dp.thick_flat10 + dp.thick_inter10; 248 249 return rad_out; 250 251 } 261 double rad_out = 0.0; 262 double out = 0.0; 263 // Perform the computation, with all weight points 264 double sum = 0.0; 265 double norm = 0.0; 266 267 // Get the dispersion points for the radius 268 vector<WeightPoint> weights_rad_core0; 269 rad_core0.get_weights(weights_rad_core0); 270 271 // Get the dispersion points for the thick 1 272 vector<WeightPoint> weights_thick_inter0; 273 thick_inter0.get_weights(weights_thick_inter0); 274 // Loop over radius weight points 275 for(int i=0; i<weights_rad_core0.size(); i++) { 276 dp.rad_core0 = weights_rad_core0[i].value; 277 // Loop over radius weight points 278 for(int j=0; j<weights_thick_inter0.size(); j++) { 279 dp.thick_inter0 = weights_thick_inter0[j].value; 280 rad_out = dp.rad_core0 + dp.thick_inter0; 281 if (dp.n_shells > 0) 282 rad_out += dp.thick_flat1 + dp.thick_inter1; 283 if (dp.n_shells > 1) 284 rad_out += dp.thick_flat2 + dp.thick_inter2; 285 if (dp.n_shells > 2) 286 rad_out += dp.thick_flat3 + dp.thick_inter3; 287 if (dp.n_shells > 3) 288 rad_out += dp.thick_flat4 + dp.thick_inter4; 289 if (dp.n_shells > 4) 290 rad_out += dp.thick_flat5 + dp.thick_inter5; 291 if (dp.n_shells > 5) 292 rad_out += dp.thick_flat6 + dp.thick_inter6; 293 if (dp.n_shells > 6) 294 rad_out += dp.thick_flat7 + dp.thick_inter7; 295 if (dp.n_shells > 7) 296 rad_out += dp.thick_flat8 + dp.thick_inter8; 297 if (dp.n_shells > 8) 298 rad_out += dp.thick_flat9 + dp.thick_inter9; 299 if (dp.n_shells > 9) 300 rad_out += dp.thick_flat10 + dp.thick_inter10; 301 sum += weights_rad_core0[i].weight*weights_thick_inter0[j].weight 302 * (rad_out); 303 norm += weights_rad_core0[i].weight*weights_thick_inter0[j].weight; 304 } 305 } 306 if (norm != 0){ 307 //return the averaged value 308 out = sum/norm;} 309 else{ 310 //return normal value 311 out = dp.rad_core0 + dp.thick_inter0; 312 if (dp.n_shells > 0) 313 out += dp.thick_flat1 + dp.thick_inter1; 314 if (dp.n_shells > 1) 315 out += dp.thick_flat2 + dp.thick_inter2; 316 if (dp.n_shells > 2) 317 out += dp.thick_flat3 + dp.thick_inter3; 318 if (dp.n_shells > 3) 319 out += dp.thick_flat4 + dp.thick_inter4; 320 if (dp.n_shells > 4) 321 out += dp.thick_flat5 + dp.thick_inter5; 322 if (dp.n_shells > 5) 323 out += dp.thick_flat6 + dp.thick_inter6; 324 if (dp.n_shells > 6) 325 out += dp.thick_flat7 + dp.thick_inter7; 326 if (dp.n_shells > 7) 327 out += dp.thick_flat8 + dp.thick_inter8; 328 if (dp.n_shells > 8) 329 out += dp.thick_flat9 + dp.thick_inter9; 330 if (dp.n_shells > 9) 331 out += dp.thick_flat10 + dp.thick_inter10; 332 } 333 334 return out; 335 336 }
Note: See TracChangeset
for help on using the changeset viewer.