Changeset 3220 for branches

Show
Ignore:
Timestamp:
12/13/11 12:30:09 (5 months ago)
Author:
erkn
Message:

Perfect crystal now works for any hkl

added support for arbitrary hkls. Still only single material diamond
structures, though.
Can now handle hits from below and backwards.
Fix to detector out data print routine to allow values closely spaced.
There was an implicit hard limit at 4 digits precision.

Location:
branches/mcxtrace-1.0
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/mcxtrace-1.0/lib/share/mccode-r.c

    r3164 r3220  
    23442344          long index   = !detector.istransposed ? i*detector.n*detector.p + j : i+j*detector.m; 
    23452345          double value = this_p1[index]; 
    2346           fprintf(detector.file_handle, "%g", value); 
     2346          fprintf(detector.file_handle, "%.12g", value); 
    23472347          fprintf(detector.file_handle, "%s", 
    23482348            (isIDL || isPython) && ((i+1)*(j+1) < detector.m*detector.n*detector.p) ? 
  • branches/mcxtrace-1.0/xlib/samples/Perfect_crystal.comp

    r3164 r3220  
    3838* width [m]                     width of the crystal (along x-axis) 
    3939* Material                      Si, Ge (maybe also GaAs?)        
     40<<<<<<< HEAD 
    4041* V [à
    4142^3]                     unit cell volume 
    4243* 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 
    4351* 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.  
    4453*  
    4554* (none) 
     
    4958 
    5059DEFINE 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)  
    5261SETTING PARAMETERS (length=0.05, width=0.02, V=160.1826, h=1, k=1, l=1, alpha=0.0) 
    5362/* OUTPUT PARAMETERS (prms_m, a,b,c,M,Z0,Y0,xi,cost0) */ 
     
    7887    b = sin(theta - alpha)/sin(theta + alpha);  /* asymmetry factor */ 
    7988     
     89<<<<<<< HEAD 
    8090    *Theta0 = Thetain + alpha;                  /* (rad) angle between Bragg planes and incident ray */  
    8191    *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 
    82103     
    83104    /* Define polarization factor: */ 
     
    123144    *R = L - sqrt(L*L - 1); 
    124145    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); 
    126148    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)); 
    128152    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); 
    131157    printf("W= %f \n",W); 
    132158    printf("kappa= %f \n",kappa); 
    133159    printf("g= %f \n",g); 
    134160    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 
    138164    *DeltaTheta0 = 0.5*(1 + 1/b)*DeltaThetas;                           /* center of reflectivity curve is at theta + DeltaTheta0 eq 31 */  
    139165  } 
     
    189215^3), asymmetry angle (rad), indices of reflection and a temperature factor 
    190216  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 crstal surface and the incident ray 
     217  double Thetain;                       // (rad) angle between the crystal surface and the incident ray 
    192218  double Theta0;                        // (rad) angle between the Bragg planes and the incident ray 
    193219  double Thetah;                        // (rad) angle between the Bragg planes and the reflected ray 
     
    222248        PROP_DL(dist);                  /* now the photon is on the mirror surface, ready to be reflected... */  
    223249        SCATTER; 
     250<<<<<<< HEAD 
    224251 
    225252        Thetain = atan(kyu/kzu);        /* (rad )The angle of incidence*/ 
    226253         
     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 
    227259        /* for a start, just define the value of atomic form factors for Si(111) at E = 8.04778keV */ 
    228260        double d=cbrt(V)/(sqrt(h*h+k*k+l*l));/*this is valid only for cubic structures*/ 
     
    232264        fpp = Table_Value(prms.m_t,E,2); 
    233265//        printf("%g %g %g %g\n",f00,f0h,fp,fpp);     
     266<<<<<<< HEAD 
    234267/*      printf("Thetain for this ray is: %g: \n",Thetain);*/ 
    235268        DarwinReflectivity(&R, &Thetah, &Theta0, &DeltaTheta0, f00, f0h, fp, fpp, V, alpha, h, k, l, M, E, Thetain,pol); 
     
    237270/*      printf("Thetaout for this ray is: %g: \n", Thetaout);*/ 
    238271 
     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 
    239304        /* 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 
    244308        NORM(kxout,kyout,kzout);  
    245309        kx=K*kxout; 
     
    250314        p*=R;  
    251315 
     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 
    252326        } else { 
    253327          RESTORE_XRAY(INDEX_CURRENT_COMP, x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p);