Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Jan 19, 2025
1 parent 849578f commit 48c1c15
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 18 deletions.
2 changes: 2 additions & 0 deletions autotest/test_prt_voronoi2.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@ def build_prt_sim(name, gwf_ws, prt_ws, targets, cell_ids):
)
gwf_budget_file = gwf_ws / f"{gwf_name}.bud"
gwf_head_file = gwf_ws / f"{gwf_name}.hds"
grb_file = gwf_ws / f"{gwf_name}.disv.grb"
flopy.mf6.ModflowPrtfmi(
prt,
packagedata=[
("GWFGRID", grb_file),
("GWFHEAD", gwf_head_file),
("GWFBUDGET", gwf_budget_file),
],
Expand Down
2 changes: 1 addition & 1 deletion doc/mf6io/mf6ivar/dfn/prt-fmi.dfn
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type string
tagged false
reader urword
longname flow type
description is the word GWFBUDGET or GWFHEAD. If GWFBUDGET is specified, then the corresponding file must be a budget file from a previous GWF Model run.
description is the word GWFBUDGET, GWFHEAD, or GRB. If GWFBUDGET is specified, then the corresponding file must be a budget file from a previous GWF Model run. If GWFHead is specified, the file must be a head file. If GRB is specified, the file must be a binary grid file.

block packagedata
name filein
Expand Down
1 change: 1 addition & 0 deletions msvs/mf6core.vfproj
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@
<File RelativePath="..\src\Utilities\DevFeature.f90"/>
<File RelativePath="..\src\Utilities\ErrorUtil.f90"/>
<File RelativePath="..\src\Utilities\GeomUtil.f90"/>
<File RelativePath="..\src\Utilities\GridFileReader.f90"/>
<File RelativePath="..\src\Utilities\HashTable.f90"/>
<File RelativePath="..\src\Utilities\HeadFileReader.f90"/>
<File RelativePath="..\src\Utilities\HGeoUtil.f90"/>
Expand Down
52 changes: 35 additions & 17 deletions src/Model/ModelUtilities/FlowModelInterface.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module FlowModelInterfaceModule
use ListModule, only: ListType
use BudgetFileReaderModule, only: BudgetFileReaderType
use HeadFileReaderModule, only: HeadFileReaderType
use GridFileReaderModule, only: GridFileReaderType
use PackageBudgetModule, only: PackageBudgetType
use BudgetObjectModule, only: BudgetObjectType, budgetobject_cr_bfr

Expand All @@ -24,6 +25,7 @@ module FlowModelInterfaceModule
type(ListType), pointer :: gwfbndlist => null() !< list of gwf stress packages
integer(I4B), pointer :: iflowsupdated => null() !< flows were updated for this time step
integer(I4B), dimension(:), pointer, contiguous :: ibound => null() !< pointer to Model ibound
class(DisBaseType), pointer :: gwfdis => null() !< flow model discretization object
real(DP), dimension(:), pointer, contiguous :: gwfflowja => null() !< pointer to the GWF flowja array
real(DP), dimension(:, :), pointer, contiguous :: gwfspdis => null() !< pointer to npf specific discharge array
real(DP), dimension(:), pointer, contiguous :: gwfhead => null() !< pointer to the GWF head array
Expand All @@ -37,12 +39,14 @@ module FlowModelInterfaceModule
integer(I4B), pointer :: iubud => null() !< unit number GWF budget file
integer(I4B), pointer :: iuhds => null() !< unit number GWF head file
integer(I4B), pointer :: iumvr => null() !< unit number GWF mover budget file
integer(I4B), pointer :: iugrb => null() !< unit number binary grid file
integer(I4B), pointer :: nflowpack => null() !< number of GWF flow packages
integer(I4B), dimension(:), pointer, contiguous :: igwfmvrterm => null() !< flag to indicate that gwf package is a mover term
type(BudgetFileReaderType) :: bfr !< budget file reader
type(HeadFileReaderType) :: hfr !< head file reader
type(GridFileReaderType) :: gfr !< grid file reader
type(PackageBudgetType), dimension(:), allocatable :: gwfpackages !< used to get flows between a package and gwf
type(BudgetObjectType), pointer :: mvrbudobj => null() !< pointer to the mover budget budget object
type(BudgetObjectType), pointer :: mvrbudobj => null() !< pointer to the mover budget object
character(len=16), dimension(:), allocatable :: flowpacknamearray !< array of boundary package names (e.g. LAK-1, SFR-3, etc.)
character(len=LENVARNAME) :: depvartype = ''

Expand All @@ -65,8 +69,7 @@ module FlowModelInterfaceModule
procedure :: initialize_gwfterms_from_gwfbndlist
procedure :: initialize_hfr
procedure :: read_options
procedure :: read_packagedata

procedure :: read_package_data
end type FlowModelInterfaceType

contains
Expand Down Expand Up @@ -110,10 +113,11 @@ subroutine fmi_df(this, dis, idryinactive)
if (this%inunit /= 0) then
call this%read_options()
end if

!
! -- Read packagedata options
if (this%inunit /= 0 .and. this%flows_from_file) then
call this%read_packagedata()
call this%read_package_data()
call this%initialize_gwfterms_from_bfr()
end if
!
Expand Down Expand Up @@ -151,6 +155,7 @@ subroutine fmi_da(this)
use MemoryManagerModule, only: mem_deallocate
! -- dummy
class(FlowModelInterfaceType) :: this

! -- todo: finalize hfr and bfr either here or in a finalize routine
!
! -- deallocate any memory stored with gwfpackages
Expand Down Expand Up @@ -181,6 +186,7 @@ subroutine fmi_da(this)
call mem_deallocate(this%iubud)
call mem_deallocate(this%iuhds)
call mem_deallocate(this%iumvr)
call mem_deallocate(this%iugrb)
call mem_deallocate(this%nflowpack)
call mem_deallocate(this%idryinactive)
!
Expand Down Expand Up @@ -208,6 +214,7 @@ subroutine allocate_scalars(this)
call mem_allocate(this%iubud, 'IUBUD', this%memoryPath)
call mem_allocate(this%iuhds, 'IUHDS', this%memoryPath)
call mem_allocate(this%iumvr, 'IUMVR', this%memoryPath)
call mem_allocate(this%iugrb, 'IUGRB', this%memoryPath)
call mem_allocate(this%nflowpack, 'NFLOWPACK', this%memoryPath)
call mem_allocate(this%idryinactive, "IDRYINACTIVE", this%memoryPath)
!
Expand All @@ -220,6 +227,7 @@ subroutine allocate_scalars(this)
this%iubud = 0
this%iuhds = 0
this%iumvr = 0
this%iugrb = 0
this%nflowpack = 0
this%idryinactive = 1
end subroutine allocate_scalars
Expand Down Expand Up @@ -325,7 +333,7 @@ end subroutine read_options

!> @brief Read packagedata block from input file
!<
subroutine read_packagedata(this)
subroutine read_package_data(this)
! -- modules
use OpenSpecModule, only: ACCESS, FORM
use ConstantsModule, only: LINELENGTH, DEM6, LENPACKAGENAME
Expand All @@ -346,12 +354,12 @@ subroutine read_packagedata(this)
iapt = 0
blockrequired = .true.
!
! -- get options block
! -- get packagedata block
call this%parser%GetBlock('PACKAGEDATA', isfound, ierr, &
blockRequired=blockRequired, &
supportOpenClose=.true.)
!
! -- parse options block if detected
! -- parse packagedata block if detected
if (isfound) then
write (this%iout, '(1x,a)') 'PROCESSING FMI PACKAGEDATA'
do
Expand Down Expand Up @@ -410,6 +418,20 @@ subroutine read_packagedata(this)
call budgetobject_cr_bfr(this%mvrbudobj, 'MVT', this%iumvr, &
this%iout)
call this%mvrbudobj%fill_from_bfr(this%dis, this%iout)
case ('GWFGRID')
call this%parser%GetStringCaps(keyword)
if (keyword /= 'FILEIN') then
call store_error('GWFGRID KEYWORD MUST BE FOLLOWED BY '// &
'"FILEIN" then by filename.')
call this%parser%StoreErrorUnit()
end if
call this%parser%GetString(fname)
inunit = getunit()
call openfile(inunit, this%iout, fname, 'DATA(BINARY)', FORM, &
ACCESS, 'UNKNOWN')
this%iugrb = inunit
call this%gfr%initialize(this%iugrb)
call this%gfr%load_grb(this%gwfdis)
case default
write (errmsg, '(a,3(1x,a))') &
'UNKNOWN', trim(adjustl(this%text)), 'PACKAGEDATA:', trim(keyword)
Expand All @@ -418,28 +440,24 @@ subroutine read_packagedata(this)
end do
write (this%iout, '(1x,a)') 'END OF FMI PACKAGEDATA'
end if
end subroutine read_packagedata
end subroutine read_package_data

!> @brief Initialize the budget file reader
!<
subroutine initialize_bfr(this)
! -- modules
class(FlowModelInterfaceType) :: this
! -- dummy
integer(I4B) :: ncrbud
!
! -- Initialize the budget file reader

! Initialize the budget file reader
call this%bfr%initialize(this%iubud, this%iout, ncrbud)
!
! -- todo: need to run through the budget terms
! and do some checking

! todo: need to run through the budget terms
! and do some checking
end subroutine initialize_bfr

!> @brief Advance the budget file reader
!!
!! Advance the budget file reader by reading the next chunk
!! of information for the current time step and stress period.
!!
!<
subroutine advance_bfr(this)
! -- modules
Expand Down
1 change: 1 addition & 0 deletions src/Model/TransportModel/tsp-fmi.f90
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ subroutine gwtfmi_da(this)
call mem_deallocate(this%iubud)
call mem_deallocate(this%iuhds)
call mem_deallocate(this%iumvr)
call mem_deallocate(this%iugrb)
call mem_deallocate(this%nflowpack)
call mem_deallocate(this%idryinactive)
!
Expand Down
1 change: 1 addition & 0 deletions src/Utilities/BudgetFileReader.f90
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ subroutine initialize(this, iu, iout, ncrbud)
integer(I4B) :: kstp_last, kper_last
integer(I4B) :: maxaux
logical :: success

this%inunit = iu
this%endoffile = .false.
this%nbudterms = 0
Expand Down
165 changes: 165 additions & 0 deletions src/Utilities/GridFileReader.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
module GridFileReaderModule

use KindModule
use SimModule, only: store_error, store_error_unit
use ConstantsModule, only: LINELENGTH
use BaseDisModule, only: DisBaseType
use InputOutputModule, only: urword, read_line
use LongLineReaderModule, only: LongLineReaderType

implicit none

private
public :: GridFileReaderType

type :: GridFileReaderType
integer(I4B), public :: inunit
! character(len=:), public, allocatable :: grid_type
! character(len=:), public, allocatable :: version
! integer(I4B), public :: ntxt
! integer(I4B), public :: lentxt
type(LongLineReaderType) :: line_reader
contains
procedure, public :: initialize
procedure, public :: load_grb
procedure, public :: finalize
procedure :: get_next_line
end type GridFileReaderType

contains

!< @brief Initialize the grid file reader.
subroutine initialize(this, iu)
class(GridFileReaderType) :: this
integer(I4B), intent(in) :: iu
this%inunit = iu
end subroutine initialize

!> @brief Load the grid file into the discretization object.
subroutine load_grb(this, dis)
! dummy
class(GridFileReaderType) :: this
class(DisBaseType), pointer :: dis
! local
character(len=LINELENGTH) :: errmsg
character(len=:), allocatable :: line
integer(I4B) :: lloc, istart, istop, ival
real(DP) :: rval
logical(LGP) :: eof

! -- Parse the attribute
do

call urword(line, lloc, istart, istop, 1, ival, rval, 0, 0)
select case (line(istart:istop))
case ('GRID')
! call urword(line, lloc, istart, istop, 1, ival, rval, 0, 0)
! this%grid = line(istart:istop)
case ('VERSION')
! call urword(line, lloc, istart, istop, 1, ival, rval, 0, 0)
! this%version = rval
case ('NTXT')
case ('LENTXT')
case ('NCELLS')
case ('NLAY')
case ('NROW')
case ('NCOL')
case ('NCPL')
case ('NVERT')
case ('NJAVERT')
case ('NJA')
case ('XORIGIN')
case ('YORIGIN')
case ('ANGROT')
case ('TOP')
case ('BOTM')
case ('VERTICES')
case ('CELLX')
case ('CELLY')
case ('IAVERT')
case ('JAVERT')
case ('IA')
case ('JA')
case ('IDOMAIN')
case ('ICELLTYPE')
case default
exit
! write (errmsg, '(a,a)') &
! 'Unknown grid file attribute: ', line(istart:istop)
! call store_error(errmsg, terminate=.TRUE.)
end select
end do

! TODO proper implementation

rewind (this%inunit)
end subroutine load_grb

!> @ brief Get the next line
!!
!! Method to get the next line from a file.
!!
!<
subroutine read_line(this, end)
! dummy variables
class(GridFileReaderType), intent(inout) :: this !< this object
logical, intent(out) :: end !< boolean indicating end of the text header section
! local variables
integer(I4B) :: ierr
integer(I4B) :: ival
integer(I4B) :: istart
integer(I4B) :: istop
real(DP) :: rval
character(len=10) :: key
logical :: lineread
!
! initialize local variables
end = .false.
ierr = 0
lineread = .false.
!
! read next line
loop1: do
if (lineread) exit loop1
call this%line_reader%rdcom(this%iuext, this%iout, this%line, ierr)
this%lloc = 1
call urword(this%line, this%lloc, istart, istop, 0, ival, rval, &
this%iout, this%iuext)
key = this%line(istart:istop)
call upcase(key)
print *, "key: ", key
if (key == 'END' .or. key == 'BEGIN') then
call uterminate_block(this%inunit, this%iout, key, &
this%blockNameFound, this%lloc, this%line, &
ierr, this%iuext)
this%iuactive = this%iuext
endOfBlock = .true.
lineread = .true.
elseif (key == '') then
! End of file reached.
! If this is an OPEN/CLOSE file, close the file and read the next
! line from this%inunit.
if (this%iuext /= this%inunit) then
close (this%iuext)
this%iuext = this%inunit
this%iuactive = this%inunit
else
errmsg = 'Unexpected end of file reached.'
call store_error(errmsg)
call this%StoreErrorUnit()
end if
else
this%lloc = 1
this%linesRead = this%linesRead + 1
lineread = .true.
end if
end do loop1
end subroutine read_line

!> @brief Finalize the grid file reader.
subroutine finalize(this)
class(GridFileReaderType) :: this
close (this%inunit)
end subroutine finalize

end module GridFileReaderModule
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ modflow_sources = files(
'Utilities' / 'DevFeature.f90',
'Utilities' / 'ErrorUtil.f90',
'Utilities' / 'GeomUtil.f90',
'Utilities' / 'GridFileReader.f90',
'Utilities' / 'HashTable.f90',
'Utilities' / 'HeadFileReader.f90',
'Utilities' / 'HGeoUtil.f90',
Expand Down

0 comments on commit 48c1c15

Please sign in to comment.