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

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

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
string = type(self).__name__ + '\n'
string += '{: <16}=\t{}\n'.format('\tID', self.id)
string += '{: <16}=\t{}\n'.format('\tMesh ID', self.mesh.id)
string += '{: <16}=\t{}\n'.format('\tBins', self.bins)
Copy link
Member

Choose a reason for hiding this comment

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

The Bins print to terminal, but the spacing is not ideal, perhaps add more white spacing to indent

MeshMaterialFilter
        ID             =        2
        Mesh ID        =        2
        Bins           =        [[644   1]
 [645   1]
 [654   1]
 [655   1]
 [744   1]
 [745   1]
 [754   1]
 [755   1]
 [844   1]
 [845   1]
 [854   1]
 [855   1]]
        Translation    =        None

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.

// First determine which elements the particle crosses (may or may not
// actually match bins so we have to adjust bins_/weight_ after)
int32_t n_start = match.bins_.size();
model::meshes[mesh_]->bins_crossed(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think defining our own FilterMatch, let's call it mesh_match, here to pass to the mesh would simplify what's going on in the loop below. We can then sequentially remove invalid bins to match from mesh_match and add the remaining valid bins to match at the end.

@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 <drshimwell@gmail.com>
Co-authored-by: Patrick Shriwise <pshriwise@gmail.com>
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