reserve_particles Subroutine

public subroutine reserve_particles(pcls, capacity)

容量を capacity 以上にする。先頭 pcls%n 個だけを写し、それより後ろの値は未定義のまま残す。

Arguments

Type IntentOptional Attributes Name
type(particles_soa), intent(inout) :: pcls
integer(kind=i32), intent(in) :: capacity

Calls

proc~~reserve_particles~~CallsGraph proc~reserve_particles reserve_particles proc~particle_capacity particle_capacity proc~reserve_particles->proc~particle_capacity

Called by

proc~~reserve_particles~~CalledByGraph proc~reserve_particles reserve_particles proc~extend_particles extend_particles proc~extend_particles->proc~reserve_particles proc~append_particles append_particles proc~append_particles->proc~extend_particles

Source Code

  subroutine reserve_particles(pcls, capacity)
    type(particles_soa), intent(inout) :: pcls
    integer(i32), intent(in) :: capacity
    real(dp), allocatable :: grown_x(:, :), grown_v(:, :), grown_q(:), grown_m(:), grown_w(:)
    integer(i32), allocatable :: grown_species_id(:), grown_source_element(:)
    logical, allocatable :: grown_alive(:)
    integer(i32) :: n

    if (capacity <= particle_capacity(pcls)) return
    n = pcls%n
    allocate (grown_x(3, capacity), grown_v(3, capacity), grown_q(capacity), grown_m(capacity), &
              grown_w(capacity), grown_species_id(capacity), grown_source_element(capacity), grown_alive(capacity))
    if (n > 0_i32) then
      grown_x(:, :n) = pcls%x(:, :n)
      grown_v(:, :n) = pcls%v(:, :n)
      grown_q(:n) = pcls%q(:n)
      grown_m(:n) = pcls%m(:n)
      grown_w(:n) = pcls%w(:n)
      grown_species_id(:n) = pcls%species_id(:n)
      grown_source_element(:n) = pcls%source_element(:n)
      grown_alive(:n) = pcls%alive(:n)
    end if
    call move_alloc(grown_x, pcls%x)
    call move_alloc(grown_v, pcls%v)
    call move_alloc(grown_q, pcls%q)
    call move_alloc(grown_m, pcls%m)
    call move_alloc(grown_w, pcls%w)
    call move_alloc(grown_species_id, pcls%species_id)
    call move_alloc(grown_source_element, pcls%source_element)
    call move_alloc(grown_alive, pcls%alive)
  end subroutine reserve_particles