I was trying to write source.f where the spherical source has been divided into couple of layers and weights have been adjusted in each layer. I have introduced these conditions in the beginning of the code (user initialization). Now, after the initialization, these arrays will be used for sampling position coordinates and accordingly weights will be assigned. I have put this condition after the initialization block ends. The write statement has been added to check if the position sampling and weights are properly taken or not, and it is found that the results are not generated as expected.
There may be some mistakes in those Do and IF loops added in the sampling part. But I am unable to solve this.
extsource.f (9.9 KB)
Could you provide a minimum example of a flair or inp file which uses your source file?
when you select the layer, you need to use greater or equal (
.GE.) in the comparison of cumulative probability instead of less than (
.LT.), and you need to compare the cumulative probability of the previous layer
Currently always the largest layer is selected, because its cumulative probability is always greater then the random number it is compared to.
Furthermore, the calculation of the radius and coordinated can be moved after the
DO loop, to have more efficient code.
Thank you @horvathd,
- It seems working now. Since I have normalised the cumulative probability, I though LT would work, for example, previously when I was manually writing the layer conditions it was like:
IF (select_layer .LT. CN1) THEN
ROUT = R1
RIN = ZERZER
weight = W1
ELSE IF (select_layer .LT. CN2) THEN
ROUT = R2
RIN = R1
weight = W2
ELSE IF (select_layer .LT. CN3) THEN
ROUT = R3
RIN = R2
weight = W3
… so on.
where these CNs are normalised cumu probability.
In this present case, I tried to write the code in a more general way. The GT worked here in this case. Is it because I have used same notation CP for both cumulative and normalised cumu probability ? I thought it will be replaced.
Yes, I will move the sampling conditions after the do loop.
Also I tried to make a txt file to print 10 values of these arrays (NLAYER = 10 in this case) : RL, W etc. I tried to incorporate that in the code (see line no 96 with another parameter KOUNT. But then I got lost in the concept how this 10 will be decided. For a single history, will it print 10 values or for a single run, only one value is getting selected out of these 10 sets ?
.LT. is working with the
ELSE IF … structure because, when a match is found, the further comparisons with larger layers are skipped.
DO loops every layer is compared, and the last matching one is used, which is always the largest layer. It is still possible to use the
.LT. comparison with the
DO loops, but you need to break out the loop after a match is found with the command
It is not clear to me what you want to print with the help of
If you only want to print the parameters related to the layers (min / max radius, weight), then you can do it with a simple do loop after they are initialized.
If you want to print the first
X number of sampled position, then you can use
KOUNT. First you need to
SAVE it and initialize it to zero. Then you need to wrap your
WRITE command into an
IF statement, like:
IF (KOUNT .LT. X) THEN
KOUNT = KOUNT + 1
Thank you so much @horvathd, I followed all the points and am able to reproduce them.