idaholab / MontePy

MontePy is the most user friendly Python library (API) to read, edit, and write MCNP input files.
https://www.montepy.org/
MIT License
32 stars 7 forks source link

No double TMP cards are allowed in MCNP cells #583

Closed dodu94 closed 1 month ago

dodu94 commented 1 month ago

Describe the bug

Hi, montepy seems to not accept double TMP cards in the same cell (and why would it?). While trying to benchmark the C-model parsing I got the error below. Apparently, multiple TMP cards do not throw errors in MCNP, I guess the code just overrides the value. I will understand if you decide not to fix this as this is quite a bizarre behaviour.

To Reproduce

put two TMP cards in a cell

problem = montepy.read_input("foo.imcnp")

Error Message (if any)

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\envs\monte\Lib\site-packages\montepy\mcnp_object.py", line 52, in __init__
    self._tree = parser.parse(input.tokenize(), input)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\ProgramData\Anaconda3\envs\monte\Lib\site-packages\montepy\input_parser\parser_base.py", line 156, in parse
    tree = super().parse(token_generator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\ProgramData\Anaconda3\envs\monte\Lib\site-packages\sly\yacc.py", line 2137, in parse
    value = p.func(self, pslice)
            ^^^^^^^^^^^^^^^^^^^^
  File "C:\ProgramData\Anaconda3\envs\monte\Lib\site-packages\montepy\input_parser\parser_base.py", line 347, in parameters
    params.append(param)
  File "C:\ProgramData\Anaconda3\envs\monte\Lib\site-packages\montepy\input_parser\syntax_node.py", line 2453, in append
    raise RedundantParameterSpecification(key, val)
montepy.errors.RedundantParameterSpecification: Multiple values given for parameter: tmp. new_value given: (Node: TMP: {'classifier': (Classifier: mod: None, prefix: (Value, TMP, padding: None), number: None, particles: None, padding: None), 'seperator': (Padding, ['=']), 'data': (list: number sequence, [(Value, 2.53005e-08, padding: (Padding, [' ', COMMENT: $bc mod remove 310470 and 310495, '\n', COMMENT: c 9999  110 -7.93 (310540 -310546 -310539 310499 -310495 310548 310503), '\n', COMMENT: c       IMP:N=1.0 IMP:P=1.0 TMP=3.87765E-10 U=1054 $ bc mod removed -310470]))])}).

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\DATA\laghida\Documents\test\profiler_cmodel.py", line 10, in <module>
    problem = montepy.read_input(input_file)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\ProgramData\Anaconda3\envs\monte\Lib\site-packages\montepy\input_parser\input_reader.py", line 31, in read_input
    problem.parse_input(replace=replace)
  File "C:\ProgramData\Anaconda3\envs\monte\Lib\site-packages\montepy\mcnp_problem.py", line 382, in parse_input
    raise e
  File "C:\ProgramData\Anaconda3\envs\monte\Lib\site-packages\montepy\mcnp_problem.py", line 367, in parse_input
    obj = obj_parser(input)
          ^^^^^^^^^^^^^^^^^
  File "C:\ProgramData\Anaconda3\envs\monte\Lib\site-packages\montepy\cell.py", line 83, in __init__
    super().__init__(input, self._parser)
  File "C:\ProgramData\Anaconda3\envs\monte\Lib\site-packages\montepy\mcnp_object.py", line 55, in __init__
    raise MalformedInputError(
montepy.errors.MalformedInputError:
: C-Model_R181031_rev190715, line 670557
Error parsing object of type: <class 'montepy.cell.Cell'>: Multiple values given for parameter: tmp. new_value given: (Node: TMP: {'classifier': (Classifier: mod: None, prefix: (Value, TMP, padding: None), number: None, particles: None, padding: None), 'seperator': (Padding, ['=']), 'data': (list: number sequence, [(Value, 2.53005e-08, padding: (Padding, [' ', COMMENT: $bc mod remove 310470 and 310495, '\n', COMMENT: c 9999  110 -7.93 (310540 -310546 -310539 310499 -310495 310548 310503), '\n', COMMENT: c       IMP:N=1.0 IMP:P=1.0 TMP=3.87765E-10 U=1054 $ bc mod removed -310470]))])}).

the full input:
310519 110 -7.93   310547 -310546 310540 -310539 -310474 310479 310503
      310322 :  -310539 310547 -310546 310540 -310479 310481 310503 310322
      310323 :  310547 -310539 -310546 310540 -310481 310483 310503 310324
      310323 :  -310539 -310546 310540 310547 -310483 310487 310503 310326
      310324 310325 :  310547 310540 -310546 -310539 310489 -310487 310503
      310326 310327 :  310547 310540 -310546 -310539 310491 -310489 310503
      310327 310328 :  310547 310540 -310539 -310546 310493 -310491 310503
      310328 310329 :  -310539 310547 310540 -310546 310498 -310493 310503
      310329 310330 :  310540 -310546 -310539 310547 310499 -310498 310330
      310548 310503
      IMP:N=1.0 IMP:P=1.0 TMP=3.87765E-10 U=1054 TMP=2.53005e-008 $bc mod remove 310470 and 310495
c 9999  110 -7.93 (310540 -310546 -310539 310499 -310495 310548 310503)
c       IMP:N=1.0 IMP:P=1.0 TMP=3.87765E-10 U=1054 $ bc mod removed -310470

MCNP input file snippet

whatever input with two TMP cards in one cell.

Version

MicahGale commented 1 month ago

Thanks for the report @dodu94, and for trying to work with ITER-C.

So it looks like multiple TMP are allowed, just not like this.

section 5.7.5

TMP is meant to specify temperatures at multiple time points (why would LANL ever need to model changing temperature? :P). In the manual the only official way is to use a TMPn syntax. There is no discussion of a default, which I assume this is implicitly using.

There's no documentation explicit on if redundant values are or are not allowed. So from an intuition stand point two temperatures for one cell doesn't make sense, and I think raising an error here still makes sense.