既存 SoA の末尾へ粒子群を追加し、既存の alive 状態を保持する。
容量が足りなければ extend_particles が 1.5 倍以上に広げるので、配列長は pcls%n より長くなり得る。
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(particles_soa), | intent(inout) | :: | pcls | |||
| 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) | :: | w(:) | |||
| integer(kind=i32), | intent(in) | :: | species_id(:) | |||
| integer(kind=i32), | intent(in), | optional | :: | source_element(:) |
subroutine append_particles(pcls, x, v, q, m, w, species_id, source_element) type(particles_soa), intent(inout) :: pcls real(dp), intent(in) :: x(:, :), v(:, :), q(:), m(:), w(:) integer(i32), intent(in) :: species_id(:) integer(i32), intent(in), optional :: source_element(:) integer(i32) :: old_count, added_count old_count = pcls%n added_count = int(size(q), i32) if (size(x, 1) /= 3 .or. size(v, 1) /= 3) error stop 'particle append first dimension must be 3' if (size(x, 2) /= added_count .or. size(v, 2) /= added_count .or. & size(m) /= added_count .or. size(w) /= added_count .or. size(species_id) /= added_count) then error stop 'particle append size mismatch' end if if (present(source_element)) then if (size(source_element) /= added_count) error stop 'particle append source_element size mismatch' end if if (added_count == 0_i32) return call extend_particles(pcls, added_count) pcls%x(:, old_count + 1:pcls%n) = x pcls%v(:, old_count + 1:pcls%n) = v pcls%q(old_count + 1:pcls%n) = q pcls%m(old_count + 1:pcls%n) = m pcls%w(old_count + 1:pcls%n) = w pcls%species_id(old_count + 1:pcls%n) = species_id if (present(source_element)) pcls%source_element(old_count + 1:pcls%n) = source_element end subroutine append_particles