Skip to content
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 rotation of hexagons in block diagrams #1648

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mgjarrett
Copy link
Contributor

@mgjarrett mgjarrett commented Feb 15, 2024

What is the change?

Rotate hex patches based on the cornersUp property before plotting for a block diagram.

Why is the change being made?

The rotation was previously hard-coded to assume a "flats up" hexagon block. This is not always the case. A new cornersUp property for the HexGrid class implemented in #1649 allows us to check for the correct orientation of the hexagons.


Checklist

  • The release notes (location doc/release/0.X.rst) are up-to-date with any important changes.
  • The documentation is still up-to-date in the doc folder.
  • If any requirements were affected, mention it in the release notes.
  • The dependencies are still up-to-date in pyproject.toml.

@mgjarrett
Copy link
Contributor Author

Note: others may be working on parallel solutions to the issues linked in the PR description. I'm just trying to share the bare-bones outline of a path we could take to fix the problem; I'm not necessarily saying this PR needs to be merged.

@john-science john-science self-requested a review February 15, 2024 21:22
@john-science
Copy link
Member

john-science commented Feb 15, 2024

As I said in the other ticket (#1278), I have am working on a PR that fixes two different HexGrid bugs. I "assigned" that ticket to me to reduce duplicating work. Sorry about that.

I like your property, and haven't looked at your plotting fix yet.

Copy link
Member

@keckler keckler left a comment

Choose a reason for hiding this comment

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

Thanks @mgjarrett for trying these changes! I think there are a couple things that need to be fixed before we can maybe merge it.

Ultimately I think we can make it work, but man this plotBlockDiagram method is frustratingly specific and fragile. In the longer term, it might make sense to split the method into two methods to handle the cases of hexagonal vs cartesian assemblies independently. I think that would make things a lot cleaner. Not asking for you to do this now, just maybe something to think about in a later ticket.

armi/utils/plotting.py Show resolved Hide resolved
armi/utils/plotting.py Show resolved Hide resolved
armi/utils/plotting.py Outdated Show resolved Hide resolved
armi/utils/plotting.py Show resolved Hide resolved
@keckler
Copy link
Member

keckler commented Feb 25, 2024

I might also suggest changing the name of the PR, since this PR is mostly about fixing the block diagrams, IMO. #1649 includes the same changes related to the new cornersUp property.

@mgjarrett
Copy link
Contributor Author

@keckler thanks for the review.

My goal here was just to show in code what the outline of my idea for fixing the problem was; I thought it would be easier than describing it in words. I knew @john-science was working on this issue, so I wanted to wait and see what the code looked like after he finished his work.

Now that he's fixed most of the confusion between flats/corners up, I think it makes sense to change the scope of this to just fixing plotBlockDiagram, as you suggest. I'll take a stab at it when I get a chance today.

@mgjarrett
Copy link
Contributor Author

@keckler I incorporated your comments; the plots look good now (at least for a flats up block; I don't have a corners up block handy for testing).

image

I merged #1649 into this branch locally and tested it, and the plotting still works. So once #1649 is merged into main, this PR can be merged with main and it should all work out.

@mgjarrett mgjarrett changed the title Add cornersUp property to HexGrid. Fix rotation of hexagons in block diagrams Feb 26, 2024
@mgjarrett
Copy link
Contributor Author

I thought about adding unit tests, but this is mostly plotting stuff that is difficult to test directly.

armi/utils/plotting.py Outdated Show resolved Hide resolved
@keckler keckler self-requested a review February 26, 2024 21:02
Copy link
Member

@keckler keckler left a comment

Choose a reason for hiding this comment

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

Thank you for working on this!

Co-authored-by: Chris Keckler <kecklerct@gmail.com>
@mgjarrett mgjarrett added the bug Something is wrong: Highest Priority label Feb 27, 2024
@mgjarrett
Copy link
Contributor Author

Hmm still needs some work for corners up. I think the plotting is right, but the generation of the pin grid is wrong.

image

@mgjarrett
Copy link
Contributor Author

Hmm still needs some work for corners up. I think the plotting is right, but the generation of the pin grid is wrong.

image

I looked into this problem a little more. There's nothing wrong with the plotting code necessarily, it's just that block.autoCreateSpatialGrids() only works if the block is "flats up". I tried to figure out a way to make it work with cornersUp blocks, but the block doesn't know what kind of grid it is going into when the local pin coordinates are auto-created.

Maybe we could check the orientation of the pin coordinates once the block has been placed in a core grid, and then rotate the pins 30 degrees counterclockwise if necessary? It's not a great solution, but it's the only thing I can think of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is wrong: Highest Priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

plotBlockDiagram() doesn't respect block orientation
3 participants