Grow the node arrays (amortized doubling) so at least need nodes fit.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(OctreeMesh3D), | intent(inout) | :: | this | |||
| integer, | intent(in) | :: | need |
subroutine EnsureCapacity_OctreeMesh3D(this,need)
!! Grow the node arrays (amortized doubling) so at least `need` nodes fit.
implicit none
class(OctreeMesh3D),intent(inout) :: this
integer,intent(in) :: need
! Local
integer :: newCap
integer,allocatable :: itmp(:),ctmp(:,:)
if(need <= this%capacity) return
newCap = this%capacity
do while(newCap < need)
newCap = 2*newCap
enddo
allocate(itmp(1:newCap))
itmp = 0
itmp(1:this%nNodes) = this%level(1:this%nNodes)
call move_alloc(itmp,this%level)
allocate(itmp(1:newCap))
itmp = 0
itmp(1:this%nNodes) = this%parent(1:this%nNodes)
call move_alloc(itmp,this%parent)
allocate(itmp(1:newCap))
itmp = 0
itmp(1:this%nNodes) = this%octant(1:this%nNodes)
call move_alloc(itmp,this%octant)
allocate(itmp(1:newCap))
itmp = 0
itmp(1:this%nNodes) = this%rootElem(1:this%nNodes)
call move_alloc(itmp,this%rootElem)
allocate(ctmp(1:8,1:newCap))
ctmp = 0
ctmp(1:8,1:this%nNodes) = this%child(1:8,1:this%nNodes)
call move_alloc(ctmp,this%child)
this%capacity = newCap
endsubroutine EnsureCapacity_OctreeMesh3D