From e41ae3604ea6a7448219be7ae764337ac0043edc Mon Sep 17 00:00:00 2001 From: aprilnovak Date: Mon, 27 Mar 2023 18:36:49 -0500 Subject: [PATCH] Clone material. Refs #2442 --- include/openmc/material.h | 3 +++ src/material.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/openmc/material.h b/include/openmc/material.h index 8db9bb6283..36a6acf933 100644 --- a/include/openmc/material.h +++ b/include/openmc/material.h @@ -90,6 +90,9 @@ public: void set_densities( const vector& name, const vector& density); + //! Clone the material by deep-copying all members + void clone(); + //---------------------------------------------------------------------------- // Accessors diff --git a/src/material.cpp b/src/material.cpp index 74a8d7e350..ec82a7eea5 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -353,6 +353,37 @@ Material::~Material() model::material_map.erase(id_); } +void Material::clone() +{ + std::unique_ptr mat = std::make_unique(); + mat->index_ = model::materials.size(); + mat->set_id(C_NONE); + + // set all other parameters to whatever the calling Material has + mat->name_ = name_; + mat->nuclide_ = nuclide_; + mat->element_ = element_; + mat->ncrystal_mat_ = ncrystal_mat_; + mat->atom_density_ = atom_density_; + mat->density_ = density_; + mat->density_gpcc_ = density_gpcc_; + mat->volume_ = volume_; + mat->fissionable_ = fissionable_; + mat->depletable_ = depletable_; + mat->p0_ = p0_; + mat->mat_nuclide_index_ = mat_nuclide_index_; + mat->thermal_tables_ = thermal_tables_; + mat->temperature_ = temperature_; + + if (ttb_) + { + std::unique_ptr ptr2{new Bremsstrahlung{*ttb_}}; + mat->ttb_ = std::move(ptr2); + } + + model::materials.push_back(std::move(mat)); +} + void Material::finalize() { // Set fissionable if any nuclide is fissionable