File: Source_pulsed.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 (287 lines) | stat: -rw-r--r-- 11,760 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*******************************************************************************
*
* Mcstas, neutron ray-tracing package
*         Copyright (C) 1997-2020, All rights reserved
*         DTU Physics, Kongens Lyngby, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Component: Source_pulsed
*
* %I
* Written by: Klaus Lieutenant, based on component 'Moderator' by K. Nielsen, M. Hagen and 'ESS_moderator_long_2001' by K. Lefmann
* Date  : Aug 2020
* Origin: FZ Juelich
*
* A pulsed source for variable proton pulse lenghts 
*
* %D
* Produces a long pulse spectrum with a wavelength distribution as a sum of up to 3 Maxwellian distributions and one of undermoderated neutrons
*
* It uses the time dependence of long pulses. Short pulses can, however, also be simulated by setting the proton pulse short.  
*
* If moderator width and height are given, it assumes a rectangular moderator, and otherwise a circular
*
* Usage example: 
*   Source_pulsed(xwidth=0.04, yheight=0.04, Lmin=1.0, Lmax=3.0, t_min=0.0, t_max=0.5, dist=0.700, focus_xw=0.020, focus_yh=0.020,
*                 freq=96.0, t_pulse=0.000208, T1=325.0, I1=7.6e09, tau1=0.000170, I_um=2.7e08, chi_um=2.5)
*
* Parameters for some sources:
*   HBS thermal source: xwidth=0.04, yheight=0.04, T1=325.0, I1=0.68e+12/freq, tau1=0.000125, n_mod=10, I_um=2.47e+10/freq, chi_um=2.5, t_pulse=0.016/freq, freq=96.0 or 24.0  
*   HBS cold source   : radius=0.010,              T1= 60.0, I1=1.75e+12/freq, tau2=0.000170, n_mod= 5, I_um=3.82e+10/freq, chi_um=0.9, t_pulse=0.016/freq, freq=24.0 or 96.0
*   HBS bi-spectral   : radius=0.022, r_i=0.010,   T1= 60.0, I1=1.75e+12/freq, tau2=0.000170,                                 
*                                                  T2=305.0, I2=0.56e+12/freq, tau1=0.000130, n_mod= 5, I_um=3.82e+10/freq, chi_um=2.5, t_pulse=0.016/freq, freq=24.0 or 96.0
*
* %P
* Input parameters:
*
* xwidth:         [m]        Width of the source
* yheight:        [m]        Height of the source
* radius:         [m]        Outer radius of the source
* r_i:            [m]        Radius of a central circle that is sorrounded by a ring of different temperature
* Lmin:           [Ang]      Lower edge of the wavelength distribution
* Lmax:           [Ang]      Upper edge of the wavelength distribution
* t_min:          [s]        Lower edge of the time interval
* t_max:          [s]        Upper edge of the time interval
* target_index:   [1]        relative index of component to focus at, e.g. next is +1 this is used to compute 'dist' automatically.
* dist:           [m]        Distance from the source to the target
* focus_xw:       [m]        Width  of the target (= focusing rectangle)
* focus_yh:       [m]        Height of the target (= focusing rectangle)
* freq:           [Hz]       Frequency of pulses
* t_pulse:        [s]        Proton pulse length
* T1:             [K]        Temperature of the 1st Maxwellian distribution, for r_i > 0 only for radii r in the range 0 < r < r_i
* I1:       [1/(cm**2*sr)]   Flux per solid angle of the 1st Maxwellian distribution (integrated over the whole wavelength range).
* tau1:           [s]        Pulse decay constant of the 1st Maxwellian distribution
* T2:             [K]        Temperature of the 2nd Maxwellian distribution, 0=none, for r_i > 0 only for radii r in the range r_i < r < radius
* I2:       [1/(cm**2*sr)]   Flux per solid angle of the 2nd Maxwellian distribution
* tau2:           [s]        Pulse decay constant of the 2nd Maxwellian distribution
* T3:             [K]        Temperature of the 3rd Maxwellian distribution, 0=none
* I3:       [1/(cm**2*sr)]   Flux per solid angle of the 3rd Maxwellian distribution
* tau3:           [s]        Pulse decay constant of the 3rd Maxwellian distribution
* n_mod:          [1]        Ratio of pulse decay constant to pulse ascend constant of moderated neutrons
* I_um:     [1/(cm**2*sr)]   Flux per solid angle for the under-moderated neutrons
* tau_um:         [s]        Pulse decay constant of under-moderated neutrons
* n_um:           [1]        Ratio of pulse decay constant to pulse ascend constant of under-moderated neutrons
* chi_um:       [1/Ang]      Factor for the wavelength dependence of under-moderated neutrons
* kap_um:         [1]        Scaling factor for the flux of under-moderated neutrons
*
* %E
*******************************************************************************/

DEFINE COMPONENT Source_pulsed

SETTING PARAMETERS (xwidth=0.0, yheight=0.0, radius=0.010, r_i=0.0,  
                    Lmin, Lmax, t_min=0.0, t_max=0.001, 
                    int target_index=1, dist=0.0, focus_xw=0.02, focus_yh=0.02, freq, t_pulse,  
                    T1=0.0, I1=0.0, tau1=0.000125,  T2=0.0, I2=0.0, tau2=0.0,  T3=0.0, I3=0.0, tau3=0.0,  n_mod=10,
                    I_um=0.0, tau_um=0.000012, n_um=5, chi_um=2.5, kap_um=2.2)

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


SHARE
%{
  /* Normalized Maxwellian distribution*/
  #pragma acc routine
  double Maxwell(double lmbd, double temp)
  {
    double a, M=0.0;

    if (temp > 0.0 && lmbd > 0.0)
    { a = 949.29/temp;
      M = 2.0*a*a*exp(-a/(lmbd*lmbd))/pow(lmbd,5);
    }
    return M;
  }

  /* distribution of under-moderated neutrons */
  #pragma acc routine
  double Mezei_N_fct(double lmbd, double chi, double kappa)
  {
    if (lmbd > 0.0)
      return 1.0 / (1.0 + exp(chi*lmbd-kappa)) / lmbd;
    else 
      return 0.0;
  }

  /* integral of the short pulse function */
  #pragma acc routine
  double Mezei_i_fct(double time, double tau, double n)
  {
    if (n > 1.0 && tau > 0.0)
      return (exp(-time/(tau/n)) - n*exp(-time/tau)) / (n-1);
    else
      return 0.0;
  }

  /* Normalized long pulse function */
  #pragma acc routine
  double Mezei_I_fct(double time, double tau, double n, double length)
  {
    if (time <= 0.0  || tau <= 0.0 || n <= 1.0 || length <= 0.0)
      return 0.0;
    else if (time <= length)
      return (Mezei_i_fct(time, tau, n)+1.0) / length;
    else
      return (  Mezei_i_fct(time,        tau, n)
              - Mezei_i_fct(time-length, tau, n)) / length;
  }
%}


DECLARE
%{
  double area;      /*   [cm^2]  moderator surface area    */
  double t_period;  /*    [s]    period of the pulse cycle */
  double alpha;     /*    [1]    duty cycle                */
  double p_in;      /* [1/Ang/s] flux normalisation factor */
%}


INITIALIZE
%{
  /* check of the input parameters */
  if (   xwidth < 0.0 ||  yheight  < 0.0 ||   radius < 0.0 ||    r_i < 0.0 ||   Lmin < 0.0 ||  Lmax < 0.0
      ||  dist  < 0.0 || focus_xw  < 0.0 || focus_yh < 0.0 ||   freq < 0.0 || t_pulse < 0.0 
      ||     T1 < 0.0 ||        I1 < 0.0 ||     tau1 < 0.0 ||     T2 < 0.0 ||      I2 < 0.0
      ||   tau2 < 0.0 ||        T3 < 0.0 ||       I3 < 0.0 ||   tau3 < 0.0 ||   n_mod < 0.0 
      ||   I_um < 0.0 ||    tau_um < 0.0 ||     n_um < 0.0 || chi_um < 0.0 ||  kap_um < 0.0)
  {
      printf("Source_pulsed: %s: Error: negative input parameter!\n"
             "ERROR          Exiting\n",           NAME_CURRENT_COMP);
      exit(-1);
  }
  if (Lmax <= Lmin || t_max <= t_min)
  {
      printf("Source_pulsed: %s: Error: wavelength or time parameters do not match!\nERROR          Exiting\n", NAME_CURRENT_COMP);
      exit(-1);
  }

  /* automatic distance */
  if (target_index > 0 && dist==0.0)
  {
    Coords ToTarget;
    double tx,ty,tz;
    ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP);
    ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget);
    coords_get(ToTarget, &tx, &ty, &tz);
    dist=sqrt(tx*tx+ty*ty+tz*tz);
  }

  /* pulse parameters */
  t_period = 1.0/freq;
  alpha    = t_pulse / t_period;

  /* area for different moderator shapes */
  if (xwidth > 0.0 && yheight > 0.0)
  { 
    area  = 10000.0 * xwidth * yheight;
  }
  else if (radius > 0.0)
  {
    area  = 10000.0 * PI*radius*radius;
  }
  else
  {
    printf("Source_pulsed: %s: Error: wavelength or time parameters do not match!\nERROR          Exiting\n", NAME_CURRENT_COMP);
    exit(-1);
  }
  p_in = (Lmax - Lmin) * (t_max - t_min) / mcget_ncount();   
%}


TRACE
%{
  double phi,    /* [rad]  orientation of the starting point for a spherical moderator */
         r,      /*  [m]   distance of the starting point from moderator center */
         v,      /* [m/s]  speed of the neutron      */
         time,   /*  [s]   */
         lambda, /* [Ang]  wavelength of the neutron */
         xf,     /*  [m]   horizontal position on the target */
         yf,     /*  [m]   vertical position on the target   */
         rf,     /*  [m]   distance between point on moderator and point on target   */
         dx,     /*  [m]   horizontal shift from moderator to target */
         dy,     /*  [m]   vertical shift from moderator to target   */
         Omega,  /* [sr]   solid angle of the target                 */
         flux;   /* [1/(cm^2 s Ang sr]  flux(lambda,time)               */

  /* Choose the starting point on the moderator surface with uniform distribution for different moderator shapes */
  if (xwidth > 0.0 && yheight > 0.0)
  { 
    x = xwidth* (rand01() - 0.5);
    y = yheight*(rand01() - 0.5);
  }
  else
  { phi = 2*PI*rand01();          
    r = sqrt(rand01())*radius; 
    x = r*cos(phi);
    y = r*sin(phi);
  }
  z = 0.0;

  /* Set zero polarization, choose wavelength and starting time */
  sx = 0.0;
  sy = 0.0;
  sz = 0.0;

  lambda = Lmin  + (Lmax  - Lmin)  * rand01();     
  t      = t_min + (t_max - t_min) * rand01(); 
  
  /* Propagate to target */
  randvec_target_rect_real(&xf, &yf, &rf, &Omega,
                           0, 0, dist, focus_xw, focus_yh, ROT_A_CURRENT_COMP, x, y, z, 2);

  /* Length of the flight path */
  dx = xf - x;
  dy = yf - y;
  rf = sqrt(dx*dx + dy*dy + dist*dist);

  /* speed of the neutron */
  v  = 3956.0346 / lambda;
  vx = v*dx/rf;
  vy = v*dy/rf;
  vz = v*dist/rf;

  /* Weight: flux in [1/(cm^2 s Ang sr] */
  flux = I_um * Mezei_N_fct(lambda, chi_um, kap_um) * Mezei_I_fct(t, tau_um, n_um,  t_pulse);
  if (r_i==0.0 || r <= r_i)
    flux += I1 * Maxwell(lambda, T1) * Mezei_I_fct(t, tau1,   n_mod, t_pulse); 
  if (r_i==0.0 || r > r_i)
    flux += I2 * Maxwell(lambda, T2) * Mezei_I_fct(t, tau2,   n_mod, t_pulse); 
  flux  +=  I3 * Maxwell(lambda, T3) * Mezei_I_fct(t, tau3,   n_mod, t_pulse);

  p  = flux * area* Omega * p_in;   /*  [1]   neutrons per pulse       */
  p /= t_period;                    /* [1/s]  time averaged intensity  */

  SCATTER;
%}


MCDISPLAY
%{
  double edge;    /* [m]  x and y position on the circle */

  if (dist > 0.0) 
  {
    if (xwidth > 0.0 && yheight > 0.0) 
    {
      rectangle("xy", 0,0,0, xwidth,yheight);
      dashed_line(-xwidth/2, -yheight/2, 0, -focus_xw/2,-focus_yh/2, dist, 4);
      dashed_line( xwidth/2, -yheight/2, 0,  focus_xw/2,-focus_yh/2, dist, 4);
      dashed_line( xwidth/2,  yheight/2, 0,  focus_xw/2, focus_yh/2, dist, 4);
      dashed_line(-xwidth/2,  yheight/2, 0, -focus_xw/2, focus_yh/2, dist, 4);
    }
    else
    {
      circle("xy", 0,0,0, radius);
      if (r_i > 0.0)
        circle("xy", 0,0,0, r_i);
      edge = radius/sqrt(2.0);
      dashed_line(-edge, -edge, 0, -focus_xw/2,-focus_yh/2, dist, 4);
      dashed_line( edge, -edge, 0,  focus_xw/2,-focus_yh/2, dist, 4);
      dashed_line( edge,  edge, 0,  focus_xw/2, focus_yh/2, dist, 4);
      dashed_line(-edge,  edge, 0, -focus_xw/2, focus_yh/2, dist, 4);
    }
  }
%}

END