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

Add Simple method to make deepcopies #469

Closed MicahGale closed 1 month ago

MicahGale commented 3 months ago

Is your feature request related to a problem? Please describe.

It's quite common to use an existing object as a "template" for a new one. For instance, when discretizing a cell into smaller ones for zone depletions it would be helpful to make copies of the cell, its surfaces, and material.

Describe the solution you'd like Add a clone method to all objects.

So you can do:

new_cell = cell.clone()

instead of:

import copy
new_cell = copy.deepcopy(cell)

Describe alternatives you've considered Currently the recommended method is copy.deepcopy

Additional context See openmc.Cell.clone

MicahGale commented 3 months ago

duplicate of #123.

tjlaboss commented 3 months ago

This will be useful.

Some questions on the mechanics to consider:

MicahGale commented 2 months ago

I think generally:

  1. Everything but the _problem should be cloned.
  2. MCNP_Object instances should automatically be linked to the same problem I think.
  3. When copying MCNP_Problem all of its children should be linked to it.