Skip to content

Commit 2996ac0

Browse files
authored
fix IDM loading of exchanges (MODFLOW-ORG#1577)
1 parent f2c9ebb commit 2996ac0

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/Utilities/Idm/IdmLoad.f90

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ end subroutine load_models
269269
subroutine load_exchanges(model_loadmask, iout)
270270
! -- modules
271271
use MemoryHelperModule, only: create_mem_path
272-
use MemoryManagerModule, only: mem_setptr, mem_allocate, mem_deallocate
272+
use MemoryManagerModule, only: mem_setptr, mem_allocate, &
273+
mem_deallocate, get_isize
273274
use CharacterStringModule, only: CharacterStringType
274275
use SimVariablesModule, only: idm_context, simfile
275276
use SourceCommonModule, only: idm_subcomponent_type, ifind_charstr
@@ -301,7 +302,7 @@ subroutine load_exchanges(model_loadmask, iout)
301302
character(len=LENCOMPONENTNAME) :: sc_type, sc_name, mtype
302303
class(StaticPkgLoadBaseType), pointer :: static_loader
303304
class(DynamicPkgLoadBaseType), pointer :: dynamic_loader
304-
integer(I4B) :: n, m1_idx, m2_idx, irem
305+
integer(I4B) :: n, m1_idx, m2_idx, irem, isize
305306
!
306307
! -- set input memory path
307308
input_mempath = create_mem_path('SIM', 'NAM', idm_context)
@@ -360,8 +361,13 @@ subroutine load_exchanges(model_loadmask, iout)
360361
mfname = mfnames(irem)
361362
mname = mnames(irem)
362363
mempath = create_mem_path(component=mname, context=idm_context)
363-
call mem_allocate(ncelldim, 'NCELLDIM', mempath)
364-
ncelldim = remote_model_ndim(mtype, mfname)
364+
call get_isize('NCELLDIM', mempath, isize)
365+
if (isize < 0) then
366+
call mem_allocate(ncelldim, 'NCELLDIM', mempath)
367+
ncelldim = remote_model_ndim(mtype, mfname)
368+
else
369+
call mem_setptr(ncelldim, 'NCELLDIM', mempath)
370+
end if
365371
else
366372
nullify (ncelldim)
367373
end if
@@ -393,13 +399,23 @@ subroutine load_exchanges(model_loadmask, iout)
393399
deallocate (static_loader)
394400
end if
395401
!
396-
! -- deallocate ncelldim as all input has been loaded
397-
if (associated(ncelldim)) call mem_deallocate(ncelldim)
398-
!
399402
end if
400403
!
401404
end do
402405
!
406+
! -- clean up temporary NCELLDIM for remote models
407+
do n = 1, size(mnames)
408+
if (model_loadmask(n) == 0) then
409+
mname = mnames(n)
410+
mempath = create_mem_path(component=mname, context=idm_context)
411+
call get_isize('NCELLDIM', mempath, isize)
412+
if (isize > 0) then
413+
call mem_setptr(ncelldim, 'NCELLDIM', mempath)
414+
call mem_deallocate(ncelldim)
415+
end if
416+
end if
417+
end do
418+
!
403419
! -- return
404420
return
405421
end subroutine load_exchanges

0 commit comments

Comments
 (0)