From ea9ff2280570f527d8c71ac8d456be7d07c74080 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 17 Jun 2020 22:46:51 -0500 Subject: [PATCH] Change data::elements to a vector of unique_ptr --- include/openmc/photon.h | 3 ++- src/material.cpp | 6 +++--- src/nuclide.cpp | 2 +- src/photon.cpp | 2 +- src/physics.cpp | 2 +- src/simulation.cpp | 8 ++++---- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/openmc/photon.h b/include/openmc/photon.h index e6e39893f..0b3688bba 100644 --- a/include/openmc/photon.h +++ b/include/openmc/photon.h @@ -8,6 +8,7 @@ #include #include "xtensor/xtensor.hpp" +#include // for unique_ptr #include #include #include // for pair @@ -119,7 +120,7 @@ namespace data { extern xt::xtensor compton_profile_pz; //! Compton profile momentum grid //! Photon interaction data for each element -extern std::vector elements; +extern std::vector> elements; extern std::unordered_map element_map; } // namespace data diff --git a/src/material.cpp b/src/material.cpp index 09a5493ed..ea5571df8 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -475,7 +475,7 @@ void Material::collision_stopping_power(double* s_col, bool positron) std::vector e_b_sq; for (int i = 0; i < element_.size(); ++i) { - const auto& elm = data::elements[element_[i]]; + const auto& elm = *data::elements[element_[i]]; double awr = data::nuclides[nuclide_[i]]->awr_; // Get atomic density of nuclide given atom/weight percent @@ -589,7 +589,7 @@ void Material::init_bremsstrahlung() // Bragg's additivity rule. for (int i = 0; i < n; ++i) { // Get pointer to current element - const auto& elm = data::elements[element_[i]]; + const auto& elm = *data::elements[element_[i]]; double awr = data::nuclides[nuclide_[i]]->awr_; // Get atomic density and mass density of nuclide given atom/weight percent @@ -838,7 +838,7 @@ void Material::calculate_photon_xs(Particle& p) const // Calculate microscopic cross section for this nuclide const auto& micro {p.photon_xs_[i_element]}; if (p.E_ != micro.last_E) { - data::elements[i_element].calculate_xs(p); + data::elements[i_element]->calculate_xs(p); } // ======================================================================== diff --git a/src/nuclide.cpp b/src/nuclide.cpp index 604cba0b5..4e5d41b4b 100644 --- a/src/nuclide.cpp +++ b/src/nuclide.cpp @@ -982,7 +982,7 @@ extern "C" int openmc_load_nuclide(const char* name, const double* temps, int n) // Read element data from HDF5 hid_t group = open_group(file_id, element.c_str()); - data::elements.emplace_back(group); + data::elements.push_back(std::make_unique(group)); close_group(group); file_close(file_id); diff --git a/src/photon.cpp b/src/photon.cpp index 2be3f0e7d..fa142609a 100644 --- a/src/photon.cpp +++ b/src/photon.cpp @@ -27,7 +27,7 @@ namespace data { xt::xtensor compton_profile_pz; -std::vector elements; +std::vector> elements; std::unordered_map element_map; } // namespace data diff --git a/src/physics.cpp b/src/physics.cpp index b307d9487..1000c3c4b 100644 --- a/src/physics.cpp +++ b/src/physics.cpp @@ -258,7 +258,7 @@ void sample_photon_reaction(Particle& p) // Sample element within material int i_element = sample_element(p); const auto& micro {p.photon_xs_[i_element]}; - const auto& element {data::elements[i_element]}; + const auto& element {*data::elements[i_element]}; // Calculate photon energy over electron rest mass equivalent double alpha = p.E_/MASS_ELECTRON_EV; diff --git a/src/simulation.cpp b/src/simulation.cpp index c2672c750..1b39c1329 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -578,13 +578,13 @@ void initialize_data() if (settings::photon_transport) { for (const auto& elem : data::elements) { - if (elem.energy_.size() >= 1) { + if (elem->energy_.size() >= 1) { int photon = static_cast(Particle::Type::photon); - int n = elem.energy_.size(); + int n = elem->energy_.size(); data::energy_min[photon] = std::max(data::energy_min[photon], - std::exp(elem.energy_(1))); + std::exp(elem->energy_(1))); data::energy_max[photon] = std::min(data::energy_max[photon], - std::exp(elem.energy_(n - 1))); + std::exp(elem->energy_(n - 1))); } }