From 05fac29164411233d423cf3170c1856c3f622646 Mon Sep 17 00:00:00 2001 From: Adam G Nelson Date: Mon, 11 Nov 2019 19:50:52 -0600 Subject: [PATCH] Revised MG code so that the energy group indices are 0-based instead of 1-based. Next commit will perform some code cleanup enabled by this change. --- src/mgxs_interface.cpp | 8 ++++---- src/particle.cpp | 4 ++-- src/particle_restart.cpp | 2 +- src/physics_mg.cpp | 18 +++++------------- src/source.cpp | 4 ++-- src/tallies/filter_energy.cpp | 6 +++--- src/tallies/tally_scoring.cpp | 4 ++-- 7 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/mgxs_interface.cpp b/src/mgxs_interface.cpp index 0bc61fa00..3076aedc8 100644 --- a/src/mgxs_interface.cpp +++ b/src/mgxs_interface.cpp @@ -298,12 +298,12 @@ get_nuclide_xs(int index, int xstype, int gin, const int* gout, int gout_c; const int* gout_c_p; if (gout != nullptr) { - gout_c = *gout - 1; + gout_c = *gout; gout_c_p = &gout_c; } else { gout_c_p = gout; } - return data::mg.nuclides_[index].get_xs(xstype, gin - 1, gout_c_p, mu, dg); + return data::mg.nuclides_[index].get_xs(xstype, gin, gout_c_p, mu, dg); } //============================================================================== @@ -315,12 +315,12 @@ get_macro_xs(int index, int xstype, int gin, const int* gout, int gout_c; const int* gout_c_p; if (gout != nullptr) { - gout_c = *gout - 1; + gout_c = *gout; gout_c_p = &gout_c; } else { gout_c_p = gout; } - return data::mg.macro_xs_[index].get_xs(xstype, gin - 1, gout_c_p, mu, dg); + return data::mg.macro_xs_[index].get_xs(xstype, gin, gout_c_p, mu, dg); } } // namespace openmc diff --git a/src/particle.cpp b/src/particle.cpp index 3ce3cf84c..da93c6723 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -123,7 +123,7 @@ Particle::from_source(const Bank* src) } else { g_ = static_cast(src->E); g_last_ = static_cast(src->E); - E_ = data::mg.energy_bin_avg_[g_ - 1]; + E_ = data::mg.energy_bin_avg_[g_]; } E_last_ = E_; } @@ -203,7 +203,7 @@ Particle::transport() } } else { // Get the MG data - data::mg.macro_xs_[material_].calculate_xs(g_ - 1, sqrtkT_, + data::mg.macro_xs_[material_].calculate_xs(g_, sqrtkT_, this->u_local(), macro_xs_.total, macro_xs_.absorption, macro_xs_.nu_fission); diff --git a/src/particle_restart.cpp b/src/particle_restart.cpp index 73e6d5d37..ce6555608 100644 --- a/src/particle_restart.cpp +++ b/src/particle_restart.cpp @@ -52,7 +52,7 @@ void read_particle_restart(Particle& p, int& previous_run_mode) // Set energy group and average energy in multi-group mode if (!settings::run_CE) { p.g_ = p.E_; - p.E_ = data::mg.energy_bin_avg_[p.g_ - 1]; + p.E_ = data::mg.energy_bin_avg_[p.g_]; } // Set particle last attributes diff --git a/src/physics_mg.cpp b/src/physics_mg.cpp index 90e76c67a..924356431 100644 --- a/src/physics_mg.cpp +++ b/src/physics_mg.cpp @@ -77,22 +77,14 @@ sample_reaction(Particle* p) void scatter(Particle* p) { - // Adjust indices for Fortran to C++ indexing - // TODO: Remove when no longer needed - int gin = p->g_last_ - 1; - int gout = p->g_ - 1; - int i_mat = p->material_; - data::mg.macro_xs_[i_mat].sample_scatter(gin, gout, p->mu_, p->wgt_); - - // Adjust return value for fortran indexing - // TODO: Remove when no longer needed - p->g_ = gout + 1; + data::mg.macro_xs_[p->material_].sample_scatter(p->g_last_, p->g_, p->mu_, + p->wgt_); // Rotate the angle p->u() = rotate_angle(p->u(), p->mu_, nullptr); // Update energy value for downstream compatability (in tallying) - p->E_ = data::mg.energy_bin_avg_[gout]; + p->E_ = data::mg.energy_bin_avg_[p->g_]; // Set event component p->event_ = EVENT_SCATTER; @@ -148,8 +140,8 @@ create_fission_sites(Particle* p, std::vector& bank) // the energy in the fission bank int dg; int gout; - data::mg.macro_xs_[p->material_].sample_fission_energy(p->g_ - 1, dg, gout); - site.E = gout + 1; + data::mg.macro_xs_[p->material_].sample_fission_energy(p->g_, dg, gout); + site.E = gout; site.delayed_group = dg + 1; // Set the delayed group on the particle as well diff --git a/src/source.cpp b/src/source.cpp index 6b5cb8aba..1d082240e 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -309,11 +309,11 @@ Particle::Bank sample_external_source() // Sample source site from i-th source distribution Particle::Bank site {model::external_sources[i].sample()}; - // If running in MG, convert site % E to group + // If running in MG, convert site.E to group if (!settings::run_CE) { site.E = lower_bound_index(data::mg.rev_energy_bins_.begin(), data::mg.rev_energy_bins_.end(), site.E); - site.E = data::mg.num_energy_groups_ - site.E; + site.E = data::mg.num_energy_groups_ - site.E - 1.; } // Set the random number generator back to the tracking stream. diff --git a/src/tallies/filter_energy.cpp b/src/tallies/filter_energy.cpp index 7737e4fac..7c8b5fbee 100644 --- a/src/tallies/filter_energy.cpp +++ b/src/tallies/filter_energy.cpp @@ -61,9 +61,9 @@ const { if (p->g_ != F90_NONE && matches_transport_groups_) { if (estimator == ESTIMATOR_TRACKLENGTH) { - match.bins_.push_back(data::mg.num_energy_groups_ - p->g_); + match.bins_.push_back(data::mg.num_energy_groups_ - p->g_ - 1); } else { - match.bins_.push_back(data::mg.num_energy_groups_ - p->g_last_); + match.bins_.push_back(data::mg.num_energy_groups_ - p->g_last_ - 1); } match.weights_.push_back(1.0); @@ -104,7 +104,7 @@ EnergyoutFilter::get_all_bins(const Particle* p, int estimator, FilterMatch& match) const { if (p->g_ != F90_NONE && matches_transport_groups_) { - match.bins_.push_back(data::mg.num_energy_groups_ - p->g_); + match.bins_.push_back(data::mg.num_energy_groups_ - p->g_ - 1); match.weights_.push_back(1.0); } else { diff --git a/src/tallies/tally_scoring.cpp b/src/tallies/tally_scoring.cpp index a2532c437..95e674735 100644 --- a/src/tallies/tally_scoring.cpp +++ b/src/tallies/tally_scoring.cpp @@ -348,9 +348,9 @@ score_fission_eout(const Particle* p, int i_tally, int i_score, int score_bin) // determine outgoing energy group from fission bank auto g_out = static_cast(bank.E); - // modify the value so that g_out = 1 corresponds to the highest energy + // modify the value so that g_out = 0 corresponds to the highest energy // bin - g_out = eo_filt.n_bins() - g_out; + g_out = eo_filt.n_bins() - g_out - 1; // change outgoing energy bin simulation::filter_matches[i_eout_filt].bins_[i_bin] = g_out;