MODFLOW 6  version 6.9.0.dev0
USGS Modular Hydrologic Model
PackageBudget.f90
Go to the documentation of this file.
1 !> @brief This module contains the PackageBudgetModule Module
2 !!
3 !! The PackageBudgetType object defined here provides flows to the GWT
4 !! model. The PackageBudgetType can be filled with flows from a budget
5 !! object that was written from a previous GWF simulation, or its
6 !! individual members can be pointed to flows that are being calculated
7 !! by a GWF model that is running as part of this simulation.
8 !<
10 
11  use kindmodule
15 
16  implicit none
17 
18  private
19  public :: packagebudgettype
20 
21  !> @brief Derived type for storing flows
22  !!
23  !! This derived type stores flows and provides them through the FMI
24  !! package to other parts of GWT.
25  !!
26  !<
28 
29  character(len=LENMEMPATH) :: memorypath = '' !< the location in the memory manager where the variables are stored
30  character(len=LENPACKAGENAME), pointer :: name => null() !< name of the package
31  character(len=LENPACKAGENAME), pointer :: budtxt => null() !< type of flow (CHD, RCH, RCHA, ...)
32  character(len=LENAUXNAME), dimension(:), pointer, &
33  contiguous :: auxname => null() !< vector of auxname
34  integer(I4B), pointer :: naux => null() !< number of auxiliary variables
35  integer(I4B), pointer :: nbound => null() !< number of boundaries for current stress period
36  integer(I4B), dimension(:), pointer, contiguous :: nodelist => null() !< vector of reduced node numbers
37  real(dp), dimension(:), pointer, contiguous :: flow => null() !< calculated flow
38  real(dp), dimension(:, :), pointer, contiguous :: auxvar => null() !< auxiliary variable array
39 
40  contains
41 
42  procedure :: initialize
43  procedure :: set_name
44  procedure :: set_auxname
45  procedure :: set_pointers
46  procedure :: copy_values
47  procedure :: get_flow
48  procedure :: da
49 
50  end type packagebudgettype
51 
52 contains
53 
54  !> @ brief Initialize a PackageBudgetType object
55  !!
56  !! Establish the memory path and allocate and initialize member variables.
57  !!
58  !<
59  subroutine initialize(this, mempath)
60  class(packagebudgettype) :: this !< PackageBudgetType object
61  character(len=*), intent(in) :: mempath !< memory path in memory manager
62  this%memoryPath = mempath
63  !
64  ! -- allocate member variables in memory manager
65  call mem_allocate(this%name, lenpackagename, 'NAME', mempath)
66  call mem_allocate(this%budtxt, lenpackagename, 'BUDTXT', mempath)
67  call mem_allocate(this%naux, 'NAUX', mempath)
68  call mem_allocate(this%auxname, lenauxname, 0, 'AUXNAME', this%memoryPath)
69  call mem_allocate(this%nbound, 'NBOUND', mempath)
70  call mem_allocate(this%nodelist, 0, 'NODELIST', mempath)
71  call mem_allocate(this%flow, 0, 'FLOW', mempath)
72  call mem_allocate(this%auxvar, 0, 0, 'AUXVAR', mempath)
73  !
74  ! -- initialize
75  this%name = ''
76  this%budtxt = ''
77  this%naux = 0
78  this%nbound = 0
79  end subroutine initialize
80 
81  !> @ brief Set names for this PackageBudgetType object
82  !!
83  !! Set the name of the package and the name of the of budget text
84  !!
85  !<
86  subroutine set_name(this, name, budtxt)
87  class(packagebudgettype) :: this !< PackageBudgetType object
88  character(len=LENPACKAGENAME) :: name !< name of the package (WEL-1, DRN-4, etc.)
89  character(len=LENPACKAGENAME) :: budtxt !< name of budget term (CHD, RCH, EVT, DRN-TO-MVR, etc.)
90  this%name = name
91  this%budtxt = budtxt
92  end subroutine set_name
93 
94  !> @ brief Set aux names for this PackageBudgetType object
95  !!
96  !! Set the number of auxiliary variables and the names of the
97  !! auxiliary variables
98  !!
99  !<
100  subroutine set_auxname(this, naux, auxname)
101  class(packagebudgettype) :: this !< PackageBudgetType object
102  integer(I4B), intent(in) :: naux !< number of auxiliary variables
103  character(len=LENAUXNAME), contiguous, &
104  dimension(:), intent(in) :: auxname !< array of names for auxiliary variables
105  this%naux = naux
106  call mem_reallocate(this%auxname, lenauxname, naux, 'AUXNAME', &
107  this%memoryPath)
108  this%auxname(:) = auxname(:)
109  end subroutine set_auxname
110 
111  !> @ brief Point members of this class to data stored in GWF packages
112  !!
113  !! The routine is called when a GWF model is being run concurrently with
114  !! a GWT model. In this situation, the member variables NBOUND, NODELIST,
115  !! FLOW, and AUXVAR are pointed into member variables of the individual
116  !! GWF Package members stored in BndType.
117  !!
118  !<
119  subroutine set_pointers(this, flowvarname, mem_path_target, input_mempath)
120  use constantsmodule, only: lenvarname
121  use memorymanagermodule, only: get_isize
122  class(packagebudgettype) :: this !< PackageBudgetType object
123  character(len=*), intent(in) :: flowvarname !< name of variable storing flow (SIMVALS, SIMTOMVR)
124  character(len=*), intent(in) :: mem_path_target !< path where target variable is stored
125  character(len=*), intent(in) :: input_mempath
126  character(len=LENVARNAME) :: auxvarname
127  integer(I4B) :: isize
128  !
129  ! -- set memory manager aux varname; use the IDM alias 'AUXVAR_IDM' if
130  ! the flow package registered one at mem_path_target, else 'AUXVAR'
131  if (input_mempath /= '') then
132  call get_isize('AUXVAR_IDM', mem_path_target, isize)
133  if (isize >= 0) then
134  auxvarname = 'AUXVAR_IDM'
135  else
136  auxvarname = 'AUXVAR'
137  end if
138  else
139  auxvarname = 'AUXVAR'
140  end if
141  !
142  ! -- Reassign pointers to variables in the flow model
143  call mem_reassignptr(this%nbound, 'NBOUND', this%memoryPath, &
144  'NBOUND', mem_path_target)
145  call mem_reassignptr(this%nodelist, 'NODELIST', this%memoryPath, &
146  'NODELIST', mem_path_target)
147  call mem_reassignptr(this%flow, 'FLOW', this%memoryPath, &
148  flowvarname, mem_path_target)
149  call mem_reassignptr(this%auxvar, 'AUXVAR', this%memoryPath, &
150  auxvarname, mem_path_target)
151  end subroutine set_pointers
152 
153  !> @ brief Copy data read from a budget file into this object
154  !!
155  !! The routine is called when GWF flows are read from a budget file
156  !! created from a previous GWF simulation. Arrays here must be
157  !! dynamically resized because maxbound is not known unless the
158  !! entire budget file was read first.
159  !!
160  !<
161  subroutine copy_values(this, nbound, nodelist, flow, auxvar)
162  class(packagebudgettype) :: this !< PackageBudgetType object
163  integer(I4B), intent(in) :: nbound !< number of entries
164  integer(I4B), dimension(:), contiguous, intent(in) :: nodelist !< array of GWT node numbers
165  real(DP), dimension(:), contiguous, intent(in) :: flow !< array of flow rates
166  real(DP), dimension(:, :), contiguous, intent(in) :: auxvar !< array of auxiliary variables
167  integer(I4B) :: i
168  !
169  ! -- Assign variables
170  this%nbound = nbound
171  !
172  ! -- Lists are not large enough (maxbound is not known), so need to
173  ! reallocate based on size in binary budget file.
174  if (size(this%nodelist) < nbound) then
175  call mem_reallocate(this%nodelist, nbound, 'NODELIST', this%memoryPath)
176  call mem_reallocate(this%flow, nbound, 'FLOW', this%memoryPath)
177  call mem_reallocate(this%auxvar, this%naux, nbound, 'AUXVAR', &
178  this%memoryPath)
179  end if
180  !
181  ! -- Copy values into member variables
182  do i = 1, nbound
183  this%nodelist(i) = nodelist(i)
184  this%flow(i) = flow(i)
185  this%auxvar(:, i) = auxvar(:, i)
186  end do
187  end subroutine copy_values
188 
189  !> @ brief Get flow rate for specified entry
190  !!
191  !! Return the flow rate for the specified entry
192  !!
193  !<
194  function get_flow(this, i) result(flow)
195  class(packagebudgettype) :: this !< PackageBudgetType object
196  integer(I4B), intent(in) :: i !< entry number
197  real(dp) :: flow
198  flow = this%flow(i)
199  end function get_flow
200 
201  !> @ brief Deallocate
202  !!
203  !! Free any memory associated with this object
204  !!
205  !<
206  subroutine da(this)
207  class(packagebudgettype) :: this
208  call mem_deallocate(this%name, 'NAME', this%memoryPath)
209  call mem_deallocate(this%budtxt, 'BUDTXT', this%memoryPath)
210  call mem_deallocate(this%naux)
211  call mem_deallocate(this%auxname, 'AUXNAME', this%memoryPath)
212  call mem_deallocate(this%nbound)
213  call mem_deallocate(this%nodelist, 'NODELIST', this%memoryPath)
214  call mem_deallocate(this%flow, 'FLOW', this%memoryPath)
215  call mem_deallocate(this%auxvar, 'AUXVAR', this%memoryPath)
216  end subroutine da
217 
218 end module packagebudgetmodule
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter lenpackagename
maximum length of the package name
Definition: Constants.f90:23
integer(i4b), parameter lenvarname
maximum length of a variable name
Definition: Constants.f90:17
integer(i4b), parameter lenauxname
maximum length of a aux variable
Definition: Constants.f90:35
integer(i4b), parameter lenmempath
maximum length of the memory path
Definition: Constants.f90:27
This module defines variable data types.
Definition: kind.f90:8
subroutine, public get_isize(name, mem_path, isize)
@ brief Get the number of elements for this variable
This module contains the PackageBudgetModule Module.
subroutine set_pointers(this, flowvarname, mem_path_target, input_mempath)
@ brief Point members of this class to data stored in GWF packages
subroutine copy_values(this, nbound, nodelist, flow, auxvar)
@ brief Copy data read from a budget file into this object
subroutine set_auxname(this, naux, auxname)
@ brief Set aux names for this PackageBudgetType object
subroutine initialize(this, mempath)
@ brief Initialize a PackageBudgetType object
real(dp) function get_flow(this, i)
@ brief Get flow rate for specified entry
subroutine set_name(this, name, budtxt)
@ brief Set names for this PackageBudgetType object
subroutine da(this)
@ brief Deallocate
Derived type for storing flows.