Changeset a1b2471 in sasview for sansmodels/src/sans
- Timestamp:
- Sep 21, 2010 5:44:24 PM (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:
- db08737
- Parents:
- 60c320b
- Location:
- sansmodels/src/sans/models
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/CoreMultiShellModel.py
r4523b68 ra1b2471 129 129 except: pass 130 130 131 131 def getProfile(self): 132 """ 133 Get SLD profile 134 135 : return: (r, beta) where r is a list of radius of the transition points 136 beta is a list of the corresponding SLD values 137 : Note: This works only for func_shell# = 2. 138 """ 139 r = [] 140 beta = [] 141 # for core at r=0 142 r.append(0) 143 beta.append(self.params['sld_core']) 144 # for core at r=rad_core 145 r.append(self.params['rad_core']) 146 beta.append(self.params['sld_core']) 147 148 # for shells 149 for n in range(1,self.n_shells+1): 150 # Left side of each shells 151 r0 = r[len(r)-1] 152 r.append(r0) 153 exec "beta.append(self.params['sld_shell%s'% str(n)])" 154 155 # Right side of each shells 156 exec "r0 += self.params['thick_shell%s'% str(n)]" 157 r.append(r0) 158 exec "beta.append(self.params['sld_shell%s'% str(n)])" 159 160 # for solvent 161 r0 = r[len(r)-1] 162 r.append(r0) 163 beta.append(self.params['sld_solv']) 164 r_solv = 5*r0/4 165 r.append(r_solv) 166 beta.append(self.params['sld_solv']) 167 168 return r, beta 169 132 170 def setParam(self, name, value): 133 171 """ -
sansmodels/src/sans/models/MultiplicationModel.py
r06c7fcc ra1b2471 82 82 ##set dispersion only from p_model 83 83 for name , value in self.p_model.dispersion.iteritems(): 84 self.dispersion[name]= value 85 84 self.dispersion[name]= value 85 86 def getProfile(self): 87 """ 88 Get SLD profile of p_model if exists 89 90 : return: (r, beta) where r is a list of radius of the transition points 91 beta is a list of the corresponding SLD values 92 : Note: This works only for func_shell# = 2 (exp function). 93 """ 94 try: 95 x,y = self.p_model.getProfile() 96 except: 97 x = None 98 y = None 99 100 return x, y 101 86 102 def _set_params(self): 87 103 """ -
sansmodels/src/sans/models/SphereExpShellModel.py
re096270 ra1b2471 42 42 for item in self.model.orientation_params: 43 43 self.orientation_params.append(item) 44 44 self.getProfile() 45 45 def _clone(self, obj): 46 46 """ … … 133 133 self.model.setParam(key, value) 134 134 except: pass 135 136 135 def getProfile(self): 136 """ 137 Get SLD profile 138 139 : return: (r, beta) where r is a list of radius of the transition points 140 beta is a list of the corresponding SLD values 141 : Note: This works only for func_shell# = 2. 142 """ 143 # max_pts for each shells 144 max_pts = 10 145 r = [] 146 beta = [] 147 # for core at r=0 148 r.append(0) 149 beta.append(self.params['sld_core']) 150 # for core at r=rad_core 151 r.append(self.params['rad_core']) 152 beta.append(self.params['sld_core']) 153 154 # for shells 155 for n in range(1,self.n_shells+1): 156 # Left side of each shells 157 r0 = r[len(r)-1] 158 r.append(r0) 159 exec "beta.append(self.params['sld_in_shell%s'% str(n)])" 160 161 exec "A = self.params['A_shell%s'% str(n)]" 162 if A ==0: 163 # Right side of each shells 164 exec "r0 += self.params['thick_shell%s'% str(n)]" 165 r.append(r0) 166 exec "beta.append(self.params['sld_in_shell%s'% str(n)])" 167 else: 168 from math import exp 169 rn = r0 170 for n_sub in range(0,max_pts): 171 # Right side of each sub_shells 172 exec "rn += self.params['thick_shell%s'% str(n)]/10.0" 173 r.append(rn) 174 exec "slope = (self.params['sld_out_shell%s'% str(n)] \ 175 -self.params['sld_in_shell%s'% str(n)]) \ 176 /(exp(self.params['A_shell%s'% str(n)])-1)" 177 exec "const = (self.params['sld_in_shell%s'% str(n)]-slope)" 178 exec "beta_n = slope*exp((self.params['A_shell%s'% str(n)]*(rn-r0) \ 179 /self.params['thick_shell%s'% str(n)])) + const" 180 beta.append(beta_n) 181 182 # for solvent 183 r0 = r[len(r)-1] 184 r.append(r0) 185 beta.append(self.params['sld_solv']) 186 r_solv = 5*r0/4 187 r.append(r_solv) 188 beta.append(self.params['sld_solv']) 189 190 return r, beta 191 137 192 def setParam(self, name, value): 138 193 """ -
sansmodels/src/sans/models/c_extensions/onion.c
re096270 ra1b2471 41 41 fun_type[n+1] = 0; 42 42 43 double bes,fun,alpha,f,vol, qr,r,contr,f2;43 double bes,fun,alpha,f,vol,vol_pre,vol_sub,qr,r,contr,f2; 44 44 double sign; 45 45 double pi; … … 48 48 f = 0.0; 49 49 r = 0.0; 50 vol = 0.0; 51 vol_pre = 0.0; 52 vol_sub = 0.0; 50 53 double r0 = 0.0; 51 54 … … 58 61 A[i] = 0.0; 59 62 } 63 vol_pre = vol; 60 64 switch(fun_type[i]){ 61 65 case 2 : … … 103 107 104 108 vol = 4.0 * pi / 3.0 * r * r * r; 109 if (j == 1 && fabs(sld_in[i]-sld_solv) < 1e-04*fabs(sld_solv) && A[i]==0.0){ 110 vol_sub += (vol_pre - vol); 111 } 105 112 f += vol * (contr * (fun) + (sld_in[i]-slope[i]) * bes); 106 113 } … … 141 148 } 142 149 vol = 4.0 * pi / 3.0 * r * r * r; 150 if (j == 1 && fabs(sld_in[i]-sld_solv) < 1e-04*fabs(sld_solv) && fun_type[i]==0){ 151 vol_sub += (vol_pre - vol); 152 } 143 153 f += vol * (bes * contr + fun * slope[i]); 144 154 } … … 147 157 148 158 } 149 159 vol += vol_sub; 150 160 f2 = f * f / vol * 1.0e8; 151 161 f2 *= scale; -
sansmodels/src/sans/models/test/utest_model_sphereexpshell.py
re096270 ra1b2471 14 14 from sans.models.SphereExpShellModel import SphereExpShellModel 15 15 from sans.models.CoreMultiShellModel import CoreMultiShellModel 16 from sans.models.VesicleModel import VesicleModel 16 17 17 18 self.model = SphereExpShellModel(n_shells=1) 18 19 self.model2 = SphereExpShellModel(n_shells=1).model 19 20 self.model3 = CoreMultiShellModel(n_shells=1) 21 self.model4 = VesicleModel() 20 22 21 23 def test_compare_Exp0_flat(self): … … 49 51 self.assertAlmostEqual(self.model2.run(0.1),self.model3.run(0.1),10) 50 52 53 def test_compare_Exp0_flat_vesicle(self): 54 """ 55 Check if Exp function with A_shell=0 gives the same value as Flat function of vesicle model when sld_solv=sld_core 56 """ 57 print "\n*****Note: All tests (test_compare_Exp0_flat and test_compare_Expsmall_line) were passes since Sept. 18, 2010..." 58 # Exp: func_shell = 2, Line: func_shell =1 , Flat: func_shell = 0. 59 # A_shell = The coefficient of the exponential function: exp(A_shell*(r-ro)/thick_shell) 60 # exp function by default 61 # exp function crosses over to flat func at A_shell=0 62 self.model.setParam("A_shell1", 0) 63 # set A_shell=1 64 self.model2.setParam("A_shell1", 1) 65 # change the function to flat function 66 self.model2.setParam("func_shell1", 0) 67 68 # model: set param values as same as the model2 69 self.model.setParam("background", 0.0) 70 self.model.setParam("rad_core", 100.0) 71 self.model.setParam("scale", 1.0) 72 self.model.setParam("sld_core", 6.36e-006) 73 self.model.setParam("sld_in_shell1", 5e-007) 74 self.model.setParam("sld_solv", 6.36e-006) 75 self.model.setParam("thick_shell1", 30.0) 76 # model2: set param values as same as the model2 77 self.model2.setParam("background", 0.0) 78 self.model2.setParam("rad_core", 100.0) 79 self.model2.setParam("scale", 1.0) 80 self.model2.setParam("sld_core", 6.36e-006) 81 self.model2.setParam("sld_in_shell1", 5e-007) 82 self.model2.setParam("sld_solv", 6.36e-006) 83 self.model2.setParam("thick_shell1", 30.0) 84 #Compare exp(A=0) to flat (where A_shell is null) function 85 self.assertEqual(self.model.run(0.1),self.model4.run(0.1)) 86 self.assertEqual(self.model2.run(0.1),self.model4.run(0.1)) 87 #self.assertAlmostEqual(self.model2.run(0.1),self.model3.run(0.1),10) 88 51 89 52 90 def test_compare_Expsmall_line(self): -
sansmodels/src/sans/models/test/utest_models.py
r9ce41c6 ra1b2471 13 13 # pylint: disable-msg=R0201 14 14 15 15 class TestSpherew(unittest.TestCase): 16 """ Unit tests for sphere model """ 17 18 def setUp(self): 19 from sans.models.CoreFourShellModel import CoreFourShellModel 20 from sans.models.CoreMultiShellModel import CoreMultiShellModel 21 self.comp = CoreMultiShellModel(4) 22 23 def test1D(self): 24 """ Test 1D model for a sphere """ 25 self.comp._set_dispersion() 16 26 17 27 class TestSphere(unittest.TestCase):
Note: See TracChangeset
for help on using the changeset viewer.