-
Notifications
You must be signed in to change notification settings - Fork 525
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
Fix for finding redundant surfaces #2263
Conversation
This looks like a nice update to me @eepeterson. General question about this (but also related to the default behavior), if someone were to specify a |
No I don't think so actually. We could do it through the |
I'll raise that as an issue so we don't lose track of it, but is there anything else you'd want to see in this PR or are you fine with a hard-code 10 decimal precision rounding? |
@eepeterson how would you feel about a default of rounding to the 10th digit, but making it a parameter of |
Agree with @pshriwise -- it would be nice to be able to turn that knob if need be |
Sounds good. I'm inclined to also set that as an attribute on the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice improvement! Adding a couple of thoughts for you to mull over, @eepeterson.
openmc/geometry.py
Outdated
@@ -17,6 +18,13 @@ class Geometry: | |||
root : openmc.UniverseBase or Iterable of openmc.Cell, optional | |||
Root universe which contains all others, or an iterable of cells that | |||
should be used to create a root universe. | |||
cull_surfaces : bool, optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably splitting hairs here, but how would you feel about a name like merge_surfaces
?
openmc/geometry.py
Outdated
|
||
""" | ||
|
||
def __init__(self, root=None): | ||
def __init__(self, root=None, cull_surfaces=False, surface_precision=10): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preference would be to set the attributes rather than expose them here.
As far as the default value of these attributes goes, I'm okay with moving to a default value of surf_map = geometry.remove_redundant_surfaces(return_mapping=True)
tally.update_surfaces(surf_map) |
Thanks for the comments @pshriwise! I'll get on those immediately. Would the |
Hah, it sure is! Duh. So I suppose one could call Or we could optionally return it from Also, is that mapping deterministic? I'm guessing that it is since it'll be based on which surfaces are visited first in the ordered dictionary of cells returned from |
I was thinking of maybe caching the redundant surface map when |
98a3a6d
to
a46cafa
Compare
Ah yeah good idea! What would you imagine the workflow for updating tally information looks like in this case? In my head this might be: geometry.remove_redundant_surfaces() # creates cache with mapping
tally.update_surfaces(geometry.surface_mapping_cache) # cache name TBD I think this would be fine but it requires users to know about this cache. And, if I'm understanding correctly, they would get an empty map if they tried to retrieve a mapping from What about caching in mapping = geometry.get_redundant_surfaces() # cache map here
tally.update_surfaces(mapping)
geometry.remove_redundant_surfaces() # use cached map and set cache to `None` at the end |
I think I got what you suggested implemented @pshriwise |
Co-authored-by: Patrick Shriwise <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me @eepeterson! I'll merge this tomorrow if there are no further comments from others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to chime in somewhat late here. Looking through the changes, I'm not super thrilled with the design and wondering if the following would simplify things:
- Let the user be responsible for calling
remove_redundant_surfaces
. That is,export_to_xml
will not remove redundant surfaces for you -- it will simply export the model to XML. To me, it makes more sense that exporting should not modify the state of the geometry/model. - The
remove_redundant_surfaces
method could return the same dict given to it byget_redundant_surfaces
for the case where a user needs to modify related data structures (like tallies). surface_precision
would only be an argument ofremove_redundant_surfaces
Geometry
then wouldn't need any of the three extra attributes
@paulromano thanks for the feedback! I agree your approach simplifies things, but it misses the two main points of the PR I was hoping to achieve. 1.) I don’t see any good reason to allow writing duplicate surfaces to xml (certainly not by default). And 2.) I would prefer the user not have to explicitly ask the geometry to take care of that. Do you have reasons why that shouldn’t be the goal of this PR or is there a way we could get there with some of your suggested simplifications? |
I agree with your goals (cleanly avoiding redundant surfaces) but I'm just hesitant about adding state to the
Personally, I think option 1 is simple enough and easy to implement. I also like that this gives the user an indication that maybe they are doing something that is not so wise in the first place. If we autoremove all redundant surfaces, it allows users to be a bit sloppier. |
Sorry for the thrashing on this PR... I'll squash the commits once we agree on a strategy to keep the history a bit cleaner. @paulromano I do like your first suggestion the most and it's actually most similar to the original implementation in this PR. Some of the nitpicks I have with the current design are below:
I think I disagree with your comment on allowing users to be sloppier. While that's one way to look at it, I think heavy use of With the addition of a couple attributes I think we benefit in a number of ways
As for options 2 and 3 you suggested above: I would prefer to not have surfaces in the xml that get removed under the hood on the C++ side - I'd like the xml to be an accurate representation of the model. As for manipulating |
@eepeterson All good points. I think you've won me over, so if you want to revert back to what you had in the first place, I'll take another pass at it. Sorry to lead you astray! |
5fbeaba
to
f5f42a4
Compare
0681510
to
1110038
Compare
Thanks @paulromano I appreciate it! I think this is ready for another pass when you get a chance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good this time, accounting for all the discussion 😄 Thanks for the improvement @eepeterson!
I was noticing some models I was generating weren't finding redundant surfaces (particularly Z cones) because some of the coefficients differed in the last few decimal places.