Change the number of live elements, preserving the elements that survive.
min(size(), n) leading elements of every field keep their values.
Growing sets the newly exposed elements to the zero value of their
type; shrinking only lowers the live count. Capacity grows
geometrically and never shrinks – see pic_soa.
On failure the container is left exactly as it was.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(particle_soa_t), | intent(inout) | :: | this |
Container to resize. |
||
| integer(kind=default_int), | intent(in) | :: | n |
New number of live elements. Must not be negative. |
||
| type(error_t), | intent(inout) | :: | err |
Error state, |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=default_int), | private | :: | keep | ||||
| integer(kind=default_int), | private | :: | new_capacity |
subroutine particle_soa_resize(this, n, err) !! Change the number of live elements, preserving the elements that !! survive. !! !! `min(size(), n)` leading elements of every field keep their values. !! Growing sets the newly exposed elements to the zero value of their !! type; shrinking only lowers the live count. Capacity grows !! geometrically and never shrinks -- see `pic_soa`. !! !! On failure the container is left exactly as it was. class(particle_soa_t), intent(inout) :: this !! Container to resize. integer(default_int), intent(in) :: n !! New number of live elements. Must not be negative. type(error_t), intent(inout) :: err !! Error state, `ERROR_VALIDATION` on a negative `n` and !! `ERROR_ALLOC` if a field array cannot be allocated. integer(default_int) :: new_capacity, keep call soa_plan_resize(this%extent, n, new_capacity, keep, err) if (err%has_error()) return call soa_resize_field(this%id, new_capacity, keep, n, err) if (err%has_error()) return call soa_resize_field(this%x, new_capacity, keep, n, err) if (err%has_error()) return call soa_resize_field(this%y, new_capacity, keep, n, err) if (err%has_error()) return call soa_resize_field(this%z, new_capacity, keep, n, err) if (err%has_error()) return call soa_resize_field(this%mass, new_capacity, keep, n, err) if (err%has_error()) return call soa_resize_field(this%active, new_capacity, keep, n, err) if (err%has_error()) return this%extent%used = n this%extent%capacity = new_capacity end subroutine particle_soa_resize