diff --git a/src/mgxs.cpp b/src/mgxs.cpp index bc2aa9c0a3..53e24c67c1 100644 --- a/src/mgxs.cpp +++ b/src/mgxs.cpp @@ -555,11 +555,10 @@ Mgxs::sample_fission_energy(int gin, int& dg, int& gout) dg = -1; // sample the outgoing energy group - gout = 0; - double prob_gout = xs_t->chi_prompt(cache[tid].a, gin, gout); - while (prob_gout < xi_gout) { - gout++; + double prob_gout = 0.; + for (gout = 0; gout < num_groups; ++gout) { prob_gout += xs_t->chi_prompt(cache[tid].a, gin, gout); + if (xi_gout < prob_gout) break; } } else { @@ -575,11 +574,10 @@ Mgxs::sample_fission_energy(int gin, int& dg, int& gout) dg = std::min(dg, num_delayed_groups - 1); // sample the outgoing energy group - gout = 0; - double prob_gout = xs_t->chi_delayed(cache[tid].a, dg, gin, gout); - while (prob_gout < xi_gout) { - gout++; + double prob_gout = 0.; + for (gout = 0; gout < num_groups; ++gout) { prob_gout += xs_t->chi_delayed(cache[tid].a, dg, gin, gout); + if (xi_gout < prob_gout) break; } } } diff --git a/src/scattdata.cpp b/src/scattdata.cpp index a8f63d0f69..5fc19c41ec 100644 --- a/src/scattdata.cpp +++ b/src/scattdata.cpp @@ -171,14 +171,12 @@ ScattData::sample_energy(int gin, int& gout, int& i_gout) { // Sample the outgoing group double xi = prn(); - + double prob = 0.; i_gout = 0; - gout = gmin[gin]; - double prob = energy[gin][i_gout]; - while((prob < xi) && (gout < gmax[gin])) { - gout++; - i_gout++; + for (gout = gmin[gin]; gout < gmax[gin]; ++gout) { prob += energy[gin][i_gout]; + if (xi < prob) break; + ++i_gout; } } @@ -358,20 +356,18 @@ ScattDataLegendre::sample(int gin, int& gout, double& mu, double& wgt) // Now we can sample mu using the scattering kernel using rejection // sampling from a rectangular bounding box double M = max_val[gin][i_gout]; - int samples = 0; - - while(true) { + int samples; + for (samples = 0; samples < MAX_SAMPLE; ++samples) { mu = 2. * prn() - 1.; double f = calc_f(gin, gout, mu); if (f > 0.) { double u = prn() * M; if (u <= f) break; } - samples++; - if (samples > MAX_SAMPLE) { - fatal_error("Maximum number of Legendre expansion samples reached"); - } - }; + } + if (samples == MAX_SAMPLE) { + fatal_error("Maximum number of Legendre expansion samples reached!"); + } // Update the weight to reflect neutron multiplicity wgt *= mult[gin][i_gout];