Skip to content

Commit

Permalink
feat(idm): support binary for regular, numeric list input blocks (#1783)
Browse files Browse the repository at this point in the history
* support binary for regular, numeric list input blocks

* some cleanup

* more cleanup

* refactor to remove exchange reference in static loader

---------

Co-authored-by: mjreno <[email protected]>
  • Loading branch information
mjreno and mjreno authored May 13, 2024
1 parent a6415f7 commit dca518a
Show file tree
Hide file tree
Showing 14 changed files with 235 additions and 187 deletions.
1 change: 1 addition & 0 deletions doc/ReleaseNotes/develop.tex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
\item A new Groundwater Energy (GWE) transport model is introduced to the code base for simulating heat transport in the subsurface. Additional information for activating the GWE model type within a MODFLOW 6 simulation is available within the mf6io.pdf document. New example problems have been developed for testing and demonstrating GWE capabilities (in addition to other internal tests that help verify the accuracy of GWE); however, additional changes to the code and input may be necessary in response to user needs and further testing.
\item A new capability has been introduced to create parameter layer export files of user input data for packages including DIS, DISV, IC, NPF, DSP(GWT), MIP(PRT), and CND(GWE). The number of supported packages is expected to increase in the future. The capability can be turned on with the package EXPORT\_ARRAY\_ASCII option. The package parameter export set is pre-defined and currently focuses on griddata. The number of parameters per package may also increase in the future.
\item Add capability to vary the hydraulic conductivity of the reach streambed (RHK) by stress period in the Streamflow Routing (SFR) package. RHK can be modified by stress period using the BEDK SFRSETTING. RHK can also be defined using a timeseries string in the PACKAGEDATA or PERIOD blocks.
\item Extend binary input support to all list style input blocks that have a regular shape and don't contain string fields (e.g. BOUNDNAME).
\end{itemize}

%\underline{EXAMPLES}
Expand Down
1 change: 1 addition & 0 deletions doc/mf6io/mf6ivar/dfn/exg-gwegwe.dfn
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ reader urword
optional true
longname auxiliary variables
description represents the values of the auxiliary variables for each GWEGWE Exchange. The values of auxiliary variables must be present for each exchange. The values must be specified in the order of the auxiliary variables specified in the OPTIONS block.
mf6internal auxvar

block exchangedata
name boundname
Expand Down
1 change: 1 addition & 0 deletions doc/mf6io/mf6ivar/dfn/exg-gwfgwf.dfn
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ reader urword
optional true
longname auxiliary variables
description represents the values of the auxiliary variables for each GWFGWF Exchange. The values of auxiliary variables must be present for each exchange. The values must be specified in the order of the auxiliary variables specified in the OPTIONS block.
mf6internal auxvar

block exchangedata
name boundname
Expand Down
1 change: 1 addition & 0 deletions doc/mf6io/mf6ivar/dfn/exg-gwtgwt.dfn
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ reader urword
optional true
longname auxiliary variables
description represents the values of the auxiliary variables for each GWTGWT Exchange. The values of auxiliary variables must be present for each exchange. The values must be specified in the order of the auxiliary variables specified in the OPTIONS block.
mf6internal auxvar

block exchangedata
name boundname
Expand Down
2 changes: 1 addition & 1 deletion src/Exchange/DisConnExchange.f90
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ subroutine source_data(this, iout)
call mem_setptr(cl1, 'CL1', this%input_mempath)
call mem_setptr(cl2, 'CL2', this%input_mempath)
call mem_setptr(hwva, 'HWVA', this%input_mempath)
call mem_setptr(auxvar, 'AUX', this%input_mempath)
call mem_setptr(auxvar, 'AUXVAR', this%input_mempath)
call mem_setptr(boundname, 'BOUNDNAME', this%input_mempath)
ndim1 = size(cellidm1, dim=1)
ndim2 = size(cellidm2, dim=1)
Expand Down
8 changes: 4 additions & 4 deletions src/Idm/exg-gwegweidm.f90
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module ExgGwegweInputModule
logical :: cl1 = .false.
logical :: cl2 = .false.
logical :: hwva = .false.
logical :: aux = .false.
logical :: auxvar = .false.
logical :: boundname = .false.
end type ExgGwegweParamFoundType

Expand Down Expand Up @@ -468,13 +468,13 @@ module ExgGwegweInputModule
)

type(InputParamDefinitionType), parameter :: &
exggwegwe_aux = InputParamDefinitionType &
exggwegwe_auxvar = InputParamDefinitionType &
( &
'EXG', & ! component
'GWEGWE', & ! subcomponent
'EXCHANGEDATA', & ! block
'AUX', & ! tag name
'AUX', & ! fortran variable
'AUXVAR', & ! fortran variable
'DOUBLE1D', & ! type
'NAUX', & ! shape
.false., & ! required
Expand Down Expand Up @@ -529,7 +529,7 @@ module ExgGwegweInputModule
exggwegwe_cl1, &
exggwegwe_cl2, &
exggwegwe_hwva, &
exggwegwe_aux, &
exggwegwe_auxvar, &
exggwegwe_boundname &
]

Expand Down
8 changes: 4 additions & 4 deletions src/Idm/exg-gwfgwfidm.f90
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module ExgGwfgwfInputModule
logical :: cl1 = .false.
logical :: cl2 = .false.
logical :: hwva = .false.
logical :: aux = .false.
logical :: auxvar = .false.
logical :: boundname = .false.
end type ExgGwfgwfParamFoundType

Expand Down Expand Up @@ -540,13 +540,13 @@ module ExgGwfgwfInputModule
)

type(InputParamDefinitionType), parameter :: &
exggwfgwf_aux = InputParamDefinitionType &
exggwfgwf_auxvar = InputParamDefinitionType &
( &
'EXG', & ! component
'GWFGWF', & ! subcomponent
'EXCHANGEDATA', & ! block
'AUX', & ! tag name
'AUX', & ! fortran variable
'AUXVAR', & ! fortran variable
'DOUBLE1D', & ! type
'NAUX', & ! shape
.false., & ! required
Expand Down Expand Up @@ -605,7 +605,7 @@ module ExgGwfgwfInputModule
exggwfgwf_cl1, &
exggwfgwf_cl2, &
exggwfgwf_hwva, &
exggwfgwf_aux, &
exggwfgwf_auxvar, &
exggwfgwf_boundname &
]

Expand Down
8 changes: 4 additions & 4 deletions src/Idm/exg-gwtgwtidm.f90
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module ExgGwtgwtInputModule
logical :: cl1 = .false.
logical :: cl2 = .false.
logical :: hwva = .false.
logical :: aux = .false.
logical :: auxvar = .false.
logical :: boundname = .false.
end type ExgGwtgwtParamFoundType

Expand Down Expand Up @@ -468,13 +468,13 @@ module ExgGwtgwtInputModule
)

type(InputParamDefinitionType), parameter :: &
exggwtgwt_aux = InputParamDefinitionType &
exggwtgwt_auxvar = InputParamDefinitionType &
( &
'EXG', & ! component
'GWTGWT', & ! subcomponent
'EXCHANGEDATA', & ! block
'AUX', & ! tag name
'AUX', & ! fortran variable
'AUXVAR', & ! fortran variable
'DOUBLE1D', & ! type
'NAUX', & ! shape
.false., & ! required
Expand Down Expand Up @@ -529,7 +529,7 @@ module ExgGwtgwtInputModule
exggwtgwt_cl1, &
exggwtgwt_cl2, &
exggwtgwt_hwva, &
exggwtgwt_aux, &
exggwtgwt_auxvar, &
exggwtgwt_boundname &
]

Expand Down
21 changes: 5 additions & 16 deletions src/Utilities/Idm/BoundInputContext.f90
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ subroutine allocate_scalars(this)
end if
!
! -- initialize package params object
call this%package_params%init(this%mf6_input, this%readasarrays, &
call this%package_params%init(this%mf6_input, 'PERIOD', this%readasarrays, &
this%naux, this%inamedbound)
!
! -- return
Expand Down Expand Up @@ -167,22 +167,11 @@ subroutine allocate_arrays(this)
call mem_allocate(cellid, 0, 0, 'CELLID', this%mf6_input%mempath)
end if
!
! -- allocate or set pointer to BOUNDNAME
if (this%inamedbound == 0) then
call mem_allocate(this%boundname_cst, LENBOUNDNAME, 0, &
'BOUNDNAME', this%mf6_input%mempath)
!
else
call mem_setptr(this%boundname_cst, 'BOUNDNAME', this%mf6_input%mempath)
end if
! -- set pointer to BOUNDNAME
call mem_setptr(this%boundname_cst, 'BOUNDNAME', this%mf6_input%mempath)
!
! -- allocate or set pointer to AUXVAR
if (this%naux == 0) then
call mem_allocate(this%auxvar, 0, 0, 'AUXVAR', this%mf6_input%mempath)
!
else
call mem_setptr(this%auxvar, 'AUXVAR', this%mf6_input%mempath)
end if
! -- set pointer to AUXVAR
call mem_setptr(this%auxvar, 'AUXVAR', this%mf6_input%mempath)
!
! -- return
return
Expand Down
48 changes: 35 additions & 13 deletions src/Utilities/Idm/DynamicPackageParams.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module DynamicPackageParamsModule

use KindModule, only: DP, I4B, LGP
use ConstantsModule, only: LINELENGTH, DZERO, IZERO
use ConstantsModule, only: LINELENGTH, LENBOUNDNAME, DZERO, IZERO
use SimVariablesModule, only: errmsg
use SimModule, only: store_error, store_error_filename
use MemoryManagerModule, only: mem_allocate
Expand All @@ -30,7 +30,8 @@ module DynamicPackageParamsModule
!<
type :: DynamicPackageParamsType
character(len=LINELENGTH), dimension(:), allocatable :: params !< in scope param tags
integer(I4B) :: naux !< number of aux variables in package
character(len=LINELENGTH) :: blockname !< name of block
integer(I4B) :: iauxiliary !< package auxiliary active, 0=inactive, active for values > 0
integer(I4B) :: inamedbound !< package inamedbound setting
integer(I4B) :: nparam !< number of in scope params
type(ModflowInputType) :: mf6_input !< description of input
Expand All @@ -47,19 +48,23 @@ module DynamicPackageParamsModule
!> @brief initialize dynamic param filter
!!
!<
subroutine init(this, mf6_input, readasarrays, naux, inamedbound)
subroutine init(this, mf6_input, blockname, readasarrays, iauxiliary, &
inamedbound)
! -- modules
! -- dummy
class(DynamicPackageParamsType) :: this
type(ModflowInputType), intent(in) :: mf6_input
character(len=*) :: blockname
logical(LGP), intent(in) :: readasarrays
integer(I4B), intent(in) :: naux
integer(I4B), intent(in) :: iauxiliary
integer(I4B), intent(in) :: inamedbound
!integer(I4B) :: iparam
! -- local
!
this%mf6_input = mf6_input
this%blockname = blockname
this%nparam = 0
this%naux = naux
this%iauxiliary = iauxiliary
this%inamedbound = inamedbound
!
! -- determine in scope input params
Expand Down Expand Up @@ -98,6 +103,8 @@ subroutine set_filtered_grid(this)
! -- local
type(InputParamDefinitionType), pointer :: idt
integer(I4B), dimension(:), allocatable :: idt_idxs
type(CharacterStringType), dimension(:), pointer, contiguous :: boundname
real(DP), dimension(:, :), pointer, contiguous :: auxvar
integer(I4B) :: keepcnt, iparam
logical(LGP) :: keep
!
Expand All @@ -112,13 +119,18 @@ subroutine set_filtered_grid(this)
! -- assign param definition pointer
idt => this%mf6_input%param_dfns(iparam)
!
if (idt%blockname /= 'PERIOD') then
if (idt%blockname /= this%blockname) then
keep = .false.
end if
!
if (idt%tagname == 'AUX') then
if (this%naux == 0) then
if (this%iauxiliary == 0) then
keep = .false.
call mem_allocate(auxvar, 0, 0, 'AUXVAR', this%mf6_input%mempath)
end if
if (this%inamedbound == 0) then
call mem_allocate(boundname, LENBOUNDNAME, 0, 'BOUNDNAME', &
this%mf6_input%mempath)
end if
end if
!
Expand Down Expand Up @@ -160,6 +172,8 @@ subroutine set_filtered_list(this)
! -- local
type(InputParamDefinitionType), pointer :: ra_idt, idt
character(len=LINELENGTH), dimension(:), allocatable :: ra_cols
type(CharacterStringType), dimension(:), pointer, contiguous :: boundname
real(DP), dimension(:, :), pointer, contiguous :: auxvar
integer(I4B) :: ra_ncol, icol, keepcnt
logical(LGP) :: keep
!
Expand All @@ -171,7 +185,7 @@ subroutine set_filtered_list(this)
get_aggregate_definition_type(this%mf6_input%aggregate_dfns, &
this%mf6_input%component_type, &
this%mf6_input%subcomponent_type, &
'PERIOD')
this%blockname)
!
! -- split recarray definition
call idt_parse_rectype(ra_idt, ra_cols, ra_ncol)
Expand All @@ -185,21 +199,26 @@ subroutine set_filtered_list(this)
idt => get_param_definition_type(this%mf6_input%param_dfns, &
this%mf6_input%component_type, &
this%mf6_input%subcomponent_type, &
'PERIOD', ra_cols(icol), '')
this%blockname, ra_cols(icol), '')
!
if (ra_cols(icol) == 'RECARRAY') then
! no-op
else if (ra_cols(icol) == 'AUX') then
if (this%naux > 0) then
if (this%iauxiliary > 0) then
keep = .true.
else
call mem_allocate(auxvar, 0, 0, 'AUXVAR', this%mf6_input%mempath)
end if
else if (ra_cols(icol) == 'BOUNDNAME') then
if (this%inamedbound /= 0) then
keep = .true.
else
call mem_allocate(boundname, LENBOUNDNAME, 0, 'BOUNDNAME', &
this%mf6_input%mempath)
end if
else
! -- determine if the param is scope
keep = pkg_param_in_scope(this%mf6_input, ra_cols(icol))
keep = pkg_param_in_scope(this%mf6_input, this%blockname, ra_cols(icol))
end if
!
if (keep) then
Expand Down Expand Up @@ -331,11 +350,12 @@ end subroutine allocate_param_dbl2d
!> @brief determine if input param is in scope for a package
!!
!<
function pkg_param_in_scope(mf6_input, tagname) result(in_scope)
function pkg_param_in_scope(mf6_input, blockname, tagname) result(in_scope)
! -- modules
use MemoryManagerModule, only: get_isize, mem_setptr
! -- dummy
type(ModflowInputType), intent(in) :: mf6_input
character(len=*), intent(in) :: blockname
character(len=*), intent(in) :: tagname
! -- return
logical(LGP) :: in_scope
Expand All @@ -350,7 +370,7 @@ function pkg_param_in_scope(mf6_input, tagname) result(in_scope)
idt => get_param_definition_type(mf6_input%param_dfns, &
mf6_input%component_type, &
mf6_input%subcomponent_type, &
'PERIOD', tagname, '')
blockname, tagname, '')
!
if (idt%required) then
! -- required params always included
Expand All @@ -376,6 +396,8 @@ function pkg_param_in_scope(mf6_input, tagname) result(in_scope)
end if
end if
!
case ('NAM')
in_scope = .true.
case default
errmsg = 'IDM unimplemented. DynamicPackageParamsType::pkg_param_in_scope &
&add case tagname='//trim(idt%tagname)
Expand Down
21 changes: 0 additions & 21 deletions src/Utilities/Idm/SourceCommon.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module SourceCommonModule
public :: idm_component_type, idm_subcomponent_type, idm_subcomponent_name
public :: set_model_shape
public :: get_shape_from_string
public :: mem_allocate_naux
public :: file_ext
public :: ifind_charstr
public :: filein_fname
Expand Down Expand Up @@ -405,26 +404,6 @@ subroutine set_model_shape(ftype, fname, model_mempath, dis_mempath, &
return
end subroutine set_model_shape

subroutine mem_allocate_naux(mempath)
use MemoryManagerModule, only: mem_allocate, mem_setptr, get_isize
character(len=*), intent(in) :: mempath
integer(I4B), pointer :: naux
integer(I4B) :: isize
!
! -- initialize
nullify (naux)
!
! -- allocate optional input scalars locally
call get_isize('NAUX', mempath, isize)
if (isize < 0) then
call mem_allocate(naux, 'NAUX', mempath)
naux = 0
end if
!
! -- return
return
end subroutine mem_allocate_naux

function ifind_charstr(array, str)
use CharacterStringModule, only: CharacterStringType
! -- Find the first array element containing str
Expand Down
Loading

0 comments on commit dca518a

Please sign in to comment.