From d4775552e04dc8ede1e7f1eff07ed87fae64c935 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 11 Jul 2018 07:01:54 -0500 Subject: [PATCH] Convert Reaction type --- CMakeLists.txt | 1 + src/reaction.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/reaction.h | 29 +++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 src/reaction.cpp create mode 100644 src/reaction.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c2dff6e10..e54c6c367 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -412,6 +412,7 @@ add_library(libopenmc SHARED src/position.cpp src/pugixml/pugixml_c.cpp src/random_lcg.cpp + src/reaction.cpp src/reaction_product.cpp src/secondary_correlated.cpp src/secondary_kalbach.cpp diff --git a/src/reaction.cpp b/src/reaction.cpp new file mode 100644 index 000000000..7e6a3ae5d --- /dev/null +++ b/src/reaction.cpp @@ -0,0 +1,48 @@ +#include "reaction.h" + +#include +#include // for move + +#include "hdf5_interface.h" + +namespace openmc { + +Reaction::Reaction(hid_t group, const std::vector& temperatures) +{ + read_attribute(group, "Q_value", q_value_); + read_attribute(group, "mt", mt_); + int cm; + read_attribute(group, "center_of_mass", cm); + scatter_in_cm_ = (cm == 1); + + // Read cross section and threshold_idx data + for (auto t : temperatures) { + // Get group corresponding to temperature + std::string temp_str {std::to_string(t) + "K"}; + hid_t temp_group = open_group(group, temp_str.c_str()); + hid_t dset = open_dataset(temp_group, "xs"); + + // Get threshold index + TemperatureXS xs; + read_attribute(dset, "threshold_idx", xs.threshold); + + // Read cross section values + read_dataset(dset, xs.value); + close_dataset(dset); + close_group(temp_group); + + // create new entry in xs vector + xs_.push_back(std::move(xs)); + } + + // Read products + for (const auto& name : group_names(group)) { + if (name.rfind("product_", 0) == 0) { + hid_t pgroup = open_group(group, name.c_str()); + products_.emplace_back(pgroup); + close_group(pgroup); + } + } +} + +} \ No newline at end of file diff --git a/src/reaction.h b/src/reaction.h new file mode 100644 index 000000000..0040bd094 --- /dev/null +++ b/src/reaction.h @@ -0,0 +1,29 @@ +#ifndef OPENMC_REACTION_H +#define OPENMC_REACTION_H + +#include + +#include "hdf5.h" +#include "reaction_product.h" + +namespace openmc { + +class Reaction { +public: + explicit Reaction(hid_t group, const std::vector& temperatures); + + struct TemperatureXS { + int threshold; + std::vector value; + }; + + int mt_; //!< ENDF MT value + double q_value_; //!< Reaction Q value in [eV] + bool scatter_in_cm_; //!< scattering system in center-of-mass? + std::vector xs_; + std::vector products_; +}; + +} + +#endif // OPENMC_REACTION_H