Skip to content

General fixes, improvements, and cleanup#7

Open
ilariacasalbore wants to merge 32 commits into
lanl:mainfrom
newcleo-dev-team:6_clean-up_repository
Open

General fixes, improvements, and cleanup#7
ilariacasalbore wants to merge 32 commits into
lanl:mainfrom
newcleo-dev-team:6_clean-up_repository

Conversation

@ilariacasalbore

@ilariacasalbore ilariacasalbore commented Apr 16, 2026

Copy link
Copy Markdown

This PR closes #1, #2, #4, #5, #6, #8.

  • Inconsistent normalization of total neutron spectrum in tape7, tape8, outp, outp2 #1: Correction of the incorrect normalization of the total neutron spectrum in tape7, tape8, outp and outp2 observed in the alpha beam configuration and in the homogeneous configuration when only (alpha, n) reactions contribute to the neutron emission.


    Description: Output tape7, which should contain the absolute spectra, shows the normalized total neutron spectrum. Furthermore, the normalized total neutron spectrum is calculated incorrectly by dividing the spectrum by the total neutron emission twice instead of once. This also leads to an incorrect output in tape8, which contains the normalized neutron spectra. The contributions per single target-source combination, however, are correct on both tapes. The same issue can be observed in the absolute and normalized total neutron spectrum in outp2 and in the spectrum reported in outp.


    Solution: The total neutron spectrum is printed in the section output grand total (alpha,n) + s.f. + d.n. neutron spectrum. Here, the absolute total neutron spectrum is written to tape7. Then, it is normalized and written to tape8.
    In cases where the neutron emission consists of a single contribution from (alpha, n) reactions, an additional section is triggered, in which the total neutron spectrum is already normalized before entering the aforementioned output section.
    As a result, the total neutron spectrum printed in tape7 is already normalized, and it undergoes a second normalization before being written in tape8. This problem was solved by removing the additional normalization step triggered in cases with a single contribution from (alpha, n) reactions.


    Tests: This changes are reflected in the output of test3, test6, test7 in the samples folder. For this test cases, tape7 and tape8 now show the correct values for the total neutron spectrum. Furthermore, the absolute and normalized total neutron spectrum in outp2 and the normalized spectrum in outp are now correct.

  • Incorrect total neutron spectrum in outp2 #2: In case of a single contribution to the neutron emission from spontaneous fission, the values of the absolute total neutron spectrum were written, in outp2, instead of the normalized total neutron spectrum, while the absolute neutron spectrum appeared to be zero.


    Description: In case of nt=0 (no targets for (alpha, n) reactions) the variable isfnq, storing the number of spontaneous fissioning nuclides, is not updated and remains initialized to zero, even in presence of spontaneous fissioning nuclides.
    The same happens for iddnq, storing the number of nuclides that emit delayed neutrons.


    Solution: This problem was solved by ensuring that the variable isfnq and the variable iddnq are correctly updated, adding a new section calculate number of spontaneus fission and delayed neutrons sources if nt=0.


    Tests: An additional test case (test9) was added in order to show this behaviour. The input of test9 consists of the same input of test1, modified to have 0 targets for (alpha, n).

  • Increase in execution time with sensitivity calculation #4: The sensitivity calculation requires a significant computational time.


    Description: The sensitivity calculation introduced in SOURCES 4D is computationally intensive, particularly when there are a large number of source nuclides or bins in the neutron spectrum. SOURCES always performs the sensitivity calculation, even when this is not required (the user may only be interested in the best-estimate values), which considerably increases the computational cost of each execution.


    Solution: Since the sensitivity calculation is not required in all use cases, it is made optional. A new input parameter is introduced, allowing the user to enable or disable the sensitivity calculation. This parameter must be added in card 2, after the idd, id, erg parameters. It accepts two values: 0 to disable the sensitivity calculation and 1 to enable it. To ensure compatibility with older inputs, this parameter is optional and, if omitted, it defaults to 0. The sensitivity calculation is only available for the homogeneous configuration and for the alpha beam configuration, therefore this parameter has no influence in calculations with other configurations.


    Tests: The additional parameter introduced is set to the value 1 in all the example inputs in the samples directory, in order to enable the sensitivity calculation. To provide an example of the impact of the sensitivity calculation, test1 required ~2 min with the sensitivity calculation, while without it only requires ~0.1 s.

  • Incorrect results for three-region interface configuration #5: The three-region interface configuration provides incorrect results.


    Description: Depending on the options provided to the compiler, inputs using the three-region interface configuration result in an error or provide incorrect results. In particular, the outputs show values for the total neutron production and for the neutron emission spectrum that are either 0 or NaN.


    Solution: This issue was caused by some variables not being properly passed between subroutines. This has been fixed by ensuring that all the required variables are correctly passed to the necessary subroutines.


    Tests: An additional test (test10) has been added in order to test the three-region configuration, since none of the present cases in the samples directory covered this configuration.

  • Clean-up repository #6: The repository should not contain the compiled executable.


    Description: To ensure code reproducibility, the executable should be removed from the repository. The bin folder should be removed and added to the .gitignore file. A Makefile should also be added, and the README updated.


    Solution: The bin folder has been removed and added to the .gitignore file. Furthermore, a Makefile has been added, that creates the bin folder before creating the executable. The README has been updated accordingly with installation instructions.

  • Inconsistent results across runs due to uninitialized variables #8: Correction of inconsistent results across different runs.


    Description: While running SOURCES4D on different machines, inconsistent results were observed across multiple runs. This behaviour is unexpected, as the code is deterministic.


    Solution: The issue was traced back to the presence of uninitialized variables, which can lead to different results depending on the execution environment and compiler. A more thorough check was performed using stricter compilation flags, revealing additional uninitialized variables. These variables have been correctly initialized.
    Minor related issues were also identified and fixed, including:

    1. section spectra for outp2 in ascending or descending order is skipped if id=1 (magnitude only), for the homog subroutine;
    2. the average energy of neutrons emitted is calculated only if id>1 (spectra are calculated), for the homog subroutine;
    3. in the neutron subroutine, some checks have been added to avoid division by zero.

    Note: in the evaluation of the derivatives of source rate density w.r.t. (alpha,n) cross sections and stopping power data, the variable fal(l) remained uninitialized in case of idd=3. It has been set to 1 to avoid runtime issues. This variable does not affect the output in pdata.


    Tests: test10 is the only test modified by the changes. In particular, the value of the Total (all targets) neutron production in tape6 is now correct. This leads to different values of the normalized spectra in tape8, that is now normalized using the new correct value of the total neutron production.

…n spectrum if (alpha,n) is the only contribution, otherwise the total neutron spectrum is normalized twice
…tion to the total neutron spectrum, otherwise remains equal to 0 in this specific case, causing incorrect output
…dd the possibility that the contribution is from spontaneous fission only or from delayed neutrons only
…ission) is updated also when nt=0 (there are no targets for (alpha,n))
…ased for sources that do not undergo spontaneous fission
…s) is updated also when nt=0 (there are no targets for (alpha,n))
… calculation of the spontaneous fission source and delayed neutrons source
…ontribution (no (alpha, n), no delayed neutrons)
…if (alpha,n) is the only contribution without skipping the section output of grand total (alpha,n) + s.f. + d.n. neutron spectrum
Comment thread src/sources4d.for Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to change this into "if(l_sdata .and. sensitivity) then" for consistency.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

Comment thread src/sources4d.for Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to open files 13 and 14 only "if (sensitivity) ".
This should allow you to change also lines 441-452 into :
if(sensitivity)then
close(unit=13)
close(unit=14)
endif

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Changed also other instances of close(unit=13), close(unit=14).

Comment thread src/sources4d.for Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be "if(l_sdata.and.sensitivity)then"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

Comment thread src/sources4d.for Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would wrap these two lines initializing dq3c and dq3s into a "if(sensitivity)" statement.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

Comment thread src/sources4d.for Outdated
c-----------------------------
c calculate number of spontaneous fission
c and delayed neutrons sources if nt=0
c-----------------------------

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment: Perhaps a better solution would have been to set ISFNFQ and IDNNFQ independently of the value on NT before line 1221: "do 1120 i=1,nt".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment thread src/sources4d.for Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing these 2 line into:
2'atoms dk constant sf decay nu neutrons',/,8x,'nuclide',
3' per cm3 (/second) branching bar sec/cm3',****
should help solving the 4 spaces disalignment in tape 6 output.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Comment thread samples/test1/tape6 Outdated

source source atoms dk constant sf decay nu neutrons
nuclide per cm**3 (/second) branching bar sec/cm**3
nuclide per cm**3 (/second) branching bar sec/cm**3

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A correction is proposed in the source code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent normalization of total neutron spectrum in tape7, tape8, outp, outp2

2 participants