File: Rotator.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 (123 lines) | stat: -rw-r--r-- 2,909 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
123
/*******************************************************************************
*
* McStas, neutron ray-tracing package
*         Copyright (C) 1997-2007, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Component: Rotator
*
* %I
*
* Written by: Emmanuel Farhi
* Date: June 20th 2013
* Origin: <a href="http://www.ill.fr">ILL</a>
*
* A rotative frame along vertical axis
*
* %Description
* All components positioned after this one are rotating at frequency 'nu' with
* phase 'phase'. Use the Derotator component to put back the model steady.
* The rotation is performed w.r.t. the position of the component, along a chosen
* main axis (use directon=1 for x, direction=2 for y, direction=3 for z).
*
* Default rotation axis is vertical axis / 'y'.
*
* Example:
*   R=Rotator(nu=14, phase=0)
*   ...
*   DR=Derotator(rotator=R)
*   AT (0,0,0) RELATIVE R
*
* %Parameters
* INPUT PARAMETERS:
* nu:       [Hz] Rotation frequency (round/s) in the rotating option (vertical axis)
* phase:   [deg] Phase shift
* direction: [1] Rotation axis selection 1=x, 2=y, 3=z
*
* CALCULATED PARAMETERS:
* angle: [deg]  rotation angle 
*
* %End
*******************************************************************************/

DEFINE COMPONENT Rotator

SETTING PARAMETERS (nu=0, phase=0, int direction=2)

/* Neutron parameters: (x,y,z,vx,vy,vz,t,sx,sy,sz,p) */

USERVARS
%{
  Rotation Rot;
%}

DECLARE
%{
  char rot_var[20];
%}

INITIALIZE
%{

  if (direction <= 0 || direction > 3) {
    fprintf(stderr,"%s: Please indicate direction=1,2 or 3 (x,y or z)\n",NAME_CURRENT_COMP,direction);
    exit(-1);
  }

  /* Initialize uservar string */
  sprintf(rot_var,"Rot_%i",_comp->_index);
  
%}


TRACE
%{

if (nu != 0 || phase != 0) { /* rotate neutron w/r to position of component */
    /* approximation of rotating frame */
    /* current coordinates of neutron in centered static frame */
    double dt=0;
    double angle;
    Rotation R;

    dt     = -z/vz; /* time shift to center of component */
    angle  = fmod(360*nu*(t+dt)+phase, 360); /* in deg */
    double rx=0,ry=0,rz=0;
    /* will rotate neutron instead of comp: negative side */
    if (direction==1) {
      rx=-angle*DEG2RAD;
    }
    else if (direction==2) {
      ry=-angle*DEG2RAD;
    }
    else if (direction==3) {
      rz=-angle*DEG2RAD;
    }
      
    rot_set_rotation(R, rx, ry, rz); 
    /* apply rotation to centered coordinates */
    Coords tmp = coords_set(x,y,z);
    coords_get(rot_apply(R, tmp),    &x, &y, &z);
    /* rotate speed */
    tmp = coords_set(vx,vy,vz);
    coords_get(rot_apply(R, tmp), &vx, &vy, &vz);
    particle_setvar_void(_particle, rot_var, &(R));
  }

%}


MCDISPLAY
%{
  int ih;


   if (nu || phase) {
      double radius = 0.1;
      /* cylinder to visualise the rotating frame */
      circle("xz", 0, 0, 0,radius);
    }
%}

END