From 57fcb078d325c53480c244c4274b8a1cee44196f Mon Sep 17 00:00:00 2001 From: liangjg Date: Thu, 11 Apr 2019 12:14:18 -0400 Subject: [PATCH] refactoring --- include/openmc/constants.h | 4 ++-- include/openmc/particle.h | 2 +- include/openmc/physics.h | 2 +- src/particle.cpp | 4 ++-- src/physics.cpp | 13 ++++++------- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/include/openmc/constants.h b/include/openmc/constants.h index a6397b2a7a..49f980cc29 100644 --- a/include/openmc/constants.h +++ b/include/openmc/constants.h @@ -108,7 +108,7 @@ constexpr std::array SUBSHELLS = { // Void material and nuclide // TODO: refactor and remove constexpr int MATERIAL_VOID {-1}; -constexpr int NUCLIDE_VOID {-1}; +constexpr int NUCLIDE_NONE {-1}; // ============================================================================ // CROSS SECTION RELATED CONSTANTS @@ -128,7 +128,7 @@ constexpr int TEMPERATURE_INTERPOLATION {2}; // Reaction types // TODO: Convert to enum -constexpr int NONE_REACTION {0}; +constexpr int REACTION_NONE {0}; constexpr int TOTAL_XS {1}; constexpr int ELASTIC {2}; constexpr int N_NONELASTIC {3}; diff --git a/include/openmc/particle.h b/include/openmc/particle.h index fcaf209a07..62923c11f1 100644 --- a/include/openmc/particle.h +++ b/include/openmc/particle.h @@ -261,7 +261,7 @@ public: // Post-collision physical data int n_bank_ {0}; //!< number of fission sites banked - int n_bank_second_ {0}; //!< number of secondary particles + int n_bank_second_ {0}; //!< number of secondary particles banked double wgt_bank_ {0.0}; //!< weight of fission sites banked int n_delayed_bank_[MAX_DELAYED_GROUPS]; //!< number of delayed fission //!< sites banked diff --git a/include/openmc/physics.h b/include/openmc/physics.h index f0e6dde015..107380eb84 100644 --- a/include/openmc/physics.h +++ b/include/openmc/physics.h @@ -44,7 +44,7 @@ void sample_positron_reaction(Particle* p); //! //! \param[in] p Particle //! \return Index in the data::nuclides vector -int sample_nuclide(Particle* p); +int sample_nuclide(const Particle* p); //! Determine the average total, prompt, and delayed neutrons produced from //! fission and creates appropriate bank sites. diff --git a/src/particle.cpp b/src/particle.cpp index 42889a981b..cbc6217caa 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -161,8 +161,8 @@ Particle::transport() // Reset event variables event_ = EVENT_KILL; - event_nuclide_ = NUCLIDE_VOID; - event_mt_ = NONE_REACTION; + event_nuclide_ = NUCLIDE_NONE; + event_mt_ = REACTION_NONE; // If the cell hasn't been determined based on the particle's location, // initiate a search for the current cell. This generally happens at the diff --git a/src/physics.cpp b/src/physics.cpp index 9b4a1a9c5f..cd29e97c26 100644 --- a/src/physics.cpp +++ b/src/physics.cpp @@ -81,6 +81,9 @@ void sample_neutron_reaction(Particle* p) // Sample a nuclide within the material int i_nuclide = sample_nuclide(p); + // Save which nuclide particle had collision with + p->event_nuclide_ = i_nuclide; + // Create fission bank sites. Note that while a fission reaction is sampled, // it never actually "happens", i.e. the weight of the particle does not // change when sampling fission sites. The following block handles all @@ -394,7 +397,7 @@ void sample_positron_reaction(Particle* p) p->event_ = EVENT_ABSORB; } -int sample_nuclide(Particle* p) +int sample_nuclide(const Particle* p) { // Sample cumulative distribution function double cutoff = prn() * p->macro_xs_.total; @@ -411,11 +414,7 @@ int sample_nuclide(Particle* p) // Increment probability to compare to cutoff prob += atom_density * p->neutron_xs_[i_nuclide].total; - if (prob >= cutoff) { - // Save which nuclide particle had collision with - p->event_nuclide_ = i_nuclide; - return i_nuclide; - } + if (prob >= cutoff) return i_nuclide; } // If we reach here, no nuclide was sampled @@ -443,7 +442,7 @@ int sample_element(Particle* p) // Increment probability to compare to cutoff prob += sigma; if (prob > cutoff) { - // Save which nuclide particle had collision with + // Save which nuclide particle had collision with for tally purpose p->event_nuclide_ = mat->nuclide_[i]; return i_element;