Changeset 3224

Show
Ignore:
Timestamp:
12/14/11 15:24:08 (5 months ago)
Author:
erkn
Message:

3rd time lucky - now arbitrary hkls work

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/mcxtrace-1.0/xlib/samples/Perfect_crystal.comp

    r3223 r3224  
    6161%{ 
    6262  %include "read_table-lib"   
    63  
     63#include <complex.h> 
    6464/* something that would be relevant for ALL crystals */ 
    6565  void DarwinReflectivity(double *R, double *Thetah, double *Theta0, double *DeltaTheta0, 
     
    103103 
    104104    /* STRUCTURE FACTOR CALCULATION: */ 
    105     /* NOTE: these structurefactors are valid for single atom structures like Si or Ge only: */ 
     105    /* NOTE: these structurefactors are valid for single atom diamond lattice structures like Si or Ge only: */ 
     106     
     107 
     108 
    106109    F0r = 8*(f00 + fp);                         /* Q=0, real part of structure factor for forward scattering */ 
    107110    F0i = 8*(fpp);                              /* Q=0, imag part of structure factor for forward scattering */ 
     
    111114      Fhi = sqrt(17)*(fpp);             /* |(4-i)| = sqrt(17) */    
    112115      } 
    113     if (h==2 && k==2 && l==0){          /* (220) reflection */ 
     116    else if (h==2 && k==2 && l==0){             /* (220) reflection */ 
    114117      Fhr = 8*(f0h + fp);        
    115118      Fhi = 8*(fpp);             
    116119      } 
    117     if (h==4 && k==0 && l==0){          /* (400) reflection */ 
     120    else if (h==4 && k==0 && l==0){             /* (400) reflection */ 
    118121      Fhr = 8*(f0h + fp);        
    119122      Fhi = 8*(fpp);             
    120123      } 
     124    else { 
     125      complex double f_hkl=(1+cexp(I*M_PI*(h+k))+cexp(I*M_PI*(k+l)) + cexp(I*M_PI*(h+l)))*(1+cexp(I*M_PI*(h/4.0 + k/4.0 + l/4.0))); 
     126      Fhr = cabs(f_hkl)*(f0h + fp); 
     127      Fhi = cabs(f_hkl)*(fpp); 
     128      F0r = cabs(f_hkl)*(f00 + fp);                             /* Q=0, real part of structure factor for forward scattering */ 
     129      F0i = cabs(f_hkl)*(fpp);                          /* Q=0, imag part of structure factor for forward scattering */ 
     130    } 
    121131 
    122132    psi0r = fabs(F0r*exp(-M)*r0*lambda*lambda/(PI*V));  
     
    233243    if (fabs(x_int)<=width/2 && fabs(z_int)<=length/2){ 
    234244        dist=sqrt(SQR(x-x_int)+SQR(y-y_int)+SQR(z-z_int)); 
    235         PROP_DL(dist);                  /* now the photon is on the mirror surface, ready to be reflected... */  
     245        PROP_DL(dist);                  /* now the photon is on the crystal surface, ready to be reflected... */  
    236246        SCATTER; 
    237247        /*Check which quadrant the k vector is in to determine sense of alpha. This to allow for hitting the crystal from behind.*/ 
     
    253263        }else if(ky>0 && kz>0){ 
    254264          /*1st quadrant - forward hit from below. Sense of alpha is reversed.*/ 
    255           DarwinReflectivity(&R, &Thetah, &Theta0, &DeltaTheta0, f00, f0h, fp, fpp, V, alpha, h, k, l, M, E, Thetain,pol); 
     265          DarwinReflectivity(&R, &Thetah, &Theta0, &DeltaTheta0, f00, f0h, fp, fpp, V, -alpha, h, k, l, M, E, Thetain,pol); 
    256266        }else if(ky>0 && kz<0){ 
    257267          /*2nd quadrant - backward hit from below. No change.*/ 
    258           DarwinReflectivity(&R, &Thetah, &Theta0, &DeltaTheta0, f00, f0h, fp, fpp, V, -alpha, h, k, l, M, E, Thetain,pol); 
     268          DarwinReflectivity(&R, &Thetah, &Theta0, &DeltaTheta0, f00, f0h, fp, fpp, V, alpha, h, k, l, M, E, Thetain,pol); 
    259269        } 
    260270        Thetaout = Thetah - alpha;      /* (rad) the angle between the crystal surface and the reflected ray */