RE: problem when reading source from a file

From: Francesco Cerutti <Francesco.Cerutti_at_cern.ch>
Date: Mon, 5 Jul 2010 17:14:17 +0200

Dear Yuanjie,

I would like to add to the Alberto's remarks that in fact the correct way
of taking primary particles from an external file, implies to load all the
file content at initialization level (leaving your READ instruction where
it was, but putting it inside a DO cycle looping over all the file lines)
and then, event by event, to sample from the particle arrays built this
way (X(N),Y(N),Z(N),PX(N),PY(N),PZ(N)), i.e. to randomly choose a particle
I in the range 1 to N (with N=1000000 in your case) and select the
corresponding values X(I),Y(I),Z(I),PX(I),PY(I),PZ(I).
This, in addition to allowing for restarting a run from an available
random seed (useful in case of crash for debugging purposes), mainly
assures to have a proper sampling, even if the simulated histories are
less (or more) than the particles in the file. Otherwise you start every
cycle from the same particle (and take always the first M, being M<N the
number of histories requested in the START card)

Cheers

Francesco

**************************************************
Francesco Cerutti
CERN-EN/STI
CH-1211 Geneva 23
Switzerland
tel. ++41 22 7678962
fax ++41 22 7668854

On Thu, 1 Jul 2010, Fasso, Alberto wrote:

> Dear Yuanjie,
>
> all the statements located between IF(LFIRST) and END IF (*** User initializatio
> n ***) are executed
> only once, the first time the source routine is called.
> Move READ(98,*) X,Y,Z,PX,PY,PZ after the user initialization, i.e. af
> ter the END IF.
>
> Apart from that, three remarks:
>
> 1) XBEAM=X/10
> YBEAM=Y/10
> ZBEAM=Z/10
> 10 is an integer, you shoud use a double precision number:
> XBEAM=X/10.D0
> YBEAM=Y/10.D0
> ZBEAM=Z/10.D0
>
> 2) SQRT(PX*PX+PY*PY+PZ*PZ) : this expression, used several times, contains a sq
> uare root which is very expensive in CPU time. Probably the compiler optimizer will take c
> are of evaluating it only once, but it is better to do that yourself:
> TEMP = SQRT(PX*PX+PY*PY+PZ*PZ)
> UBEAM = PX/TEMP
> VBEAM = PY/TEMP
> WBEAM = PZ/TEMP
>
> 3) PBEAM=SQRT(PX*PX+PY*PY+PZ*PZ)* AM (IONID)
> Why the multiplication by AM (IONID)? The momentum is just the vectorial s
> um of PX, PY, PZ
>
> Alberto
> ________________________________________
>> From: owner-fluka-discuss_at_mi.infn.it [owner-fluka-discuss_at_mi.infn.it] On Behalf
>> Of ?????? [biyuanjie_at_tsinghua.org.cn]
>> Sent: Tuesday, June 29, 2010 7:30 PM
>> To: fluka-discuss_at_fluka.org
>> Subject: problem when reading source from a file
>>
>> Dear everyone
>>
>> I read in the source from a file which includes 1e6 particles.
>> I do the following in source.f :
>>
>> * | *** User initialization ***
>> OPEN(98,FILE='../loss.txt',STATUS='OLD',FORM='FORMATTED')
>> READ(98,*) X,Y,Z,PX,PY,PZ
>> *
>> ...................
>>
>> *... to this point: don't change anything
>> XBEAM=X/10
>>
>> YBEAM=Y/10
>>
>> ZBEAM=Z/10
>>
>>
>> UBEAM=PX/SQRT(PX*PX+PY*PY+PZ*PZ)
>>
>> VBEAM=PY/SQRT(PX*PX+PY*PY+PZ*PZ)
>>
>> WBEAM=PZ/SQRT(PX*PX+PY*PY+PZ*PZ)
>>
>>
>> PBEAM=SQRT(PX*PX+PY*PY+PZ*PZ)* AM (IONID)
>>
>> Now the question is:
>> Everytime when calling source.f, only the first line in loss.txt is readed in.
>> How could I solve it?
>> Thanks very much!
>
>> Best wishes
>> Yuanjie
>
>
>
Received on Mon Jul 05 2010 - 17:50:03 CEST

This archive was generated by hypermail 2.2.0 : Mon Jul 05 2010 - 17:50:09 CEST