MODFLOW 6  version 6.5.0.dev2
MODFLOW 6 Code Documentation
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 !<
8 module tvkmodule
9  use basedismodule, only: disbasetype
11  use kindmodule, only: i4b, dp
14  use simmodule, only: store_error
15  use simvariablesmodule, only: errmsg
17 
18  implicit none
19 
20  private
21 
22  public :: tvktype
23  public :: tvk_cr
24 
25  type, extends(tvbasetype) :: tvktype
26  integer(I4B), pointer :: ik22overk => null() !< NPF flag that k22 is specified as anisotropy ratio
27  integer(I4B), pointer :: ik33overk => null() !< NPF flag that k33 is specified as anisotropy ratio
28  real(dp), dimension(:), pointer, contiguous :: k11 => null() !< NPF hydraulic conductivity; if anisotropic, then this is Kx prior to rotation
29  real(dp), dimension(:), pointer, contiguous :: k22 => null() !< NPF hydraulic conductivity; if specified then this is Ky prior to rotation
30  real(dp), dimension(:), pointer, contiguous :: k33 => null() !< NPF hydraulic conductivity; if specified then this is Kz prior to rotation
31  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)
32  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)
33  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)
34 
35  contains
36 
37  procedure :: da => tvk_da
39  procedure :: read_option => tvk_read_option
44  end type tvktype
45 
46 contains
47 
48  !> @brief Create a new TvkType object
49  !!
50  !! Create a new time-varying conductivity (TvkType) object.
51  !<
52  subroutine tvk_cr(tvk, name_model, inunit, iout)
53  ! -- dummy
54  type(tvktype), pointer, intent(out) :: tvk
55  character(len=*), intent(in) :: name_model
56  integer(I4B), intent(in) :: inunit
57  integer(I4B), intent(in) :: iout
58  !
59  allocate (tvk)
60  call tvk%init(name_model, 'TVK', 'TVK', inunit, iout)
61  !
62  ! -- Return
63  return
64  end subroutine tvk_cr
65 
66  !> @brief Announce package and set pointers to variables
67  !!
68  !! Announce package version and set array and variable pointers from the NPF
69  !! package for access by TVK.
70  !<
71  subroutine tvk_ar_set_pointers(this)
72  ! -- dummy
73  class(tvktype) :: this
74  ! -- local
75  character(len=LENMEMPATH) :: npfMemoryPath
76  ! -- formats
77  character(len=*), parameter :: fmttvk = &
78  "(1x,/1x,'TVK -- TIME-VARYING K PACKAGE, VERSION 1, 08/18/2021', &
79  &' INPUT READ FROM UNIT ', i0, //)"
80  !
81  ! -- Print a message identifying the TVK package
82  write (this%iout, fmttvk) this%inunit
83  !
84  ! -- Set pointers to other package variables
85  ! -- NPF
86  npfmemorypath = create_mem_path(this%name_model, 'NPF')
87  call mem_setptr(this%ik22overk, 'IK22OVERK', npfmemorypath)
88  call mem_setptr(this%ik33overk, 'IK33OVERK', npfmemorypath)
89  call mem_setptr(this%k11, 'K11', npfmemorypath)
90  call mem_setptr(this%k22, 'K22', npfmemorypath)
91  call mem_setptr(this%k33, 'K33', npfmemorypath)
92  call mem_setptr(this%kchangeper, 'KCHANGEPER', npfmemorypath)
93  call mem_setptr(this%kchangestp, 'KCHANGESTP', npfmemorypath)
94  call mem_setptr(this%nodekchange, 'NODEKCHANGE', npfmemorypath)
95  !
96  ! -- Return
97  return
98  end subroutine tvk_ar_set_pointers
99 
100  !> @brief Read a TVK-specific option from the OPTIONS block
101  !!
102  !! Process a single TVK-specific option. Used when reading the OPTIONS block
103  !! of the TVK package input file.
104  !<
105  function tvk_read_option(this, keyword) result(success)
106  ! -- dummy
107  class(tvktype) :: this
108  character(len=*), intent(in) :: keyword
109  ! -- return
110  logical :: success
111  !
112  ! -- There are no TVK-specific options, so just return false
113  success = .false.
114  !
115  ! -- Return
116  return
117  end function tvk_read_option
118 
119  !> @brief Get an array value pointer given a variable name and node index
120  !!
121  !! Return a pointer to the given node's value in the appropriate NPF array
122  !! based on the given variable name string.
123  !<
124  function tvk_get_pointer_to_value(this, n, varName) result(bndElem)
125  ! -- dummy
126  class(tvktype) :: this
127  integer(I4B), intent(in) :: n
128  character(len=*), intent(in) :: varname
129  ! -- return
130  real(dp), pointer :: bndelem
131  !
132  select case (varname)
133  case ('K')
134  bndelem => this%k11(n)
135  case ('K22')
136  bndelem => this%k22(n)
137  case ('K33')
138  bndelem => this%k33(n)
139  case default
140  bndelem => null()
141  end select
142  !
143  ! -- Return
144  return
145  end function tvk_get_pointer_to_value
146 
147  !> @brief Mark property changes as having occurred at (kper, kstp)
148  !!
149  !! Deferred procedure implementation called by the TvBaseType code when a
150  !! property value change occurs at (kper, kstp).
151  !<
152  subroutine tvk_set_changed_at(this, kper, kstp)
153  ! -- dummy
154  class(tvktype) :: this
155  integer(I4B), intent(in) :: kper
156  integer(I4B), intent(in) :: kstp
157  !
158  this%kchangeper = kper
159  this%kchangestp = kstp
160  !
161  ! -- Return
162  return
163  end subroutine tvk_set_changed_at
164 
165  !> @brief Clear all per-node change flags
166  !!
167  !! Deferred procedure implementation called by the TvBaseType code when a
168  !! new time step commences, indicating that any previously set per-node
169  !! property value change flags should be reset.
170  !<
171  subroutine tvk_reset_change_flags(this)
172  ! -- dummy variables
173  class(tvktype) :: this
174  ! -- local variables
175  integer(I4B) :: i
176  !
177  ! -- Clear NPF's nodekchange array
178  do i = 1, this%dis%nodes
179  this%nodekchange(i) = 0
180  end do
181  !
182  ! -- Return
183  return
184  end subroutine tvk_reset_change_flags
185 
186  !> @brief Check that a given property value is valid
187  !!
188  !! Deferred procedure implementation called by the TvBaseType code after a
189  !! property value change occurs. Check if the property value of the given
190  !! variable at the given node is invalid, and log an error if so. Update
191  !! K22 and K33 values appropriately when specified as anisotropy.
192  !<
193  subroutine tvk_validate_change(this, n, varName)
194  ! -- dummy
195  class(tvktype) :: this
196  integer(I4B), intent(in) :: n
197  character(len=*), intent(in) :: varName
198  ! -- local
199  character(len=LINELENGTH) :: cellstr
200  ! -- formats
201  character(len=*), parameter :: fmtkerr = &
202  "(1x, a, ' changed hydraulic property ', a, ' is <= 0 for cell ', a, &
203  &' ', 1pg15.6)"
204  !
205  ! -- Mark the node as being changed this time step
206  this%nodekchange(n) = 1
207  !
208  ! -- Check the changed value is ok
209  if (varname == 'K') then
210  if (this%k11(n) <= dzero) then
211  call this%dis%noder_to_string(n, cellstr)
212  write (errmsg, fmtkerr) &
213  trim(adjustl(this%packName)), 'K', trim(cellstr), this%k11(n)
214  call store_error(errmsg)
215  end if
216  elseif (varname == 'K22') then
217  if (this%ik22overk == 1) then
218  this%k22(n) = this%k22(n) * this%k11(n)
219  end if
220  if (this%k22(n) <= dzero) then
221  call this%dis%noder_to_string(n, cellstr)
222  write (errmsg, fmtkerr) &
223  trim(adjustl(this%packName)), 'K22', trim(cellstr), this%k22(n)
224  call store_error(errmsg)
225  end if
226  elseif (varname == 'K33') then
227  if (this%ik33overk == 1) then
228  this%k33(n) = this%k33(n) * this%k11(n)
229  end if
230  if (this%k33(n) <= dzero) then
231  call this%dis%noder_to_string(n, cellstr)
232  write (errmsg, fmtkerr) &
233  trim(adjustl(this%packName)), 'K33', trim(cellstr), this%k33(n)
234  call store_error(errmsg)
235  end if
236  end if
237  !
238  ! -- Return
239  return
240  end subroutine tvk_validate_change
241 
242  !> @brief Deallocate package memory
243  !!
244  !! Deallocate TVK package scalars and arrays.
245  !<
246  subroutine tvk_da(this)
247  ! -- dummy
248  class(tvktype) :: this
249  !
250  ! -- Nullify pointers to other package variables
251  nullify (this%ik22overk)
252  nullify (this%ik33overk)
253  nullify (this%k11)
254  nullify (this%k22)
255  nullify (this%k33)
256  nullify (this%kchangeper)
257  nullify (this%kchangestp)
258  nullify (this%nodekchange)
259  !
260  ! -- Deallocate parent
261  call tvbase_da(this)
262  !
263  ! -- Return
264  return
265  end subroutine tvk_da
266 
267 end module tvkmodule
Announce package and set pointers to variables.
Definition: TvBase.f90:54
Get an array value pointer given a variable name and node index.
Definition: TvBase.f90:83
Announce package and set pointers to variables.
Definition: TvBase.f90:67
Clear all per-node change flags.
Definition: TvBase.f90:118
Mark property changes as having occurred at (kper, kstp)
Definition: TvBase.f90:101
Check that a given property value is valid.
Definition: TvBase.f90:133
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition: Constants.f90:44
real(dp), parameter dzero
real constant zero
Definition: Constants.f90:64
integer(i4b), parameter lenmempath
maximum length of the memory path
Definition: Constants.f90:26
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:92
This module contains simulation variables.
Definition: SimVariables.f90:9
character(len=maxcharlen) errmsg
error message string
This module contains common time-varying property functionality.
Definition: TvBase.f90:8
subroutine, public tvbase_da(this)
Deallocate package memory.
Definition: TvBase.f90:472
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:153
subroutine tvk_da(this)
Deallocate package memory.
Definition: gwf-tvk.f90:247
logical function tvk_read_option(this, keyword)
Read a TVK-specific option from the OPTIONS block.
Definition: gwf-tvk.f90:106
subroutine, public tvk_cr(tvk, name_model, inunit, iout)
Create a new TvkType object.
Definition: gwf-tvk.f90:53
subroutine tvk_ar_set_pointers(this)
Announce package and set pointers to variables.
Definition: gwf-tvk.f90:72
real(dp) function, pointer tvk_get_pointer_to_value(this, n, varName)
Get an array value pointer given a variable name and node index.
Definition: gwf-tvk.f90:125
subroutine tvk_validate_change(this, n, varName)
Check that a given property value is valid.
Definition: gwf-tvk.f90:194
subroutine tvk_reset_change_flags(this)
Clear all per-node change flags.
Definition: gwf-tvk.f90:172