File: Bragg_crystal_simple.comp

package info (click to toggle)
mccode 3.5.19%2Bds5-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,113,256 kB
  • sloc: ansic: 40,697; python: 25,137; yacc: 8,438; sh: 5,405; javascript: 4,596; lex: 1,632; cpp: 742; perl: 296; lisp: 273; makefile: 226; fortran: 132
file content (95 lines) | stat: -rw-r--r-- 2,538 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*******************************************************************************
*
* McXtrace, x-ray tracing package
*         Copyright, All rights reserved
*         DTU Physics, Kgs. Lyngby, Denmark
*         Synchrotron SOLEIL, Saint-Aubin, France
*
* Component: Bragg_crystal_simple
*
* %Identification
*
* Written by: Jose I. Robledo
* Date: February 2016
* Version: $Revision$
* Release: McXtrace 1.2
* Origin: FaMAF - UNC, Argentina
*
* Perfect Bragg reflecting slab
*
* %Description
*
* Rectangle of matter perfectly reflecting the incident X-ray beam
* that fulfills Bragg's law for a set of scattering vectors in the
* vicinity of the theoretical Q given a d-spacing.
* The rectangle is in the x-y plane.
*
* Example: Bragg_crystal_simple( yheight=0.05, xwidth=0.02, DM=3.1356, err_Q= 0.000075, r0=1.0)
*
* %Parameters
* Input parameters:
* xwidth: [m]    Width in the x direction
* yheight: [m]   Height in the y direction
* r0: [ ]        Maximum reflectivity
* DM: [AA⁻1]     d-spacing of the crystal
* err_Q: [ ]     dQ/Q relative error of the modulus of Q vector. Approximates the Darwin width of the crystal.
*
* %End
*******************************************************************************/

DEFINE COMPONENT Bragg_crystal_simple

SETTING PARAMETERS (xmin=1.0,xmax=1.0,ymin=1.0,ymax=1.0,xwidth=0.0,yheight=0.0,r0=1,DM=0,err_Q=0.0001)

/* X-ray parameters: (x,y,z,kx,ky,kz,phi,t,Ex,Ey,Ez,p) */

DECLARE %{
  double Q;
  double dQ;
%}

INITIALIZE %{
  if (DM != 0) {
    Q=2*PI/DM; dQ=Q*err_Q;
  }else{
    fprintf(stderr,"WARNING: Bragg_crystal_simple (%s) d-spacing==0, crystal will ABSORB all X-rays.\n",NAME_CURRENT_COMP);
  }

  if (xwidth>0)  { xmax = xwidth/2;  xmin=-xmax; }
  if (yheight>0) { ymax = yheight/2; ymin=-ymax; }

  if (xmin==xmax || ymin==ymax)
    exit(fprintf(stderr, "Bragg_crystal_simple (%s) : Surface is null (xmin,xmax,ymin,ymax)\n", NAME_CURRENT_COMP));
  %}
TRACE
%{
  double k,e,theta_bragg;

  k=sqrt(kx*kx+ky*ky+kz*kz);
  e=K2E*k*1E-3;
  theta_bragg=atan(kz/ky);

  PROP_Z0; //MOVING TOWARDS THE CRYSTAL.
  if (inside_rectangle(x, y, xwidth, yheight))
  {if (Q>(2*k*sin(theta_bragg)-dQ) && Q<(2*k*sin(theta_bragg)+dQ))
    {kz=-kz;
      SCATTER;
    }else{
      ABSORB;
    }
  }

%}

MCDISPLAY
%{
  /* A bit ugly; hard-coded dimensions. */
  magnify("");
  line(-xwidth/2,-yheight/2,0,xwidth/2,-yheight/2,0);
  line(-xwidth/2,yheight/2,0,xwidth/2,yheight/2,0);
  line(-xwidth/2,-yheight/2,0,-xwidth/2,yheight/2,0);
  line(xwidth/2,-yheight/2,0,xwidth/2,yheight/2,0);

%}

END