Merge pull request #2444 from aprilnovak/material-clone

Clone material
This commit is contained in:
Patrick Shriwise 2023-03-30 08:51:05 -05:00 committed by GitHub
commit 682ce5c3a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View file

@ -90,6 +90,12 @@ public:
void set_densities(
const vector<std::string>& name, const vector<double>& density);
//! 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();
//----------------------------------------------------------------------------
// Accessors

View file

@ -353,6 +353,35 @@ Material::~Material()
model::material_map.erase(id_);
}
Material & Material::clone()
{
std::unique_ptr<Material> mat = std::make_unique<Material>();
// 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_)
mat->ttb_ = std::make_unique<Bremsstrahlung>(*ttb_);
mat->index_ = model::materials.size();
mat->set_id(C_NONE);
model::materials.push_back(std::move(mat));
return *model::materials.back();
}
void Material::finalize()
{
// Set fissionable if any nuclide is fissionable