Rebind to a new element count, reusing host pools and device buffers where they fit (AMR Stage 6b), and without uploading zeros the way Init does.
The mortar buffers are sized by mesh%nMortars, not nElem, and nMortars changes with the mesh independently of the element count, so they are invalidated here and lazily re-created at the right size by the next mortar exchange. Leaving a stale buffer in place would silently under-size that exchange.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(MappedScalar2D), | intent(inout) | :: | this | |||
| type(Lagrange), | intent(in), | target | :: | interp | ||
| integer, | intent(in) | :: | nVar | |||
| integer, | intent(in) | :: | nElem |
subroutine Resize_MappedScalar2D(this,interp,nVar,nElem)
!! Rebind to a new element count, reusing host pools and device buffers where they fit
!! (AMR Stage 6b), and without uploading zeros the way Init does.
!!
!! The mortar buffers are sized by mesh%nMortars, not nElem, and nMortars changes with the
!! mesh independently of the element count, so they are invalidated here and lazily
!! re-created at the right size by the next mortar exchange. Leaving a stale buffer in place
!! would silently under-size that exchange.
implicit none
class(MappedScalar2D),intent(inout) :: this
type(Lagrange),intent(in),target :: interp
integer,intent(in) :: nVar
integer,intent(in) :: nElem
! Local
integer :: n,iError
call Resize_MappedScalar2D_t(this,interp,nVar,nElem)
call EnsureDeviceBuffers_MappedScalar2D(this)
if(c_associated(this%mortarBuff_gpu)) then
call gpuCheck(hipFree(this%mortarBuff_gpu))
this%mortarBuff_gpu = c_null_ptr
endif
! The aggregated halo-exchange state is sized by the mesh/partition, not by nElem
! alone: the packed buffer bytes scale with the shared-side count, the persistent
! requests bake in per-neighbor counts, displacements, and ranks, and
! halo_static_done records that the static (non-stepped) variables' traces have
! already been carried - none of which survives a regrid. Tear all of it down so
! the next SideExchangeStart rebuilds against the new mesh. This defect was latent
! here (the 2-D adaptive MPI test's halo layout happens to fit the first
! allocation) and surfaced as a GPU memory fault on the 3-D multi-rank adaptive
! path; the fix is applied symmetrically.
if(c_associated(this%halo_sendbuf_gpu)) call gpuCheck(hipFree(this%halo_sendbuf_gpu))
if(c_associated(this%halo_recvbuf_gpu)) call gpuCheck(hipFree(this%halo_recvbuf_gpu))
this%halo_sendbuf_gpu = c_null_ptr
this%halo_recvbuf_gpu = c_null_ptr
if(allocated(this%halo_reqs)) then
! Resize runs between time steps with MPI up (unlike Free, which may run after
! the last mesh finalized MPI), so the requests can be released unconditionally.
do n = 1,size(this%halo_reqs)
call MPI_REQUEST_FREE(this%halo_reqs(n),iError)
enddo
deallocate(this%halo_reqs)
endif
this%halo_nactive = 0
this%halo_inflight = 0
this%halo_static_done = .false.
endsubroutine Resize_MappedScalar2D