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