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