- Timestamp:
- 12/13/11 12:30:09 (5 months ago)
- Location:
- branches/mcxtrace-1.0
- Files:
-
- 2 modified
-
lib/share/mccode-r.c (modified) (1 diff)
-
xlib/samples/Perfect_crystal.comp (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/mcxtrace-1.0/lib/share/mccode-r.c
r3164 r3220 2344 2344 long index = !detector.istransposed ? i*detector.n*detector.p + j : i+j*detector.m; 2345 2345 double value = this_p1[index]; 2346 fprintf(detector.file_handle, "% g", value);2346 fprintf(detector.file_handle, "%.12g", value); 2347 2347 fprintf(detector.file_handle, "%s", 2348 2348 (isIDL || isPython) && ((i+1)*(j+1) < detector.m*detector.n*detector.p) ? -
branches/mcxtrace-1.0/xlib/samples/Perfect_crystal.comp
r3164 r3220 38 38 * width [m] width of the crystal (along x-axis) 39 39 * Material Si, Ge (maybe also GaAs?) 40 <<<<<<< HEAD 40 41 * V [Ã 41 42 ^3] unit cell volume 42 43 * h,k,l indices of reflection (111)(220)(400) 44 ======= 45 * V [Ã 46 ^3] unit cell volume160.1826 47 * h [] Miller index of reflection 48 * k [] Miller index of reflection 49 * l [] Miller index of reflection 50 >>>>>>> Perfect crystal now works for any hkl 43 51 * alpha [rad] asymmetry angle (alpha=0 for symmetric reflection, ie the Bragg planes are parallel to the crystal surface) 52 * R0 [] Reflectivity. Overrides the computed Darwin reflectivity. Probably only useful for debugging. 44 53 * 45 54 * (none) … … 49 58 50 59 DEFINE COMPONENT Perfect_crystal 51 DEFINITION PARAMETERS (string form_factors="FormFactors.txt", string material="Si.txt" )60 DEFINITION PARAMETERS (string form_factors="FormFactors.txt", string material="Si.txt",R0=0) 52 61 SETTING PARAMETERS (length=0.05, width=0.02, V=160.1826, h=1, k=1, l=1, alpha=0.0) 53 62 /* OUTPUT PARAMETERS (prms_m, a,b,c,M,Z0,Y0,xi,cost0) */ … … 78 87 b = sin(theta - alpha)/sin(theta + alpha); /* asymmetry factor */ 79 88 89 <<<<<<< HEAD 80 90 *Theta0 = Thetain + alpha; /* (rad) angle between Bragg planes and incident ray */ 81 91 *Thetah = b*(*Theta0 - theta) + theta; /* (rad) Angle betweeb Bragg planes and reflected ray */ 92 ======= 93 b = sin(theta + alpha)/sin(theta - alpha); /* asymmetry factor */ 94 95 *Theta0 = Thetain - alpha; /* (rad) angle between Bragg planes and incident ray */ 96 *Thetah = b*(*Theta0 - theta) + theta; /* (rad) Angle betweeb Bragg planes and reflected ray */ 97 /*check if Bragg angle is less than alpha. If so return 0 reflectivity*/ 98 if (theta<alpha) { 99 *R=0; 100 *DeltaTheta0 = -1; /*to mark it irrelevant*/ 101 } 102 >>>>>>> Perfect crystal now works for any hkl 82 103 83 104 /* Define polarization factor: */ … … 123 144 *R = L - sqrt(L*L - 1); 124 145 DeltaThetas = r0*(lambda*lambda)*F0r/(sin(2*theta)*PI*V); /* eq 32 */ 125 /* printf("E,lambda= %f , %f \n",E,lambda); 146 #ifdef MCDEBUG 147 printf("E,lambda= %f , %f \n",E,lambda); 126 148 printf("theta= %f \n",theta*180/PI); 127 printf("sqrt(b)= %f \n",sqrt(b)); 149 printf("Theta0= %f \n",*Theta0*180/PI); 150 printf("theta = %g rad, alpha=%g rad.\n",theta,alpha); 151 printf("b,sqrt(b)= %f %f\n",b,sqrt(b)); 128 152 printf("1/sqrt(b)= %f \n",1/sqrt(b)); 129 printf("sqrt(b)*sin(2*theta)= %f \n",sqrt(b)*sin(2*theta)); 130 printf("C * psihr= %f \n",C * psihr); 153 printf("Fhr, Fhi, F0r, F0i= %g %g %g %g\n",Fhr, Fhi, F0r, F0i); 154 printf("psihr, psihi, psi0r, psi0i= %g %g %g %g\n",psihr, psihi, psi0r, psi0i); 155 printf("sqrt(b)*sin(2*theta)= %g \n",sqrt(b)*sin(2*theta)); 156 printf("C, pis0r,C * psihr= %g %g %g\n",C, psi0r,C * psihr); 131 157 printf("W= %f \n",W); 132 158 printf("kappa= %f \n",kappa); 133 159 printf("g= %f \n",g); 134 160 printf("L= %f \n",L); 135 printf("R= %f \n",*R); */136 //printf("DeltaThetas %f \n",3600*DeltaThetas*180/PI);137 161 printf("R= %f \n",*R); 162 printf("DeltaThetas %f \n",3600*DeltaThetas*180/PI); 163 #endif 138 164 *DeltaTheta0 = 0.5*(1 + 1/b)*DeltaThetas; /* center of reflectivity curve is at theta + DeltaTheta0 eq 31 */ 139 165 } … … 189 215 ^3), asymmetry angle (rad), indices of reflection and a temperature factor 190 216 double f00, f0h, fp, fpp; // atomic form factors for Q=0 is (f00 + fp + i*fpp) and for Q= ha*+kb*+lc* it is (f0h + fp + i*fpp). 191 double Thetain; // (rad) angle between the cr stal surface and the incident ray217 double Thetain; // (rad) angle between the crystal surface and the incident ray 192 218 double Theta0; // (rad) angle between the Bragg planes and the incident ray 193 219 double Thetah; // (rad) angle between the Bragg planes and the reflected ray … … 222 248 PROP_DL(dist); /* now the photon is on the mirror surface, ready to be reflected... */ 223 249 SCATTER; 250 <<<<<<< HEAD 224 251 225 252 Thetain = atan(kyu/kzu); /* (rad )The angle of incidence*/ 226 253 254 ======= 255 /*Check which quadrant the k vector is in to determine sense of alpha. This to allow for hitting the crystal from behind.*/ 256 int quadrant; 257 Thetain=fabs(atan(ky/kz)); 258 >>>>>>> Perfect crystal now works for any hkl 227 259 /* for a start, just define the value of atomic form factors for Si(111) at E = 8.04778keV */ 228 260 double d=cbrt(V)/(sqrt(h*h+k*k+l*l));/*this is valid only for cubic structures*/ … … 232 264 fpp = Table_Value(prms.m_t,E,2); 233 265 // printf("%g %g %g %g\n",f00,f0h,fp,fpp); 266 <<<<<<< HEAD 234 267 /* printf("Thetain for this ray is: %g: \n",Thetain);*/ 235 268 DarwinReflectivity(&R, &Thetah, &Theta0, &DeltaTheta0, f00, f0h, fp, fpp, V, alpha, h, k, l, M, E, Thetain,pol); … … 237 270 /* printf("Thetaout for this ray is: %g: \n", Thetaout);*/ 238 271 272 ======= 273 //printf("Thetain for this ray is: %g: \n",Thetain); 274 if (ky<0 && kz>0){ 275 /*4th quadrant - forward hit from above. No change.*/ 276 DarwinReflectivity(&R, &Thetah, &Theta0, &DeltaTheta0, f00, f0h, fp, fpp, V, alpha, h, k, l, M, E, Thetain,pol); 277 }else if(ky<0 && kz<0){ 278 /*3rd quadrant - backward hit from above. Sense of alpha is reversed.*/ 279 DarwinReflectivity(&R, &Thetah, &Theta0, &DeltaTheta0, f00, f0h, fp, fpp, V, -alpha, h, k, l, M, E, Thetain,pol); 280 }else if(ky>0 && kz>0){ 281 /*1st quadrant - forward hit from below. Sense of alpha is reversed.*/ 282 DarwinReflectivity(&R, &Thetah, &Theta0, &DeltaTheta0, f00, f0h, fp, fpp, V, alpha, h, k, l, M, E, Thetain,pol); 283 }else if(ky>0 && kz<0){ 284 /*2nd quadrant - backward hit from below. No change.*/ 285 DarwinReflectivity(&R, &Thetah, &Theta0, &DeltaTheta0, f00, f0h, fp, fpp, V, -alpha, h, k, l, M, E, Thetain,pol); 286 } 287 Thetaout = Thetah - alpha; /* (rad) the angle between the crystal surface and the reflected ray */ 288 //printf("Thetaout for this ray is: %g: ref=%g\n", Thetaout, R); 289 290 /*reflect ray in normal to crystal planes*/ 291 //printf("kin: %g %g %g\n",kx,ky,kz); 292 do { 293 double ax,ay,az,vnx,vny,vnz; 294 ax=0;ay=-sin(alpha);az=cos(alpha); 295 vnx=kx-scalar_prod(kx,ky,kz,ax,ay,az)*ax; 296 vny=ky-scalar_prod(kx,ky,kz,ax,ay,az)*ay; 297 vnz=kz-scalar_prod(kx,ky,kz,ax,ay,az)*az; 298 //printf("a=[ %g %g %g ] vn=[ %g %g %g ]\n",ax,ay,az,vnx,vny,vnz); 299 kx=kx-2*vnx; 300 ky=ky-2*vny; 301 kz=kz-2*vnz; 302 }while(0); 303 >>>>>>> Perfect crystal now works for any hkl 239 304 /* The direction of the reflected ray: */ 240 kxout = kxu; 241 kyout = -sqrt(kyu*kyu + kzu*kzu)*sin(Thetaout); 242 kzout = sqrt(kyu*kyu + kzu*kzu)*cos(Thetaout); 243 305 // printf("kout: %g %g %g\n",kx,ky,kz); 306 307 <<<<<<< HEAD 244 308 NORM(kxout,kyout,kzout); 245 309 kx=K*kxout; … … 250 314 p*=R; 251 315 316 ======= 317 /* apply Darwin reflectivity if not is supplied from outside*/ 318 if (!R0){ 319 p*=R; 320 }else{ 321 p*=R0; 322 } 323 /*catch dead rays*/ 324 if (p==0) ABSORB; 325 >>>>>>> Perfect crystal now works for any hkl 252 326 } else { 253 327 RESTORE_XRAY(INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);
