init_particles Subroutine

public subroutine init_particles(pcls, x, v, q, m, w, species_id, source_element)

位置・速度・電荷・質量(と任意重み)配列から particles_soa を検証付きで構築する。

Arguments

Type IntentOptional Attributes Name
type(particles_soa), intent(out) :: pcls

検証済み配列を内部に保持した particles_soa 構造体。

real(kind=dp), intent(in) :: x(:,:)
real(kind=dp), intent(in) :: v(:,:)
real(kind=dp), intent(in) :: q(:)
real(kind=dp), intent(in) :: m(:)
real(kind=dp), intent(in), optional :: w(:)
integer(kind=i32), intent(in), optional :: species_id(:)
integer(kind=i32), intent(in), optional :: source_element(:)

Calls

proc~~init_particles~~CallsGraph proc~init_particles init_particles proc~allocate_particles allocate_particles proc~init_particles->proc~allocate_particles

Source Code

  subroutine init_particles(pcls, x, v, q, m, w, species_id, source_element)
    type(particles_soa), intent(out) :: pcls
    real(dp), intent(in) :: x(:, :), v(:, :), q(:), m(:)
    real(dp), intent(in), optional :: w(:)
    integer(i32), intent(in), optional :: species_id(:)
    integer(i32), intent(in), optional :: source_element(:)
    integer(i32) :: n

    n = size(q)
    if (size(x, 1) /= 3 .or. size(v, 1) /= 3) then
      error stop "particle input first dimension must be 3"
    end if
    if (size(x, 2) /= n .or. size(v, 2) /= n .or. size(m) /= n) then
      error stop "particle input size mismatch"
    end if

    call allocate_particles(pcls, n)
    pcls%x = x
    pcls%v = v
    pcls%q = q
    pcls%m = m
    if (present(w)) then
      if (size(w) /= n) error stop "w size mismatch"
      pcls%w = w
    end if
    if (present(species_id)) then
      if (size(species_id) /= n) error stop "species_id size mismatch"
      pcls%species_id = species_id
    end if
    if (present(source_element)) then
      if (size(source_element) /= n) error stop "source_element size mismatch"
      pcls%source_element = source_element
    end if
  end subroutine init_particles