From e41ae3604ea6a7448219be7ae764337ac0043edc Mon Sep 17 00:00:00 2001 From: aprilnovak Date: Mon, 27 Mar 2023 18:36:49 -0500 Subject: [PATCH 1/6] 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 From a44c1f89de907292863b47ecdc62b10cb6685d40 Mon Sep 17 00:00:00 2001 From: aprilnovak Date: Mon, 27 Mar 2023 19:21:30 -0500 Subject: [PATCH 2/6] Address review comments. Refs #2442 --- src/material.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/material.cpp b/src/material.cpp index ec82a7eea5..165a5c2e79 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -353,7 +353,7 @@ Material::~Material() model::material_map.erase(id_); } -void Material::clone() +Material & Material::clone() { std::unique_ptr mat = std::make_unique(); mat->index_ = model::materials.size(); @@ -376,12 +376,10 @@ void Material::clone() mat->temperature_ = temperature_; if (ttb_) - { - std::unique_ptr ptr2{new Bremsstrahlung{*ttb_}}; - mat->ttb_ = std::move(ptr2); - } + mat->ttb_ = std::make_unique(*ttb_); model::materials.push_back(std::move(mat)); + return *mat; } void Material::finalize() From fa222a4b314dac399d471fd2016e839a9c98549a Mon Sep 17 00:00:00 2001 From: aprilnovak Date: Mon, 27 Mar 2023 19:23:04 -0500 Subject: [PATCH 3/6] Address review comments. --- include/openmc/material.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/openmc/material.h b/include/openmc/material.h index 36a6acf933..36d7c34c6d 100644 --- a/include/openmc/material.h +++ b/include/openmc/material.h @@ -91,7 +91,7 @@ public: const vector& name, const vector& density); //! Clone the material by deep-copying all members - void clone(); + Material & clone(); //---------------------------------------------------------------------------- // Accessors From b84a021c58623e8198cf315c6993e64e3b051613 Mon Sep 17 00:00:00 2001 From: aprilnovak Date: Tue, 28 Mar 2023 13:50:02 -0500 Subject: [PATCH 4/6] Improve documentation. Refs #2442 --- include/openmc/material.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/openmc/material.h b/include/openmc/material.h index 36d7c34c6d..deaee2469b 100644 --- a/include/openmc/material.h +++ b/include/openmc/material.h @@ -90,7 +90,10 @@ public: void set_densities( const vector& name, const vector& density); - //! Clone the material by deep-copying all members + //! Clone the material by deep-copying all members, except for the ID, + // which will get auto-assigned to the next available ID. After creating + // the new material, it is added to openmc::model::materials. + //! \return reference to the cloned material Material & clone(); //---------------------------------------------------------------------------- From ca061bc7e5ecad80ca074070438ebeab9b791b0b Mon Sep 17 00:00:00 2001 From: aprilnovak Date: Tue, 28 Mar 2023 19:20:49 -0500 Subject: [PATCH 5/6] Return non-null. --- src/material.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/material.cpp b/src/material.cpp index 165a5c2e79..092055aa17 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -379,7 +379,7 @@ Material & Material::clone() mat->ttb_ = std::make_unique(*ttb_); model::materials.push_back(std::move(mat)); - return *mat; + return *model::materials.back(); } void Material::finalize() From c3fdf4edd2ee6dc7d9ea2a9e5c48c3d0efb670f4 Mon Sep 17 00:00:00 2001 From: aprilnovak Date: Wed, 29 Mar 2023 14:40:37 -0500 Subject: [PATCH 6/6] Group openmc::model lines together. Refs #2442 --- src/material.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/material.cpp b/src/material.cpp index 092055aa17..82dd0d4d9e 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -356,8 +356,6 @@ Material::~Material() Material & 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_; @@ -378,6 +376,8 @@ Material & Material::clone() if (ttb_) mat->ttb_ = std::make_unique(*ttb_); + mat->index_ = model::materials.size(); + mat->set_id(C_NONE); model::materials.push_back(std::move(mat)); return *model::materials.back(); }