MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
gwf-tvk.f90
Go to the documentation of this file.
1!> @brief This module contains time-varying conductivity package methods
2!!
3!! This module contains the methods used to allow hydraulic conductivity
4!! parameters in the NPF package (K11, K22, K33) to be varied throughout
5!! a simulation.
6!!
7!<
11 use kindmodule, only: i4b, dp
14 use simmodule, only: store_error
15 use simvariablesmodule, only: errmsg
16 use tdismodule, only: kper
18
19 implicit none
20
21 private
22
23 public :: tvktype
24 public :: tvk_cr
25
26 type, extends(tvbasetype) :: tvktype
27 integer(I4B), pointer :: ik22overk => null() !< NPF flag that k22 is specified as anisotropy ratio
28 integer(I4B), pointer :: ik33overk => null() !< NPF flag that k33 is specified as anisotropy ratio
29 real(dp), dimension(:), pointer, contiguous :: k11 => null() !< NPF hydraulic conductivity (before VSC adjustment if VSC is active); if anisotropic, then this is Kx prior to rotation
30 real(dp), dimension(:), pointer, contiguous :: k22 => null() !< NPF hydraulic conductivity (before VSC adjustment if VSC is active); if specified then this is Ky prior to rotation
31 real(dp), dimension(:), pointer, contiguous :: k33 => null() !< NPF hydraulic conductivity (before VSC adjustment if VSC is active); if specified then this is Kz prior to rotation
32 integer(I4B), pointer :: kchangeper => null() !< NPF last stress period in which any node K (or K22, or K33) values were changed (0 if unchanged from start of simulation)
33 integer(I4B), pointer :: kchangestp => null() !< NPF last time step in which any node K (or K22, or K33) values were changed (0 if unchanged from start of simulation)
34 integer(I4B), dimension(:), pointer, contiguous :: nodekchange => null() !< NPF grid array of flags indicating for each node whether its K (or K22, or K33) value changed (1) at (kchangeper, kchangestp) or not (0)
35 real(dp), dimension(:), pointer, contiguous :: k11_src => null() !< input K values
36 real(dp), dimension(:), pointer, contiguous :: k22_src => null() !< input K22 values
37 real(dp), dimension(:), pointer, contiguous :: k33_src => null() !< input K33 values
38
39 contains
40
41 procedure :: da => tvk_da
47 end type tvktype
48
49contains
50
51 !> @brief Create a new TvkType object
52 !!
53 !! Create a new time-varying conductivity (TvkType) object.
54 !<
55 subroutine tvk_cr(tvk, name_model, mempath, inunit, iout)
56 ! -- dummy
57 type(tvktype), pointer, intent(out) :: tvk
58 character(len=*), intent(in) :: name_model
59 character(len=*), intent(in) :: mempath
60 integer(I4B), intent(in) :: inunit
61 integer(I4B), intent(in) :: iout
62 !
63 allocate (tvk)
64 call tvk%init(name_model, 'TVK', 'TVK', mempath, inunit, iout)
65 end subroutine tvk_cr
66
67 !> @brief Announce package and set pointers to variables
68 !!
69 !! Announce package version and set array and variable pointers from the NPF
70 !! package for access by TVK.
71 !<
72 subroutine tvk_ar_set_pointers(this)
73 ! -- dummy
74 class(tvktype) :: this
75 ! -- local
76 character(len=LENMEMPATH) :: npfMemoryPath
77 integer(I4B), pointer :: invsc
78 ! -- formats
79 character(len=*), parameter :: fmttvk = &
80 "(1x,/1x,'TVK -- TIME-VARYING K PACKAGE, VERSION 1, 08/18/2021', &
81 &' INPUT READ FROM MEMPATH ', A, //)"
82 !
83 write (this%iout, fmttvk) this%input_mempath
84 !
85 npfmemorypath = create_mem_path(this%name_model, 'NPF')
86 call mem_setptr(this%ik22overk, 'IK22OVERK', npfmemorypath)
87 call mem_setptr(this%ik33overk, 'IK33OVERK', npfmemorypath)
88 !
89 ! -- with VSC active, change the K values that VSC scales by the
90 ! viscosity ratio each time step
91 call mem_setptr(invsc, 'INVSC', npfmemorypath)
92 if (invsc > 0) then
93 call mem_setptr(this%k11, 'K11INPUT', npfmemorypath)
94 call mem_setptr(this%k22, 'K22INPUT', npfmemorypath)
95 call mem_setptr(this%k33, 'K33INPUT', npfmemorypath)
96 else
97 call mem_setptr(this%k11, 'K11', npfmemorypath)
98 call mem_setptr(this%k22, 'K22', npfmemorypath)
99 call mem_setptr(this%k33, 'K33', npfmemorypath)
100 end if
101 call mem_setptr(this%kchangeper, 'KCHANGEPER', npfmemorypath)
102 call mem_setptr(this%kchangestp, 'KCHANGESTP', npfmemorypath)
103 call mem_setptr(this%nodekchange, 'NODEKCHANGE', npfmemorypath)
104 !
105 ! -- set input mempath pointers
106 call mem_setptr(this%k11_src, 'K', this%input_mempath)
107 call mem_setptr(this%k22_src, 'K22', this%input_mempath)
108 call mem_setptr(this%k33_src, 'K33', this%input_mempath)
109 end subroutine tvk_ar_set_pointers
110
111 !> @brief Apply this node's K/K22/K33 input values to node.
112 !!
113 !! Called for every tracked node; the DNODATA check on each field
114 !! makes this a no-op except where a value is set. node may be invalid
115 !! even when a field has a value at nodeu, so each field validates
116 !! node itself before using it.
117 !<
118 subroutine tvk_apply_row_changes(this, nodeu, node)
119 ! -- dummy
120 class(tvktype) :: this
121 integer(I4B), intent(in) :: nodeu
122 integer(I4B), intent(in) :: node
123 ! -- local
124 character(len=LINELENGTH) :: cellstr
125 ! -- formats
126 character(len=*), parameter :: fmtvalchg = &
127 "(a, ' package: Setting ', a, ' value for cell ', a, ' at start of &
128 &stress period ', i0, ' = ', g12.5)"
129 !
130 ! -- K is processed before K22/K33 so that validate_change can use
131 ! -- the already-updated k11 value when ik22overk/ik33overk are set.
132 if (this%k11_src(nodeu) /= dnodata) then
133 if (node < 1 .or. node > this%dis%nodes) then
134 call this%dis%noder_to_string(node, cellstr)
135 write (errmsg, '(a,2(1x,a))') &
136 'CELLID', trim(cellstr), 'is not in the active model domain.'
137 call store_error(errmsg)
138 else
139 this%k11(node) = this%k11_src(nodeu)
140 call this%validate_change(node, 'K')
141 if (this%iprpak /= 0) then
142 call this%dis%noder_to_string(node, cellstr)
143 write (this%iout, fmtvalchg) &
144 trim(adjustl(this%packName)), 'K', trim(cellstr), kper, &
145 this%k11(node)
146 end if
147 end if
148 end if
149 !
150 if (this%k22_src(nodeu) /= dnodata) then
151 if (node < 1 .or. node > this%dis%nodes) then
152 call this%dis%noder_to_string(node, cellstr)
153 write (errmsg, '(a,2(1x,a))') &
154 'CELLID', trim(cellstr), 'is not in the active model domain.'
155 call store_error(errmsg)
156 else
157 this%k22(node) = this%k22_src(nodeu)
158 call this%validate_change(node, 'K22')
159 if (this%iprpak /= 0) then
160 call this%dis%noder_to_string(node, cellstr)
161 write (this%iout, fmtvalchg) &
162 trim(adjustl(this%packName)), 'K22', trim(cellstr), kper, &
163 this%k22(node)
164 end if
165 end if
166 end if
167 !
168 if (this%k33_src(nodeu) /= dnodata) then
169 if (node < 1 .or. node > this%dis%nodes) then
170 call this%dis%noder_to_string(node, cellstr)
171 write (errmsg, '(a,2(1x,a))') &
172 'CELLID', trim(cellstr), 'is not in the active model domain.'
173 call store_error(errmsg)
174 else
175 this%k33(node) = this%k33_src(nodeu)
176 call this%validate_change(node, 'K33')
177 if (this%iprpak /= 0) then
178 call this%dis%noder_to_string(node, cellstr)
179 write (this%iout, fmtvalchg) &
180 trim(adjustl(this%packName)), 'K33', trim(cellstr), kper, &
181 this%k33(node)
182 end if
183 end if
184 end if
185 end subroutine tvk_apply_row_changes
186
187 !> @brief Mark property changes as having occurred at (kper, kstp)
188 !!
189 !! Deferred procedure implementation called by the TvBaseType code when a
190 !! property value change occurs at (kper, kstp).
191 !<
192 subroutine tvk_set_changed_at(this, kper, kstp)
193 ! -- dummy
194 class(tvktype) :: this
195 integer(I4B), intent(in) :: kper
196 integer(I4B), intent(in) :: kstp
197 !
198 this%kchangeper = kper
199 this%kchangestp = kstp
200 end subroutine tvk_set_changed_at
201
202 !> @brief Clear all per-node change flags
203 !!
204 !! Deferred procedure implementation called by the TvBaseType code when a
205 !! new time step commences, indicating that any previously set per-node
206 !! property value change flags should be reset.
207 !<
208 subroutine tvk_reset_change_flags(this)
209 ! -- dummy variables
210 class(tvktype) :: this
211 ! -- local variables
212 integer(I4B) :: i
213 !
214 do i = 1, this%dis%nodes
215 this%nodekchange(i) = 0
216 end do
217 end subroutine tvk_reset_change_flags
218
219 !> @brief Check that a given property value is valid
220 !!
221 !! Deferred procedure implementation called by the TvBaseType code after a
222 !! property value change occurs. Check if the property value of the given
223 !! variable at the given node is invalid, and log an error if so. Update
224 !! K22 and K33 values appropriately when specified as anisotropy.
225 !<
226 subroutine tvk_validate_change(this, n, varName)
227 ! -- dummy
228 class(tvktype) :: this
229 integer(I4B), intent(in) :: n
230 character(len=*), intent(in) :: varName
231 ! -- local
232 character(len=LINELENGTH) :: cellstr
233 ! -- formats
234 character(len=*), parameter :: fmtkerr = &
235 "(1x, a, ' changed hydraulic property ', a, ' is <= 0 for cell ', a, &
236 &' ', 1pg15.6)"
237 !
238 ! -- Mark the node as being changed this time step
239 this%nodekchange(n) = 1
240 !
241 ! -- Check the changed value is ok
242 if (varname == 'K') then
243 if (this%k11(n) <= dzero) then
244 call this%dis%noder_to_string(n, cellstr)
245 write (errmsg, fmtkerr) &
246 trim(adjustl(this%packName)), 'K', trim(cellstr), this%k11(n)
247 call store_error(errmsg)
248 end if
249 elseif (varname == 'K22') then
250 if (this%ik22overk == 1) then
251 this%k22(n) = this%k22(n) * this%k11(n)
252 end if
253 if (this%k22(n) <= dzero) then
254 call this%dis%noder_to_string(n, cellstr)
255 write (errmsg, fmtkerr) &
256 trim(adjustl(this%packName)), 'K22', trim(cellstr), this%k22(n)
257 call store_error(errmsg)
258 end if
259 elseif (varname == 'K33') then
260 if (this%ik33overk == 1) then
261 this%k33(n) = this%k33(n) * this%k11(n)
262 end if
263 if (this%k33(n) <= dzero) then
264 call this%dis%noder_to_string(n, cellstr)
265 write (errmsg, fmtkerr) &
266 trim(adjustl(this%packName)), 'K33', trim(cellstr), this%k33(n)
267 call store_error(errmsg)
268 end if
269 end if
270 end subroutine tvk_validate_change
271
272 !> @brief Deallocate package memory
273 !!
274 !! Deallocate TVK package scalars and arrays.
275 !<
276 subroutine tvk_da(this)
277 ! -- dummy
278 class(tvktype) :: this
279 !
280 nullify (this%ik22overk)
281 nullify (this%ik33overk)
282 nullify (this%k11)
283 nullify (this%k22)
284 nullify (this%k33)
285 nullify (this%kchangeper)
286 nullify (this%kchangestp)
287 nullify (this%nodekchange)
288 nullify (this%k11_src)
289 nullify (this%k22_src)
290 nullify (this%k33_src)
291 call tvbase_da(this)
292 end subroutine tvk_da
293
294end module tvkmodule
Apply this node's current input value(s) to the model property array(s).
Definition TvBase.f90:72
Announce package and set pointers to variables.
Definition TvBase.f90:57
Clear all per-node change flags.
Definition TvBase.f90:103
Mark property changes as having occurred at (kper, kstp).
Definition TvBase.f90:87
Check that a given property value is valid.
Definition TvBase.f90:118
This module contains simulation constants.
Definition Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition Constants.f90:45
real(dp), parameter dnodata
real no data constant
Definition Constants.f90:95
real(dp), parameter dzero
real constant zero
Definition Constants.f90:65
integer(i4b), parameter lenmempath
maximum length of the memory path
Definition Constants.f90:27
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 simulation methods.
Definition Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition Sim.f90:94
This module contains simulation variables.
character(len=maxcharlen) errmsg
error message string
integer(i4b) iout
file unit number for simulation output
integer(i4b), pointer, public kper
current stress period number
Definition tdis.f90:26
This module contains common time-varying property functionality.
Definition TvBase.f90:8
subroutine, public tvbase_da(this)
Deallocate package memory.
Definition TvBase.f90:336
This module contains time-varying conductivity package methods.
Definition gwf-tvk.f90:8
subroutine tvk_set_changed_at(this, kper, kstp)
Mark property changes as having occurred at (kper, kstp).
Definition gwf-tvk.f90:193
subroutine tvk_da(this)
Deallocate package memory.
Definition gwf-tvk.f90:277
subroutine tvk_ar_set_pointers(this)
Announce package and set pointers to variables.
Definition gwf-tvk.f90:73
subroutine tvk_validate_change(this, n, varname)
Check that a given property value is valid.
Definition gwf-tvk.f90:227
subroutine tvk_apply_row_changes(this, nodeu, node)
Apply this node's K/K22/K33 input values to node.
Definition gwf-tvk.f90:119
subroutine tvk_reset_change_flags(this)
Clear all per-node change flags.
Definition gwf-tvk.f90:209
subroutine, public tvk_cr(tvk, name_model, mempath, inunit, iout)
Create a new TvkType object.
Definition gwf-tvk.f90:56