mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Generalize russian_roulette function
This commit is contained in:
parent
f18caa1712
commit
de50a7bfca
5 changed files with 18 additions and 23 deletions
|
|
@ -9,7 +9,9 @@
|
|||
namespace openmc {
|
||||
|
||||
//! \brief Performs the russian roulette operation for a particle
|
||||
void russian_roulette(Particle& p);
|
||||
//! \param[in,out] p Particle object
|
||||
//! \param[in] weight_cutoff Weight below which particles are rouletted
|
||||
void russian_roulette(Particle& p, double weight_survive);
|
||||
|
||||
} // namespace openmc
|
||||
#endif // OPENMC_PHYSICS_COMMON_H
|
||||
|
|
|
|||
|
|
@ -151,9 +151,9 @@ void sample_neutron_reaction(Particle& p)
|
|||
|
||||
// Play russian roulette if survival biasing is turned on
|
||||
if (settings::survival_biasing) {
|
||||
russian_roulette(p);
|
||||
if (!p.alive())
|
||||
return;
|
||||
if (p.wgt() < settings::weight_cutoff) {
|
||||
russian_roulette(p, settings::weight_survive);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,15 +9,13 @@ namespace openmc {
|
|||
// RUSSIAN_ROULETTE
|
||||
//==============================================================================
|
||||
|
||||
void russian_roulette(Particle& p)
|
||||
void russian_roulette(Particle& p, double weight_survive)
|
||||
{
|
||||
if (p.wgt() < settings::weight_cutoff) {
|
||||
if (settings::weight_survive * prn(p.current_seed()) < p.wgt()) {
|
||||
p.wgt() = settings::weight_survive;
|
||||
} else {
|
||||
p.wgt() = 0.;
|
||||
p.alive() = false;
|
||||
}
|
||||
if (weight_survive * prn(p.current_seed()) < p.wgt()) {
|
||||
p.wgt() = weight_survive;
|
||||
} else {
|
||||
p.wgt() = 0.;
|
||||
p.alive() = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,9 +64,9 @@ void sample_reaction(Particle& p)
|
|||
|
||||
// Play Russian roulette if survival biasing is turned on
|
||||
if (settings::survival_biasing) {
|
||||
russian_roulette(p);
|
||||
if (!p.alive())
|
||||
return;
|
||||
if (p.wgt() < settings::weight_cutoff) {
|
||||
russian_roulette(p, settings::weight_survive);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "openmc/hdf5_interface.h"
|
||||
#include "openmc/particle.h"
|
||||
#include "openmc/particle_data.h"
|
||||
#include "openmc/physics_common.h"
|
||||
#include "openmc/search.h"
|
||||
#include "openmc/xml_interface.h"
|
||||
|
||||
|
|
@ -94,14 +95,8 @@ void apply_weight_windows(Particle& p)
|
|||
// if the particle weight is below the window, play Russian roulette
|
||||
double weight_survive =
|
||||
std::min(weight * weight_window.max_split, weight_window.survival_weight);
|
||||
if (weight_survive * prn(p.current_seed()) <= weight) {
|
||||
p.wgt() = weight_survive;
|
||||
} else {
|
||||
p.alive() = false;
|
||||
p.wgt() = 0.0;
|
||||
}
|
||||
// else particle is in the window, continue as normal
|
||||
}
|
||||
russian_roulette(p, weight_survive);
|
||||
} // else particle is in the window, continue as normal
|
||||
}
|
||||
|
||||
void free_memory_weight_windows()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue