Skip to content

Commit

Permalink
refactor(GwfMvr): store mover variables in memory manager (#940)
Browse files Browse the repository at this point in the history
* create new GwfMvrPeriodData object for reading and storing mover stress period data
* store mover stress period data as vectors in the memory manager
* revise the low-level mover object to point into the input data
* update makefile
* doxygenate
  • Loading branch information
langevin-usgs authored May 9, 2022
1 parent b514b81 commit 2df8d6e
Show file tree
Hide file tree
Showing 8 changed files with 305 additions and 168 deletions.
2 changes: 1 addition & 1 deletion make/makedefaults
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# makedefaults created by pymake (version 1.2.3) for the 'mf6' executable.
# makedefaults created by pymake (version 1.2.5) for the 'mf6' executable.

# determine OS
ifeq ($(OS), Windows_NT)
Expand Down
3 changes: 2 additions & 1 deletion make/makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# makefile created by pymake (version 1.2.3) for the 'mf6' executable.
# makefile created by pymake (version 1.2.5) for the 'mf6' executable.


include ./makedefaults
Expand Down Expand Up @@ -145,6 +145,7 @@ $(OBJDIR)/GwtAdvOptions.o \
$(OBJDIR)/gwf3tvs8.o \
$(OBJDIR)/GwfStorageUtils.o \
$(OBJDIR)/Mover.o \
$(OBJDIR)/GwfMvrPeriodData.o \
$(OBJDIR)/GwfBuyInputData.o \
$(OBJDIR)/gwf3disu8.o \
$(OBJDIR)/GridSorting.o \
Expand Down
1 change: 1 addition & 0 deletions msvs/mf6core.vfproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
<File RelativePath="..\src\Model\ModelUtilities\DiscretizationBase.f90"/>
<File RelativePath="..\src\Model\ModelUtilities\DisvGeom.f90"/>
<File RelativePath="..\src\Model\ModelUtilities\GwfBuyInputData.f90"/>
<File RelativePath="..\src\Model\ModelUtilities\GwfMvrPeriodData.f90"/>
<File RelativePath="..\src\Model\ModelUtilities\GwfNpfGridData.f90"/>
<File RelativePath="..\src\Model\ModelUtilities\GwfNpfOptions.f90"/>
<File RelativePath="..\src\Model\ModelUtilities\GwfStorageUtils.f90"/>
Expand Down
55 changes: 31 additions & 24 deletions src/Model/GroundWaterFlow/gwf3mvr8.f90
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ module GwfMvrModule
use BudgetObjectModule, only: BudgetObjectType, budgetobject_cr
use NumericalPackageModule, only: NumericalPackageType
use BlockParserModule, only: BlockParserType
use GwfMvrPeriodDataModule, only: GwfMvrPeriodDataType
use PackageMoverModule, only: PackageMoverType
use BaseDisModule, only: DisBaseType
use InputOutputModule, only: urword
Expand All @@ -136,6 +137,7 @@ module GwfMvrModule
character(len=LENPACKAGENAME), &
dimension(:), pointer, contiguous :: paknames => null() !< array of package names
type(MvrType), dimension(:), pointer, contiguous :: mvr => null() !< array of movers
type(GwfMvrPeriodDataType), pointer :: gwfmvrperioddata => null() !< input data object
type(BudgetType), pointer :: budget => null() !< mover budget object (used to write table)
type(BudgetObjectType), pointer :: budobj => null() !< new budget container (used to write binary file)
type(PackageMoverType), &
Expand Down Expand Up @@ -284,7 +286,7 @@ subroutine mvr_rp(this)
! -- local
integer(I4B) :: i, ierr, nlist, ipos
integer(I4B) :: ii, jj
logical :: isfound, endOfBlock
logical :: isfound
character(len=LINELENGTH) :: line, errmsg
character(len=LENMODELNAME) :: mname
! -- formats
Expand Down Expand Up @@ -344,32 +346,25 @@ subroutine mvr_rp(this)
! will happen only the first time
call this%assign_packagemovers()
!
! -- Read each mover entry
do
call this%parser%GetNextLine(endOfBlock)
if (endOfBlock) exit
call this%parser%GetCurrentLine(line)
!
! -- Raise error if movers exceeds maxmvr
if (i > this%maxmvr) then
write(errmsg,'(4x,a,a)') 'MOVERS EXCEED MAXMVR ON LINE: ', &
trim(adjustl(line))
call store_error(errmsg)
call this%parser%StoreErrorUnit()
endif
!
! -- Process the water mover line (mname = '' if this is an exchange)
call this%mvr(i)%set(line, this%parser%iuactive, this%iout, mname, &
this%pckMemPaths, this%pakmovers)
!
! -- Echo input
! -- Call the period data input reader
call this%gwfmvrperioddata%read_from_parser(this%parser, nlist, mname)
!
! -- Process the input data into the individual mover objects
do i = 1, nlist
call this%mvr(i)%set_values(this%gwfmvrperioddata%mname1(i), &
this%gwfmvrperioddata%pname1(i), &
this%gwfmvrperioddata%id1(i), &
this%gwfmvrperioddata%mname2(i), &
this%gwfmvrperioddata%pname2(i), &
this%gwfmvrperioddata%id2(i), &
this%gwfmvrperioddata%imvrtype(i), &
this%gwfmvrperioddata%value(i))
call this%mvr(i)%prepare(this%parser%iuactive, &
this%pckMemPaths, &
this%pakmovers)
if(this%iprpak == 1) call this%mvr(i)%echo(this%iout)
!
! -- increment counter
i = i + 1
end do
write(this%iout,'(/,1x,a,1x,i6,/)') 'END OF DATA FOR PERIOD', kper
nlist = i - 1
!
! -- Set the number of movers for this period to nlist
this%nmvr = nlist
Expand Down Expand Up @@ -710,6 +705,11 @@ subroutine mvr_da(this)
deallocate(this%paknames)
deallocate(this%pakmovers)
!
! -- allocate the perioddata object
call this%gwfmvrperioddata%destroy()
deallocate(this%gwfmvrperioddata)
nullify(this%gwfmvrperioddata)
!
! -- budget object
call this%budget%budget_da()
deallocate(this%budget)
Expand Down Expand Up @@ -1132,6 +1132,9 @@ subroutine allocate_scalars(this)
this%iexgmvr = 0
this%imodelnames = 0
!
! -- allocate the period data input object
allocate(this%gwfmvrperioddata)
!
! -- Return
return
end subroutine allocate_scalars
Expand Down Expand Up @@ -1164,6 +1167,10 @@ subroutine allocate_arrays(this)
call nulllify_packagemover_pointer(this%pakmovers(i))
end do
!
! -- allocate the perioddata object
call this%gwfmvrperioddata%construct(this%maxmvr, this%memoryPath)
!
!
! -- allocate the object and assign values to object variables
call mem_allocate(this%ientries, this%maxcomb, 'IENTRIES', this%memoryPath)
!
Expand Down
1 change: 0 additions & 1 deletion src/Model/GroundWaterTransport/gwt1.f90
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
! Groundwater Transport (GWT) Model
! The following are additional features/checks to add
! * Add check that discretization is the same between both models
! * Program GWT-GWT exchange transport (awaiting implementation of interface model)
! * Consider implementation of steady-state transport (affects MST, IST)
! * Check and handle pore space discrepancy between flow and transport (porosity vs specific yield)
! * UZT may not have the required porosity term
Expand Down
174 changes: 174 additions & 0 deletions src/Model/ModelUtilities/GwfMvrPeriodData.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
!> @brief This module contains the GwfMvrPeriodDataModule Module
!!
!! This module contains the code for storing and reading
!! stress period data for the GwfMvr Package.
!!
!<
module GwfMvrPeriodDataModule
use KindModule, only: DP, I4B
use ConstantsModule, only: LENMEMPATH, LENMODELNAME, LENPACKAGENAME, &
LINELENGTH
use SimVariablesModule, only: errmsg
use SimModule, only: store_error
use BlockParserModule, only: BlockParserType

implicit none
private
public GwfMvrPeriodDataType

!> @brief Derived type for GwfMvrPeriodDataType
!!
!! This derived type contains information and methods for
!! the data read for the GwfMvr Package.
!!
!<
type GwfMvrPeriodDataType
character(len=LENMODELNAME), dimension(:), pointer, contiguous :: mname1 => null() !< provider model name
character(len=LENPACKAGENAME), dimension(:), pointer, contiguous :: pname1 => null() !< provider package name
character(len=LENMODELNAME), dimension(:), pointer, contiguous :: mname2 => null() !< receiver model name
character(len=LENPACKAGENAME), dimension(:), pointer, contiguous :: pname2 => null() !< receiver package name
integer(I4B), dimension(:), pointer, contiguous :: id1 => null() !< provider reach number
integer(I4B), dimension(:), pointer, contiguous :: id2 => null() !< receiver reach number
integer(I4B), dimension(:), pointer, contiguous :: imvrtype => null() !< mover type (1, 2, 3, 4) corresponds to mvrtypes
real(DP), dimension(:), pointer, contiguous :: value => null() !< factor or rate depending on mvrtype
contains
procedure :: construct
procedure :: read_from_parser
procedure :: destroy
end type GwfMvrPeriodDataType

contains

!> @ brief Construct arrays
!!
!! Allocate maximum space for mover input.
!!
!<
subroutine construct(this, maxsize, memoryPath)
! -- modules
use MemoryManagerModule, only: mem_allocate
! -- dummy
class(GwfMvrPeriodDataType) :: this !< GwfMvrPeriodDataType
integer(I4B), intent(in) :: maxsize !< size of arrays
character(len=LENMEMPATH), intent(in) :: memoryPath !< memory manager path

! -- character arrays
allocate(this%mname1(maxsize))
allocate(this%pname1(maxsize))
allocate(this%mname2(maxsize))
allocate(this%pname2(maxsize))

! -- integer and real
call mem_allocate(this%id1, maxsize, 'ID1', memoryPath)
call mem_allocate(this%id2, maxsize, 'ID2', memoryPath)
call mem_allocate(this%imvrtype, maxsize, 'IMVRTYPE', memoryPath)
call mem_allocate(this%value, maxsize, 'VALUE', memoryPath)

return
end subroutine construct

!> @ brief Fill the arrays from parser
!!
!! Use the provided block parser to fill the input arrays.
!!
!<
subroutine read_from_parser(this, parser, nmvr, modelname)
! -- dummy
class(GwfMvrPeriodDataType) :: this !< GwfMvrPeriodDataType
type(BlockParserType), intent(inout) :: parser !< block parser
integer(I4B), intent(out) :: nmvr !< number of mover entries read
character(len=LENMODELNAME), intent(in) :: modelname !< name of model or empty string
! -- local
integer(I4B) :: i
integer(I4B) :: maxmvr
logical :: endOfBlock
character(len=LINELENGTH) :: line
character(len=12) :: mvrtype_char
!
! -- Initialize
i = 1
maxmvr = size(this%id1)
!
! -- Read each mover entry
do
call parser%GetNextLine(endOfBlock)
if (endOfBlock) exit
!
! -- Raise error if movers exceeds maxmvr
if (i > maxmvr) then
call parser%GetCurrentLine(line)
write(errmsg,'(4x,a,a)') 'MOVERS EXCEED MAXMVR ON LINE: ', &
trim(adjustl(line))
call store_error(errmsg)
call parser%StoreErrorUnit()
endif
!
! -- modelname, package name, id for provider
if (modelname == '') then
call parser%GetStringCaps(this%mname1(i))
else
this%mname1(i) = modelname
end if
call parser%GetStringCaps(this%pname1(i))
this%id1(i) = parser%GetInteger()
!
! -- modelname, package name, id for receiver
if (modelname == '') then
call parser%GetStringCaps(this%mname2(i))
else
this%mname2(i) = modelname
end if
call parser%GetStringCaps(this%pname2(i))
this%id2(i) = parser%GetInteger()
!
! -- Mover type and value
call parser%GetStringCaps(mvrtype_char)
select case(mvrtype_char)
case('FACTOR')
this%imvrtype(i) = 1
case('EXCESS')
this%imvrtype(i) = 2
case('THRESHOLD')
this%imvrtype(i) = 3
case('UPTO')
this%imvrtype(i) = 4
case default
call store_error('INVALID MOVER TYPE: '//trim(mvrtype_char))
call parser%StoreErrorUnit()
end select
this%value(i) = parser%GetDouble()
i = i + 1
end do
nmvr = i - 1
return
end subroutine read_from_parser

!> @ brief Destroy memory
!!
!! Deallocate memory from the memory manager.
!!
!<
subroutine destroy(this)
! -- modules
use MemoryManagerModule, only: mem_deallocate
! -- dummy
class(GwfMvrPeriodDataType) :: this !< GwfMvrPeriodDataType

! -- character arrays
deallocate(this%mname1)
deallocate(this%pname1)
deallocate(this%mname2)
deallocate(this%pname2)

! -- integer and real
call mem_deallocate(this%id1)
call mem_deallocate(this%id2)
call mem_deallocate(this%imvrtype)
call mem_deallocate(this%value)

return
end subroutine destroy


end module GwfMvrPeriodDataModule

Loading

0 comments on commit 2df8d6e

Please sign in to comment.