Re: [fluka-discuss]: Fw: Sampling direction cosines with SOURCE is buggy 5 times out of 10

From: Primidis, Thomas <Thomas.Primidis_at_liverpool.ac.uk>
Date: Thu, 31 Oct 2019 13:07:21 +0000

Dear Mario,


I removed the lines that check cx**2+cy**2+cz**2 .EQ. ONEONE and the code run fine and results appear as expected. So, either these lines were changing the values slightly which resulted to lost precision at the last decimal point or FLUKA is a bit flexible when it comes to accepting direction cosine values.


In short, just setting cz=SQRT(ONEONE-cx**2-cy**2) is enough. If after that you ask whether cx**2+cy**2+cz**2 .EQ. ONEONE, there is 50% chance you will get .FALSE. due to loss of precision at the 16th decimal point.


Best wishes,

Thomas

________________________________
From: Santana, Mario <msantana_at_slac.stanford.edu>
Sent: Wednesday, October 30, 2019 3:41:10 PM
To: Primidis, Thomas
Subject: Re: [fluka-discuss]: Fw: Sampling direction cosines with SOURCE is buggy 5 times out of 10

Hi Thomas,

If you send me the input file and user routine I could take a look.

-M

On Oct 29, 2019, at 2:09 AM, Primidis, Thomas <Thomas.Primidis_at_liverpool.ac.uk<mailto:Thomas.Primidis_at_liverpool.ac.uk>> wrote:


Hello Mario,

cz,cy,cz are double precision. I am using cx,cy,cz because I want to keep the original source.f code clean and have all my edits separate. So, at the end I can use a simple TXFLK{ NPFLKA} = CX etc.

My distributions are analytical, continuous functions.

Regards,
Thomas


________________________________
From: Primidis, Thomas
Sent: Tuesday, October 29, 2019 9:07 AM
To: Santana, Mario
Subject: Re: Sampling direction cosines with SOURCE is buggy 5 times out of 10

Hello Mario,

cz,cy,cz are double precision. I am using cx,cy,cz because I want to keep the original source.f code clean and have all my edits separate. So, at the end I can use a simple TXFLK{ NPFLKA} = CX etc.

My distributions are analytical, continuous functions.

Regards,
Thomas
________________________________
From: Santana, Mario <msantana_at_slac.stanford.edu<mailto:msantana_at_slac.stanford.edu>>
Sent: Tuesday, October 29, 2019 6:49:06 AM
To: Primidis, Thomas
Subject: Re: Sampling direction cosines with SOURCE is buggy 5 times out of 10

Hi Thomas,

What is the type of cx, cy, cz variables that you are using? DOUBLE PRECISION? why aren't you using T{X/Y/K}FLK variables if within the source.f routine? Also, what kind of distribution are you sampling?

-M
________________________________
From: owner-fluka-discuss_at_mi.infn.it<mailto:owner-fluka-discuss_at_mi.infn.it> <owner-fluka-discuss_at_mi.infn.it<mailto:owner-fluka-discuss_at_mi.infn.it>> on behalf of Primidis, Thomas <Thomas.Primidis_at_liverpool.ac.uk<mailto:Thomas.Primidis_at_liverpool.ac.uk>>
Sent: Monday, October 28, 2019 6:46 PM
To: fluka-discuss <fluka-discuss_at_fluka.org<mailto:fluka-discuss_at_fluka.org>>
Subject: [fluka-discuss]: Sampling direction cosines with SOURCE is buggy 5 times out of 10

Dear forum,

I am using source.f to describe an x-ray source. I am assigning x and y direction cosines and then I calculate z direction cosine by cz=sqrt(ONEONE-cx**2-cy**2). After that calculation, I test whether the final sum of squares is still .EQ. ONEONE and if not I repeat the sampling until the condition is satisfied. For the record, I sample the photon position (x,y,z) on the XY plane and I assume an x-ray virtual point origin at Z=-2mm thus the direction vector (cx,cy,cz)=(x,y,z)/sqrt(x**2+y**2+z**2), with cz actually calculated via sqrt(1-cx**2-cy**2) to force cx**2+cy**2+cz**2.EQ.ONEONE.

I am counting how many times the sampling is incorrect&repeated and I have seen that 50% of the time the initial sampling is incorrect. I believe this causes particular angles to not be sampled which might be the reason for a beam that looks like the one attached. I can confirm that the XY plane position is sampled correctly because if I force cz=ONEONE and the rest ZERZER, the figure is a smooth as expected (smaller) disk. But when I sample the angles, these radial steps emerge.

When the sampling is repeated its because the sum of the squares is slightly different than ONEONE. Repeating the normalisation (cx,cy,cz)=(cx,cy,cz)/sqrt(cx**2+cy**2+cz**2) and recalculating cz, results in infinite loops with this as the result of the sum of squares:
First calculation

0.99999999999999989
After renormalisations
0.99999999999999989
0.99999999999999989
0.99999999999999989
1.0000000000000002
1.0000000000000002
1.0000000000000002
1.0000000000000002
...
...
Is there a workaround for this issue?

Best regards,
Thomas



__________________________________________________________________________
You can manage unsubscription from this mailing list at https://www.fluka.org/fluka.php?id=acc_info
Received on Thu Oct 31 2019 - 15:08:38 CET

This archive was generated by hypermail 2.3.0 : Thu Oct 31 2019 - 15:08:40 CET