mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-21 14:35:27 -04:00
Converted physics_common to C++
This commit is contained in:
parent
6dce5e3157
commit
cd493057bf
4 changed files with 52 additions and 22 deletions
|
|
@ -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
|
||||
|
|
|
|||
16
include/openmc/physics_common.h
Normal file
16
include/openmc/physics_common.h
Normal file
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
26
src/physics_common.cpp
Normal file
26
src/physics_common.cpp
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue