Rebind a live model to a new mesh/geometry pair (AMR regrid). The mesh-sized solution storage is reallocated and the boundary-condition registrations and maps are rebuilt for the new mesh, while everything that is not mesh-sized is preserved: the time state (t, dt, entropy, IO counter), the time-integrator selection, configuration flags, and any model-specific parameters (Init is intent(out) and would reset all of these). nvar/nstepped are unchanged - the model solves the same equations on a new mesh.
The solution interior is left UNINITIALIZED: the caller transfers the solution from the previous mesh (e.g. ApplyTransferPlan on a BuildTransferPlan mapping) and then calls solution%UpdateDevice. Regrid runs once per adaptation epoch, between time steps; it is not a per-step hot path.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(DGModel2D_t), | intent(inout) | :: | this | |||
| type(Mesh2D), | intent(in), | target | :: | mesh | ||
| type(SEMQuad), | intent(in), | target | :: | geometry |
subroutine Regrid_DGModel2D_t(this,mesh,geometry)
!! Rebind a live model to a new mesh/geometry pair (AMR regrid). The mesh-sized solution
!! storage is reallocated and the boundary-condition registrations and maps are rebuilt
!! for the new mesh, while everything that is not mesh-sized is preserved: the time state
!! (t, dt, entropy, IO counter), the time-integrator selection, configuration flags, and
!! any model-specific parameters (Init is intent(out) and would reset all of these).
!! nvar/nstepped are unchanged - the model solves the same equations on a new mesh.
!!
!! The solution interior is left UNINITIALIZED: the caller transfers the solution from the
!! previous mesh (e.g. ApplyTransferPlan on a BuildTransferPlan mapping) and then calls
!! solution%UpdateDevice. Regrid runs once per adaptation epoch, between time steps; it is
!! not a per-step hot path.
implicit none
class(DGModel2D_t),intent(inout) :: this
type(Mesh2D),intent(in),target :: mesh
type(SEMQuad),intent(in),target :: geometry
if(.not. associated(this%mesh)) then
print*,__FILE__,':',__LINE__, &
' : Error : Regrid called on a model that has not been initialized.'
stop 1
endif
! Free everything sized by the old mesh, mirroring Free (AdditionalFree releases any
! model-specific mesh-sized state so AdditionalInit can rebuild it below).
! Boundary-condition registrations are rebuilt because the boundary side set changes with the
! mesh. The mesh-sized fields are NOT freed: they are resized in place below (AMR Stage 6b),
! which reuses their host pools and device buffers whenever the new element count fits.
call this%hyperbolicBCs%Free()
call this%parabolicBCs%Free()
call this%AdditionalFree()
! Rebuild on the new mesh, mirroring the mesh-sized portion of Init.
this%mesh => mesh
this%geometry => geometry
! Resize rather than Free + Init. Init is intent(out), so it would reset the whole object,
! reallocate every array, zero it, reconstruct the equation parsers and - on GPU builds -
! upload the zeros, all of which the adaptive loop then discards. Profiling attributed over
! half of an adaptation to exactly that cycle.
call this%solution%Resize(geometry%x%interp,this%nvar,this%mesh%nElem)
call this%workSol%Resize(geometry%x%interp,this%nvar,this%mesh%nElem)
call this%dSdt%Resize(geometry%x%interp,this%nvar,this%mesh%nElem)
call this%solutionGradient%Resize(geometry%x%interp,this%nvar,this%mesh%nElem)
call this%flux%Resize(geometry%x%interp,this%nvar,this%mesh%nElem)
call this%source%Resize(geometry%x%interp,this%nvar,this%mesh%nElem)
call this%fluxDivergence%Resize(geometry%x%interp,this%nvar,this%mesh%nElem)
call this%solution%AssociateGeometry(geometry)
call this%solutionGradient%AssociateGeometry(geometry)
call this%flux%AssociateGeometry(geometry)
call this%fluxDivergence%AssociateGeometry(geometry)
call this%hyperbolicBCs%Init()
call this%parabolicBCs%Init()
call this%AdditionalInit()
call this%MapBoundaryConditions()
call this%SetMetadata()
endsubroutine Regrid_DGModel2D_t