Inter-component transformations - Bender

Philipp Bernhardt bernhard at amos.krist.uni-erlangen.de
Fri Feb 12 11:01:05 CET 1999


Hi Kristian,

Sorry for answering so late. Thanks for your help. I have changed the
TOF-monitor component and now everything works fine. 

I have included a new bender-version, which is a little bit shorter, has
more explanations and
accepts also benders, where it is possible for neutrons to pass without a
reflection. There are also two pictures (xfig-format) to show the
geometry. (Input.fig shows the input-variables and variab.fig shows
variables, which are used by the programme). 

 - Philipp

---------------------------
Philipp Bernhardt
Lehrstuhl für Kristallographie und Strukturphysik
email: philipp.bernhardt at krist.uni-erlangen.de



-------------- next part --------------
/*******************************************************************************
*
* Component: Bender
*
* Written by: Philipp Bernhardt, Februar 7 1999
*
* Models a curved neutron guide. The entrance lies in the X-Y plane, centered 
* on the Z axis. The neutrons will also leave the bender in the X-Y plane at 
* the z-value r*Win, so you do not have to calculate the real exit coordinates 
* and you do not need a new arm. The bender is bent to the negative X axis; 
* it behaves like a parallel guide in the Y axis.
* There is no warning, if the input parameters are wrong, so please make sure 
* that
*   w,h,r,d,Win,k are positive numbers and 
*   k*d is smaller than the width w.
*
* INPUT PARAMETERS:
*
* w:       (m)          Width at the bender entry and exit
* h:       (m)          Height at the bender entry and exit
* r:       (m)          Radius of the bender
* d:       (m)          Thickness of the partition, which separates the channels
* Win:     (rad)        Angle of the deflection of the whole bender 
* k:       (1)          Number of channels inside the bender
* R0a,Qca,alphaa,ma,Wa: Parameters, which are describing the mirror at concave 
*                       side of the bender
* R0i,Qci,alphai,mi,Wi: Parameters, which are describing the mirror at convex 
*                       side of the bender
* R0s,Qcs,alphas,ms,Ws: Parameters, which are describing the mirror at the top 
*                       and bottom side of the bender 
*
* Example values: w=0.05 h=0.12 r=250 d=0.001 Win=0.04 k=3 ma=3 mi=2 ms=2
*******************************************************************************/
 
DEFINE COMPONENT Bender
DEFINITION PARAMETERS (w,h,r,d,Win,k,R0a,Qca,alphaa,ma,Wa,R0i,Qci,alphai,mi,Wi,R0s,Qcs,alphas,ms,Ws)
SETTING PARAMETERS ()
OUTPUT PARAMETERS ()
STATE PARAMETERS (x, y, z, vx, vy, vz, t, s1, s2, p)

DECLARE
 %{
      double bk; 

      #ifndef BENDER_DECLARE
         #define BENDER_DECLARE
         double sgn(double x) {
            if (x>=0)
               return 1.0;
            else
               return -1.0; } 
      #endif
 %}

INITIALIZE
 %{
      /* width of one channel + thickness d of partition */
      bk=(w+d)/k; 
 %}

TRACE
 %{
      int i,num,numa,numi;
      double dru,ab,dab,R,Q,arg,arga,argi,Ta,vpl;
      double einwin,auswin,zykwin,aeuwin,innwin,ref,innref,aeuref;
      double einzei,auszei,zykzei;

      /* does the neutron hit the bender at the entrance? */
      PROP_Z0;
      if ((fabs(x)>w/2) || (fabs(y)>h/2))    
         ABSORB;



      /*** reflections in the XZ-plane ***/

      /* distance between neutron and concave side of the channel at the entrance */ 
      dru=floor((w/2-x)/bk)*bk;          
      ab=w/2.0-x-dru;                        

      /* radius of the channel */
      R=r-dru;                            

      /* does the neutron hit the partition at the entrance? */
      if (ab>bk-d)  
         ABSORB; 

      /* velocity in the XZ-plane */
      vpl=sqrt(vx*vx+vz*vz);

      /* divergence of the neutron at the entrance */
      einwin=atan(vx/vz); 	

      /* maximal distance between neutron and concave side of the channel */
      dab=R-cos(einwin)*(R-ab);       

      /* reflection angle at the concave side */ 
      aeuwin=acos((R-dab)/R); 
                         
      /* reflection coefficient at the concave side */
      arga=0.0;
      Q=2.0*V2K*vpl*sin(aeuwin); 
      if (Q<=Qca) 
         aeuref=R0a;
      else {
         arga=(Q-ma*Qca)/Wa;
         aeuref=0.5*R0a*(1.0-tanh(arga))*(1.0-alphaa*(Q-Qca)); }  

      /* does the neutron hit the convex side of the channel? */
      innwin=0.0;
      innref=1.0;
      argi=0.0;
      if (dab>bk-d) {              

         /* reflection coefficient at the convex side */ 
         innwin=acos((R-dab)/(R-bk+d));        
         Q=2.0*V2K*vpl*sin(innwin);
         if (Q<=Qci) 
            innref=R0i;
         else {
            argi=(Q-mi*Qci)/Wi;
            innref=0.5*R0i*(1.0-tanh(argi))*(1.0-alphai*(Q-Qci)); } }    
    
      /* divergence of the neutron at the exit */
      zykwin=2.0*(aeuwin-innwin);
      auswin=fmod(Win+einwin+aeuwin-innwin*(1.0+sgn(einwin)),zykwin)-zykwin/2.0;
      auswin+=innwin*sgn(auswin);
 
      /* number of reflections at the concave side */
      numa=(Win+einwin+aeuwin-innwin*(1.0+sgn(einwin)))/zykwin;

      /* number of reflections at the convex side */ 
      numi=numa;
      if (auswin*einwin<0) {
         if (auswin-einwin>0) 
            numi++;            
         else
            numi--; }
 
      /* is the reflection coefficient too small? */
      if (((numa>0) && (arga>10.0)) || ((numi>0) && (argi>10.0)))
         ABSORB;

      /* calculation of the neutron probability weight p */
      for (i=1;i<=numa;i++)
          p*=aeuref;
      for (i=1;i<=numi;i++)
          p*=innref;

      /* time to cross the bender */
      Ta=(2*numa*(tan(aeuwin)-tan(innwin))+tan(auswin)-tan(einwin)-tan(innwin)*
         (sgn(auswin)-sgn(einwin)))*(R-dab)/vpl;
      t+=Ta;

      /* distance between neutron and concave side of channel at the exit */
      ab=R-(R-dab)/cos(auswin);      

      /* calculation of the exit coordinates in the XZ-plane */
      x=w/2.0-ab-dru;
      z=r*Win;
      vx=sin(auswin)*vpl;
      vz=cos(auswin)*vpl;



      /*** reflections at top and bottom side (Y axis) ***/ 

      if (vy!=0.0) {

         /* reflection coefficent at the top and bottom side */
         Q=2.0*V2K*fabs(vy);
         if (Q<=Qcs) 
            ref=R0s;
         else {
            arg=(Q-ms*Qcs)/Ws;
            ref=0.5*R0s*(1.0-tanh(arg))*(1.0-alphas*(Q-Qcs)); }          

         /* number of reflections at top and bottom */
         einzei=h/2.0/fabs(vy)+y/vy; 
         zykzei=h/fabs(vy);
         num=(Ta+einzei)/zykzei;

         /* time between the last reflection and the exit */
         auszei=fmod(Ta+einzei,zykzei);

         /* is the reflection coefficient too small? */ 
         if ((num>0) && (arg>10.0))
            ABSORB;

         /* calculation of the probability weight p */
         for (i=1;i<=num;i++) {             
              p*=ref;
              vy*=-1.0; }

         /* calculation of the exit coordinate */
         y=auszei*vy-vy*h/fabs(vy)/2.0; }

 %}

END


-------------- next part --------------
#FIG 3.2
Landscape
Center
Metric
A4      
100.00
Single
-2
1200 2
5 1 0 2 0 7 0 0 -1 0.000 0 0 0 0 4050.000 5700.000 900 2700 4050 1350 7200 2700
5 1 0 2 0 7 0 0 -1 0.000 0 0 0 0 4034.255 6078.912 1890 3705 4050 2880 6195 3720
5 1 0 1 0 7 0 0 -1 0.000 0 0 1 1 4055.600 5777.681 3735 5550 4035 5385 4365 5535
	1 1 1.00 60.00 120.00
	1 1 1.00 60.00 120.00
5 1 0 1 0 7 0 0 -1 0.000 0 0 0 0 4012.742 5763.083 1560 3375 4050 2340 6480 3390
5 1 0 1 0 7 0 0 -1 0.000 0 0 0 0 4013.279 5712.100 1515 3315 4050 2250 6540 3345
5 1 0 1 0 7 0 0 -1 0.000 0 0 0 0 4042.494 5855.371 1230 3060 4050 1890 6840 3045
5 1 0 1 0 7 0 0 -1 0.000 0 0 0 0 4035.000 5784.281 1185 3000 4050 1800 6885 3000
2 2 0 2 0 7 0 0 -1 0.000 0 0 -1 0 0 5
	 450 450 7650 450 7650 6300 450 6300 450 450
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 1 1 2
	1 1 1.00 60.00 120.00
	1 1 1.00 60.00 120.00
	 4050 5850 5055 1470
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 1 1 2
	1 1 1.00 60.00 120.00
	1 1 1.00 60.00 120.00
	 2310 1740 2880 3090
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 0 0 3
	 1845 2580 1350 4485 2145 2910
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 0 0 2
	 1440 2250 1350 4470
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 0 0 3
	 900 2715 4050 5865 7200 2715
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 0 0 3
	 6465 2670 6750 1665 6150 3045
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 0 0 3
	 3330 1845 3390 3660 3555 2250
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 0 0 2
	 3735 2880 3405 3615
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 0 0 3
	 5265 2835 5760 1305 5625 2430
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 0 0 2
	 5850 1980 5760 1305
2 1 0 2 0 7 0 0 -1 0.000 0 0 -1 0 0 2
	 1162 3007 1229 3074
4 0 0 0 0 0 12 0.0000 4 90 135 2445 1980 w\001
4 0 0 0 0 0 12 0.0000 4 135 315 3675 5370 Win\001
4 0 0 0 0 0 12 0.0000 4 90 60 4575 3990 r\001
4 0 0 0 0 0 12 0.0000 4 135 1650 5760 5760 k: number of channels\001
4 0 0 0 0 0 12 0.0000 4 180 645 5760 5400 h: height\001
4 0 0 0 0 0 12 0.0000 4 180 1290 3420 6630 Input parameters\001
4 0 0 0 0 0 12 0.0000 4 135 990 900 4770 concave side\001
4 0 0 0 0 0 12 0.0000 4 135 900 2940 3870 convex side\001
4 0 0 0 0 0 12 0.0000 4 135 675 5445 1125 channels\001
4 0 0 0 0 0 12 0.0000 4 135 540 3825 900 Bender\001
4 0 0 0 0 0 12 0.0000 4 135 90 1058 3218 d\001
4 0 0 0 0 0 12 0.0000 4 180 720 6465 1530 partitions\001

-------------- next part --------------
#FIG 3.2
Landscape
Center
Metric
A4      
100.00
Single
-2
1200 2
5 1 0 2 0 7 0 0 -1 0.000 0 0 0 0 4050.000 5700.000 900 2700 4050 1350 7200 2700
5 1 0 2 0 7 0 0 -1 0.000 0 0 0 0 4034.255 6078.912 1890 3705 4050 2880 6195 3720
5 1 0 1 0 7 0 0 -1 0.000 0 0 0 0 4012.742 5763.083 1560 3375 4050 2340 6480 3390
5 1 0 1 0 7 0 0 -1 0.000 0 0 0 0 4013.279 5712.100 1515 3315 4050 2250 6540 3345
5 1 0 1 0 7 0 0 -1 0.000 0 0 0 0 4042.494 5855.371 1230 3060 4050 1890 6840 3045
5 1 0 1 0 7 0 0 -1 0.000 0 0 0 0 4035.000 5784.281 1185 3000 4050 1800 6885 3000
5 1 0 1 0 7 0 0 -1 0.000 0 0 0 0 2112.500 2500.833 2160 2385 2235 2475 2220 2565
5 1 0 1 0 7 0 0 -1 0.000 0 0 0 0 4081.428 5172.143 3915 5025 4080 4950 4260 5040
5 1 0 1 0 7 0 0 -1 0.000 0 0 0 0 5906.786 2711.786 5940 2655 5970 2730 5925 2775
2 2 0 2 0 7 0 0 -1 0.000 0 0 -1 0 0 5
	 450 450 7650 450 7650 6300 450 6300 450 450
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 0 0 3
	 900 2715 4050 5865 7200 2715
2 1 0 2 0 7 0 0 -1 0.000 0 0 -1 0 0 9
	 1395 3240 1815 2595 2620 2540 3345 1942 4140 2250 5040 2025
	 5580 2610 6390 2655 6615 3285
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 0 0 3
	 3352 1965 4050 5850 5032 2025
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 0 0 2
	 1680 2970 1110 3525
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 0 0 2
	 6435 3120 6840 3510
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 0 0 3
	 1500 3945 1605 3015 1605 3000
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 0 0 2
	 6495 3135 6450 4080
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 0 0 2
	 5835 2730 5700 2880
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 0 0 2
	 2280 2940 2085 2505
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 0 0 2
	 4095 4545 4095 5100
2 1 0 2 0 7 0 0 -1 0.000 0 0 -1 0 0 2
	 1240 3079 1396 3231
2 1 0 2 0 7 0 0 -1 0.000 0 0 -1 0 0 2
	 3795 1335 3810 1620
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 0 0 2
	 1725 1410 2940 2280
2 1 0 1 0 7 0 0 -1 0.000 0 0 -1 0 0 2
	 4725 1605 5655 1035
2 1 0 2 0 7 0 0 -1 0.000 0 0 -1 0 0 4
	 1080 2895 2317 1717 5340 1560 7005 2910
4 0 0 0 0 0 12 0.0000 4 180 540 3855 4410 zykwin\001
4 0 0 0 0 0 12 0.0000 4 135 495 5490 3075 innwin\001
4 0 0 0 0 0 12 0.0000 4 135 495 1245 4230 einwin\001
4 0 0 0 0 0 12 0.0000 4 135 540 6210 4320 auswin\001
4 0 0 0 0 0 12 0.0000 4 135 690 3660 6570 variables\001
4 0 0 0 0 0 12 0.0000 4 135 180 1117 3300 ab\001
4 0 0 0 0 0 12 0.0000 4 135 285 7185 4200 exit\001
4 0 0 0 0 0 12 0.0000 4 105 660 480 3945 entrance\001
4 0 0 0 0 0 12 0.0000 4 135 270 3870 1552 dab\001
4 0 0 0 0 0 12 0.0000 4 180 1380 5820 1080 garland-reflection\001
4 0 0 0 0 0 12 0.0000 4 135 1545 705 1245 zick-zack reflection\001
4 0 0 0 0 0 12 0.0000 4 135 540 2340 3000 aeuwin\001



More information about the mcstas-users mailing list