mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Link Fortran RNG constants to C++ definitions
This commit is contained in:
parent
168f202e3e
commit
ed5ff626f4
4 changed files with 26 additions and 24 deletions
|
|
@ -415,12 +415,12 @@ module constants
|
|||
! ============================================================================
|
||||
! RANDOM NUMBER STREAM CONSTANTS
|
||||
|
||||
integer, parameter :: N_STREAMS = 5
|
||||
integer, parameter :: STREAM_TRACKING = 1
|
||||
integer, parameter :: STREAM_TALLIES = 2
|
||||
integer, parameter :: STREAM_SOURCE = 3
|
||||
integer, parameter :: STREAM_URR_PTABLE = 4
|
||||
integer, parameter :: STREAM_VOLUME = 5
|
||||
integer(C_INT), bind(C, name='N_STREAMS') :: N_STREAMS
|
||||
integer(C_INT), bind(C, name='STREAM_TRACKING') :: STREAM_TRACKING
|
||||
integer(C_INT), bind(C, name='STREAM_TALLIES') :: STREAM_TALLIES
|
||||
integer(C_INT), bind(C, name='STREAM_SOURCE') :: STREAM_SOURCE
|
||||
integer(C_INT), bind(C, name='STREAM_URR_PTABLE') :: STREAM_URR_PTABLE
|
||||
integer(C_INT), bind(C, name='STREAM_VOLUME') :: STREAM_VOLUME
|
||||
integer(C_INT64_T), parameter :: DEFAULT_SEED = 1_8
|
||||
|
||||
! ============================================================================
|
||||
|
|
|
|||
|
|
@ -13,14 +13,6 @@ const uint64_t prn_mask = 0x7fffffffffffffff; // 2^63 - 1
|
|||
const uint64_t prn_stride = 152917LL; // stride between particles
|
||||
const double prn_norm = pow(2, -63); // 2^-63
|
||||
|
||||
// Module constants
|
||||
const int N_STREAMS = 5;
|
||||
const int STREAM_TRACKING = 1;
|
||||
const int STREAM_TALLIES = 2;
|
||||
const int STREAM_SOURCE = 3;
|
||||
const int STREAM_URR_PTABLE = 4;
|
||||
const int STREAM_VOLUME = 5;
|
||||
|
||||
// Current PRNG state
|
||||
uint64_t prn_seed[N_STREAMS]; // current seed
|
||||
int stream; // current RNG stream
|
||||
|
|
@ -121,7 +113,7 @@ future_seed(uint64_t n, uint64_t seed)
|
|||
extern "C" void
|
||||
prn_set_stream(int i)
|
||||
{
|
||||
stream = i - 1; // Shift by one to move from Fortran to C indexing.
|
||||
stream = i; // Shift by one to move from Fortran to C indexing.
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -129,7 +121,7 @@ prn_set_stream(int i)
|
|||
//==============================================================================
|
||||
|
||||
extern "C" int
|
||||
openmc_set_seed(uint64_t new_seed)
|
||||
openmc_set_seed(int64_t new_seed)
|
||||
{
|
||||
seed = new_seed;
|
||||
#pragma omp parallel
|
||||
|
|
|
|||
|
|
@ -7,39 +7,38 @@ module random_lcg
|
|||
integer(C_INT64_T), bind(C) :: seed
|
||||
|
||||
interface
|
||||
function prn() result(pseudo_rn) bind(C, name='prn')
|
||||
function prn() result(pseudo_rn) bind(C)
|
||||
use ISO_C_BINDING
|
||||
implicit none
|
||||
real(C_DOUBLE) :: pseudo_rn
|
||||
end function prn
|
||||
|
||||
function future_prn(n) result(pseudo_rn) bind(C, name='future_prn')
|
||||
function future_prn(n) result(pseudo_rn) bind(C)
|
||||
use ISO_C_BINDING
|
||||
implicit none
|
||||
integer(C_INT64_T), value :: n
|
||||
real(C_DOUBLE) :: pseudo_rn
|
||||
end function future_prn
|
||||
|
||||
subroutine set_particle_seed(id) bind(C, name='set_particle_seed')
|
||||
subroutine set_particle_seed(id) bind(C)
|
||||
use ISO_C_BINDING
|
||||
implicit none
|
||||
integer(C_INT64_T), value :: id
|
||||
end subroutine set_particle_seed
|
||||
|
||||
subroutine advance_prn_seed(n) bind(C, name='advance_prn_seed')
|
||||
subroutine advance_prn_seed(n) bind(C)
|
||||
use ISO_C_BINDING
|
||||
implicit none
|
||||
integer(C_INT64_T), value :: n
|
||||
end subroutine advance_prn_seed
|
||||
|
||||
subroutine prn_set_stream(n) bind(C, name='prn_set_stream')
|
||||
subroutine prn_set_stream(n) bind(C)
|
||||
use ISO_C_BINDING
|
||||
implicit none
|
||||
integer(C_INT), value :: n
|
||||
end subroutine prn_set_stream
|
||||
|
||||
function openmc_set_seed(new_seed) result(err) &
|
||||
bind(C, name='openmc_set_seed')
|
||||
function openmc_set_seed(new_seed) result(err) bind(C)
|
||||
use ISO_C_BINDING
|
||||
implicit none
|
||||
integer(C_INT64_T), value :: new_seed
|
||||
|
|
|
|||
|
|
@ -3,6 +3,17 @@
|
|||
|
||||
#include <cstdint>
|
||||
|
||||
//==============================================================================
|
||||
// Module constants.
|
||||
//==============================================================================
|
||||
|
||||
extern "C" const int N_STREAMS = 5;
|
||||
extern "C" const int STREAM_TRACKING = 0;
|
||||
extern "C" const int STREAM_TALLIES = 1;
|
||||
extern "C" const int STREAM_SOURCE = 2;
|
||||
extern "C" const int STREAM_URR_PTABLE = 3;
|
||||
extern "C" const int STREAM_VOLUME = 4;
|
||||
|
||||
//==============================================================================
|
||||
// PRN generates a pseudo-random number using a linear congruential generator.
|
||||
//==============================================================================
|
||||
|
|
@ -51,6 +62,6 @@ extern "C" void prn_set_stream(int n);
|
|||
// API FUNCTIONS
|
||||
//==============================================================================
|
||||
|
||||
extern "C" int openmc_set_seed(uint64_t new_seed);
|
||||
extern "C" int openmc_set_seed(int64_t new_seed);
|
||||
|
||||
#endif // RANDOM_LCG_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue