File: Slit_N.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 (122 lines) | stat: -rw-r--r-- 3,160 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
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
/*******************************************************************************
*
* McXtrace, X-ray tracing package
*         Copyright 1997-2002, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Component: Slit
*
* %I
* Written by: Erik Knudsen
* Date: June 16, 2009
* Origin: Risoe
* Release: McXtrace 0.1
*
* Rectangular/circular slit, duplicated
*
* %Description
* Based on Slit-comp by Kim Lefmann and Henrik Roennow
* A simple rectangular or circular slit. You may either
* specify the radius (circular shape), which takes precedence,
* or the rectangular bounds. The slits are separated with 'd', and arranged along X.
* No transmission around the slit is allowed.
* If cutting option is used, low-weight x-rays are ABSORBED
*
* Example: Slit_N(xwidth=0.01, yheight=0.01, d=0.02)
*          Slit_N(radius=0.01, cut=1e-10, d=0.03)
*
* %Parameters
* INPUT PARAMETERS
*
* radius:   [m] Radius of slit in the z=0 plane, centered at Origo
* xwidth:   [m] Width of slit. Overrides xmin,xmax.
* yheight:  [m] Height of slit. Overrides ymin,ymax.
* N:        [1] Number of slit openings along X
* d:        [m] Separation of slits
*
* Optional parameters:
* cut:  Lower limit for allowed weight (1)
*
* %End
*******************************************************************************/


DEFINE COMPONENT Slit_N
SETTING PARAMETERS (radius=0, cut=0, xwidth=0, yheight=0, N=2, d=0)

DECLARE
%{
  double xmax;
  double ymax;
  double xmin;
  double ymin;
%}

INITIALIZE
%{
  if (xwidth)  { xmax=xwidth/2;  xmin=-xmax; }
  if (yheight) { ymax=yheight/2; ymin=-ymax; }
  if (xmin == 0 && xmax == 0 && ymin == 0 && ymax == 0 && radius == 0)
    { fprintf(stderr,"Slit_N: %s: Error: give geometry\n", NAME_CURRENT_COMP); exit(-1); }
  if ( (radius && d<2*radius) || d<xwidth){
      fprintf(stderr,"Slit_N: %s: Error: Separation of slits less than slit width\n",NAME_CURRENT_COMP);exit(-1);}


%}

TRACE
%{
  PROP_Z0;
  double xx=-((N-1)/2.0)*d;
  int i=0;
  while(x>xx && i<N){
    i++;
    xx+=d;
  }
  if( fabs(x-xx)>fabs(x-(xx-d))){
    i--;
    xx-=d;
  }
  xx=x-xx;

  if (((radius == 0) && (xx<xmin || xx>xmax || y<ymin || y>ymax))
      || ((radius != 0) && (xx*xx + y*y > radius*radius)))
    ABSORB;
  else
    if (p < cut)
      ABSORB;
    else
      SCATTER;
%}

MCDISPLAY
%{
  int i;
  
  for(i=0;i<N;i++){
    double xx;
    xx=(-(N-1)/2.0 +i)*d;
    if (radius == 0) {
      double xw, yh;
      xw = (xmax - xmin)/2.0;
      yh = (ymax - ymin)/2.0;
      multiline(3, xmin+xx-xw, (double)ymax, 0.0,
          (double)xmin+xx, (double)ymax, 0.0,
          (double)xmin+xx, ymax+yh, 0.0);
      multiline(3, xmax+xx+xw, (double)ymax, 0.0,
          (double)xmax+xx, (double)ymax, 0.0,
          (double)xmax+xx, ymax+yh, 0.0);
      multiline(3, xmin+xx-xw, (double)ymin, 0.0,
          (double)xmin+xx, (double)ymin, 0.0,
          (double)xmin+xx, ymin-yh, 0.0);
      multiline(3, xmax+xx+xw, (double)ymin, 0.0,
          (double)xmax+xx, (double)ymin, 0.0,
          (double)xmax+xx, ymin-yh, 0.0);
    } else {
      circle("xy",xx,0,0,radius);
    }
  }
%}

END