A bug of source_newgen.f?

We used source_newgen.f to define a complicated neutron source (FNG neutron source). There is an angular dependence of the source energy distribution. There are total of 19 angular dependence spectrum files. Here are just two samples as shown in followed figure 1.

we sample the moment_engery according to the various beam direction as the following code:

   call sample_isotropic_direction( direction_cosx, direction_cosy, direction_cosz )
    i = 1
   
    do i = 1, 18
 	   
     if ((direction_cosz <= Ang_list(i+1)) .and. (direction_cosz > Ang_list(i))) then           
     
      
      momentum_energy = sample_spectrum_momentum_energy( SPEC_filenamelist(i),  "MeV" )
      print *,'FILE NAME is ', SPEC_filenamelist(i), momentum_energy, direction_cosz
   
    end do

We found there seems some error in sampling the momentum_energy from spec_files.
The debug log file is shown as follows.


As shown in figure1, the energy range of SPEC_2.TXT is from 14.3 to 15.1 MeV, while the energy range of SPEC_15.TXT is about 13.4 to 13.8 MeV. But the results show the energy does not fit on the energy range of spec_file.
We think there is a bug happening on the function ‘sample_spectrum_momentum_energy’. it just loaded the spec_file to memory one time without updating the latest spec_file to the memory. then it will cause this error to happen.
Hoping to get feedback from exporters. Thank you in advance.

Dear lijia,

you are correct, the current implementation of the spectrum sampling function only reads from the file specified during the first call to it.

For a future release of FLUKA, it is planned to extend its functionality to read and sample from multiple files, like you want to use it now.

For now, you could modify the function to fit your needs. My solution would be along the lines:

  • The function is in the file <path_to_fluka>/include/source_library.inc.

  • Copy it into the end of your source routine with a different name.

  • Change the bins, energy, intensity, and probability variables into 2D arrays, with the new dimension equal to the number of files you have. Like:

     integer, dimension(19) :: bins
     double precision, allocatable, dimension(19, :) :: energy, intensity, probability
    
  • Change the input variable filename to an integer which will be used to select which file you want to sample from.

  • in the first_run of the function, read all your files to the appropriate elements of the arrays.

Cheers,
David

Thank you for your quick response!
I have done what you suggested for the current.
It works well!