Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write surface source files per batch #3124

Merged
merged 24 commits into from
Oct 3, 2024

Conversation

zoeprieto
Copy link
Contributor

@zoeprieto zoeprieto commented Sep 4, 2024

Description

This is a preliminary solution to the first part of the issue #3123 for writing surface source files in the last N active batches chosen by the user.

By default it still saves a surface source file only in the last batch. The difference is that the files will be named: surface_source_batch_N.h5 with N being the number of the last batch.

It has also added the ability to print the number of particles that were saved per batch as the simulation runs.

Fixes #3123

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 15) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

Copy link
Contributor

@pshriwise pshriwise left a comment

Choose a reason for hiding this comment

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

Some minor comments on verbosity and file naming formats, and I finally figured out what I think we should do:

The current implementation is very nice and accomplishes the goal of this feature (to allow more surface crossings to be generated by the simulation than allowed by the max_particles setting on the surface source). In the end though, I think this feature should behave in a similar manner to the openmc.Settings.statepoint['batches'] capability.

image

So for this features we would incorporate a openmc.Settings.surf_source_batches option that would allow users to specify a list of batches after which the surface source bank will be written to file and the surface source bank in memory will be cleared. With this method the user can specify that they'd like to write the current set of source particles after as many batches as they like. If they'd like all of the batches it's as simple as specifying:

settings.surface_source_batches = [i for i in range(settings.batches)]

Sorry it took me so long to come to this conclusion. What do you think @zoeprieto?

openmc/settings.py Outdated Show resolved Hide resolved
src/simulation.cpp Outdated Show resolved Hide resolved
@zoeprieto
Copy link
Contributor Author

zoeprieto commented Sep 12, 2024

Thanks for all the suggestions @pshriwise . I think using the same format of creating files as in statepoint is really very good, and simplifies the need to create more variables. Also, it adds the ability to not be so strict on whether it's in all batches or just the last batch.
When I implemented it to make it consistent with the statepoint implementation, the variable that is added is ‘batches’ inside surface_source_write, and it receives a list. By default the list is unitary and only has the value of the last batch.

Copy link
Contributor

@pshriwise pshriwise left a comment

Choose a reason for hiding this comment

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

This looks really nice @zoeprieto. 🥇 Mainly a couple of high-level questions here to address.

src/settings.cpp Outdated Show resolved Hide resolved
src/simulation.cpp Outdated Show resolved Hide resolved
tests/regression_tests/dagmc/legacy/test.py Outdated Show resolved Hide resolved
src/settings.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@pshriwise pshriwise left a comment

Choose a reason for hiding this comment

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

A couple more thoughts, but I think this is really close.

src/settings.cpp Outdated Show resolved Hide resolved
src/simulation.cpp Outdated Show resolved Hide resolved
src/simulation.cpp Outdated Show resolved Hide resolved
src/settings.cpp Outdated Show resolved Hide resolved
src/simulation.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@pshriwise pshriwise left a comment

Choose a reason for hiding this comment

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

Almost there! If you don't mind, let's add one test with the batches property set to ensure the correct number of files and filenames are generated.

docs/source/io_formats/settings.rst Outdated Show resolved Hide resolved
docs/source/io_formats/settings.rst Outdated Show resolved Hide resolved
docs/source/usersguide/settings.rst Outdated Show resolved Hide resolved
src/simulation.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@pshriwise pshriwise left a comment

Choose a reason for hiding this comment

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

Teeny-tiny documentation tweak and then I'm happy! 😄

docs/source/io_formats/settings.rst Outdated Show resolved Hide resolved
Copy link
Contributor

@pshriwise pshriwise left a comment

Choose a reason for hiding this comment

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

Thank you @zoeprieto!

@pshriwise pshriwise enabled auto-merge (squash) September 17, 2024 23:00
Copy link
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

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

Sorry to stall the merging -- wanted to take a look at this but haven't had a chance to yet. I'll try to review in the next few days!

Copy link
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

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

To summarize some discussion that @pshriwise @zoeprieto and I had offline -- rather than writing a surface source file at specific batches, I am recommending that we write the surface source file at the point where it fills up and then give the user an option as to how many times they are allowing a full source file to be written. If the surface source bank is not full by the end of the simulation, it will write out the surface source as is. This removes some of the guess work for the user in figuring out how often they should be writing the surface source (i.e., which batches).

auto-merge was automatically disabled September 26, 2024 17:13

Head branch was pushed to by a user without write access

@zoeprieto
Copy link
Contributor Author

Thank you @paulromano for your comment. You are right, it is more reasonable to create another file only if the first one is full. I solved it by adding a max_surf_files variable which defaults is 1. I had to create another variable called current_surface_file to know which is the current surface source file I'm writing to.
The documentation and tests were also updated.

Copy link
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

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

Thanks again for this enhancement @zoeprieto. I made the following changes on this branch:

  • Renamed global variables to all start with ssw_ to indicate they are related to surface source writing.
  • Introduced a new write_source_point function to consistently handle the logic for writing either a .h5 and .mcpl file
  • Changed the name of the user input "max_surf_files" to "max_source_files"
  • Updated the test case

@paulromano paulromano enabled auto-merge (squash) October 3, 2024 19:43
@zoeprieto
Copy link
Contributor Author

Thank you @paulromano for your feedback and changes!

@paulromano paulromano merged commit 9686851 into openmc-dev:develop Oct 3, 2024
15 checks passed
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.

Write and read more than one surface source files
3 participants