Skip to content

Streamline use of CompositeSurface with SurfaceFilter - #3167

Merged
paulromano merged 12 commits into
openmc-dev:developfrom
zoeprieto:CompositeSurface
Feb 21, 2025
Merged

paulromano merged 12 commits into
openmc-dev:developfrom
zoeprieto:CompositeSurface

Conversation

@zoeprieto

@zoeprieto zoeprieto commented Oct 11, 2024 •

Copy link
Copy Markdown
Contributor

Description

This is a preliminary solution to issue #3158. The solution b) proposed in the issue was chosen:

  • Adding a CompositeSurfaces.get_surfaces() method that returns a list of the objects surface objects to make it simpler to create the desired filter, leaving SurfaceFilter as-is.

Additionally the following changes were made:

  • Added a method that is get_id_surfaces() to be able to write CompositeSurface surface source files.
  • Added a preliminary test in tests/unit_tests/test_filters.py.

Fixes #3158

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)

@pshriwise pshriwise 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.

A few minor thoughts for your consideration @zoeprieto.

Comment thread openmc/model/surface_composite.py Outdated
Comment thread openmc/model/surface_composite.py Outdated
Comment thread tests/unit_tests/test_filters.py Outdated
box_model.geometry.root_universe = openmc.Universe(cells=[c])

tally = openmc.Tally()
tally.filters = [openmc.SurfaceFilter(box.get_surfaces())]

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.

I think better yet we'd be able to pass a CompositeSurface directly to the SurfaceFilter class, which might require some additional handling in that object.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think it is clearer. It is already done. I thought it was easier to change the SurfaceFilter class than to make a CompositeSurface always return a list of surfaces. Let me know what you think.

zoeprieto and others added 4 commits October 15, 2024 14:56
Co-authored-by: Patrick Shriwise <pshriwise@gmail.com>
Co-authored-by: Patrick Shriwise <pshriwise@gmail.com>

@pshriwise pshriwise 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.

A couple of additional thoughts on streamlining use of CompositeFilter.

Comment thread openmc/filter.py Outdated
Comment on lines +734 to +738
if(type(bins)==list or isinstance(bins, np.ndarray) or
isinstance(bins, openmc.Surface)):
bins = np.atleast_1d(bins)
else:
bins = np.atleast_1d(bins.component_surfaces)

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.

I think ideally a user would be able to provide the CompositeSurface object in the bins argument alongside the other surfaces:

surfaces = [openmc.ZCylinder(r=1), openmc.ZCylinder(r=2), openmc.ZCylinder(r=3)]
prism = openmc.model.RectgangularPrism(7, 7)

surface_filter = openmc.SurfaceFilter(surfaces + [prism])

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.

We'll probably also want to show a warning explaining that many bins will be added for the CompositeSurface if one exists to the user isn't confused about extra bins appearing in the tally results when applying the resulting filter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The feature to combine Surface and CompositeSurface is now available. And I have also added a user warning.

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.

Based on @paulromano's latest, I let's update this warning to a ValueError directing the user to the method for retrieving the surfaces of the CompositeSurface.

Comment thread openmc/filter.py Outdated

@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.

I personally don't like the approach of automatically expanding the composite surface into multiple bins, invisible to the user. As the Zen of Python says, "explicit is better than implicit", so I'd rather leave it to the user to decide which of the underlying surfaces they are interested in. In some cases, it doesn't make sense to use all; for example, a one-sided cone has a disambiguation plane that is not really part of the visible surface.

I suggest updating this PR to simply add the component_surfaces that gives the user an easy way to access the underlying surfaces. I would also consider changing the name to primitive_surfaces.

@paulromano paulromano changed the title Fix for issue #3158 - Streamline use of CompositeSurface with SurfaceFilter Streamline use of CompositeSurface with SurfaceFilter Jan 10, 2025
@pshriwise

Copy link
Copy Markdown
Contributor

Fair enough, I was dubious about having multiple tally bins appear in the output for a single object passed here. By going through the mechanics of getting the primitive surfaces themselves, the user will understand. I like it.

Good point about the disambiguation surfaces, I hadn't considered that for some of the CompositeSurface types.

@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.

I reverted most of the changes here and just left the component_surfaces property. @pshriwise let me know if you're good with this

@paulromano
paulromano enabled auto-merge (squash) February 20, 2025 00:44
@pshriwise

Copy link
Copy Markdown
Contributor

Looks good!

@paulromano
paulromano merged commit 2b788ea into openmc-dev:develop Feb 21, 2025
apingegno pushed a commit to apingegno/openmc that referenced this pull request May 7, 2026
Co-authored-by: Patrick Shriwise <pshriwise@gmail.com>
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.

Streamline use of CompositeSurface with SurfaceFilter

3 participants