Re: FLUKA: Source file
Dear Yann,
you must write a SOURCE routine, compile it with the fff script,
linking it with lfluka, and put a SOURCE command in your input.
(See chap. 22} in the Manual).
In the SOURCE subroutine, you must pick up randomly a point (x,y).
Let's call S your array:
DIMENSION S(-8:8,-6:6)
For a discrete distribution this is the simplest way:
IX = INT(FLRNDM(XX)*17.D0)
IY = INT(FLRNDM(YY)*13.D0)
give you two random integer numbers distributed uniformly
between 0 and 16, resp. 0 and 12. Your starting position will be:
X = DBLE(-8 + IX)
Y = DBLE(-6 + IY)
and you must assign to the particle a weight equal to
S(-8+IX,-6+IY)
But maybe you prefer having the same weight for all source particles.
We need to make a cumulative distribution: a 1-dimensional array
of dimensions 17*13+1=222. However, better set 0 as the lowest
value of the index:
DIMENSION CUMUL(0:221)
CUMUL(0) = 0.D0
N = 0
DO IX = -8, +8
DO IY = -6, +6
N = N + 1
CUMUL(N) = CUMUL(N) + S(IX,IY)
END DO
END DO
Now we normalize the cumulative distribution:
DO N = 0, 221
CUMUL(N) = CUMUL(N)/CUMUL(221)
END DO
Take a random number G and find the value of K
for which CUMUL(K-1) <= G < CUMUL(K):
G = FLRNDM(GG)
DO 1 N = 1, 221
IF(CUMUL(N) .GE. G) THEN
K = N
GO TO 2
END IF
1 CONTINUE
2 CONTINUE
Now get X and Y from K:
IY = MOD(K-1, 13) + 1
IX = (K - IY)/13 + 1
X = DBLE(-9+IX)
Y = DBLE(-7+IY)
So far we have sampled from a discrete distribution of 221 values.
It is possible also to sample from a continuous distribution,
making an interpolation between the nearest points. However,
this is easy in one dimension, but more complicated in two
dimensions (as it is in your case). Therefore, I leave it to you
as an exercise :-)
Best regards,
Alberto
On Thu, 13 Dec 2001, foucher wrote:
> Dear FLUKA users and authors,
>
> I would like to run an input file with a special beam profile.
> I would like to have a position dependant source as a function of x and
> y.
> For this I got a file of data which contains the probability of emission
> for each point.
> The format of this file is a matrix (17*13)
> The bin structure is -8 < x < 8 cm and the bin width is 1
> cm (17 values)
> -6 < y < 6 cm and the bin
> width is 1 cm (13 values)
>
> The sum over all the points is equal to 1.
> In attachment, you can find the probability of emission of each point.
> Is there anyone who could tell me how to this ?
> Thanks in advance
>
> Yann FOUCHER
> Paul Scherrer Institut
>
>
>
--
Alberto Fassò
CERN-EP/AIP, CH-1211 Geneve 23 (Switzerland)
Phone: (41 22) 767 2398 Fax: (41 22) 767 9480 Alberto.Fasso@cern.ch
Partial thread listing: