Changeset 2d1b700 in sasview
- Timestamp:
- Jan 5, 2012 10:52:13 AM (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:
- dd60b45
- Parents:
- 7ffa8196
- Files:
-
- 2 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/c_extensions/refl.h
r67424cd r2d1b700 3 3 #if !defined(o_h) 4 4 #define refl_h 5 #include "parameters.hh" 5 6 6 7 /** … … 31 32 //[ORIENTATION_PARAMS]= <text> </text> 32 33 33 typedef struct { 34 /// number of layers 35 // [DEFAULT]=n_layers=1 36 int n_layers; 34 class ReflModel{ 35 public: 36 // Model parameters 37 /// number of layers 38 // [DEFAULT]=n_layers=1 39 Parameter n_layers; 37 40 /// Scale factor 38 41 // [DEFAULT]=scale= 1.0 39 doublescale;40 /// 42 Parameter scale; 43 /// thick_inter0 [A] 41 44 // [DEFAULT]=thick_inter0=1.0 [A] 42 doublethick_inter0;43 ///func_inter044 45 doublefunc_inter0;46 ///sld_bottom0 [1/A^(2)]47 48 doublesld_bottom0;49 ///sld_medium [1/A^(2)]50 51 doublesld_medium;52 53 54 doublebackground;45 Parameter thick_inter0; 46 /// func_inter0 47 // [DEFAULT]=func_inter0= 0 48 Parameter func_inter0; 49 /// sld_bottom0 [1/A^(2)] 50 // [DEFAULT]=sld_bottom0= 2.07e-6 [1/A^(2)] 51 Parameter sld_bottom0; 52 /// sld_medium [1/A^(2)] 53 // [DEFAULT]=sld_medium= 1.0e-6 [1/A^(2)] 54 Parameter sld_medium; 55 /// Background 56 // [DEFAULT]=background=0 57 Parameter background; 55 58 56 59 // [DEFAULT]=sld_flat1=4.0e-06 [1/A^(2)] 57 doublesld_flat1;60 Parameter sld_flat1; 58 61 // [DEFAULT]=sld_flat2=3.5e-06 [1/A^(2)] 59 doublesld_flat2;62 Parameter sld_flat2; 60 63 // [DEFAULT]=sld_flat3=4.0e-06 [1/A^(2)] 61 doublesld_flat3;64 Parameter sld_flat3; 62 65 // [DEFAULT]=sld_flat4=3.5e-06 [1/A^(2)] 63 doublesld_flat4;66 Parameter sld_flat4; 64 67 // [DEFAULT]=sld_flat5=4.0e-06 [1/A^(2)] 65 doublesld_flat5;68 Parameter sld_flat5; 66 69 // [DEFAULT]=sld_flat6=3.5e-06 [1/A^(2)] 67 doublesld_flat6;70 Parameter sld_flat6; 68 71 // [DEFAULT]=sld_flat7=4.0e-06 [1/A^(2)] 69 doublesld_flat7;72 Parameter sld_flat7; 70 73 // [DEFAULT]=sld_flat8=3.5e-06 [1/A^(2)] 71 doublesld_flat8;74 Parameter sld_flat8; 72 75 // [DEFAULT]=sld_flat9=4.0e-06 [1/A^(2)] 73 doublesld_flat9;76 Parameter sld_flat9; 74 77 // [DEFAULT]=sld_flat10=3.5e-06 [1/A^(2)] 75 doublesld_flat10;78 Parameter sld_flat10; 76 79 77 80 // [DEFAULT]=thick_inter1=1 [A] 78 doublethick_inter1;81 Parameter thick_inter1; 79 82 // [DEFAULT]=thick_inter2=1 [A] 80 doublethick_inter2;83 Parameter thick_inter2; 81 84 // [DEFAULT]=thick_inter3=1 [A] 82 doublethick_inter3;85 Parameter thick_inter3; 83 86 // [DEFAULT]=thick_inter4=1 [A] 84 doublethick_inter4;87 Parameter thick_inter4; 85 88 // [DEFAULT]=thick_inter5=1 [A] 86 doublethick_inter5;89 Parameter thick_inter5; 87 90 // [DEFAULT]=thick_inter6=1 [A] 88 doublethick_inter6;91 Parameter thick_inter6; 89 92 // [DEFAULT]=thick_inter7=1 [A] 90 doublethick_inter7;93 Parameter thick_inter7; 91 94 // [DEFAULT]=thick_inter8=1 [A] 92 doublethick_inter8;95 Parameter thick_inter8; 93 96 // [DEFAULT]=thick_inter9=1 [A] 94 doublethick_inter9;97 Parameter thick_inter9; 95 98 // [DEFAULT]=thick_inter10=1 [A] 96 doublethick_inter10;99 Parameter thick_inter10; 97 100 98 101 // [DEFAULT]=thick_flat1=10 [A] 99 doublethick_flat1;102 Parameter thick_flat1; 100 103 // [DEFAULT]=thick_flat2=100 [A] 101 doublethick_flat2;104 Parameter thick_flat2; 102 105 // [DEFAULT]=thick_flat3=100 [A] 103 doublethick_flat3;106 Parameter thick_flat3; 104 107 // [DEFAULT]=thick_flat4=100 [A] 105 doublethick_flat4;108 Parameter thick_flat4; 106 109 // [DEFAULT]=thick_flat5=100 [A] 107 doublethick_flat5;110 Parameter thick_flat5; 108 111 // [DEFAULT]=thick_flat6=100 [A] 109 doublethick_flat6;112 Parameter thick_flat6; 110 113 // [DEFAULT]=thick_flat7=100 [A] 111 doublethick_flat7;114 Parameter thick_flat7; 112 115 // [DEFAULT]=thick_flat8=100 [A] 113 doublethick_flat8;116 Parameter thick_flat8; 114 117 // [DEFAULT]=thick_flat9=100 [A] 115 doublethick_flat9;118 Parameter thick_flat9; 116 119 // [DEFAULT]=thick_flat10=100 [A] 117 doublethick_flat10;120 Parameter thick_flat10; 118 121 119 122 // [DEFAULT]=func_inter1=0 120 doublefunc_inter1;123 Parameter func_inter1; 121 124 // [DEFAULT]=func_inter2=0 122 doublefunc_inter2;125 Parameter func_inter2; 123 126 // [DEFAULT]=func_inter3=0 124 doublefunc_inter3;127 Parameter func_inter3; 125 128 // [DEFAULT]=func_inter4=0 126 doublefunc_inter4;129 Parameter func_inter4; 127 130 // [DEFAULT]=func_inter5=0 128 doublefunc_inter5;131 Parameter func_inter5; 129 132 // [DEFAULT]=func_inter6=0 130 doublefunc_inter6;133 Parameter func_inter6; 131 134 // [DEFAULT]=func_inter7=0 132 doublefunc_inter7;135 Parameter func_inter7; 133 136 // [DEFAULT]=func_inter8=0 134 doublefunc_inter8;137 Parameter func_inter8; 135 138 // [DEFAULT]=func_inter9=0 136 doublefunc_inter9;139 Parameter func_inter9; 137 140 // [DEFAULT]=func_inter10=0 138 doublefunc_inter10;141 Parameter func_inter10; 139 142 140 143 141 } ReflParameters; 144 // Constructor 145 ReflModel(); 142 146 143 double re_kernel(double dq[], double q); 144 145 /// 1D scattering function 146 double refl_analytical_1D(ReflParameters *pars, double q); 147 148 /// 2D scattering function 149 double refl_analytical_2D(ReflParameters *pars, double q, double phi); 150 double refl_analytical_2DXY(ReflParameters *pars, double qx, double qy); 147 // Operators to get I(Q) 148 double operator()(double q); 149 double operator()(double qx, double qy); 150 double calculate_ER(); 151 double evaluate_rphi(double q, double phi); 152 }; 151 153 152 154 #endif -
sansmodels/src/c_models/models.hh
r7ffa8196 r2d1b700 26 26 27 27 using namespace std; 28 29 class ReflModel{30 public:31 // Model parameters32 Parameter n_layers;33 Parameter scale;34 Parameter thick_inter0;35 Parameter func_inter0;36 Parameter sld_bottom0;37 Parameter sld_medium;38 Parameter background;39 40 Parameter sld_flat1;41 Parameter sld_flat2;42 Parameter sld_flat3;43 Parameter sld_flat4;44 Parameter sld_flat5;45 Parameter sld_flat6;46 Parameter sld_flat7;47 Parameter sld_flat8;48 Parameter sld_flat9;49 Parameter sld_flat10;50 51 Parameter thick_inter1;52 Parameter thick_inter2;53 Parameter thick_inter3;54 Parameter thick_inter4;55 Parameter thick_inter5;56 Parameter thick_inter6;57 Parameter thick_inter7;58 Parameter thick_inter8;59 Parameter thick_inter9;60 Parameter thick_inter10;61 62 Parameter thick_flat1;63 Parameter thick_flat2;64 Parameter thick_flat3;65 Parameter thick_flat4;66 Parameter thick_flat5;67 Parameter thick_flat6;68 Parameter thick_flat7;69 Parameter thick_flat8;70 Parameter thick_flat9;71 Parameter thick_flat10;72 73 Parameter func_inter1;74 Parameter func_inter2;75 Parameter func_inter3;76 Parameter func_inter4;77 Parameter func_inter5;78 Parameter func_inter6;79 Parameter func_inter7;80 Parameter func_inter8;81 Parameter func_inter9;82 Parameter func_inter10;83 84 // Constructor85 ReflModel();86 87 // Operators to get I(Q)88 double operator()(double q);89 double operator()(double qx, double qy);90 double calculate_ER();91 double evaluate_rphi(double q, double phi);92 };93 94 28 95 29 class ReflAdvModel{ -
sansmodels/src/c_models/refl.cpp
r67424cd r2d1b700 1 1 2 2 #include <math.h> 3 #include "models.hh"4 3 #include "parameters.hh" 5 4 #include <stdio.h> 5 #include <stdlib.h> 6 #include "refl.h" 6 7 using namespace std; 7 8 8 9 extern "C" { 9 #include "refl.h" 10 } 11 10 #include "libmultifunc/librefl.h" 11 } 12 13 #define lamda 4.62 14 15 double re_kernel(double dp[], double q) { 16 int n = dp[0]; 17 int i,j; 18 19 double scale = dp[1]; 20 double thick_inter_sub = dp[2]; 21 double sld_sub = dp[4]; 22 double sld_super = dp[5]; 23 double background = dp[6]; 24 25 double total_thick=0.0; 26 double nsl=21.0; //nsl = Num_sub_layer: 27 int n_s; 28 double sld_i,dz,phi,R,ko2; 29 double fun; 30 double pi; 31 32 double* sld; 33 double* thick_inter; 34 double* thick; 35 int*fun_type; 36 complex phi1,alpha,alpha2,kn,fnm,fnp,rn,Xn,nn,nn2,an,nnp1,one,two,n_sub,n_sup,knp1,Xnp1; 37 38 sld = (double*)malloc((n+2)*sizeof(double)); 39 thick_inter = (double*)malloc((n+2)*sizeof(double)); 40 thick = (double*)malloc((n+2)*sizeof(double)); 41 fun_type = (int*)malloc((n+2)*sizeof(int)); 42 43 fun_type[0] = dp[3]; 44 for (i =1; i<=n; i++){ 45 sld[i] = dp[i+6]; 46 thick_inter[i]= dp[i+16]; 47 thick[i] = dp[i+26]; 48 fun_type[i] = dp[i+36]; 49 total_thick += thick[i] + thick_inter[i]; 50 } 51 sld[0] = sld_sub; 52 sld[n+1] = sld_super; 53 54 thick[0] = total_thick/5.0; 55 thick[n+1] = total_thick/5.0; 56 thick_inter[0] = thick_inter_sub; 57 thick_inter[n+1] = 0.0; 58 59 pi = 4.0*atan(1.0); 60 Xn = cassign(0.0,0.0); 61 one = cassign(1.0,0.0); 62 two = cassign(0.0,-2.0); 63 64 //Checking if floor is available. 65 //no imaginary sld inputs in this function yet 66 n_sub=cassign(1.0-sld_sub*pow(lamda,2.0)/(2.0*pi),0.0); 67 n_sup=cassign(1.0-sld_super*pow(lamda,2.0)/(2.0*pi),0.0); 68 ko2 = pow(2.0*pi/lamda,2.0); 69 70 phi = asin(lamda*q/(4.0*pi)); 71 phi1 = cplx_div(rcmult(phi,one),n_sup); 72 alpha = cplx_mult(n_sup,cplx_cos(phi1)); 73 alpha2 = cplx_mult(alpha,alpha); 74 75 nnp1=n_sub; 76 knp1=cplx_sqrt(rcmult(ko2,cplx_sub(cplx_mult(nnp1,nnp1),alpha2))); //nnp1*ko*sin(phinp1) 77 Xnp1=cassign(0.0,0.0); 78 dz = 0.0; 79 // iteration for # of layers +sub from the top 80 for (i=1;i<=n+1; i++){ 81 if (fun_type[i-1]==1) 82 fun = 5; 83 else 84 fun = 0; 85 //iteration for 9 sub-layers 86 for (j=0;j<2;j++){ 87 for (n_s=0;n_s<nsl; n_s++){ 88 if (j==1){ 89 if (i==n+1) 90 break; 91 dz = thick[i]; 92 sld_i = sld[i]; 93 } 94 else{ 95 dz = thick_inter[i-1]/nsl;//nsl; 96 if (sld[i-1] == sld[i]){ 97 sld_i = sld[i]; 98 } 99 else{ 100 sld_i = intersldfunc(fun,nsl, n_s+0.5, 2.5, sld[i-1], sld[i]); 101 } 102 } 103 nn = cassign(1.0-sld_i*pow(lamda,2.0)/(2.0*pi),0.0); 104 nn2=cplx_mult(nn,nn); 105 106 kn=cplx_sqrt(rcmult(ko2,cplx_sub(nn2,alpha2))); //nn*ko*sin(phin) 107 an=cplx_exp(rcmult(dz,cplx_mult(two,kn))); 108 109 fnm=cplx_sub(kn,knp1); 110 fnp=cplx_add(kn,knp1); 111 rn=cplx_div(fnm,fnp); 112 Xn=cplx_mult(an,cplx_div(cplx_add(rn,Xnp1),cplx_add(one,cplx_mult(rn,Xnp1)))); //Xn=an*((rn+Xnp1*anp1)/(1+rn*Xnp1*anp1)) 113 114 Xnp1=Xn; 115 knp1=kn; 116 117 if (j==1) 118 break; 119 } 120 } 121 } 122 R=pow(Xn.re,2.0)+pow(Xn.im,2.0); 123 // This temperarily fixes the total reflection for Rfunction and linear. 124 // ToDo: Show why it happens that Xn.re=0 and Xn.im >1! 125 if (Xn.im == 0.0){ 126 R=1.0; 127 } 128 R *= scale; 129 R += background; 130 131 free(sld); 132 free(thick_inter); 133 free(thick); 134 free(fun_type); 135 136 return R; 137 138 } 12 139 ReflModel :: ReflModel() { 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 140 n_layers = Parameter(1.0); 141 scale = Parameter(1.0); 142 thick_inter0 = Parameter(1.0); 143 func_inter0 = Parameter(0); 144 sld_bottom0 = Parameter(2.07e-06); 145 sld_medium = Parameter(1.0e-06); 146 background = Parameter(0.0); 147 148 149 sld_flat1 = Parameter(3.0e-06); 150 sld_flat2 = Parameter(3.5e-06); 151 sld_flat3 = Parameter(4.0e-06); 152 sld_flat4 = Parameter(3.5e-06); 153 sld_flat5 = Parameter(4.0e-06); 154 sld_flat6 = Parameter(3.5e-06); 155 sld_flat7 = Parameter(4.0e-06); 156 sld_flat8 = Parameter(3.5e-06); 157 sld_flat9 = Parameter(4.0e-06); 158 sld_flat10 = Parameter(3.5e-06); 159 160 161 thick_inter1 = Parameter(1); 162 thick_inter2 = Parameter(1); 163 thick_inter3 = Parameter(1); 164 thick_inter4 = Parameter(1); 165 thick_inter5 = Parameter(1); 166 thick_inter6 = Parameter(1); 167 thick_inter7 = Parameter(1); 168 thick_inter8 = Parameter(1); 169 thick_inter9 = Parameter(1); 170 thick_inter10 = Parameter(1); 171 172 173 thick_flat1 = Parameter(15); 174 thick_flat2 = Parameter(100); 175 thick_flat3 = Parameter(100); 176 thick_flat4 = Parameter(100); 177 thick_flat5 = Parameter(100); 178 thick_flat6 = Parameter(100); 179 thick_flat7 = Parameter(100); 180 thick_flat8 = Parameter(100); 181 thick_flat9 = Parameter(100); 182 thick_flat10 = Parameter(100); 183 184 185 func_inter1 = Parameter(0); 186 func_inter2 = Parameter(0); 187 func_inter3 = Parameter(0); 188 func_inter4 = Parameter(0); 189 func_inter5 = Parameter(0); 190 func_inter6 = Parameter(0); 191 func_inter7 = Parameter(0); 192 func_inter8 = Parameter(0); 193 func_inter9 = Parameter(0); 194 func_inter10 = Parameter(0); 68 195 69 196 } … … 75 202 */ 76 203 double ReflModel :: operator()(double q) { 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 204 double dp[47]; 205 // Fill parameter array for IGOR library 206 // Add the background after averaging 207 dp[0] = n_layers(); 208 dp[1] = scale(); 209 dp[2] = thick_inter0(); 210 dp[3] = func_inter0(); 211 dp[4] = sld_bottom0(); 212 dp[5] = sld_medium(); 213 dp[6] = background(); 214 215 dp[7] = sld_flat1(); 216 dp[8] = sld_flat2(); 217 dp[9] = sld_flat3(); 218 dp[10] = sld_flat4(); 219 dp[11] = sld_flat5(); 220 dp[12] = sld_flat6(); 221 dp[13] = sld_flat7(); 222 dp[14] = sld_flat8(); 223 dp[15] = sld_flat9(); 224 dp[16] = sld_flat10(); 225 226 dp[17] = thick_inter1(); 227 dp[18] = thick_inter2(); 228 dp[19] = thick_inter3(); 229 dp[20] = thick_inter4(); 230 dp[21] = thick_inter5(); 231 dp[22] = thick_inter6(); 232 dp[23] = thick_inter7(); 233 dp[24] = thick_inter8(); 234 dp[25] = thick_inter9(); 235 dp[26] = thick_inter10(); 236 237 dp[27] = thick_flat1(); 238 dp[28] = thick_flat2(); 239 dp[29] = thick_flat3(); 240 dp[30] = thick_flat4(); 241 dp[31] = thick_flat5(); 242 dp[32] = thick_flat6(); 243 dp[33] = thick_flat7(); 244 dp[34] = thick_flat8(); 245 dp[35] = thick_flat9(); 246 dp[36] = thick_flat10(); 247 248 dp[37] = func_inter1(); 249 dp[38] = func_inter2(); 250 dp[39] = func_inter3(); 251 dp[40] = func_inter4(); 252 dp[41] = func_inter5(); 253 dp[42] = func_inter6(); 254 dp[43] = func_inter7(); 255 dp[44] = func_inter8(); 256 dp[45] = func_inter9(); 257 dp[46] = func_inter10(); 258 259 // Get the dispersion points for the radius 260 //vector<WeightPoint> weights_thick; 261 //thick_inter0.get_weights(weights_thick_inter0); 262 263 264 return re_kernel(dp,q); 138 265 } 139 266 … … 145 272 */ 146 273 double ReflModel :: operator()(double qx, double qy) { 147 148 149 150 151 152 274 // For 2D set qy as q, ignoring qx. 275 double q = qy;//sqrt(qx*qx + qy*qy); 276 if (q < 0.0){ 277 return 0.0; 278 } 279 return (*this).operator()(q); 153 280 } 154 281 … … 161 288 */ 162 289 double ReflModel :: evaluate_rphi(double q, double phi) { 163 290 return (*this).operator()(q); 164 291 } 165 292 … … 169 296 */ 170 297 double ReflModel :: calculate_ER() { 171 172 173 } 298 //NOT implemented yet!!! 299 return 0.0; 300 } -
sansmodels/src/python_wrapper/WrapperGenerator.py
rd62f422 r2d1b700 56 56 """ 57 57 58 def __init__(self, filename ):58 def __init__(self, filename, output_dir='.'): 59 59 """ Initialization """ 60 60 … … 90 90 ## parameters with orientation 91 91 self.orientation_params =[] 92 ## output directory for wrappers 93 self.output_dir = output_dir 92 94 93 95 … … 289 291 The file is written in C[PYTHONCLASS].c 290 292 """ 291 292 file = open("C"+self.pythonClass+'.cpp', 'w') 293 template = open("classTemplate.txt", 'r') 293 file_path = os.path.join(self.output_dir, "C"+self.pythonClass+'.cpp') 294 file = open(file_path, 'w') 295 296 template = open(os.path.join(os.path.dirname(__file__), "classTemplate.txt"), 'r') 294 297 295 298 tmp_buf = template.read() … … 414 417 The file is written in ../[PYTHONCLASS].py 415 418 """ 416 417 file = open( "../sans/models/"+self.pythonClass+'.py', 'w')418 template = open( "modelTemplate.txt", 'r')419 file_path = os.path.join(self.output_dir, "../sans/models/"+self.pythonClass+'.py') 420 file = open(file_path, 'w') 421 template = open(os.path.join(os.path.dirname(__file__), "modelTemplate.txt"), 'r') 419 422 420 423 tmp_buf = template.read() -
sansmodels/src/python_wrapper/wrapping.py
r67424cd r2d1b700 4 4 from WrapperGenerator import WrapperGenerator 5 5 6 def generate_wrappers(header_dir, output_dir='.'): 7 nModels=0 8 for item in os.listdir(header_dir): 9 toks = os.path.splitext(os.path.basename(item)) 10 if toks[1]=='.h': 11 nModels += 1 12 name = toks[0] 13 app = WrapperGenerator(os.path.join(header_dir, name+".h"), output_dir=output_dir) 14 app.read() 15 app.write_c_wrapper() 16 app.write_python_wrapper() 17 #print app 18 print "Total number of model wrappers created is %s" % nModels 6 19 7 header_dir = os.path.join('..', 'c_extensions') 20 if __name__ == '__main__': 21 header_dir = os.path.join('..', 'c_extensions') 22 generate_wrappers(header_dir) 8 23 9 nModels=0 10 for item in os.listdir(header_dir): 11 toks = os.path.splitext(os.path.basename(item)) 12 if toks[1]=='.h': 13 nModels += 1 14 name = toks[0] 15 app = WrapperGenerator(os.path.join(header_dir, name+".h")) 16 app.read() 17 app.write_c_wrapper() 18 app.write_python_wrapper() 19 print app 20 print "Number total of models is %s" % nModels 24 -
setup.py
r67424cd r2d1b700 217 217 smear_dir = os.path.join("sansmodels", "src", "c_smearer") 218 218 wrapper_dir = os.path.join("sansmodels", "src", "python_wrapper") 219 220 sys.path.append(wrapper_dir) 221 from wrapping import generate_wrappers 222 generate_wrappers(header_dir=srcdir, output_dir=wrapper_dir) 219 223 220 224 IGNORED_FILES = ["a.exe",
Note: See TracChangeset
for help on using the changeset viewer.