File: multi_pipe.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 (361 lines) | stat: -rw-r--r-- 10,250 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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/*******************************************************************************
*
* McStas, neutron ray-tracing package
*         Copyright (C) 1997-2008, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Component: multi_pipe
*
* %I
* Written by: Uwe Filges
* Date: March, 2005
*
* multi pipe circular slit.
*
* %D
* No transmission around the slit is allowed.
*
* example for an input file
* # user defined geometry
* # x(i) y(i) r(i) [m]
*   0.02 0.03 0.01
*  -0.04 0.015 0.005
*
*  warning: at least two values must be in the file
*
* Example: multi_pipe(xmin=-0.01, xmax=0.01, ymin=-0.01, ymax=0.01)
*
* %P
* INPUT PARAMETERS
*
* radius: []       radius of a single hole
* xmin: [m]        Lower x bound 
* xmax: [m]        Upper x bound 
* ymin: [m]        Lower y bound 
* ymax: [m]        Upper y bound 
* xwidth: [m]      Width of slit plate. Overrides xmin,xmax. 
* yheight: [m]     Height of slit plate. Overrides ymin,ymax. 
* gap: [m]         distance between holes 
* thickness: [m]   thickness of the pipe 
* filename: [str]  define user table of holes 
*
* %E
*******************************************************************************/

DEFINE COMPONENT multi_pipe

SETTING PARAMETERS (string filename=0, xmin,xmax,ymin,ymax,radius=0.0,gap=0.0,thickness=0.0, xwidth=0, yheight=0)

/* Neutron parameters: (x,y,z,vx,vy,vz,t,sx,sy,sz,p) */
SHARE
%{
%include "read_table-lib"
%}

DECLARE
%{
t_Table pTable;
int user_file;
int ynum;
int xnum;
double diam;
double w_pipe;
double h_pipe;
int h_number;
%}


INITIALIZE
%{

char file_name[1024];
char *pos;
char *fu;
int  check;

if (xwidth  > 0) { xmax = xwidth/2;  xmin = -xmax; }
  if (yheight > 0) { ymax = yheight/2; ymin = -ymax; }

  if (xmin == 0 && xmax == 0 && ymin == 0 && ymax == 0 && radius == 0 && gap==0)
    { fprintf(stderr,"multi_pipe: %s: Error: give geometry\n", NAME_CURRENT_COMP); exit(-1); }
  user_file=0;
  if (filename != NULL) {
     fu=(char*)malloc(sizeof(char)*(strlen(filename)+1));
     strcpy(fu,filename);

     user_file=1;

     Table_Read(&pTable, fu, 1);  /* read 1st block data from file into pTable */
     if (pTable.rows < 2) Table_Free(&pTable);
     Table_Info(pTable);
     free(fu);

  } else {
    /* no user file is set */
    /* calculate the number of holes */
    diam=2*radius;
    w_pipe=xmax-xmin;
    h_pipe=ymax-ymin;
    xnum = (int) (w_pipe/(diam+gap));
    ynum = (int) (h_pipe/(diam+gap));
    h_number= xnum*ynum;
    fprintf(stderr,"multi_pipe-hole number: %d\n", h_number);
    user_file=2;
  }
%}

TRACE
%{
    int check1,check2;
    double test_pipes;
    double test_pipe2;
    double xl,yl,dt0;
    int i,ii;
    int valuex,valuey;
    int even_x,even_y;

    PROP_Z0;
    if (x<xmin || x>xmax || y<ymin || y>ymax) {
       /* neutrons outside of component */
       ABSORB;
    } else {
      if (user_file==1) {
         /*  use file data */
         if (pTable.data != NULL)
         {
             double uradius;

             check1=0;
             check2=0;

             for (i=0;i<pTable.rows;i++) {
                xl = Table_Index(pTable, i,   0); /* 1st column */
                yl = Table_Index(pTable, i,   1); /* 2nd column */
                uradius = Table_Index(pTable, i,   2); /* 3rd column */
                test_pipes=((x-xl)*(x-xl))+((y-yl)*(y-yl));
                if (test_pipes < (uradius*uradius)) {
                   check1=1;
                   if (thickness==0) {
                      /* nothing to do */
                   } else {
                      /* check if neutron absorb inside the component */
                      dt0=thickness/vz;
                      PROP_DT(dt0);
                      check2=0;
                      test_pipe2=((x-xl)*(x-xl))+((y-yl)*(y-yl));
                      if (test_pipe2 > (uradius*uradius)) {
                         check2=1;
                         ABSORB;
                      }

                   }
                   break;
                }
             }
         }
      } else if (user_file==2) {
         /* automatic generated holes */
         /* inside component - proof whether the neutrons come into a hole */
         valuex=0;
         even_x = (xnum % 2);
         /* check if xnum is odd or even */
         if (even_x==0) {
            valuex=1;
         } else {
            valuex=2;
         }
         valuey=0;
         even_y = (ynum % 2);
         /* check if ynum is odd or even */
         if (even_y==0) {
            /* even */
            valuey=1;
         } else {
            valuey=2;
         }
         test_pipes=0;
         check1=0;
         for(i=-(xnum/2);i<(xnum/2+1);i++)
         {
            /* calculate local coordiantes */
            if (valuex==1) {
               if (i==xnum/2) {
                  /* outside */
               } else {
                  xl=i*(diam+gap)+radius+gap/2.0;
               }
             } else {
               xl=i*(diam+gap);
             }
             /* fprintf(stderr,"xl: %f\n", xl); */
             for (ii=-(ynum/2);ii<(ynum/2+1);ii++)
             {
                if (valuey==1) {
                   if (ii==ynum/2) {
                      /* ouside */
                   } else {
                      yl=ii*(diam+gap)+radius+gap/2;
                      test_pipes=((x-xl)*(x-xl))+((y-yl)*(y-yl));
                      if (test_pipes < (radius*radius)) {
                         check1=1;
                         if (thickness==0) {
                            /* nothing to do */
                         } else {
                            /* check if neutron absorb inside the component */
                            dt0=thickness/vz;
                            PROP_DT(dt0);
                            check2=0;
                            test_pipe2=((x-xl)*(x-xl))+((y-yl)*(y-yl));
                            if (test_pipe2 > (radius*radius)) {
                               check2=1;
                               ABSORB;
                            }
                         }
                         break;
                      }
                   }
                } else {
                   yl=ii*(diam+gap);
                   test_pipes=((x-xl)*(x-xl))+((y-yl)*(y-yl));
                   if (test_pipes < (radius*radius)) {
                      check1=1;
                      if (thickness==0) {
                         /* nothing to do */
                      } else {
                         /* check if neutron absorb inside the component */
                         dt0=thickness/vz;
                         PROP_DT(dt0);
                         check2=0;
                         test_pipe2=((x-xl)*(x-xl))+((y-yl)*(y-yl));
                         if (test_pipe2 > (radius*radius)) {
                            check2=1;
                            ABSORB;
                         }
                      }
                      break;
                   }
                }
             }
         }
      }
      if (check1==1) {
         SCATTER;
      } else {
         ABSORB;
      }
   }
%}

FINALLY
%{
  Table_Free(&pTable);
%}

MCDISPLAY
%{
  int even_x,even_y;
  int valuex,valuey;
  double xl,yl;
  int i,ii;
  t_Table plot_table;
  double uradius;
  char *fu2;

  
  multiline(5,
            xmin, ymin, 0.0,
            xmax, ymin, 0.0,
            xmax, ymax, 0.0,
            xmin, ymax, 0.0,
            xmin, ymin, 0.0);
  if (thickness > 0) {
     multiline(5,
            xmin, ymin, (double)thickness,
            xmax, ymin, (double)thickness,
            xmax, ymax, (double)thickness,
            xmin, ymax, (double)thickness,
            xmin, ymin, (double)thickness);
     line(xmin, ymin, 0, xmin, ymin, (double)thickness);
     line(xmax, ymin, 0, xmax, ymin, (double)thickness);
     line(xmax, xmax, 0, xmax, ymax, (double)thickness);
     line(xmin, xmax, 0, xmin, ymax, (double)thickness);
  }

  if (user_file==1) {
     /* open user file */
      if (filename != NULL) {
         fu2=(char*)malloc(sizeof(char)*(strlen(filename)+1));
         strcpy(fu2,filename);
         Table_Read(&plot_table, fu2, 1);  /* read 1st block data from file into pTable */
         if (plot_table.rows < 2) Table_Free(&plot_table);
         Table_Info(plot_table);
         free(fu2);
          for (i=0;i<plot_table.rows;i++) {
             xl = Table_Index(plot_table, i,   0); /* 1st column */
             yl = Table_Index(plot_table, i,   1); /* 2nd column */
             uradius = Table_Index(plot_table, i,   2); /* 3rd column */
             circle("xy", xl, yl, 0, uradius);
             if (thickness > 0 ) {
               circle("xy", xl, yl, (double)thickness, uradius);
             }
          }
       }
     Table_Free(&plot_table);

   } else if (user_file==2) {
      valuex=0;
      even_x = (xnum % 2);
      /* check if xnum is odd or even */
      if (even_x==0) {
         valuex=1;
      } else {
         valuex=2;
      }
      valuey=0;
      even_y = (ynum % 2);
      /* check if ynum is odd or even */
      if (even_y==0) {
         /* even */
         valuey=1;
      } else {
         valuey=2;
      }
      for(i=-(xnum/2);i<(xnum/2+1);i++)
      {
         /* calculate local coordiantes */
         if (valuex==1) {
            if (i==xnum/2)
            {
               /* outside */
            } else {
              xl=i*(2*radius+gap)+radius+gap/2.0;
            }
          } else {
              xl=i*(2*radius+gap);
          }
          for (ii=-(ynum/2);ii<(ynum/2+1);ii++)
          {
             if (valuey==1) {
                if (ii==ynum/2) {
                   /* ouside */
                } else {
                   yl=ii*(2*radius+gap)+radius+gap/2;
                   circle("xy", xl, yl, 0, radius);
                   if (thickness > 0 ) {
                      circle("xy", xl, yl, (double)thickness, radius);
                   }
                }
             } else {
                yl=ii*(2*radius+gap);
                circle("xy", xl, yl, 0, radius);
                if (thickness > 0 ) {
                   circle("xy", xl, yl, (double)thickness, radius);
                }
             }
          }
      }
   }
%}

END