Changeset 499fe7a in sasview for sansmodels/src/sans/models/ReflectivityIIModel.py
- Timestamp:
- Apr 18, 2012 1:51:32 PM (13 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:
- 2dda7ae1
- Parents:
- 279e371
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/ReflectivityIIModel.py
r1352c78 r499fe7a 5 5 from math import floor 6 6 from math import fabs 7 from scipy.special import erf8 7 func_list = {'Erf(|nu|*z)':0, 'RPower(z^|nu|)':1, 'LPower(z^|nu|)':2, \ 9 8 'RExp(-|nu|*z)':3, 'LExp(-|nu|*z)':4} … … 15 14 """ 16 15 def __init__(self, multfactor=1): 16 """ 17 :param multfactor: number of layers in the model, 18 assumes 0<= n_layers <=10. 19 """ 17 20 BaseComponent.__init__(self) 18 """19 :param multfactor: number of layers in the model,20 assumes 0<= n_layers <=10.21 """22 21 23 22 ## Setting model name model description 24 self.description =""23 self.description = "" 25 24 model = ReflAdvModel() 26 25 self.model = model 27 26 self.name = "ReflectivityIIModel" 28 self.description =model.description27 self.description = model.description 29 28 self.n_layers = int(multfactor) 30 29 ## Define parameters … … 54 53 # [int(maximum no. of functionality),"str(Titl), 55 54 # [str(name of function0),...], [str(x-asix name of sld),...]] 56 self.multiplicity_info = [max_nshells, "No. of Layers:",[],['Depth']]55 self.multiplicity_info = [max_nshells, "No. of Layers:", [], ['Depth']] 57 56 ## independent parameter name and unit [string] 58 57 self.input_name = "Q" … … 92 91 """ 93 92 # rearrange the parameters for the given # of shells 94 for name 93 for name, value in self.model.params.iteritems(): 95 94 n = 0 96 95 pos = len(name.split('_'))-1 … … 103 102 continue 104 103 elif first_name == 'func': 105 n = -1106 while n <self.n_layers:104 n = -1 105 while n < self.n_layers: 107 106 n += 1 108 107 if last_name == 'inter%s' % str(n): 109 self.params[name] =value108 self.params[name] = value 110 109 continue 111 110 112 111 #continue 113 112 elif last_name[0:5] == 'inter': 114 n = -1115 while n <self.n_layers:113 n = -1 114 while n < self.n_layers: 116 115 n += 1 117 116 if last_name == 'inter%s' % str(n): 118 self.params[name] = value117 self.params[name] = value 119 118 continue 120 119 elif last_name[0:4] == 'flat': 121 while n <self.n_layers:120 while n < self.n_layers: 122 121 n += 1 123 122 if last_name == 'flat%s' % str(n): 124 self.params[name] = value123 self.params[name] = value 125 124 continue 126 125 elif name == 'n_layers': 127 126 continue 128 127 else: 129 self.params[name] = value128 self.params[name] = value 130 129 131 130 self.model.params['n_layers'] = self.n_layers … … 139 138 this model details 140 139 """ 141 for name ,detail in self.model.details.iteritems():140 for name, detail in self.model.details.iteritems(): 142 141 if name in self.params.iterkeys(): 143 self.details[name] = detail142 self.details[name] = detail 144 143 145 144 … … 155 154 continue 156 155 if key.split('_')[0] == 'func': 157 158 156 self.model.setParam(key, 0) 157 continue 159 158 160 159 for nshell in range(self.n_layers,max_nshells): … … 166 165 value = self.model.params['sldIM_medium'] 167 166 self.model.setParam(key, value) 168 except: pass 167 except: 168 message = "ReflectivityIIModel evaluation problem" 169 raise RuntimeError, message 169 170 170 171 def _get_func_list(self): 171 172 """ 172 Get the list of functions in each layer (shell) 173 """ 174 #func_list = {} 173 Get the list of functions in each layer (shell) 174 """ 175 175 return func_list 176 176 … … 186 186 z = [] 187 187 beta = [] 188 sub_range = int(floor(n_sub/2.0))189 188 z.append(0) 190 189 beta.append(self.params['sld_bottom0']) … … 193 192 dz = 0.0 194 193 # for layers from the top 195 for n_lyr in range(1, self.n_layers+2):194 for n_lyr in range(1, self.n_layers+2): 196 195 i = n_lyr 197 196 # j=0 for interface, j=1 for flat layer 198 for j in range(0, 2):197 for j in range(0, 2): 199 198 # interation for sub-layers 200 for n_s in range(0, n_sub):199 for n_s in range(0, n_sub): 201 200 # for flat layer 202 if j ==1:203 if i ==self.n_layers+1:201 if j == 1: 202 if i == self.n_layers+1: 204 203 break 205 204 # shift half sub thickness for the first point 206 205 z0 -= dz/2.0 207 206 z.append(z0) 208 sld_i = self.params['sld_flat%s' % str(i)]207 sld_i = self.params['sld_flat%s' % str(i)] 209 208 beta.append(sld_i) 210 dz = self.params['thick_flat%s' % str(i)]209 dz = self.params['thick_flat%s' % str(i)] 211 210 z0 += dz 212 211 else: 213 dz = self.params['thick_inter%s' % str(i-1)]/n_sub214 nu = fabs(self.params['nu_inter%s' % str(i-1)])212 dz = self.params['thick_inter%s' % str(i-1)]/n_sub 213 nu = fabs(self.params['nu_inter%s' % str(i-1)]) 215 214 if n_s == 0: 216 215 # shift half sub thickness for the point … … 220 219 sld_l = self.params['sld_bottom0'] 221 220 else: 222 sld_l = self.params['sld_flat%s' % str(i-1)]221 sld_l = self.params['sld_flat%s' % str(i-1)] 223 222 if i == self.n_layers+1: 224 223 sld_r = self.params['sld_medium'] 225 224 else: 226 sld_r = self.params['sld_flat%s' % str(i)]225 sld_r = self.params['sld_flat%s' % str(i)] 227 226 if sld_r == sld_l: 228 227 sld_i = sld_r 229 228 else: 230 func_idx = self.params['func_inter%s' % str(i-1)]229 func_idx = self.params['func_inter%s' % str(i-1)] 231 230 # calculate the sld 232 231 sld_i = self._get_sld(func_idx, n_sub, n_s+0.5, nu, … … 235 234 z.append(z0) 236 235 beta.append(sld_i) 237 if j==1: break 238 else: z0 += dz 236 if j == 1: 237 break 238 else: 239 z0 += dz 239 240 # put substrate and superstrate profile 240 241 z.append(z0) … … 246 247 z.append(z0+z_ext) 247 248 beta.append(self.params['sld_medium']) 248 z.insert(0, -z_ext)249 beta.insert(0, self.params['sld_bottom0'])249 z.insert(0, -z_ext) 250 beta.insert(0, self.params['sld_bottom0']) 250 251 # rearrange the profile for NR sld profile style 251 252 z = [z0 - x for x in z] … … 269 270 sld_cal = SLDCalFunc() 270 271 # set params 271 sld_cal.setParam('fun_type', func_idx)272 sld_cal.setParam('npts_inter', n_sub)273 sld_cal.setParam('shell_num', n_s)274 sld_cal.setParam('nu_inter', nu)275 sld_cal.setParam('sld_left', sld_l)276 sld_cal.setParam('sld_right', sld_r)272 sld_cal.setParam('fun_type', func_idx) 273 sld_cal.setParam('npts_inter', n_sub) 274 sld_cal.setParam('shell_num', n_s) 275 sld_cal.setParam('nu_inter', nu) 276 sld_cal.setParam('sld_left', sld_l) 277 sld_cal.setParam('sld_right', sld_r) 277 278 # return sld value 278 279 return sld_cal.run() … … 289 290 290 291 ## setParam to model 291 if name =='sld_medium':292 if name == 'sld_medium': 292 293 # the sld_*** model.params not in params must set 293 294 # to value of sld_solv 294 295 for key in self.model.params.iterkeys(): 295 296 if key not in self.params.keys()and key.split('_')[0] == 'sld': 296 297 self.model.setParam(key, value) 297 298 298 299 self.model.setParam( name, value) … … 342 343 ## Now (May27,10) directly uses the model eval function 343 344 ## instead of the for-loop in Base Component. 344 def evalDistribution(self, x = []):345 def evalDistribution(self, x): 345 346 """ 346 347 Evaluate the model in cartesian coordinates
Note: See TracChangeset
for help on using the changeset viewer.