Repository navigation
Conversation
In a multigroup simulation the source bank stores the energy group index of each site in E, and so do the source point files written from it (source.<batch>.h5 and source.h5). FileSource read E as an energy in eV and converted it to a group: with two groups, a site of group 1 was started in group 0, and a site of group 0 was rejected by the default energy bounds, which require E > 0, or, with wider bounds, given the invalid group index G when the lowest group edge is above zero. These source point files now have an energy_mode attribute equal to "multi-group". FileSource reads it, or the energy_mode dataset of a state point, and then keeps the stored group of each site: it checks that E is an integer from 0 to G - 1, skips the conversion from eV and does not apply energy bounds to these sites, with a warning when bounds are given. A continuous-energy simulation refuses such a file, and an unrecognized energy_mode value is an error. Files without the marker, such as surface source files, which store energies, older source files and files written by openmc.write_source_file, are read in eV as before. The decision is made per source, so the other sources of a simulation are converted as before. The file format version is unchanged: the attribute is optional, and older versions ignore it.
Add tests of the energy_mode marker that multigroup simulations write to their source point files and of how a FileSource reads them. The marker is on source.<batch>.h5 and source.h5 only. Fixed source and eigenvalue simulations from such a file start every particle in its stored group, and sampling keeps that group with default and with widened energy bounds; one warning is printed when bounds are given, while domain and time constraints still apply. A multigroup state point is read through its energy_mode dataset. Group indices that are out of range, fractional or NaN, an unknown energy_mode value, and a marked file or multigroup state point in a continuous-energy simulation are refused. Files that hold energies are unmarked and read in eV as before: surface source files written by a multigroup simulation, source points of a continuous-energy simulation and files written by openmc.write_source_file, also when another source of the simulation holds group indices. With --mpi, the writer and two readers run on several processes.
State that FileSource also accepts 'continuous-energy' (energies in eV, as without the attribute), that any other value is an error, and that files written by ParticleList.export_to_hdf5 have no energy_mode attribute either.
Run a fixed source simulation from the source file of a two-group simulation, whose sites are all in group 1, with energy bounds of 1 keV to 20 MeV. Read as energies in eV, the stored indices would be rejected; as group indices, the sites start in their group, and one warning says that the bounds are not applied.
5 tasks done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In a multigroup simulation the source bank stores the energy group index of each site in
E, and so do the source files written from it:source.<batch>.h5andsource.h5(Settings.sourcepoint) and the source bank of a statepoint.FileSourcereadEas an energy in eV and converted it to a group again (#4183). A site in group g >= 1 started in the group whose energy range contains g eV, or at the invalid index G (for G groups) when g eV lies below the lowest group edge. A site in group 0 was rejected by the default energy bounds; with widened bounds it was given group G - 1 or the invalid index G, depending on whether the lowest group edge is 0. With the default bounds, a file whose sites are all in group 0, such as any one-group file, could not be used at all.This PR marks the source point files of multigroup runs, and
FileSourcethen keeps the stored group of each site.Fixes #4183
Changes
The PR has four commits. The first is the fix described below, and the third extends its description of the
energy_modeattribute inio_formats/source.rst. The second and the fourth add the tests (see "New tests").Writer.
write_source_point()andwrite_h5_source_point()take a new trailing argument,bool group_indices = false. The two source-bank calls infinalize_batch()pass!settings::run_CE, so the source point files of a multigroup run get the root attributeenergy_mode= "multi-group". It is written likefiletype, in the samempi::master || parallelblock, so under parallel HDF5 every rank takes part in the write. Nothing else writes the attribute: not continuous-energy runs, not surface source files (their sites store energies in eV,site.E = p.E()), notinitial_source.h5, not statepoints, and not the Python writers. Existing callers compile unchanged and write unmarked files.Reader. After the
filetypecheck,FileSource::load_sites_from_file()reads the marker of an HDF5 file. For a source file it is the root attributeenergy_mode; for a statepoint it is the root datasetenergy_modethat every statepoint already has.Eis an energy in eV, read and converted exactly as before.Eholds group indices.sample_external_source()checks that the sampledEis an integer with 0 <= E < G and returns the site before the conversion from eV, so the particle starts in its stored group. A site that fails the check stops the run, for example withSource site has energy group index 0.5, which is not valid for 2 energy groups.NaN fails the check too.Every rank reads the marker itself. The decision is made per source (
Source::energy_is_group_index(), false by default), so in a model with several sources the other sources are converted as before. Because statepoints are read through their existingenergy_modedataset, multigroup statepoints keep their groups too, including those written before this PR.Refusals and energy bounds.
Source file '...' holds multigroup energy group indices and cannot be used in a continuous-energy simulation.sample_with_constraints()skips only the energy test for them; the spatial, time and fissionable constraints and the rejection strategy apply as before. If the bounds differ from the defaults, loading prints one warning that names the file.Unchanged.
openmc.write_source_file()orParticleList.export_to_hdf5(). A multigroup run still converts an eV file to groups. Nothing in such a file distinguishes a file written by a continuous-energy run from a user-written one, and the conversion is correct for both.openmc -r) reads the source bank without any conversion. This PR does not change it.FileSource::sample()and the existing conversion block insample_external_source()are textually unchanged.ParticleList.from_hdf5()returnsEas stored and ignores the attribute, andexport_to_hdf5()does not write one.Documentation.
io_formats/source.rstdescribes the attribute and whatEthen holds. It gives both values, 'multi-group' for group indices and 'continuous-energy' for energies in eV, and says that a file without the attribute is read as 'continuous-energy'. It also says thatFileSourcetreats any other value, and a 'multi-group' file in a continuous-energy simulation, as an error, and that OpenMC writes the attribute only to the source point files of multigroup runs.io_formats/statepoint.rstgets one sentence in thesource_bankentry. The "File-based Sources" section ofusersguide/settings.rstgets a paragraph. The docstrings ofFileSource,SourceParticle,ParticleList.from_hdf5()andParticleList.export_to_hdf5()are updated.Not covered.
ekin = E * 1e-6MeV), and it is read back as an energy in eV.ParticleList. A multigroup file read withfrom_hdf5()and written withexport_to_hdf5()loses the marker, and its group indices are then read as eV. Theexport_to_hdf5()docstring says so.initial_source.h5(Settings.write_initial_source) is not marked. It has nofiletypeattribute, soFileSourcerefuses it both before and after this PR (Specified starting source file not a source file type.).Eholds group indices; it does not record the groups. A group-index file read with a different multigroup library is therefore accepted whenever its indices are in range. For example, a file written by a two-group run and read in a 70-group run starts its group-1 sites in group 1 of 70. Such a file was misread before this PR too.Compatibility
energy_modevalue, without complaint.FileSourcenow starts each site in its stored group instead of a converted one, also when it was written before this PR. That is the fix. Continuous-energy statepoints are read as before.The script of #4183
Output on develop (a5bc348), with one thread, as in #4183:
Output on this branch, with one thread (exit code 0):
On this branch, stderr holds two warnings, one for each of the two one-group cases sampled with widened bounds. Here the run directory is shortened to
<dir>and each message is joined onto one line:Tests
New tests
The second commit, "Test multigroup source files read by FileSource", adds
tests/unit_tests/test_source_file_mg.py. The fourth, "Test that energy bounds are not applied to group indices", adds one test to it, which gives 21 test functions and 48 test cases. They use the model and the five libraries described under "Checks outside the test suite". Each test either runs OpenMC in a subprocess or samples the source in memory throughopenmc.lib.The tests check that:
energy_modevalue, and a marked file or multigroup statepoint in a continuous-energy run are refused.As guards, they also check that multigroup surface source files, continuous-energy source points and files written by
openmc.write_source_file()are unmarked and still read in eV, and that energy bounds still apply to such files. With--mpi, the writer and two readers run on several processes. The models cap a history at 1000 events, so that a particle left in an invalid group fails the test instead of running forever. The three continuous-energy cases (H-1, U-235) run with CI's nuclear data; the other 45 are data-free.On develop (a5bc348) with this test file, 32 of the 48 cases fail, and 4 end the test process. Those 4 sample the four files of group-0 sites with the default bounds, which hits the source rejection limit. The fatal error then ends the process: here with a segmentation fault after the error message, and with exit code 255 in the MPI build. The other 12 pass: the 9 guards, and 3 cases that develop already gets right (no warning without bounds or with the default bounds, and widened sampling of the one-group file whose lowest edge is 0). With
--mpithe outcomes on develop are the same. On this branch all 48 pass in history mode (3.05 s), with--event(7.52 s) and with--mpi(2 ranks x 2 threads, 12.15 s).Checks outside the test suite
These checks used the model of the script in #4183: an infinite medium (a reflective 10 cm cube) with no group transfer, and fission only in the group that chi feeds. It was run with five data-free libraries: one group with edges [1e-5, 2e7] or [0, 2e7] eV, and two groups with edges [1e-5, 0.625, 2e7] eV and every fission neutron born in group 1, or born in group 0 with a lowest edge of 1e-5 or 0 eV. The multigroup runs used 1000 particles per batch. Every case ran in a fresh process with seed 1 and one thread per process, on develop (a5bc348) and on this branch.
source.3.h5andsource.h5of a multigroup eigenvalue runEis the creation group; attributesfiletype,versionsource_bank, plusenergy_mode= "multi-group"openmc.lib.sample_external_source(), 1000 sites, default boundsEis the stored group, for all five filesEis 0Eis 1, and every site lies in the cellFileSourceopenmc.write_source_file()(0.1 eV and 1 MeV), and a copy withenergy_mode= "continuous-energy"Eis 0.312505 or 10000000.3125 eV (the group midpoints), no marker; sampled as groups 1 and 0filetype,versionE= 2, 0.5, -1 or NaNenergy_mode= "foo"initial_source.h5as aFileSourceopenmc -r statepoint.2.h5 source.2.h5k_generation,k_combinedand the tally results are byte-identical to develop's and to an uninterrupted runTest suite
The test set of CI (
tests/test_matplotlib_import.py tests/unit_tests tests/regression_tests) was run on a5bc348 and on the fix commit of this PR, in the same environment. The other three commits change only the new test file andio_formats/source.rst. The environment used the NNDC HDF5 library (itscross_sections.xmlmatches the md5 intests/conftest.py) andOMP_NUM_THREADS=2.--event--mpi --mpi-np=2(2 ranks x 2 threads)No test failed in any run. The skipped tests and the tests with errors are the same on both sides, and every error is raised at setup by the environment:
OPENMC_ENDF_DATA, which was not set (test_data_*.py,test_deplete_chain.py,test_endf.py).cpp_driver,source_dlopen,source_parameterized_dlopen) build against an installed OpenMC, and these builds were not installed.mpi4py, which was not installed.MPI run. The MPI run used Open MPI 4.1.6 with process binding off, through a small wrapper around
mpiexec. The wrapper unsets theOMPI_*,PMIX_*,OPAL_*andORTE_*environment variables before it callsmpiexec. Without it, the in-processopenmc.lib.init()of the CMFD regression tests (a singletonMPI_Initunder Open MPI) leaves these variables in the pytest process, and every latermpiexec -n 2 openmcin that process aborts, on develop and on this PR alike.Reference files. Regenerating every regression reference with
pytest --update tests/regression_tests(history mode) on a5bc348 and on the fix commit gives byte-identical files, apart from run-to-run differences:collision_track, the fourdeplete_*directories,microxs,surface_source,surface_source_write). All 58 also differ between two runs of develop.depletion timedataset. The same two kinds of fields differ between two 1-thread runs of develop.No existing reference value changes.
Other checks.
cteston the serial and the MPI build: 14 tests, 13 passed,test_mcpl_stat_sumskipped because MCPL is not enabled. The same holds on a5bc348 and with all four commits.--dry-run --Werror) reports no changes for the five changed C++ files. pyflakes 3.2.0 onopenmc/source.pyand the new test file, and pycodestyle 2.11.1 on their diff, report nothing.Not run (CI configurations not reproduced):
mpi4py.OPENMC_ENDF_DATAor an installed OpenMC (errors on both sides, listed above).Related PRs
sample_external_source(). This PR leaves that block textually unchanged, and a three-way merge of this PR with Adding multigroup photon transport capability in MC mode #4141'ssrc/source.cpphunk is clean. The group-index path returns before Adding multigroup photon transport capability in MC mode #4141's checks, though, so once both PRs are in, it should also apply Adding multigroup photon transport capability in MC mode #4141's particle-type check againstdata::mg.particle_type_. Whichever PR lands second should add that check.sample_external_source(), after the multigroup conversion. It refuses point detectors in multigroup mode, so the early return here for group-index sites, which exist only in multigroup runs, does not affect it. If Implementation of point detectors #3757 later supports multigroup mode, the group-index path will need the same call.boolargument towrite_source_point()andwrite_h5_source_point(). Whichever of the two PRs lands second needs a rebase that keeps both arguments.AI Assistance
Code, tests, analysis, reviews and text:
Review of the change:
Checklist
Summary by CodeRabbit