MODFLOW 6  version 6.7.0.dev2
USGS Modular Hydrologic Model
gwf-api.f90
Go to the documentation of this file.
1 !> @brief This module contains the API package methods
2 !!
3 !! This module contains the overridden methods from the base model package
4 !! class for the API package. The API package is designed to be used with the
5 !! shared object and have period data specified using the MODFLOW API. Several
6 !! methods need to be overridden since no period data are specified in the
7 !! API input file. Overridden methods include:
8 !! - bnd_rp no period data is specified
9 !! - bnd_fc BOUND array is not filled. hcof and rhs are specified dierctly
10 !!
11 !<
12 module apimodule
13  use kindmodule, only: dp, i4b
16  use bndmodule, only: bndtype
21  !
22  implicit none
23  !
24  private
25  public :: api_create
26  public :: apitype
27  !
28  character(len=LENFTYPE) :: ftype = 'API'
29  character(len=LENPACKAGENAME) :: text = ' API'
30  !
31  type, extends(bndtype) :: apitype
32  contains
33  procedure :: read_options => source_options
34  procedure :: read_dimensions => source_dimensions
35  procedure :: bnd_rp => api_rp
36  procedure :: bnd_fc => api_fc
37  ! -- methods for observations
38  procedure, public :: bnd_obs_supported => api_obs_supported
39  procedure, public :: bnd_df_obs => api_df_obs
40  end type apitype
41 
42 contains
43 
44  !> @ brief Create a new package object
45  !!
46  !! Create a new USR Package object
47  !!
48  !<
49  subroutine api_create(packobj, id, ibcnum, inunit, iout, namemodel, pakname, &
50  mempath)
51  ! -- dummy variables
52  class(bndtype), pointer :: packobj !< pointer to default package type
53  integer(I4B), intent(in) :: id !< package id
54  integer(I4B), intent(in) :: ibcnum !< boundary condition number
55  integer(I4B), intent(in) :: inunit !< unit number of USR package input file
56  integer(I4B), intent(in) :: iout !< unit number of model listing file
57  character(len=*), intent(in) :: namemodel !< model name
58  character(len=*), intent(in) :: pakname !< package name
59  character(len=*), intent(in) :: mempath !< input mempath
60  ! -- local variables
61  type(apitype), pointer :: apiobj
62  !
63  ! -- allocate the object and assign values to object variables
64  allocate (apiobj)
65  packobj => apiobj
66  !
67  ! -- create name and memory path
68  call packobj%set_names(ibcnum, namemodel, pakname, ftype, mempath)
69  packobj%text = text
70  !
71  ! -- allocate scalars
72  call packobj%allocate_scalars()
73  !
74  ! -- initialize package
75  call packobj%pack_initialize()
76  !
77  packobj%inunit = inunit
78  packobj%iout = iout
79  packobj%id = id
80  packobj%ibcnum = ibcnum
81  packobj%ncolbnd = 2
82  packobj%iscloc = 2
83  packobj%ictMemPath = create_mem_path(namemodel, 'NPF')
84  end subroutine api_create
85 
86  !> @ brief Source package options from input context
87  !<
88  subroutine source_options(this)
93  ! -- dummy variables
94  class(apitype), intent(inout) :: this
95  type(gwfapiparamfoundtype) :: found
96  ! -- formats
97  character(len=*), parameter :: fmtflow2 = &
98  &"(4x, 'FLOWS WILL BE SAVED TO BUDGET FILE SPECIFIED IN OUTPUT CONTROL')"
99 
100  ! update default values from input context
101  call mem_set_value(this%iprpak, 'IPRPAK', this%input_mempath, found%iprpak)
102  call mem_set_value(this%iprflow, 'IPRFLOW', this%input_mempath, found%iprflow)
103  call mem_set_value(this%ipakcb, 'IPAKCB', this%input_mempath, found%ipakcb)
104  call mem_set_value(this%inamedbound, 'BOUNDNAMES', this%input_mempath, &
105  found%boundnames)
106  call mem_set_value(this%imover, 'MOVER', this%input_mempath, found%mover)
107 
108  ! update internal state
109  if (found%ipakcb) this%ipakcb = -1
110 
111  ! enforce 0 or 1 OBS6_FILENAME entries in option block
112  if (filein_fname(this%obs%inputFilename, 'OBS6_FILENAME', &
113  this%input_mempath, this%input_fname)) then
114  this%obs%active = .true.
115  this%obs%inUnitObs = getunit()
116  call openfile(this%obs%inUnitObs, this%iout, this%obs%inputFilename, 'OBS')
117  end if
118 
119  ! log package options
120  write (this%iout, '(/1x,a)') 'PROCESSING '//trim(adjustl(this%text)) &
121  //' OPTIONS'
122  if (found%iprpak) then
123  write (this%iout, '(4x,a)') &
124  'LISTS OF '//trim(adjustl(this%text))//' CELLS WILL BE PRINTED.'
125  end if
126  if (found%iprflow) then
127  write (this%iout, '(4x,a)') trim(adjustl(this%text))// &
128  ' FLOWS WILL BE PRINTED TO LISTING FILE.'
129  end if
130  if (found%ipakcb) write (this%iout, fmtflow2)
131  if (found%boundnames) then
132  write (this%iout, '(4x,a)') trim(adjustl(this%text))// &
133  ' BOUNDARIES HAVE NAMES IN LAST COLUMN.'
134  end if
135  if (found%mover) write (this%iout, '(4x,A)') 'MOVER OPTION ENABLED'
136  write (this%iout, '(1x,a)') &
137  'END OF '//trim(adjustl(this%text))//' OPTIONS'
138  end subroutine source_options
139 
140  !> @ brief Source package dimensions from input context
141  !<
142  subroutine source_dimensions(this)
143  use simvariablesmodule, only: errmsg
147  ! -- dummy variables
148  class(apitype), intent(inout) :: this
149  ! -- local variables
150  type(gwfapiparamfoundtype) :: found
151 
152  ! update dimensions from input context
153  call mem_set_value(this%maxbound, 'MAXBOUND', this%input_mempath, &
154  found%maxbound)
155 
156  ! log dimensions
157  write (this%iout, '(/1x,a)') 'PROCESSING '//trim(adjustl(this%text))// &
158  ' DIMENSIONS'
159  write (this%iout, '(4x,a,i7)') 'MAXBOUND = ', this%maxbound
160  write (this%iout, '(1x,a)') &
161  'END OF '//trim(adjustl(this%text))//' DIMENSIONS'
162 
163  ! verify dimensions
164  if (this%maxbound <= 0) then
165  write (errmsg, '(a)') 'MAXBOUND must be an integer greater than zero.'
166  call store_error(errmsg)
167  call store_error_filename(this%input_fname)
168  end if
169  end subroutine source_dimensions
170 
171  !> @ brief Read and prepare stress period data for package
172  !!
173  !! Method reads and prepares stress period data for the USR package.
174  !! This method overrides the base read and prepare method and does not read
175  !! any stress period data from the USR package input file.
176  !!
177  !<
178  subroutine api_rp(this)
179  ! -- dummy variables
180  class(apitype), intent(inout) :: this
181  end subroutine api_rp
182 
183  !> @ brief Fill A and r for the package
184  !!
185  !! Fill the coefficient matrix and right-hand side with the USR
186  !! package terms.
187  !!
188  !<
189  subroutine api_fc(this, rhs, ia, idxglo, matrix_sln)
190  ! -- dummy variables
191  class(apitype) :: this
192  real(DP), dimension(:), intent(inout) :: rhs !< right-hand side vector
193  integer(I4B), dimension(:), intent(in) :: ia !< pointer to the rows in A matrix
194  integer(I4B), dimension(:), intent(in) :: idxglo !< position of entries in A matrix
195  class(matrixbasetype), pointer :: matrix_sln !< A matrix for solution
196  ! -- local variables
197  integer(I4B) :: i
198  integer(I4B) :: n
199  integer(I4B) :: ipos
200  real(DP) :: qusr
201  !
202  ! -- pakmvrobj fc
203  if (this%imover == 1) then
204  call this%pakmvrobj%fc()
205  end if
206  !
207  ! -- Copy package rhs and hcof into solution rhs and amat
208  do i = 1, this%nbound
209  n = this%nodelist(i)
210  rhs(n) = rhs(n) + this%rhs(i)
211  ipos = ia(n)
212  call matrix_sln%add_value_pos(idxglo(ipos), this%hcof(i))
213  !
214  ! -- If mover is active and this boundary is discharging,
215  ! store available water (as positive value).
216  qusr = this%rhs(i) - this%hcof(i) * this%xnew(n)
217  if (this%imover == 1 .and. qusr > dzero) then
218  call this%pakmvrobj%accumulate_qformvr(i, qusr)
219  end if
220  end do
221  end subroutine api_fc
222 
223  ! -- Procedures related to observations
224 
225  !> @brief Determine if observations are supported.
226  !!
227  !! Function to determine if observations are supported by the USR package.
228  !! Observations are supported by the USR package.
229  !!
230  !<
231  logical function api_obs_supported(this)
232  ! -- dummy variables
233  class(apitype) :: this
234  !
235  ! -- set variables
236  api_obs_supported = .true.
237  end function api_obs_supported
238 
239  !> @brief Define the observation types available in the package
240  !!
241  !! Method to define the observation types available in the USR package.
242  !!
243  !<
244  subroutine api_df_obs(this)
245  ! -- dummy variables
246  class(apitype) :: this
247  ! -- local variables
248  integer(I4B) :: indx
249  !
250  ! -- initialize observations
251  call this%obs%StoreObsType('api', .true., indx)
252  this%obs%obsData(indx)%ProcessIdPtr => defaultobsidprocessor
253  !
254  ! -- Store obs type and assign procedure pointer
255  ! for to-mvr observation type.
256  call this%obs%StoreObsType('to-mvr', .true., indx)
257  this%obs%obsData(indx)%ProcessIdPtr => defaultobsidprocessor
258  end subroutine api_df_obs
259 
260 end module apimodule
This module contains the API package methods.
Definition: gwf-api.f90:12
subroutine, public api_create(packobj, id, ibcnum, inunit, iout, namemodel, pakname, mempath)
@ brief Create a new package object
Definition: gwf-api.f90:51
character(len=lenpackagename) text
Definition: gwf-api.f90:29
character(len=lenftype) ftype
Definition: gwf-api.f90:28
subroutine api_rp(this)
@ brief Read and prepare stress period data for package
Definition: gwf-api.f90:179
subroutine source_options(this)
@ brief Source package options from input context
Definition: gwf-api.f90:89
logical function api_obs_supported(this)
Determine if observations are supported.
Definition: gwf-api.f90:232
subroutine source_dimensions(this)
@ brief Source package dimensions from input context
Definition: gwf-api.f90:143
subroutine api_df_obs(this)
Define the observation types available in the package.
Definition: gwf-api.f90:245
subroutine api_fc(this, rhs, ia, idxglo, matrix_sln)
@ brief Fill A and r for the package
Definition: gwf-api.f90:190
This module contains the base boundary package.
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter lenpackagename
maximum length of the package name
Definition: Constants.f90:23
integer(i4b), parameter lenftype
maximum length of a package type (DIS, WEL, OC, etc.)
Definition: Constants.f90:39
real(dp), parameter dzero
real constant zero
Definition: Constants.f90:65
integer(i4b) function, public getunit()
Get a free unit number.
subroutine, public openfile(iu, iout, fname, ftype, fmtarg_opt, accarg_opt, filstat_opt, mode_opt)
Open a file.
Definition: InputOutput.f90:30
This module defines variable data types.
Definition: kind.f90:8
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
This module contains the derived type ObsType.
Definition: Obs.f90:127
subroutine, public defaultobsidprocessor(obsrv, dis, inunitobs, iout)
@ brief Process IDstring provided for each observation
Definition: Obs.f90:246
This module contains simulation methods.
Definition: Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition: Sim.f90:92
subroutine, public store_error_filename(filename, terminate)
Store the erroring file name.
Definition: Sim.f90:203
This module contains simulation variables.
Definition: SimVariables.f90:9
character(len=maxcharlen) errmsg
error message string
This module contains the SourceCommonModule.
Definition: SourceCommon.f90:7
logical(lgp) function, public filein_fname(filename, tagname, input_mempath, input_fname)
enforce and set a single input filename provided via FILEIN keyword
type(timeserieslinktype) function, pointer, public gettimeserieslinkfromlist(list, indx)
Get time series link from a list.
@ brief BndType