Skip to content

Commit

Permalink
Merge branch 'alpha-test-dev' into 631_update
Browse files Browse the repository at this point in the history
  • Loading branch information
MicahGale authored Feb 12, 2025
2 parents bd78f7a + 6e5a313 commit 281d85b
Show file tree
Hide file tree
Showing 13 changed files with 300 additions and 216 deletions.
3 changes: 3 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ MontePy Changelog
* Added ability to parse all MCNP objects from a string (:issue:`88`).
* Added function: :func:`~montepy.mcnp_problem.MCNP_Problem.parse` to parse arbitrary MCNP object (:issue:`88`).
* An error is now raised when typos in object attributes are used, e.g., ``cell.nubmer`` (:issue:`508`).
* Warnings are no longer raised for comments that exceed the maximum line lengths (:issue:`188`).
* Particle type exceptions are now warnings, not errors (:issue:`381`).


**Bugs Fixed**

Expand Down
1 change: 1 addition & 0 deletions montepy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +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.
Expand Down
2 changes: 0 additions & 2 deletions montepy/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ def handle_error(e):
except (
BrokenObjectLinkError,
MalformedInputError,
ParticleTypeNotInProblem,
ParticleTypeNotInCell,
) as e:
handle_error(e)
continue
Expand Down
9 changes: 8 additions & 1 deletion montepy/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Copyright 2024, Battelle Energy Alliance, LLC All Rights Reserved.
# Copyright 2024-2025, Battelle Energy Alliance, LLC All Rights Reserved.
import re

from montepy.errors import UnsupportedFeature

"""
Expand All @@ -25,6 +27,11 @@
Number of spaces in a new line before it's considered a continuation.
"""

COMMENT_FINDER = re.compile(rf"\s{{0,{BLANK_SPACE_CONTINUE - 1}}}c", re.IGNORECASE)
"""
A regular expression for finding the start of a ``c`` style comment.
"""

LINE_LENGTH = {
(5, 1, 60): 80,
(6, 1, 0): 80,
Expand Down
12 changes: 7 additions & 5 deletions montepy/data_inputs/importance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import collections
import copy
import math
import warnings
from montepy.data_inputs.cell_modifier import CellModifierInput, InitInput
from montepy.errors import *
from montepy.constants import DEFAULT_VERSION, rel_tol, abs_tol
Expand Down Expand Up @@ -279,8 +280,9 @@ def _clear_data(self):
def _check_particle_in_problem(self, particle_type):
if self._problem:
if particle_type not in self._problem.mode:
raise ParticleTypeNotInProblem(
f"Particle type: {particle_type} not included in problem mode."
warnings.warn(
f"Particle type: {particle_type} not included in problem mode.",
ParticleTypeNotInProblem,
)

def _collect_new_values(self):
Expand All @@ -291,9 +293,10 @@ def _collect_new_values(self):
try:
tree = cell.importance._particle_importances[particle]
except KeyError:
raise ParticleTypeNotInCell(
raise NotImplementedError(
f"Importance data not available for cell {cell.number} for particle: "
f"{particle}, though it is in the problem"
f"{particle}, though it is in the problem, and default importance logic "
"is not yet implemented in MontePy."
)
new_vals[particle].append(tree["data"][0])
if len(particle_pairings[particle]) == 0:
Expand Down Expand Up @@ -483,7 +486,6 @@ def __create_particle_imp_doc(particle_type):
:type importnace: float
:returns: the importance for the particle type. If not set, defaults to 0.
:rtype: float
:raises ParticleTypeNotInProblem: raised if this particle is accessed while not in the problem mode.
"""


Expand Down
21 changes: 14 additions & 7 deletions montepy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,26 +153,33 @@ def __init__(self, key, new_value):
super().__init__(self.message)


class ParticleTypeNotInProblem(ValueError):
class ParticleTypeWarning(Warning):
"""
Raised when data are set for a particle type not in
the problem's mode.
Base class for incongruencies between particle types
in problem mode, cell importances, and tallies
"""

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


class ParticleTypeNotInCell(ValueError):
class ParticleTypeNotInProblem(ParticleTypeWarning):
"""
Raised when data, such as cell importance or tally type,
are set for a particle type not in the problem's mode.
"""

pass


class ParticleTypeNotInCell(ParticleTypeWarning):
"""
Raised when data for importance data for a particle in
the problem is not provided for a cell.
"""

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


class UnsupportedFeature(NotImplementedError):
Expand Down
28 changes: 18 additions & 10 deletions montepy/input_parser/input_syntax_reader.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Copyright 2024, Battelle Energy Alliance, LLC All Rights Reserved.
from .block_type import BlockType
# Copyright 2024-2025, Battelle Energy Alliance, LLC All Rights Reserved.
from collections import deque
from .. import errors
import itertools
import io
import re
import os
import warnings

from montepy.constants import *
from montepy.errors import *
from montepy.input_parser.block_type import BlockType
from montepy.input_parser.input_file import MCNP_InputFile
from montepy.input_parser.mcnp_input import Input, Message, ReadInput, Title
from montepy.input_parser.read_parser import ReadParser
from montepy.utilities import is_comment
import os
import warnings


reading_queue = []

Expand Down Expand Up @@ -174,15 +176,21 @@ def flush_input():
yield from flush_input()
# die if it is a vertical syntax format
if "#" in line[0:BLANK_SPACE_CONTINUE] and not line_is_comment:
raise errors.UnsupportedFeature("Vertical Input format is not allowed")
raise UnsupportedFeature("Vertical Input format is not allowed")
# cut line down to allowed length
old_line = line
line = line[:line_length]
if len(old_line) != len(line):
warnings.warn(
f"The line: {old_line} exceeded the allowed line length of: {line_length} for MCNP {mcnp_version}",
errors.LineOverRunWarning,
)
if len(line.split("$")[0]) >= line_length and not COMMENT_FINDER.match(
line
):
warnings.warn(
f"The line: {old_line} exceeded the allowed line length of: {line_length} for MCNP {mcnp_version}",
LineOverRunWarning,
)
# if extra length is a comment keep it long
else:
line = old_line
if line.endswith(" &\n"):
continue_input = True
else:
Expand Down
34 changes: 22 additions & 12 deletions montepy/mcnp_object.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 __future__ import annotations
from abc import ABC, ABCMeta, abstractmethod
import copy
Expand All @@ -14,6 +14,7 @@
from montepy.errors import *
from montepy.constants import (
BLANK_SPACE_CONTINUE,
COMMENT_FINDER,
get_max_line_length,
rel_tol,
abs_tol,
Expand Down Expand Up @@ -324,17 +325,26 @@ def wrap_string_for_mcnp(
for line in strings:
buffer = wrapper.wrap(line)
if len(buffer) > 1:
warning = LineExpansionWarning(
f"The line exceeded the maximum length allowed by MCNP, and was split. The line was:\n{line}"
)
warning.cause = "line"
warning.og_value = line
warning.new_value = buffer
warnings.warn(
warning,
LineExpansionWarning,
stacklevel=2,
)
# don't warn for comments, nor line wrap
# this order assumes that comment overruns are rare
if COMMENT_FINDER.match(line):
buffer = [line]
elif "$" in line:
parts = line.split("$")
buffer = wrapper.wrap(parts[0])
buffer[-1] = "$".join([buffer[-1]] + parts[1:])
else:
warning = LineExpansionWarning(
f"The line exceeded the maximum length allowed by MCNP, and was split. The line was:\n{line}"
)
warning.cause = "line"
warning.og_value = line
warning.new_value = buffer
warnings.warn(
warning,
LineExpansionWarning,
stacklevel=2,
)
# lazy final guard against extra lines
if suppress_blank_end:
buffer = [s for s in buffer if s.strip()]
Expand Down
8 changes: 1 addition & 7 deletions montepy/mcnp_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,7 @@ def handle_error(e):
for surface in self._surfaces:
try:
surface.update_pointers(self.surfaces, self._data_inputs)
except (
BrokenObjectLinkError,
ParticleTypeNotInProblem,
ParticleTypeNotInCell,
) as e:
except (BrokenObjectLinkError,) as e:
handle_error(e)
to_delete = []
for data_index, data_input in enumerate(self._data_inputs):
Expand All @@ -441,8 +437,6 @@ def handle_error(e):
except (
BrokenObjectLinkError,
MalformedInputError,
ParticleTypeNotInProblem,
ParticleTypeNotInCell,
) as e:
handle_error(e)
continue
Expand Down
2 changes: 1 addition & 1 deletion tests/inputs/test.imcnp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ C Iron
m2 26054.80c 5.85
plib= 80p
26056.80c 91.75
26057.80c 2.12
26057.80c 2.12 $ very very very very very very very very very very very very very very long line that exceeds line limit
26058.80c 0.28 $ trailing comment shouldn't move #458.
C water
C foo
Expand Down
48 changes: 48 additions & 0 deletions tests/inputs/test_not_imp.imcnp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
A test with a default importance (Not Implemented)
C cells
c
1 1 20
-1000 $ dollar comment
U=350 trcl=5
imp:n,p=1 $ imp:e should default to 1
2 2 8
-1005
imp:n,p=1 $ imp:e should default to 1
3 3 -1
1000 1005 -1010
imp:n=3 $ imp:e and imp:p should default to 1
99 0
1010
imp:n=9 $ imp:e should default to 1
imp:p=0
5 0
#99
imp:n=0 $ imp:e should default to 0
imp:p=0
c foo end comment

C surfaces
1000 SO 1
1005 RCC 0 1.5 -0.5 0 0 1 0.25
1010 SO 3

C data
C materials
C UO2 5 atpt enriched
m1 92235.80c 5 &
92238.80c 95
C Iron
m2 26054.80c 5.85
26056.80c 91.75
26057.80c 2.12
26058.80c 0.28
C water
m3 1001.80c 2
8016.80c 1
MT3 lwtr.23t
C execution
ksrc 0 0 0
kcode 100000 1.000 50 1050
phys:p j 1 2j 1
mode n p e

1 change: 1 addition & 0 deletions tests/inputs/test_universe.imcnp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ c
c foo end comment

C surfaces
c this comment is a ver very very very very very very very very very long line in a comment that shouldn't raise a warning but maybe?
1000 SO 1
1005 RCC 0 1.5 -0.5 0 0 1 0.25
1010 SO 3
Expand Down
Loading

0 comments on commit 281d85b

Please sign in to comment.