Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
0132b0f
exception for undefined new block in mcnp input
kordusas Oct 7, 2025
f3561a5
added block length counter to calculate the line of the extra block…
kordusas Oct 7, 2025
6e00363
testing error raising for the extra input
kordusas Oct 7, 2025
aab3a8a
black formatting
kordusas Oct 7, 2025
13b0bcf
changelog feuture addition
kordusas Oct 7, 2025
5f74b73
changelog addition
kordusas Oct 7, 2025
6c59b5b
Merge branch 'feature/525-detect-empty-lines' of https://github.com/k…
kordusas Oct 7, 2025
e6f8f2f
exception for undefined new block in mcnp input
kordusas Oct 7, 2025
6b62642
added block length counter to calculate the line of the extra block…
kordusas Oct 7, 2025
18b6723
testing error raising for the extra input
kordusas Oct 7, 2025
9fe1ba8
black formatting
kordusas Oct 7, 2025
aa5c1fc
changelog addition
kordusas Oct 7, 2025
7ada573
changelog feuture addition
kordusas Oct 7, 2025
1eb1c95
Merge branch 'feature/525-detect-empty-lines' of https://github.com/k…
kordusas Oct 7, 2025
3ffdd0e
Revert "changelog feuture addition"
kordusas Oct 7, 2025
7d3c955
Revert "changelog addition"
kordusas Oct 7, 2025
d2061cd
correct changelog
kordusas Oct 7, 2025
86c76a7
added input to list of "BAD" inputs
kordusas Oct 10, 2025
eef45f5
bug fix for extra line printing after DATA BLOCK when cell data shoul…
kordusas Oct 10, 2025
bdd1054
Merge branch 'develop' into feature/525-detect-empty-lines
MicahGale Oct 10, 2025
b201a11
bug fix comment
kordusas Oct 12, 2025
deaac50
updated the block parsing by using termination and stop parsing after…
kordusas Oct 12, 2025
c7feacd
corrected test according to updated error message
kordusas Oct 12, 2025
2a8749d
changed to isinstance. Comparing obj (last object read in BLOCK) to D…
kordusas Oct 12, 2025
337402a
Merge branch 'feature/525-detect-empty-lines' of https://github.com/k…
kordusas Oct 12, 2025
770a797
fixed \n error
kordusas Oct 12, 2025
2d1b5e5
Merge branch 'develop' into feature/525-detect-empty-lines
MicahGale Oct 13, 2025
292bf6a
Merge branch 'develop' into feature/525-detect-empty-lines
MicahGale Oct 14, 2025
aed4e73
Merge branch 'develop' into feature/525-detect-empty-lines
MicahGale Oct 14, 2025
1811498
updated description
kordusas Oct 15, 2025
9b3c5c4
updated IF condition
kordusas Oct 15, 2025
6a2c424
Merge branch 'develop' into feature/525-detect-empty-lines
kordusas Oct 15, 2025
9c10c65
Merge branch 'feature/525-detect-empty-lines' of https://github.com/k…
kordusas Oct 15, 2025
f24db49
Merge branch 'develop' into feature/525-detect-empty-lines
MicahGale Oct 17, 2025
45d607d
using return to get out of the generator instead of using bool flag
kordusas Oct 21, 2025
caedfbd
fixed issue of getting errors if there are even more blocks than 4 ..
kordusas Oct 21, 2025
0c05f4e
added comment on issue fix
kordusas Oct 21, 2025
721e90a
Merge branch 'feature/525-detect-empty-lines' of https://github.com/k…
kordusas Oct 21, 2025
7845890
formatting
kordusas Oct 21, 2025
1b9e231
removed leftover redundant lines during testing
kordusas Oct 22, 2025
b2ff351
fixing up changelog
kordusas Oct 22, 2025
5e58b8f
Merge branch 'develop' into feature/525-detect-empty-lines
MicahGale Oct 23, 2025
8429ea3
Added issue number to changelog.
MicahGale Oct 23, 2025
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
6 changes: 4 additions & 2 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ MontePy Changelog

**Features Added**

* Allow multiple universe fills to accept 2D MNCP lattices (:issue:`719`)
* Added checking for additional input after the ``data`` block, and raising a warning if it exists (:issue:`525`).
* Allow multiple universe fills to accept 2D MNCP lattices (:issue:`719`).
* Make `LatticeType.RECTANGULAR` and `LatticeType.HEXAHEDRAL` synonymous (:issue:`808`).
* Allow setting ``cell.fill.universes`` with a numpy array of universe IDs (:issue:`736`).

**Bugs Fixed**

* Fixed bug where lines that were the allowed length was raising a ``LineOverRunWarning`` when read by MontePy (:issue:`517`).
* Added descriptive TypeError messages (:issue:`801`)
* Fixed a bug that caused to write an extra termination line between the data block and the cell data section in the MCNP input. (:pull:`819`) (:issue:`703`).

**Documentation**

Expand All @@ -37,7 +39,6 @@ MontePy Changelog

1.1.3
--------------

**Features Added**

* Added Boundary condition type to the representation of a ``montepy.Surface`` (e.g., ``repr(surf)``) (:issue:`682`).
Expand All @@ -51,6 +52,7 @@ MontePy Changelog
* Fixed bug where lines that were the allowed length was raising a ``LineOverRunWarning`` when read by MontePy (:issue:`517`).
* Added descriptive TypeError messages (:issue:`801`)


1.1.2
--------------

Expand Down
7 changes: 7 additions & 0 deletions montepy/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ def __init__(self, message):
self.message = message


class UndefinedBlock(UserWarning):
"""Raised when additional blocks exist after the default data block."""

def __init__(self, message):
self.message = message


class MalformedInputError(ValueError):
"""Raised when there is an error with the MCNP input not related to the parser."""

Expand Down
13 changes: 13 additions & 0 deletions montepy/input_parser/input_syntax_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def read_data(fh, mcnp_version, block_type=None, recursion=False):

def flush_block():
nonlocal block_counter, block_type
# keep parsing while there is input or termination has not been triggered
if len(input_raw_lines) > 0:
yield from flush_input()
block_counter += 1
Expand All @@ -154,6 +155,17 @@ def flush_block():

def flush_input():
nonlocal input_raw_lines
# IF 3 BLOCKS are parsed, the rest should be ignored with a warning and print 3 lines
if block_counter >= 3:
joined_lines = "\n".join(input_raw_lines[0:3])
msg = f"Unexpected input after line {current_file.lineno - 1}\n line content: {joined_lines}\n"
warnings.warn(
msg,
UndefinedBlock,
stacklevel=6,
)
return

start_line = current_file.lineno + 1 - len(input_raw_lines)
input = Input(
input_raw_lines,
Expand Down Expand Up @@ -191,6 +203,7 @@ def flush_input():
and input_raw_lines
):
yield from flush_input()

# die if it is a vertical syntax format
start_o_line = line[0:BLANK_SPACE_CONTINUE]
# eliminate comments, and inputs that use # for other syntax
Expand Down
14 changes: 8 additions & 6 deletions montepy/mcnp_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,14 +612,16 @@ def _write_to_stream(self, inp):
warning.handled = True
for line in lines:
inp.write(line + "\n")
if terminate:

# writing cell data in DATA BLOCK if the last written object inherits DataInputAbstract and there is cell data to write
if objects is self.data_inputs:
for line in self.cells._run_children_format_for_mcnp(
self.data_inputs, self.mcnp_version
):
inp.write(line + "\n")
elif terminate:
inp.write("\n")
for line in self.cells._run_children_format_for_mcnp(
self.data_inputs, self.mcnp_version
):
inp.write(line + "\n")

inp.write("\n")
self._handle_warnings(warning_catch)

def _handle_warnings(self, warning_queue):
Expand Down
1 change: 1 addition & 0 deletions tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"test_extra_data_param.imcnp",
"test_extra_data_imp.imcnp",
"number_conflict_pin_cell.imcnp",
"test_pin_cell_extra_block_warning.imcnp",
}
IGNORE_FILES = {
"testReadRec1.imcnp",
Expand Down
36 changes: 36 additions & 0 deletions tests/inputs/test_pin_cell_extra_block_warning.imcnp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Made up PWR pin Cell Problem
c uranium rod
1 1 10.0 -1 101 -102 imp:n=1
c gas gap
2 0 1 -2 101 -102 imp:n=1
c cladding
3 10 5.0 2 -3 101 -102 imp:n=1
c water cell
5 2 1.0 2 101 -102
103 -104
105 -106 imp:n=1

1 CZ 0.39
2 CZ 0.40
3 CZ 0.46
101 PZ -0.63
102 PZ 0.63
103 PX -0.63
104 PX 0.63
105 PY -0.63
106 PY 0.63

M1 92235.80c 0.04
92238.80c 0.96
M2 1001.80c 0.66
8016.80c 0.33
M10 40090.80c 0.515
40091.80c 0.112
40092.80c 0.171
40094.80c 0.174
40096.80c 0.028
mode n
nps 1e3

M101 92235.80c 0.04
92238.80c 0.96
28 changes: 28 additions & 0 deletions tests/test_syntax_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from montepy.input_parser.shortcuts import Shortcuts
from montepy.input_parser import syntax_node
from montepy.particle import Particle
from montepy.exceptions import UndefinedBlock
import warnings


Expand Down Expand Up @@ -1472,6 +1473,33 @@ def test_jump_and_a_hop(self):
str(jump)
repr(jump)

def test_extra_block_warning(self):
# Define constants for better readability and maintainability
INPUT_FILE = "tests/inputs/test_pin_cell_extra_block_warning.imcnp"
EXPECTED_LINE = 34
EXPECTED_CONTENT = "M101 92235.80c 0.04\n 92238.80c 0.96\n"
EXPECTED_WARNING_TYPE = UndefinedBlock

# Setup: Use the common pattern for defining the generator
generator = input_syntax_reader.read_input_syntax(MCNP_InputFile(INPUT_FILE))

# Check that the expected warning is raised
with pytest.warns(EXPECTED_WARNING_TYPE) as recs:
# Exhaust generator so parser runs and warnings are emitted
for _ in generator:
pass

# Assertions
assert len(recs) == 1, f"Expected exactly one warning, but got {len(recs)}"
warning = recs[0]
assert issubclass(
warning.category, EXPECTED_WARNING_TYPE
), f"Expected warning type {EXPECTED_WARNING_TYPE}, but got {warning.category}"
assert (
str(warning.message)
== f"Unexpected input after line {EXPECTED_LINE}\n line content: {EXPECTED_CONTENT}"
), f"Expected warning message 'Unexpected input after line {EXPECTED_LINE}\n line content: {EXPECTED_CONTENT}', but got '{str(warning.message)}'"


class TestClassifierNode:
def test_classifier_init(self):
Expand Down