File: Pol_Bfield_stop.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 (121 lines) | stat: -rw-r--r-- 3,332 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
/**************************************************************************
*
* McStas, neutron ray-tracing package
*         Copyright 1997-2006, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Component: Pol_Bfield_stop
*
* %I
* Written by: Erik B Knudsen, Peter Christiansen, and Peter Willendrup
* Date: August 2006
* Origin: RISOE
*
* Magnetic field component.
*
* %D 
*
* End of magnetic field region defined by the latest preceeding Pol_Bfield component.
*
* The component is concentric. It means that it requires a 
*
* // START MAGNETIC FIELD
* COMPONENT msf =
* Pol_Bfield(xw=0.08, yh=0.08, length=0.2, Bx=0, By=-0.678332e-4, Bz=0)
*      AT (0, 0, 0) RELATIVE armMSF
*
* // HERE CAN BE OTHER COMPONENTS INSIDE THE MAGNETIC FIELD
*
* // STOP MAGNETIC FIELD
* COMPONENT msfCp = Pol_Bfield_stop()
*      AT ("SOMEWHERE") RELATIVE armMSF
*
* In between the two components the propagation routine
* PROP_DT also handles the spin propagation.
* The current algorithm used for spin propagation is:
* SimpleNumMagnetPrecession
* in pol-lib.
* and does not handle gravity.
*
* GRAVITY: NO
* POLARISATION: YES
*
* Example: Pol_Bfield_stop()
*
* %P
* INPUT PARAMETERS:
* geometry: [str] Name of an Object File Format (OFF) or PLY file for complex field-geometry.
* xwidth: [m]               Width of opening.
* yheight: [m]              Height of opening.
* zdepth: [m]               Length of field.
* radius: [m]               Radius of field if it is cylindrical or spherical.

*
* %E
****************************************************************************/

DEFINE COMPONENT Pol_Bfield_stop

SETTING PARAMETERS (string geometry="", yheight=0, xwidth=0, zdepth=0, radius=0)

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

SHARE
%{
  %include "pol-lib"
%}
DECLARE
%{
  int shape;
%}
INITIALIZE
%{
    enum shapes {NONE=0, BOX, WINDOW, CYLINDER, SPHERE, ANY};
    /*if a start component is given, and no geometry is set, inherent geometry from start comp.*/
    if(geometry && strlen(geometry)){
        shape=ANY;
    }else if(xwidth && yheight && zdepth){
        shape=BOX;
    }else if (xwidth && yheight && !zdepth){
        shape=WINDOW;
    }else if(radius && yheight){
        shape=CYLINDER;
    }else if (radius) {
        shape=SPHERE;
    }else{
        shape=NONE;
    }
%}

TRACE
%{
    double t0,t1;
    int nofield=0;
    enum shapes {NONE=0, BOX, WINDOW, CYLINDER, SPHERE, ANY};
    /*enter through whatever object we are*/
    switch (shape){
        case BOX:
            box_intersect(&t0,&t1,x,y,z,vx,vy,vz,xwidth,yheight,zdepth);
	    if (t0>FLT_EPSILON) PROP_DT(t0);/*this is to get a hollow inside the field.*/
            else PROP_DT(t1);
            break;
        case CYLINDER:
            cylinder_intersect(&t0,&t1,x,y,z,vx,vy,vz,radius,yheight);/*this is to get a hollow inside the field.*/
            if (t0>FLT_EPSILON) PROP_DT(t0);
            else PROP_DT(t1);
            break;
        case WINDOW:
            PROP_Z0;
            /*terminate neutrons which miss the exit window*/
            if (2*x>xwidth || 2*x<-xwidth || 2*y>yheight || 2*y<-yheight){
                ABSORB;
            }
            break;
        default:
            PROP_Z0;
    }
    mcmagnet_pop(_particle);
%}

END