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.

This commit is contained in:
Adam G Nelson 2019-11-11 19:50:52 -06:00
parent 677f4f7d8b
commit 05fac29164
7 changed files with 19 additions and 27 deletions

View file

@ -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

View file

@ -123,7 +123,7 @@ Particle::from_source(const Bank* src)
} else {
g_ = static_cast<int>(src->E);
g_last_ = static_cast<int>(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);

View file

@ -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

View file

@ -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<Particle::Bank>& 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

View file

@ -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.

View file

@ -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 {

View file

@ -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<int>(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;