Skip to content

Bugs with setting multiple Cell importances after adding to Problem #913

@tjlaboss

Description

@tjlaboss

Bug Description

The Cell.importance parameter has some odd behavior when it is set for multiple particle types after adding a Cell to an MCNP_Problem. If the importance for the particle types is the same, it is printed multiple times: first for the first particle only, and then for the growing combination of particles. If the importance for the particle types is different, it causes an error.

To Reproduce

import io
import montepy
deck = montepy.read_input("base_problem.i")

# Works, but produces invalid MCNP
c2 = montepy.Cell(number=2)
c2.geometry = -deck.surfaces[2] & +deck.surfaces[3]
deck.cells.append(c2)
c2.importance.photon = 2.0 
c2.importance.neutron = 2.0 

with io.StringIO() as stream:
    deck.write_problem(stream)
    stream.seek(0)
    print(stream.read())
    stream.close()

# Crashes MontePy
c3 = montepy.Cell(number=3)
c3.geometry = -deck.surfaces[3] & +deck.surfaces[4]
deck.cells.append(c3)
c3.importance.photon = 3.0 
c3.importance.neutron = 4.0 

with io.StringIO() as stream:
    deck.write_problem(stream)
    stream.seek(0)
    print(stream.read())
    stream.close()

Input MCNP file snippet

Details

base_problem.i

Example MCNP Input File
C cells
1 1 20 -1
        imp:n,p=1 
9 0     +1  imp:n,p=0
C New cells are added here 

C surfaces
1 SO 9
2 SO 8
3 SO 7
4 SO 6
5 SO 5

C data
mode n p
C materials
C UO2 5 atpt enriched
m1       92238.80c  1.0
c transforms
c run parameters
ksrc  0.0  0.0  1.0
kcode 100 0.1 1 11

Output MCNP file snippet

Details
Example MCNP Input File
C cells
1 1 20 -1
        imp:n,p=1 
9 0     +1  imp:n,p=0
C New cells are added here 
2 0 -2 3 IMP:n=2.0 IMP:p,n=2.0 

C surfaces
1 SO 9
2 SO 8
3 SO 7
4 SO 6
5 SO 5

C data
mode n p
C materials
C UO2 5 atpt enriched
m1       92238.80c  1.0
c transforms
c run parameters
ksrc  0.0  0.0  1.0
kcode 100 0.1 1 11

Traceback

Details
Traceback (most recent call last):
  File "./example.py", line 18, in <module>
    deck.write_problem(stream)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "./montepy/mcnp_problem.py", line 548, in write_problem
    self._write_to_stream(new_file)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "./montepy/mcnp_problem.py", line 602, in _write_to_stream
    lines = obj.format_for_mcnp_input(self.mcnp_version)
  File "./montepy/mcnp_object.py", line 49, in wrapped
    add_line_number_to_exception(e, self)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "./montepy/exceptions.py", line 235, in add_line_number_to_exception
    raise error
  File "./montepy/mcnp_object.py", line 41, in wrapped
    return func(*args, **kwargs)
  File "./montepy/cell.py", line 835, in format_for_mcnp_input
    getattr(self, attr).format_for_mcnp_input(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        mcnp_version, param is not final_param
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "./montepy/mcnp_object.py", line 49, in wrapped
    add_line_number_to_exception(e, self)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "./montepy/exceptions.py", line 235, in add_line_number_to_exception
    raise error
  File "./montepy/mcnp_object.py", line 41, in wrapped
    return func(*args, **kwargs)
  File "./montepy/data_inputs/cell_modifier.py", line 292, in format_for_mcnp_input
    self._format_tree(),
    ~~~~~~~~~~~~~~~~~^^
  File "./montepy/mcnp_object.py", line 49, in wrapped
    add_line_number_to_exception(e, self)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "./montepy/exceptions.py", line 259, in add_line_number_to_exception
    raise error.with_traceback(trace)
  File "./montepy/mcnp_object.py", line 41, in wrapped
    return func(*args, **kwargs)
  File "./montepy/data_inputs/importance.py", line 265, in _format_tree
    other_particles.remove(removee)
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "./montepy/input_parser/syntax_node.py", line 1599, in remove
    self._order.remove(value)
    ~~~~~~~~~~~~~~~~~~^^^^^^^
ValueError: list.remove(x): x not in list

Error came from IMPORTANCE: neutron=4.0, photon=3.0 from an unknown file.

Version

  • Version 1.3.0

Additional context

Possibly related #892

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsA deviation from expected behavior that does not reach the level of being reportable as an "Error".bugs of unusual importanceBugs related to the Rube Goldberg machine that is the Importance class.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions