Skip to content

Implement a new MeshMaterialFilter #3406

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

Merged
merged 12 commits into from
Jun 6, 2025

Conversation

paulromano
Copy link
Contributor

Description

This PR implements a new MeshMaterialFilter that allows tallying specific combinations of mesh elements and materials. In principle, one can already do this by combining a MeshFilter and a MaterialFilter. However, in many cases a single mesh element only contains a few materials, which means tallying every single material for each mesh element would be very wasteful. This new filter works in conjunction with the Mesh.material_volumes() method, which returns a MeshMaterialVolumes object. This filter has a from_volumes() classmethod that will create a filter with bins for all mesh element-material combinations that were found from the call to material_volumes(). So, the workflow is basically:

# Build your model
model = openmc.Model()
...

# Set up a mesh
mesh = openmc.RegularMesh()
...


# Determine materials present in each mesh element
mat_vols = mesh.material_volumes(model, ...)

# Create corresponding filter
mm_filter = openmc.MeshMaterialFilter.from_volumes(mat_vols)

This new filter is one of the last infrastructural pieces needed to carry out mesh-based subvoxel R2S calculations.

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)

@paulromano paulromano requested a review from pshriwise May 11, 2025 21:43
@shimwell shimwell self-requested a review May 30, 2025 12:46
@shimwell shimwell self-assigned this May 30, 2025
@ilhamv ilhamv mentioned this pull request Jun 2, 2025
5 tasks
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.

Nice @paulromano! I'm looking forward to trying this out. Some potential small refactors suggested here.

@shimwell
Copy link
Member

shimwell commented Jun 3, 2025

Awesome, thanks Patrick, looks like lots of good changes.

I've been putting this branch to use to see how the workflow goes.

I can probably improve this draft notebook. It does appear possible to do and R2S workflow with this new MeshMaterialFilter. I can't say it was easy and I'm not 100% sure I've done all the processing correctly but I've got something here.

https://github.com/fusion-energy/neutronics-workshop/blob/testing-MeshMaterialFilter/tasks/task_11_CSG_shut_down_dose_tallies/3_R2S_regularmesh_shutdown_dose_rate.ipynb

I think we could consider adding some utility functions to make some of the stages more compact.

Co-authored-by: Jonathan Shimwell <[email protected]>
Co-authored-by: Patrick Shriwise <[email protected]>
@paulromano
Copy link
Contributor Author

@shimwell @pshriwise Thanks for the reviews on this PR and glad to hear that you are already incorporating it into your workflows Jon. There are a few more pieces that are needed IMO to make the mesh-based R2S workflow correct/seamless including, as you suggested, some utility functions. I have another branch or two I'm working on with exactly that.

In any case, all the comments have been addressed other than a few which I've responded directly to about why I haven't incorporated them. Let me know if you have any further requests for changes.

@shimwell
Copy link
Member

shimwell commented Jun 4, 2025

I don't have any further changes. Looks good from my point of view

I clicked resolve on my only remaining comment as you addressed it with the /n

I would be keen to evolve the R2S example I made to make use of your utility functions as they arrive. It will be really satisfying to shrink that example down to a more manageable script.

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.

Looks good @paulromano! I'll give this a short cooldown and merge tomorrow.

@pshriwise pshriwise merged commit 7fda3eb into openmc-dev:develop Jun 6, 2025
15 checks passed
@paulromano paulromano deleted the mesh-material-filter branch June 6, 2025 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants