sample_uniform_positions Subroutine

public subroutine sample_uniform_positions(low, high, x)

直方体領域 [low, high] 内で一様分布の初期位置をサンプリングする。

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: low(3)
real(kind=dp), intent(in) :: high(3)
real(kind=dp), intent(out) :: x(:,:)

Called by

proc~~sample_uniform_positions~~CalledByGraph proc~sample_uniform_positions sample_uniform_positions proc~init_random_beam_particles init_random_beam_particles proc~init_random_beam_particles->proc~sample_uniform_positions proc~sample_species_state sample_species_state proc~sample_species_state->proc~sample_uniform_positions proc~init_particle_batch_from_config init_particle_batch_from_config proc~init_particle_batch_from_config->proc~sample_species_state proc~init_particles_from_config init_particles_from_config proc~init_particles_from_config->proc~sample_species_state

Source Code

  subroutine sample_uniform_positions(low, high, x)
    real(dp), intent(in) :: low(3), high(3)
    real(dp), intent(out) :: x(:, :)
    real(dp), allocatable :: u(:, :)

    if (size(x, 1) /= 3) error stop "x first dimension must be 3"
    if (any(high < low)) error stop "high must be >= low for all axes"

    allocate (u(3, size(x, 2)))
    call random_number(u)
    x = spread(low, dim=2, ncopies=size(x, 2)) + spread(high - low, dim=2, ncopies=size(x, 2))*u
  end subroutine sample_uniform_positions