diff --git a/CMakeLists.txt b/CMakeLists.txt index 9facdf7ba..e62c41347 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -423,6 +423,7 @@ add_library(libopenmc SHARED src/nuclide.cpp src/output.cpp src/particle.cpp + src/physics_common.cpp src/plot.cpp src/position.cpp src/pugixml/pugixml_c.cpp diff --git a/include/openmc/physics_common.h b/include/openmc/physics_common.h new file mode 100644 index 000000000..33fb8ed61 --- /dev/null +++ b/include/openmc/physics_common.h @@ -0,0 +1,16 @@ +//! \file physics_common.h +//! A collection of physics methods common to MG, CE, photon, etc. + +#ifndef OPENMC_PHYSICS_COMMON_H +#define OPENMC_PHYSICS_COMMON_H + +#include "openmc/particle.h" + +namespace openmc { + +//! \brief Performs the russian roulette operation for a particle +extern "C" void +russian_roulette(Particle* p); + +} // namespace openmc +#endif // OPENMC_PHYSICS_COMMON_H diff --git a/src/physics_common.F90 b/src/physics_common.F90 index 63bf62ce6..0d5b9fb32 100644 --- a/src/physics_common.F90 +++ b/src/physics_common.F90 @@ -1,33 +1,20 @@ module physics_common - use constants + use, intrinsic :: ISO_C_BINDING + use particle_header, only: Particle - use random_lcg, only: prn - use settings, only: weight_cutoff, weight_survive implicit none -contains - !=============================================================================== -! RUSSIAN_ROULETTE +! RUSSIAN_ROULETTE FROM C !=============================================================================== - subroutine russian_roulette(p) - - type(Particle), intent(inout) :: p - - if (p % wgt < weight_cutoff) then - if (prn() < p % wgt / weight_survive) then - p % wgt = weight_survive - p % last_wgt = p % wgt - else - p % wgt = ZERO - p % last_wgt = ZERO - p % alive = .false. - end if - end if - - end subroutine russian_roulette + interface + subroutine russian_roulette(p) bind(C) + import Particle + type(Particle), intent(inout) :: p + end subroutine russian_roulette + end interface end module physics_common diff --git a/src/physics_common.cpp b/src/physics_common.cpp new file mode 100644 index 000000000..02c77ae7d --- /dev/null +++ b/src/physics_common.cpp @@ -0,0 +1,26 @@ +#include "openmc/physics_common.h" + +#include "openmc/settings.h" +#include "openmc/random_lcg.h" + +namespace openmc { + +//============================================================================== +// RUSSIAN_ROULETTE +//============================================================================== + +void russian_roulette(Particle* p) +{ + if (p->wgt < settings::weight_cutoff) { + if (prn() < p->wgt / settings::weight_survive) { + p->wgt = settings::weight_survive; + p->last_wgt = p->wgt; + } else { + p->wgt = 0.; + p->last_wgt = 0.; + p->alive = false; + } + } +} + +} //namespace openmc