idaholab/MontePy

Add Simple method to make deepcopies

Closed this issue · 3 comments

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

duplicate of #123.

This will be useful.

Some questions on the mechanics to consider:

  • How deep should the deepcopy clones go? For instance, cloning a Material should copy the material_components, and it shouldn't copy the _problem.
  • Should cloning automatically link to a Materials instance and to an MCNP_Problem?
  • Does the clone automatically get assigned a new number? Will it use append_renumber(), request_number(*args), etc.?

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.