extend_particles Subroutine

public subroutine extend_particles(pcls, added)

末尾に added 個の枠を足して pcls%n を進める。新しい枠は重み 1、粒子種 0、放出元 -1、alive で、 位置・速度・電荷・質量は呼出し元が埋める。容量が足りなければ必要数と現容量の 1.5 倍の大きい方へ広げ、 二次電子の世代ごとの追加で毎回全粒子を写し直さない。

Arguments

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

Calls

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

Called by

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

Source Code

  subroutine extend_particles(pcls, added)
    type(particles_soa), intent(inout) :: pcls
    integer(i32), intent(in) :: added
    integer(i32) :: old_count, new_count, capacity

    old_count = pcls%n
    if (added < 0_i32) error stop 'particle append count must be >= 0'
    if (old_count < 0_i32 .or. old_count > huge(0_i32) - added) error stop 'particle append count overflow'
    if (old_count > 0_i32) then
      if (.not. allocated(pcls%x) .or. .not. allocated(pcls%v) .or. .not. allocated(pcls%q) .or. &
          .not. allocated(pcls%m) .or. .not. allocated(pcls%w) .or. .not. allocated(pcls%species_id) .or. &
          .not. allocated(pcls%source_element) .or. .not. allocated(pcls%alive)) then
        error stop 'particle append requires a complete existing SoA'
      end if
    end if
    new_count = old_count + added
    capacity = particle_capacity(pcls)
    if (new_count > capacity) then
      call reserve_particles(pcls, max(new_count, capacity + min(capacity/2_i32, huge(0_i32) - capacity)))
    end if
    pcls%w(old_count + 1:new_count) = 1.0_dp
    pcls%species_id(old_count + 1:new_count) = 0_i32
    pcls%source_element(old_count + 1:new_count) = -1_i32
    pcls%alive(old_count + 1:new_count) = .true.
    pcls%n = new_count
  end subroutine extend_particles