Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ MontePy Changelog

* Made it so that a material created from scratch can be written to file (:issue:`512`).
* Added support for parsing materials with parameters mixed throughout the definition (:issue:`182`).
* Fixed bug where ``surf.is_reflecting`` would put an extra space in the output e.g., ``* 1 PZ...`` (:issue:`697`).
* Fixed bug where setting a lattice would print as ``LAT=None``. Also switched ``CellModifier`` to print in the cell block by default (:issue:`699`).

**Breaking Changes**
Expand Down
2 changes: 1 addition & 1 deletion montepy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Copyright 2024-2025, Battelle Energy Alliance, LLC All Rights Reserved.
# Copyright 2024, Battelle Energy Alliance, LLC All Rights Reserved.
"""MontePy is a library for reading, editing, and writing MCNP input files.

This creates a semantic understanding of the MCNP input file.
Expand All @@ -19,6 +18,7 @@
from montepy.data_inputs.transform import Transform
from montepy.data_inputs.nuclide import Library, Nuclide
from montepy.data_inputs.element import Element
from montepy.data_inputs.lattice import Lattice
from montepy.data_inputs.thermal_scattering import ThermalScatteringLaw
from montepy.data_inputs.data_parser import parse_data

Expand Down
8 changes: 4 additions & 4 deletions montepy/input_parser/surface_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024, Battelle Energy Alliance, LLC All Rights Reserved.
# Copyright 2024-2025, Battelle Energy Alliance, LLC All Rights Reserved.
from montepy.input_parser.parser_base import MCNP_Parser
from montepy.input_parser.tokens import SurfaceLexer
from montepy.input_parser import syntax_node
Expand Down Expand Up @@ -42,10 +42,10 @@ def surface(self, p):
@_('"*" number_phrase', '"+" number_phrase', "number_phrase")
def surface_id(self, p):
ret = {}
token = None
if isinstance(p[0], str) and p[0] in {"*", "+"}:
ret["modifier"] = syntax_node.ValueNode(p[0], str)
else:
ret["modifier"] = syntax_node.ValueNode(None, str)
token = p[0]
ret["modifier"] = syntax_node.ValueNode(token, str, never_pad=True)

ret["number"] = p.number_phrase
return syntax_node.SyntaxNode("surface_number", ret)
25 changes: 23 additions & 2 deletions tests/test_surfaces.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright 2024, Battelle Energy Alliance, LLC All Rights Reserved.
# Copyright 2024-2025, Battelle Energy Alliance, LLC All Rights Reserved.
from unittest import TestCase
import pytest

import montepy

from montepy.errors import MalformedInputError
from montepy.input_parser.block_type import BlockType
from montepy.input_parser.mcnp_input import Input
Expand Down Expand Up @@ -135,6 +135,7 @@ def test_surface_is_reflecting_setter(self):
surf = Surface(card)
surf.is_reflecting = True
self.assertTrue(surf.is_reflecting)
self.verify_export(surf)
with self.assertRaises(TypeError):
surf.is_reflecting = 1

Expand All @@ -144,6 +145,7 @@ def test_surface_is_white_bound_setter(self):
surf = Surface(card)
surf.is_white_boundary = True
self.assertTrue(surf.is_white_boundary)
self.verify_export(surf)
with self.assertRaises(TypeError):
surf.is_white_boundary = 1

Expand Down Expand Up @@ -312,3 +314,22 @@ def test_cylinder_location_setter(self):
# test length issues
with self.assertRaises(ValueError):
surf.coordinates = [3, 4, 5]

def verify_export(_, surf):
output = surf.format_for_mcnp_input((6, 3, 0))
print("Surface output", output)
new_surf = Surface("\n".join(output))
assert surf.number == new_surf.number, "Material number not preserved."
assert len(surf.surface_constants) == len(
new_surf.surface_constants
), "number of surface constants not kept."
for old_const, new_const in zip(
surf.surface_constants, new_surf.surface_constants
):
assert old_const == pytest.approx(new_const)
assert surf.is_reflecting == new_surf.is_reflecting
assert surf.is_white_boundary == new_surf.is_white_boundary
if surf.old_periodic_surface:
assert surf.old_periodic_surface == new_surf.old_periodic_surface
if surf.old_transform_number:
assert surf.old_transform_number == new_surf._old_transform_number