sample_shifted_maxwell_velocities Subroutine

public subroutine sample_shifted_maxwell_velocities(drift_velocity, m_particle, v, temperature_k, thermal_speed)

ドリフト速度付きMaxwell分布(温度または熱速度指定)から粒子速度を生成する。

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: drift_velocity(3)
real(kind=dp), intent(in) :: m_particle

粒子1個あたりの質量 [kg](temperature_k 指定時に使用)。

real(kind=dp), intent(out) :: v(:,:)
real(kind=dp), intent(in), optional :: temperature_k

熱運動の温度 [K](thermal_speed 未指定時に使用)。

real(kind=dp), intent(in), optional :: thermal_speed

熱速度の標準偏差 sigma [m/s](指定時は温度より優先)。


Called by

proc~~sample_shifted_maxwell_velocities~~CalledByGraph proc~sample_shifted_maxwell_velocities sample_shifted_maxwell_velocities proc~init_random_beam_particles init_random_beam_particles proc~init_random_beam_particles->proc~sample_shifted_maxwell_velocities proc~sample_reservoir_face_particles sample_reservoir_face_particles proc~sample_reservoir_face_particles->proc~sample_shifted_maxwell_velocities proc~sample_species_state sample_species_state proc~sample_species_state->proc~sample_shifted_maxwell_velocities proc~sample_species_state->proc~sample_reservoir_face_particles 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_shifted_maxwell_velocities(drift_velocity, m_particle, v, temperature_k, thermal_speed)
    real(dp), intent(in) :: drift_velocity(3)
    real(dp), intent(in) :: m_particle
    real(dp), intent(out) :: v(:, :)
    real(dp), intent(in), optional :: temperature_k
    real(dp), intent(in), optional :: thermal_speed
    integer :: n
    real(dp) :: sigma
    real(dp), allocatable :: z(:, :)

    if (size(v, 1) /= 3) error stop "v first dimension must be 3"
    if (m_particle <= 0.0_dp) error stop "m_particle must be > 0"

    if (.not. present(temperature_k) .and. .not. present(thermal_speed)) then
      error stop "either temperature_k or thermal_speed must be provided"
    end if

    if (present(thermal_speed)) then
      if (thermal_speed < 0.0_dp) error stop "thermal_speed must be >= 0"
      sigma = thermal_speed
    else
      if (temperature_k < 0.0_dp) error stop "temperature_k must be >= 0"
      sigma = sqrt(k_boltzmann*temperature_k/m_particle)
    end if

    n = size(v, 2)
    allocate (z(3, n))
    call sample_standard_normal(z)

    v = sigma*z + spread(drift_velocity, dim=2, ncopies=n)
  end subroutine sample_shifted_maxwell_velocities