Repository navigation
Add HalfSpace.mcnp_str and format_for_mcnp_input - #1033
SpaceOceanCorp wants to merge 8 commits into
Conversation
Print just a cell's geometry as it appears in the MCNP input, e.g. cell.geometry.mcnp_str() -> '-123 234'. The version defaults to the linked cell's problem, then montepy.MCNP_VERSION. Long geometries wrap like any other input.
|
Closed for not using the PR template; you can re-open this if the description is updated to use the template. |
|
@MicahGale Thanks, I've updated the description to use the PR template. GitHub won't let me reopen it since a maintainer closed it, so could you reopen it when you get a chance? The branch is unchanged. |
Put the testcode block in the default group so its testoutput is checked, and use a literal for montepy.MCNP_VERSION, which has no Sphinx target.
MicahGale
left a comment
There was a problem hiding this comment.
The code looks good. However, it introduces a new uncovered line: https://coveralls.io/jobs/190688554
Covers the branch that takes the default version from the cell's problem, which coveralls reported as uncovered.
|
Thanks. The uncovered line was the branch in One limit I found while writing it: a cell made with |
This sounds like a bug, and why don't you investigate if the link needs to be made when using the geometry setter. |
The geometry setter only linked the root node, parsed cells were not linked at all, and clones kept a link to a deep copy of the original cell. So HalfSpace.replace and the divider setter could skip Cell.surfaces, replace could raise KeyError on a clone, and mcnp_str could ignore the version of the cell's problem. Add HalfSpace._link_to_cell, which links every node without resolving dividers, and use it in the setter and _parse_geometry. Seed the deepcopy memo in Cell.clone with the new cell.
|
I looked into it, and you're right that it's a bug. The setter does make the link, but only on the root node, so the leaves keep The setter can't be used from Two related things I left alone: reassigning Separately, |
|
This linking bug is significant enough that we should document it in an issue as well. |
|
Actually could you cherry-pick the bug fix into it's own branch? I want to split this into to separate PRs: one for the bug, and the other for the feature. |
|
Will do next week. |
As requested in review, the bug fix is now in idaholab#1055, so this pull request only adds the feature. This reverts f493a2f.
|
55a199f takes the link fix out of this branch, so this PR now only adds |
Pull Request Checklist for MontePy
Description
cell.geometry.mcnp_str()now prints just the geometry as it appears in the cell card, e.g.-123 234for1 0 -123 234 imp:n=1 u=2.HalfSpace.format_for_mcnp_input()returns the wrapped lines, so long geometries split the same way as any other input. Without an explicit version,mcnp_str()uses the version of the problem the geometry's cell belongs to, thenmontepy.MCNP_VERSION.Cell.format_for_mcnp_input()still formats the geometry through the cell's syntax tree. Calling the new method from there would wrap the geometry lines a second time, so I left the cell path unchanged. Happy to restructure if you prefer that.Tests cover parsed geometries (intersections, unions, groups, complements), geometry built from surfaces with
&and|, a cell whose geometry is replaced, and line wrapping. Changelog entry added under Next Version.Fixes #942
General Checklist
blackversion 25 or 26.LLM Disclosure
Are you?
Were any large language models (LLM or "AI") used in to generate any of this code?
Documentation Checklist
.. versionchanged::or.. versionadded::directives.Infrastructure Changes
N/A, no infrastructure changes.
Significant features or Behavior changes
N/A, small API addition; the method docstring has a doctest example.
First-Time Contributor Checklist
pyproject.tomlif you wish to do so.Additional Notes for Reviewers
Ensure that:
📚 Documentation preview 📚: https://montepy--1033.org.readthedocs.build/en/1033/