bem_counter_rng Module

PCG64 による counter-based 乱数。実行順序・rank・thread に依存せず、(seed, counter, draw) だけで値が決まる。

counter(粒子 slot、境界 event など任意長の整数組)と seed から Murmur3 で 128 bit の鍵を作り、 上位 64 bit を PCG64 の初期状態、下位 64 bit を stream 番号に使う。draw 番目の値は stream を draw 回進めて取り出す。 鍵の計算は 32 bit の Murmur3 を 4 系統の seed で回すもので、整数演算は 16 bit 分割の乗算で 符号付き 64 bit の範囲に収めている(Fortran の整数 overflow を起こさない)。


Uses

  • module~~bem_counter_rng~~UsesGraph module~bem_counter_rng bem_counter_rng iso_c_binding iso_c_binding module~bem_counter_rng->iso_c_binding m_pcg64_bind m_pcg64_bind module~bem_counter_rng->m_pcg64_bind module~bem_kinds bem_kinds module~bem_counter_rng->module~bem_kinds iso_fortran_env iso_fortran_env module~bem_kinds->iso_fortran_env

Used by

  • module~~bem_counter_rng~~UsedByGraph module~bem_counter_rng bem_counter_rng module~bem_app_config_particle_runtime_slots bem_app_config_particle_runtime_slots module~bem_app_config_particle_runtime_slots->module~bem_counter_rng module~bem_injection_random bem_injection_random module~bem_app_config_particle_runtime_slots->module~bem_injection_random module~bem_injection bem_injection module~bem_app_config_particle_runtime_slots->module~bem_injection module~bem_app_config_particle_runtime bem_app_config_particle_runtime module~bem_app_config_particle_runtime_slots->module~bem_app_config_particle_runtime module~bem_injection_flux bem_injection_flux module~bem_injection_flux->module~bem_counter_rng module~bem_injection_flux->module~bem_injection_random module~bem_injection_random->module~bem_counter_rng module~bem_random_stream bem_random_stream module~bem_injection_random->module~bem_random_stream module~bem_particle_stepper bem_particle_stepper module~bem_particle_stepper->module~bem_counter_rng module~bem_photoelectron_injection bem_photoelectron_injection module~bem_photoelectron_injection->module~bem_counter_rng module~bem_photoelectron_injection->module~bem_injection_flux module~bem_photoelectron_injection->module~bem_injection_random module~bem_random_stream->module~bem_counter_rng module~bem_secondary_emission bem_secondary_emission module~bem_secondary_emission->module~bem_counter_rng module~bem_simulator_particles bem_simulator_particles module~bem_simulator_particles->module~bem_counter_rng module~bem_simulator_particles->module~bem_particle_stepper module~bem_simulator_particles->module~bem_photoelectron_injection module~bem_simulator_particles->module~bem_secondary_emission module~bem_simulator bem_simulator module~bem_simulator_particles->module~bem_simulator module~bem_app_config_parser bem_app_config_parser module~bem_app_config_parser->module~bem_injection_flux module~bem_injection->module~bem_injection_flux module~bem_injection->module~bem_injection_random module~bem_injection->module~bem_photoelectron_injection module~bem_simulator->module~bem_particle_stepper module~bem_app_config bem_app_config module~bem_simulator->module~bem_app_config module~bem_app_config_runtime bem_app_config_runtime module~bem_simulator->module~bem_app_config_runtime module~bem_app_config->module~bem_app_config_parser module~bem_app_config->module~bem_app_config_runtime module~bem_app_config_parser_finalize bem_app_config_parser_finalize module~bem_app_config_parser_finalize->module~bem_app_config_parser module~bem_app_config_parser_preflight_particles bem_app_config_parser_preflight_particles module~bem_app_config_parser_preflight_particles->module~bem_app_config_parser module~bem_app_config_parser_preflight_sim bem_app_config_parser_preflight_sim module~bem_app_config_parser_preflight_sim->module~bem_app_config_parser module~bem_app_config_parser_preflight_surface bem_app_config_parser_preflight_surface module~bem_app_config_parser_preflight_surface->module~bem_app_config_parser module~bem_app_config_parser_read_mesh bem_app_config_parser_read_mesh module~bem_app_config_parser_read_mesh->module~bem_app_config_parser module~bem_app_config_parser_read_particles bem_app_config_parser_read_particles module~bem_app_config_parser_read_particles->module~bem_app_config_parser module~bem_app_config_parser_read_sim bem_app_config_parser_read_sim module~bem_app_config_parser_read_sim->module~bem_app_config_parser module~bem_app_config_parser_read_surface bem_app_config_parser_read_surface module~bem_app_config_parser_read_surface->module~bem_app_config_parser module~bem_app_config_parser_validate bem_app_config_parser_validate module~bem_app_config_parser_validate->module~bem_app_config_parser module~bem_app_config_particle_runtime->module~bem_injection module~bem_simulator_charge bem_simulator_charge module~bem_simulator_charge->module~bem_simulator module~bem_simulator_io bem_simulator_io module~bem_simulator_io->module~bem_simulator module~bem_simulator_io->module~bem_app_config_runtime module~bem_simulator_loop bem_simulator_loop module~bem_simulator_loop->module~bem_simulator module~bem_simulator_loop->module~bem_app_config_runtime module~bem_zhao_outflow_refresh bem_zhao_outflow_refresh module~bem_simulator_loop->module~bem_zhao_outflow_refresh module~bem_simulator_stats bem_simulator_stats module~bem_simulator_stats->module~bem_simulator program~main main program~main->module~bem_simulator program~main->module~bem_app_config module~bem_app_config_particle_runtime_batch bem_app_config_particle_runtime_batch module~bem_app_config_particle_runtime_batch->module~bem_app_config_particle_runtime module~bem_app_config_particle_runtime_sampling bem_app_config_particle_runtime_sampling module~bem_app_config_particle_runtime_sampling->module~bem_app_config_particle_runtime module~bem_app_config_runtime->module~bem_app_config_particle_runtime module~bem_zhao_outflow_refresh->module~bem_app_config

Derived Types

type, public ::  counter_stream_type

1 つの (seed, counter) の draw を連番で引く列。鍵の計算と PCG64 生成器の作成を 1 回で済ませ、 next_uniform の n 回目は counter_uniform(seed, counter, first_draw + n - 1) と同じ値を返す。 生成器は C++ 側で確保するので、open したら close する。

Type-Bound Procedures

procedure, public :: open => open_counter_stream
procedure, public :: next_uniform => counter_stream_next_uniform
procedure, public :: close => close_counter_stream

Functions

public function counter_uniform(seed, counter, draw) result(uniform)

(seed, counter, draw) で決まる (0, 1) の一様乱数。

Arguments

Type IntentOptional Attributes Name
integer(kind=i32), intent(in) :: seed

実行の乱数 seed(run.rng_seed)。

integer(kind=i64), intent(in) :: counter(:)
integer(kind=i64), intent(in) :: draw

同じ対象の中で何番目の値か(0 以上)。

Return Value real(kind=dp)

public pure function counter_child_id(parent_id, ordinal) result(child_id)

親の乱数 id と子の番号から、衝突しにくい 63 bit の子 id を作る(二次電子などの派生粒子用)。

Arguments

Type IntentOptional Attributes Name
integer(kind=i64), intent(in) :: parent_id
integer(kind=i64), intent(in) :: ordinal

Return Value integer(kind=i64)

public function pcg64_open_uniform(state_seed, stream, draw) result(uniform)

PCG64(state_seed, stream) を draw 回進めた次の値を (0, 1) で返す(変換は open_uniform_from_double53)。

Arguments

Type IntentOptional Attributes Name
integer(kind=i64), intent(in) :: state_seed
integer(kind=i64), intent(in) :: stream
integer(kind=i64), intent(in) :: draw

Return Value real(kind=dp)

public pure function open_uniform_from_double53(raw) result(uniform)

53 bit 格子値 raw = k/2^53(k = 0..2^53-1)を (0, 1) へ写す。 raw に 2^-54 を足し、binary64 の最近接丸めで 1.0 になる最上端 k = 2^53-1 だけを 1 の直前値 1-2^-53 に留める。 それ以外の k では raw + 2^-54 と同じ binary64 値を返す。

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: raw

pcg64_random_double53 の戻り値([0, 1) の 53 bit 格子値)。

Return Value real(kind=dp)


Subroutines

public subroutine counter_uniforms(seed, counter, first_draw, uniforms)

(seed, counter) の draw first_draw .. first_draw + size(uniforms) - 1 をまとめて返す。 値は同じ draw の counter_uniform と一致する。

Arguments

Type IntentOptional Attributes Name
integer(kind=i32), intent(in) :: seed
integer(kind=i64), intent(in) :: counter(:)
integer(kind=i64), intent(in) :: first_draw
real(kind=dp), intent(out) :: uniforms(:)

public pure subroutine counter_key(seed, counter, state_seed, stream)

seed と counter から PCG64 の (初期状態 seed, stream) を作る。

Arguments

Type IntentOptional Attributes Name
integer(kind=i32), intent(in) :: seed
integer(kind=i64), intent(in) :: counter(:)
integer(kind=i64), intent(out) :: state_seed
integer(kind=i64), intent(out) :: stream