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 bug with how new material components are exported. #598

Merged
18 changes: 12 additions & 6 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,35 @@ Please provide a summary of the change, referencing the issue it fixes, if appli
- [ ] I have performed a self-review of my own code.
- [ ] The code follows the standards outlined in the [development documentation](https://idaholab.github.io/MontePy/developing.html).
- [ ] I have added tests that prove my fix is effective or that my feature works (if applicable).
- [ ] I have made corresponding changes to the documentation, providing clear details on the added or modified functionality (if applicable).

---

### Documentation Checklist
<details open>

<summary><h3>Documentation Checklist</h3></summary>

- [ ] I have documented all added classes and methods.
- [ ] For infrastructure updates, I have updated the developer's guide.
- [ ] For significant new features, I have added a section to the getting started guide.

</details>

---

### First-Time Contributor Checklist
<details>
<summary><h3>First-Time Contributor Checklist</h3></summary>

- [ ] If this is your first contribution, add yourself to `pyproject.toml` if you wish to do so.

</details>

---

### Additional Notes for Reviewers

Ensure that:

- The submitted code is consistent with the merge checklist outlined [here](https://www.montepy.org/developing.html#merge-checklist).
- The tests pass locally before CI checks.
- The PR covers all relevant aspects according to the development guidelines.
- [ ] The submitted code is consistent with the merge checklist outlined [here](https://www.montepy.org/developing.html#merge-checklist).
- [ ] The PR covers all relevant aspects according to the development guidelines.
- [ ] 100% coverage of the patch is achieved, or justification for a variance is given.
"""
7 changes: 7 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ MontePy Changelog
0.5 releases
============

#Next Version#
--------------

**Bug Fixes**

* Fixed how material components work so new components can actually be added to a material and exported (:issue`597`).

0.5.2
--------------

Expand Down
7 changes: 6 additions & 1 deletion montepy/data_inputs/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,13 @@ def format_for_mcnp_input(self, mcnp_version):

def _update_values(self):
new_list = syntax_node.IsotopesNode("new isotope list")
for isotope, component in self._material_components.items():
for idx, (isotope, component) in enumerate(self._material_components.items()):
isotope._tree.value = isotope.mcnp_str()
node = component._tree
node.is_negatable_float = True
node.is_negative = not self.is_atom_fraction
if idx < len(self._material_components) - 1 and not node.padding:
node.padding = syntax_node.PaddingNode(" ")
new_list.append(("_", isotope._tree, component._tree))
self._tree.nodes["data"] = new_list

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ test = [
"coverage[toml]>=6.3.2",
"hypothesis",
"pytest",
"hypothesis",
"pytest-profiling",
"montepy[build]",
"phmutest",
Expand Down
31 changes: 31 additions & 0 deletions tests/test_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,37 @@ def test_material_sort(self):
self.assertEqual(mat, answers[i])


@pytest.mark.parametrize(
"isotope_str, atom_frac, fraction",
[("2004.80c", False, 0.1), ("1001.70c", True, 0.1)],
)
@pytest.mark.filterwarnings("ignore")
def test_material_component_add(isotope_str, atom_frac, fraction):
frac_marker = "-" if not atom_frac else ""
in_str = f"M20 1001.80c {frac_marker}0.5 8016.80c {frac_marker}0.5"
input_card = Input([in_str], BlockType.DATA)
material = Material(input_card)
iso = Isotope(isotope_str)
comp = MaterialComponent(iso, fraction)
material.material_components[iso] = comp
verify_export(material)


def verify_export(mat):
output = mat.format_for_mcnp_input((6, 3, 0))
print(output)
new_mat = Material(Input(output, BlockType.DATA))
assert mat.number == new_mat.number, "Material number not preserved."
assert len(mat.material_components) == len(new_mat.material_components)
for old_comp, new_comp in zip(
mat.material_components.values(), new_mat.material_components.values()
):
assert str(old_comp.isotope) == str(
new_comp.isotope
), "Material didn't preserve nuclides."
assert old_comp.fraction == pytest.approx(new_comp.fraction)
MicahGale marked this conversation as resolved.
Show resolved Hide resolved


def test_material_format_mcnp():
in_strs = ["M20 1001.80c 0.5", " 8016.80c 0.5"]
input_card = Input(in_strs, BlockType.DATA)
Expand Down
Loading