MODFLOW 6  version 6.7.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
17 
18  implicit none
19 
20  private
21 
22  public :: tvstype
23  public :: tvs_cr
24 
25  type, extends(tvbasetype) :: tvstype
26  integer(I4B), pointer :: integratechanges => null() !< STO flag indicating if mid-simulation ss and sy changes should be integrated via an additional matrix formulation term
27  integer(I4B), pointer :: iusesy => null() !< STO flag set if any cell is convertible (0, 1)
28  real(dp), dimension(:), pointer, contiguous :: ss => null() !< STO specific storage or storage coefficient
29  real(dp), dimension(:), pointer, contiguous :: sy => null() !< STO specific yield
30 
31  contains
32 
33  procedure :: da => tvs_da
35  procedure :: read_option => tvs_read_option
40  end type tvstype
41 
42 contains
43 
44  !> @brief Create a new TvsType object
45  !!
46  !! Create a new time-varying storage (TVS) object.
47  !<
48  subroutine tvs_cr(tvs, name_model, inunit, iout)
49  ! -- dummy
50  type(tvstype), pointer, intent(out) :: tvs
51  character(len=*), intent(in) :: name_model
52  integer(I4B), intent(in) :: inunit
53  integer(I4B), intent(in) :: iout
54  !
55  allocate (tvs)
56  call tvs%init(name_model, 'TVS', 'TVS', inunit, iout)
57  end subroutine tvs_cr
58 
59  !> @brief Announce package and set pointers to variables
60  !!
61  !! Announce package version, set array and variable pointers from the STO
62  !! package for access by TVS, and enable storage change integration.
63  !<
64  subroutine tvs_ar_set_pointers(this)
65  ! -- dummy
66  class(tvstype) :: this
67  ! -- local
68  character(len=LENMEMPATH) :: stoMemoryPath
69  ! -- formats
70  character(len=*), parameter :: fmttvs = &
71  "(1x,/1x,'TVS -- TIME-VARYING S PACKAGE, VERSION 1, 08/18/2021', &
72  &' INPUT READ FROM UNIT ', i0, //)"
73  !
74  ! -- Print a message identifying the TVS package
75  write (this%iout, fmttvs) this%inunit
76  !
77  ! -- Set pointers to other package variables
78  ! -- STO
79  stomemorypath = create_mem_path(this%name_model, 'STO')
80  call mem_setptr(this%integratechanges, 'INTEGRATECHANGES', stomemorypath)
81  call mem_setptr(this%iusesy, 'IUSESY', stomemorypath)
82  call mem_setptr(this%ss, 'SS', stomemorypath)
83  call mem_setptr(this%sy, 'SY', stomemorypath)
84  !
85  ! -- Instruct STO to integrate storage changes, since TVS is active
86  this%integratechanges = 1
87  end subroutine tvs_ar_set_pointers
88 
89  !> @brief Read a TVS-specific option from the OPTIONS block
90  !!
91  !! Process a single TVS-specific option. Used when reading the OPTIONS block
92  !! of the TVS package input file.
93  !<
94  function tvs_read_option(this, keyword) result(success)
95  ! -- dummy
96  class(tvstype) :: this
97  character(len=*), intent(in) :: keyword
98  ! -- return
99  logical :: success
100  ! -- formats
101  character(len=*), parameter :: fmtdsci = &
102  "(4X, 'DISABLE_STORAGE_CHANGE_INTEGRATION OPTION:', /, 1X, &
103  &'Storage derivative terms will not be added to STO matrix formulation')"
104  !
105  select case (keyword)
106  case ('DISABLE_STORAGE_CHANGE_INTEGRATION')
107  success = .true.
108  this%integratechanges = 0
109  write (this%iout, fmtdsci)
110  case default
111  success = .false.
112  end select
113  end function tvs_read_option
114 
115  !> @brief Get an array value pointer given a variable name and node index
116  !!
117  !! Return a pointer to the given node's value in the appropriate STO array
118  !! based on the given variable name string.
119  !<
120  function tvs_get_pointer_to_value(this, n, varName) result(bndElem)
121  ! -- dummy
122  class(tvstype) :: this
123  integer(I4B), intent(in) :: n
124  character(len=*), intent(in) :: varname
125  ! -- return
126  real(dp), pointer :: bndelem
127  !
128  select case (varname)
129  case ('SS')
130  bndelem => this%ss(n)
131  case ('SY')
132  bndelem => this%sy(n)
133  case default
134  bndelem => null()
135  end select
136  end function tvs_get_pointer_to_value
137 
138  !> @brief Mark property changes as having occurred at (kper, kstp)
139  !!
140  !! Deferred procedure implementation called by the TvBaseType code when a
141  !! property value change occurs at (kper, kstp).
142  !<
143  subroutine tvs_set_changed_at(this, kper, kstp)
144  ! -- dummy
145  class(tvstype) :: this
146  integer(I4B), intent(in) :: kper
147  integer(I4B), intent(in) :: kstp
148  !
149  ! -- No need to record TVS/STO changes, as no other packages cache
150  ! -- Ss or Sy values
151  end subroutine tvs_set_changed_at
152 
153  !> @brief Clear all per-node change flags
154  !!
155  !! Deferred procedure implementation called by the TvBaseType code when a
156  !! new time step commences, indicating that any previously set per-node
157  !! property value change flags should be reset.
158  !<
159  subroutine tvs_reset_change_flags(this)
160  ! -- dummy
161  class(tvstype) :: this
162  !
163  ! -- No need to record TVS/STO changes, as no other packages cache
164  ! -- Ss or Sy values
165  end subroutine tvs_reset_change_flags
166 
167  !> @brief Check that a given property value is valid
168  !!
169  !! Deferred procedure implementation called by the TvBaseType code after a
170  !! property value change occurs. Check if the property value of the given
171  !! variable at the given node is invalid, and log an error if so.
172  !<
173  subroutine tvs_validate_change(this, n, varName)
174  ! -- dummy
175  class(tvstype) :: this
176  integer(I4B), intent(in) :: n
177  character(len=*), intent(in) :: varName
178  ! -- local
179  character(len=LINELENGTH) :: cellstr
180  ! -- formats
181  character(len=*), parameter :: fmtserr = &
182  "(1x, a, ' changed storage property ', a, ' is < 0 for cell ', a,' ', &
183  &1pg15.6)"
184  character(len=*), parameter :: fmtsyerr = &
185  "(1x, a, ' cannot change ', a ,' for cell ', a, ' because SY is unused &
186  &in this model (all ICONVERT flags are 0).')"
187  !
188  ! -- Check the changed value is ok and convert to storage capacity
189  if (varname == 'SS') then
190  if (this%ss(n) < dzero) then
191  call this%dis%noder_to_string(n, cellstr)
192  write (errmsg, fmtserr) trim(adjustl(this%packName)), 'SS', &
193  trim(cellstr), this%ss(n)
194  call store_error(errmsg)
195  end if
196  elseif (varname == 'SY') then
197  if (this%iusesy /= 1) then
198  call this%dis%noder_to_string(n, cellstr)
199  write (errmsg, fmtsyerr) trim(adjustl(this%packName)), 'SY', &
200  trim(cellstr)
201  call store_error(errmsg)
202  elseif (this%sy(n) < dzero) then
203  call this%dis%noder_to_string(n, cellstr)
204  write (errmsg, fmtserr) trim(adjustl(this%packName)), 'SY', &
205  trim(cellstr), this%sy(n)
206  call store_error(errmsg)
207  end if
208  end if
209  end subroutine tvs_validate_change
210 
211  !> @brief Deallocate package memory
212  !!
213  !! Deallocate TVS package scalars and arrays.
214  !<
215  subroutine tvs_da(this)
216  ! -- dummy
217  class(tvstype) :: this
218  !
219  ! -- Nullify pointers to other package variables
220  nullify (this%integratechanges)
221  nullify (this%iusesy)
222  nullify (this%ss)
223  nullify (this%sy)
224  !
225  ! -- Deallocate parent
226  call tvbase_da(this)
227  end subroutine tvs_da
228 
229 end module tvsmodule
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:45
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: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:460
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:65
subroutine tvs_validate_change(this, n, varName)
Check that a given property value is valid.
Definition: gwf-tvs.f90:174
subroutine tvs_set_changed_at(this, kper, kstp)
Mark property changes as having occurred at (kper, kstp)
Definition: gwf-tvs.f90:144
logical function tvs_read_option(this, keyword)
Read a TVS-specific option from the OPTIONS block.
Definition: gwf-tvs.f90:95
real(dp) function, pointer tvs_get_pointer_to_value(this, n, varName)
Get an array value pointer given a variable name and node index.
Definition: gwf-tvs.f90:121
subroutine tvs_reset_change_flags(this)
Clear all per-node change flags.
Definition: gwf-tvs.f90:160
subroutine tvs_da(this)
Deallocate package memory.
Definition: gwf-tvs.f90:216
subroutine, public tvs_cr(tvs, name_model, inunit, iout)
Create a new TvsType object.
Definition: gwf-tvs.f90:49