MODFLOW 6  version 6.8.0.dev0
USGS Modular Hydrologic Model
gwf-tvs.f90
Go to the documentation of this file.
1 !> @brief This module contains the time-varying storage package methods
2 !!
3 !! This module contains the methods used to allow storage parameters in the
4 !! STO package (specific storage and specific yield) to be varied throughout
5 !! a simulation.
6 !!
7 !<
8 module tvsmodule
9  use basedismodule, only: disbasetype
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 :: tvstype
24  public :: tvs_cr
25 
26  type, extends(tvbasetype) :: tvstype
27  integer(I4B), pointer :: integratechanges => null() !< STO flag indicating if mid-simulation ss and sy changes should be integrated via an additional matrix formulation term
28  integer(I4B), pointer :: iusesy => null() !< STO flag set if any cell is convertible (0, 1)
29  real(dp), dimension(:), pointer, contiguous :: ss => null() !< STO specific storage or storage coefficient
30  real(dp), dimension(:), pointer, contiguous :: sy => null() !< STO specific yield
31  real(dp), dimension(:), pointer, contiguous :: ss_src => null() !< input SS values
32  real(dp), dimension(:), pointer, contiguous :: sy_src => null() !< input SY values
33 
34  contains
35 
36  procedure :: da => tvs_da
38  procedure :: source_package_options => tvs_source_package_options
43  end type tvstype
44 
45 contains
46 
47  !> @brief Create a new TvsType object
48  !!
49  !! Create a new time-varying storage (TVS) object.
50  !<
51  subroutine tvs_cr(tvs, name_model, mempath, inunit, iout)
52  ! -- dummy
53  type(tvstype), pointer, intent(out) :: tvs
54  character(len=*), intent(in) :: name_model
55  character(len=*), intent(in) :: mempath
56  integer(I4B), intent(in) :: inunit
57  integer(I4B), intent(in) :: iout
58  !
59  allocate (tvs)
60  call tvs%init(name_model, 'TVS', 'TVS', mempath, inunit, iout)
61  end subroutine tvs_cr
62 
63  !> @brief Announce package and set pointers to variables
64  !!
65  !! Announce package version, set array and variable pointers from the STO
66  !! package for access by TVS, and enable storage change integration.
67  !<
68  subroutine tvs_ar_set_pointers(this)
69  ! -- dummy
70  class(tvstype) :: this
71  ! -- local
72  character(len=LENMEMPATH) :: stoMemoryPath
73  ! -- formats
74  character(len=*), parameter :: fmttvs = &
75  "(1x,/1x,'TVS -- TIME-VARYING S PACKAGE, VERSION 1, 08/18/2021', &
76  &' INPUT READ FROM MEMPATH ', A, //)"
77  !
78  write (this%iout, fmttvs) this%input_mempath
79  !
80  stomemorypath = create_mem_path(this%name_model, 'STO')
81  call mem_setptr(this%integratechanges, 'INTEGRATECHANGES', stomemorypath)
82  call mem_setptr(this%iusesy, 'IUSESY', stomemorypath)
83  call mem_setptr(this%ss, 'SS', stomemorypath)
84  call mem_setptr(this%sy, 'SY', stomemorypath)
85  !
86  ! -- Instruct STO to integrate storage changes, since TVS is active
87  this%integratechanges = 1
88  !
89  ! -- set input mempath pointers
90  call mem_setptr(this%ss_src, 'SS', this%input_mempath)
91  call mem_setptr(this%sy_src, 'SY', this%input_mempath)
92  end subroutine tvs_ar_set_pointers
93 
94  !> @brief Source TVS-specific options from the input memory path.
95  !<
96  subroutine tvs_source_package_options(this)
97  ! -- dummy
98  class(tvstype) :: this
99  ! -- locals
100  integer(I4B) :: isize
101  ! -- formats
102  character(len=*), parameter :: fmtdsci = &
103  "(4X, 'DISABLE_STORAGE_CHANGE_INTEGRATION OPTION:', /, 6X, &
104  &'Storage derivative terms will not be added to STO matrix formulation')"
105  !
106  ! -- DISABLE_STORAGE_CHANGE_INTEGRATION is a keyword; check via get_isize
107  call get_isize('DISABLE_SC_INT', this%input_mempath, isize)
108  if (isize > 0) then
109  this%integratechanges = 0
110  write (this%iout, fmtdsci)
111  end if
112  end subroutine tvs_source_package_options
113 
114  !> @brief Apply input SS/SY column changes for period-data row n to node.
115  !<
116  subroutine tvs_apply_row_changes(this, n, node)
117  ! -- dummy
118  class(tvstype) :: this
119  integer(I4B), intent(in) :: n
120  integer(I4B), intent(in) :: node
121  ! -- local
122  character(len=LINELENGTH) :: cellstr
123  ! -- formats
124  character(len=*), parameter :: fmtvalchg = &
125  "(a, ' package: Setting ', a, ' value for cell ', a, ' at start of &
126  &stress period ', i0, ' = ', g12.5)"
127  !
128  if (this%ss_src(n) /= dnodata) then
129  this%ss(node) = this%ss_src(n)
130  call this%validate_change(node, 'SS')
131  if (this%iprpak /= 0) then
132  call this%dis%noder_to_string(node, cellstr)
133  write (this%iout, fmtvalchg) &
134  trim(adjustl(this%packName)), 'SS', trim(cellstr), kper, this%ss(node)
135  end if
136  end if
137  !
138  if (this%sy_src(n) /= dnodata) then
139  this%sy(node) = this%sy_src(n)
140  call this%validate_change(node, 'SY')
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)), 'SY', trim(cellstr), kper, this%sy(node)
145  end if
146  end if
147  end subroutine tvs_apply_row_changes
148 
149  !> @brief Mark property changes as having occurred at (kper, kstp)
150  !!
151  !! Deferred procedure implementation called by the TvBaseType code when a
152  !! property value change occurs at (kper, kstp).
153  !<
154  subroutine tvs_set_changed_at(this, kper, kstp)
155  ! -- dummy
156  class(tvstype) :: this
157  integer(I4B), intent(in) :: kper
158  integer(I4B), intent(in) :: kstp
159  !
160  ! -- No need to record TVS/STO changes, as no other packages cache
161  ! -- Ss or Sy values
162  end subroutine tvs_set_changed_at
163 
164  !> @brief Clear all per-node change flags
165  !!
166  !! Deferred procedure implementation called by the TvBaseType code when a
167  !! new time step commences, indicating that any previously set per-node
168  !! property value change flags should be reset.
169  !<
170  subroutine tvs_reset_change_flags(this)
171  ! -- dummy
172  class(tvstype) :: this
173  !
174  ! -- No need to record TVS/STO changes, as no other packages cache
175  ! -- Ss or Sy values
176  end subroutine tvs_reset_change_flags
177 
178  !> @brief Check that a given property value is valid
179  !!
180  !! Deferred procedure implementation called by the TvBaseType code after a
181  !! property value change occurs. Check if the property value of the given
182  !! variable at the given node is invalid, and log an error if so.
183  !<
184  subroutine tvs_validate_change(this, n, varName)
185  ! -- dummy
186  class(tvstype) :: this
187  integer(I4B), intent(in) :: n
188  character(len=*), intent(in) :: varName
189  ! -- local
190  character(len=LINELENGTH) :: cellstr
191  ! -- formats
192  character(len=*), parameter :: fmtserr = &
193  "(1x, a, ' changed storage property ', a, ' is < 0 for cell ', a,' ', &
194  &1pg15.6)"
195  character(len=*), parameter :: fmtsyerr = &
196  "(1x, a, ' cannot change ', a ,' for cell ', a, ' because SY is unused &
197  &in this model (all ICONVERT flags are 0).')"
198  !
199  if (varname == 'SS') then
200  if (this%ss(n) < dzero) then
201  call this%dis%noder_to_string(n, cellstr)
202  write (errmsg, fmtserr) trim(adjustl(this%packName)), 'SS', &
203  trim(cellstr), this%ss(n)
204  call store_error(errmsg)
205  end if
206  elseif (varname == 'SY') then
207  if (this%iusesy /= 1) then
208  call this%dis%noder_to_string(n, cellstr)
209  write (errmsg, fmtsyerr) trim(adjustl(this%packName)), 'SY', &
210  trim(cellstr)
211  call store_error(errmsg)
212  elseif (this%sy(n) < dzero) then
213  call this%dis%noder_to_string(n, cellstr)
214  write (errmsg, fmtserr) trim(adjustl(this%packName)), 'SY', &
215  trim(cellstr), this%sy(n)
216  call store_error(errmsg)
217  end if
218  end if
219  end subroutine tvs_validate_change
220 
221  !> @brief Deallocate package memory
222  !!
223  !! Deallocate TVS package scalars and arrays.
224  !<
225  subroutine tvs_da(this)
226  ! -- dummy
227  class(tvstype) :: this
228  !
229  nullify (this%integratechanges)
230  nullify (this%iusesy)
231  nullify (this%ss)
232  nullify (this%sy)
233  nullify (this%ss_src)
234  nullify (this%sy_src)
235  call tvbase_da(this)
236  end subroutine tvs_da
237 
238 end module tvsmodule
Apply input column changes for period-data row n to node.
Definition: TvBase.f90:63
Announce package and set pointers to variables.
Definition: TvBase.f90:54
Clear all per-node change flags.
Definition: TvBase.f90:94
Mark property changes as having occurred at (kper, kstp)
Definition: TvBase.f90:78
Check that a given property value is valid.
Definition: TvBase.f90:109
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
subroutine, public get_isize(name, mem_path, isize)
@ brief Get the number of elements for this variable
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
integer(i4b), pointer, public kper
current stress period number
Definition: tdis.f90:23
This module contains common time-varying property functionality.
Definition: TvBase.f90:8
subroutine, public tvbase_da(this)
Deallocate package memory.
Definition: TvBase.f90:302
This module contains the time-varying storage package methods.
Definition: gwf-tvs.f90:8
subroutine tvs_ar_set_pointers(this)
Announce package and set pointers to variables.
Definition: gwf-tvs.f90:69
subroutine tvs_validate_change(this, n, varName)
Check that a given property value is valid.
Definition: gwf-tvs.f90:185
subroutine tvs_set_changed_at(this, kper, kstp)
Mark property changes as having occurred at (kper, kstp)
Definition: gwf-tvs.f90:155
subroutine tvs_source_package_options(this)
Source TVS-specific options from the input memory path.
Definition: gwf-tvs.f90:97
subroutine tvs_reset_change_flags(this)
Clear all per-node change flags.
Definition: gwf-tvs.f90:171
subroutine tvs_apply_row_changes(this, n, node)
Apply input SS/SY column changes for period-data row n to node.
Definition: gwf-tvs.f90:117
subroutine tvs_da(this)
Deallocate package memory.
Definition: gwf-tvs.f90:226
subroutine, public tvs_cr(tvs, name_model, mempath, inunit, iout)
Create a new TvsType object.
Definition: gwf-tvs.f90:52