Skip to content

Adding openmc.read_source_file - #2858

Merged
paulromano merged 3 commits into
openmc-dev:developfrom
pshriwise:read-source-file
Feb 16, 2024
Merged

paulromano merged 3 commits into
openmc-dev:developfrom
pshriwise:read-source-file

Conversation

@pshriwise

Copy link
Copy Markdown
Contributor

Description

We currently have the ability to write a list of openmc.SourceParticle objects to an HDF5 file, but no ability to read a file into a list of those objects that I'm aware of. I found it useful to be able to do so today and added that function so I thought I'd contribute it
here.

I added testing of this function to test_source_file.py, but left the checks using h5py in place as it hammers on that file spec a bit so I think it's still useful to have them around.

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)

@gonuke

gonuke commented Jan 24, 2024

Copy link
Copy Markdown
Contributor

I thought this did exist somewhere... I'll have to dig and take a look. That's how we tested it when we introduced the feature???

@paulromano paulromano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @pshriwise!

@paulromano
paulromano enabled auto-merge (squash) February 16, 2024 16:23
@gonuke

gonuke commented Feb 16, 2024

Copy link
Copy Markdown
Contributor

How does this relate to openmc.settings.surf_source_read(). While this may be named poorly, I think it might do a similar thing that you are aiming for here?

@pshriwise

Copy link
Copy Markdown
Contributor Author

How does this relate to openmc.settings.surf_source_read(). While this may be named poorly, I think it might do a similar thing that you are aiming for here?

openmc.Settings.surf_source_read is a dictionary on the openmc.Settings class that is serialized into the XML. It contains a path to a source file to be read into the OpenMC simulation on initialization of the problem. In contrast, this provides a way to read a general source file (fission source, surface source, what have you) into the Python API. It came in handy for some work I was doing. While this is something that we can interact with via the openmc.lib module using openmc.lib.sample_external_source, it seems a reasonable mirror to the write_source_file function that's currently part of the Python API.

@paulromano
paulromano merged commit 3b575a4 into openmc-dev:develop Feb 16, 2024
church89 pushed a commit to openmsr/openmc that referenced this pull request Jul 18, 2024
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
apingegno pushed a commit to apingegno/openmc that referenced this pull request May 7, 2026
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
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.

3 participants