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

Can't make a material from scratch and export it. #512

Open MicahGale opened 3 months ago

MicahGale commented 3 months ago

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

A short code snippet of what you have ran. Please change or remove any specific values or anything that can't be public. For example:

import montepy

def gen_mega_mat():
    mat = montepy.data_inputs.Material()
    mat.number = 1
    mat._is_atom_fraction = True
    for i in range(1,93):
        iso = montepy.data_inputs.isotope.Isotope(f"{int(i*1000 + i*2.1)}.80c")
        mat.material_components[iso] = montepy.data_inputs.material_component.MaterialComponent(iso, 0.01)
    print(mat.format_for_mcnp_input((6,3,0)))

gen_mega_mat()                           

Error Message (if any)

Press ENTER or type command to continue
  File "/home/mgale/dev/montepy/gen_big_model.py", line 10
    print(mat.format_for_mcnp_input((6,3,0))
         ^
SyntaxError: '(' was never closed

shell returned 1

Press ENTER or type command to continue
Traceback (most recent call last):
  File "/home/mgale/dev/montepy/gen_big_model.py", line 12, in <module>
    gen_mega_mat()
  File "/home/mgale/dev/montepy/gen_big_model.py", line 10, in gen_mega_mat
    print(mat.format_for_mcnp_input((6,3,0)))
  File "/home/mgale/dev/montepy/montepy/data_inputs/material.py", line 145, in format_for_mcnp_input
    lines = super().format_for_mcnp_input(mcnp_version)
  File "/home/mgale/dev/montepy/montepy/mcnp_object.py", line 130, in format_for_mcnp_input
    self._update_values()
  File "/home/mgale/dev/montepy/montepy/data_inputs/material.py", line 155, in _update_values
    self._tree.nodes["data"] = new_list
AttributeError: 'Material' object has no attribute '_tree'

Version

MicahGale commented 3 months ago

This is #84

Also surfaces:

SURFACE: 1, CZ
Traceback (most recent call last):
  File "/home/mgale/dev/montepy/gen_big_model.py", line 65, in <module>
    gen_geometry(mat)
  File "/home/mgale/dev/montepy/gen_big_model.py", line 59, in gen_geometry
    problem.write_problem("big_model.imcnp")
  File "/home/mgale/dev/montepy/montepy/mcnp_problem.py", line 409, in write_problem
    self._write_to_stream(fh)
  File "/home/mgale/dev/montepy/montepy/mcnp_problem.py", line 454, in _write_to_stream
    lines = obj.format_for_mcnp_input(self.mcnp_version)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgale/dev/montepy/montepy/mcnp_object.py", line 130, in format_for_mcnp_input
    self._update_values()
  File "/home/mgale/dev/montepy/montepy/surfaces/surface.py", line 271, in _update_values
    modifier = self._tree["surface_num"]["modifier"]
               ^^^^^^^^^^
AttributeError: 'CylinderOnAxis' object has no attribute '_tree'
MicahGale commented 3 months ago

ThermalScatteringLaw too:

  File "/home/mgale/dev/montepy/gen_big_model.py", line 85, in <module>
    gen_geometry(mat)
  File "/home/mgale/dev/montepy/gen_big_model.py", line 81, in gen_geometry
    problem.write_problem("big_model.imcnp", overwrite=True)
  File "/home/mgale/dev/montepy/montepy/mcnp_problem.py", line 409, in write_problem
    self._write_to_stream(fh)
  File "/home/mgale/dev/montepy/montepy/mcnp_problem.py", line 454, in _write_to_stream
    lines = obj.format_for_mcnp_input(self.mcnp_version)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgale/dev/montepy/montepy/data_inputs/material.py", line 147, in format_for_mcnp_input
    lines += self.thermal_scattering.format_for_mcnp_input(mcnp_version)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgale/dev/montepy/montepy/mcnp_object.py", line 130, in format_for_mcnp_input
    self._update_values()
  File "/home/mgale/dev/montepy/montepy/data_inputs/thermal_scattering.py", line 112, in _update_values
    self._tree["classifier"].number.value = self.parent_material.number
    ^^^^^^^^^^
AttributeError: 'ThermalScatteringLaw' object has no attribute '_tree'
MicahGale commented 3 months ago
Traceback (most recent call last):
  File "/home/mgale/dev/montepy/gen_big_model.py", line 86, in <module>
    gen_geometry(mat)
  File "/home/mgale/dev/montepy/gen_big_model.py", line 82, in gen_geometry
    problem.write_problem("big_model.imcnp", overwrite=True)
  File "/home/mgale/dev/montepy/montepy/mcnp_problem.py", line 409, in write_problem
    self._write_to_stream(fh)
  File "/home/mgale/dev/montepy/montepy/mcnp_problem.py", line 469, in _write_to_stream
    for line in self.cells._run_children_format_for_mcnp(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgale/dev/montepy/montepy/cells.py", line 167, in _run_children_format_for_mcnp
    if buf := getattr(self, attr).format_for_mcnp_input(mcnp_version):
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgale/dev/montepy/montepy/data_inputs/cell_modifier.py", line 265, in format_for_mcnp_input
    if (self.in_cell_block != print_in_data_block) and self._is_worth_printing:
                                                       ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgale/dev/montepy/montepy/data_inputs/cell_modifier.py", line 170, in _is_worth_printing
    for cell in self._problem.cells:
                ^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'cells'
MicahGale commented 3 months ago
cell = montepy.Cell()
cell.link_to_problem()
problem.cells.append_renumber(cell)
Traceback (most recent call last):
  File "/home/mgale/dev/montepy/gen_big_model.py", line 86, in <module>
    gen_geometry(mat)
  File "/home/mgale/dev/montepy/gen_big_model.py", line 80, in gen_geometry
    problem.cells.append_renumber(cell)
  File "/home/mgale/dev/montepy/montepy/numbered_object_collection.py", line 236, in append_renumber
    self.append(obj)
  File "/home/mgale/dev/montepy/montepy/numbered_object_collection.py", line 205, in append
    f"{obj} to {type(self)}. Conflict was with {self[obj.number]}"
                                                ~~~~^^^^^^^^^^^^
  File "/home/mgale/dev/montepy/montepy/numbered_object_collection.py", line 323, in __getitem__
    raise TypeError("index must be an int or slice")
TypeError: index must be an int or slice

shell returned 1
MicahGale commented 3 months ago
Traceback (most recent call last):
  File "/home/mgale/dev/montepy/gen_big_model.py", line 86, in <module>
    gen_geometry(mat)
  File "/home/mgale/dev/montepy/gen_big_model.py", line 82, in gen_geometry
    problem.write_problem("big_model.imcnp", overwrite=True)
  File "/home/mgale/dev/montepy/montepy/mcnp_problem.py", line 409, in write_problem
    self._write_to_stream(fh)
  File "/home/mgale/dev/montepy/montepy/mcnp_problem.py", line 469, in _write_to_stream
    for line in self.cells._run_children_format_for_mcnp(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgale/dev/montepy/montepy/cells.py", line 167, in _run_children_format_for_mcnp
    if buf := getattr(self, attr).format_for_mcnp_input(mcnp_version):
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgale/dev/montepy/montepy/data_inputs/cell_modifier.py", line 265, in format_for_mcnp_input
    if (self.in_cell_block != print_in_data_block) and self._is_worth_printing:
                                                       ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgale/dev/montepy/montepy/data_inputs/cell_modifier.py", line 170, in _is_worth_printing
    for cell in self._problem.cells:
                ^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'cells'

This is actually the problem.cells.cell_modifier that's the issue.

MicahGale commented 3 months ago

In general update_values is not being used.