Fix manually set default importances not printed#921
Fix manually set default importances not printed#921
Conversation
…n-newly-created-cells
tests/test_importance.py
Outdated
| # Cell 4 should give "imp:n=4.0" | ||
| c4 = montepy.Cell(number=7) | ||
| c4.geometry = -problem.surfaces[1010] | ||
| c4.importance.neutron = 4.0 | ||
| problem.cells.append(c4) |
There was a problem hiding this comment.
Finally, I noticed that in the tests for cell 4 only importance.neutron is set but the expected behavior is to print the default value for importance.photon. I decided to ignore this for now, and we can discuss
Because the problem is in mode n p, then the photon importance needs to be printed as well.
There was a problem hiding this comment.
So whenever any importance is set all importances for that cell should print?
There was a problem hiding this comment.
All importances for the problem mode should print*, else MCNP will error out with X entries not equal to number of cells = Y.
*unless explicitly nullified for all cells, which is a feature that can be supported at a later date. See MCNP 6.3.1 Manual § 5.12.1:
Similarly, if an
IMP:parameter appears on one cell card, a fatal error occurs if a
comparable entry does not appear on all cell card
tests/test_importance.py
Outdated
| for cell_num, imp_str in { | ||
| 4: "IMP:n=2.0 IMP:p=2.0", | ||
| 6: "IMP:n=1.0 IMP:p=1.0", | ||
| 7: "IMP:n=4.0", |
Pull Request Checklist for MontePy
Description
This fixes the bug where cells made from scratch almost never prints their importance in the output no matter if the importance were manually set (#892). Turns out that the parameter
self._explicilty_setis set toTruewhen the official setters are used, however, this value is never checked for formatting. To fix this was rather trivial.However this issue brought up a question of behavior. In the test case
cell.importance.all=1.0is used on an unattached cell. It's assumed that this would set all importance. However, the documentation says that this only works on the particles in the problem. The code assumed that if the cell is not attached to a problem thatcell.importance.allhas no effect. This is rather intuitive. So I decided on the following behavior. Is this correct?importance.allsets the importance for every (~37) particle types.problem.modebefore printing. This is to avoid ~37 separateimp:X=1clauses.Finally, I noticed that in the tests for cell 4 only
importance.neutronis set but the expected behavior is to print the default value forimportance.photon. I decided to ignore this for now, and we can discuss.lFixes #892
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
First-Time Contributor Checklist
pyproject.tomlif you wish to do so.Additional Notes for Reviewers
Ensure that:
📚 Documentation preview 📚: https://montepy--921.org.readthedocs.build/en/921/