Grow the node arrays (amortized doubling) so at least need nodes fit.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(QuadTreeMesh2D), | intent(inout) | :: | this | |||
| integer, | intent(in) | :: | need |
subroutine EnsureCapacity_QuadTreeMesh2D(this,need)
!! Grow the node arrays (amortized doubling) so at least `need` nodes fit.
implicit none
class(QuadTreeMesh2D),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%quadrant(1:this%nNodes); call move_alloc(itmp,this%quadrant)
allocate(itmp(1:newCap))
itmp = 0; itmp(1:this%nNodes) = this%rootElem(1:this%nNodes); call move_alloc(itmp,this%rootElem)
allocate(ctmp(1:4,1:newCap))
ctmp = 0; ctmp(1:4,1:this%nNodes) = this%child(1:4,1:this%nNodes); call move_alloc(ctmp,this%child)
this%capacity = newCap
endsubroutine EnsureCapacity_QuadTreeMesh2D