MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
gwf-uzf-input.f90
Go to the documentation of this file.
1!> @brief Source and check the static UZF cell properties
2!<
3submodule(uzfmodule) uzfmoduleinput
4contains
5
6 !> @brief Source PACKAGEDATA block from input context
7 !<
8 module procedure uzf_source_packagedata
9 ! -- modules
11 ! -- local
12 integer(I4B), dimension(:), pointer, contiguous :: ifno => null()
13 integer(I4B), dimension(:, :), pointer, contiguous :: cellid_idm => null()
14 integer(I4B), dimension(:), pointer, contiguous :: landflag => null()
15 integer(I4B), dimension(:), pointer, contiguous :: ivertcon => null()
16 real(DP), dimension(:), pointer, contiguous :: surfdep => null()
17 real(DP), dimension(:), pointer, contiguous :: vks => null()
18 real(DP), dimension(:), pointer, contiguous :: thtr => null()
19 real(DP), dimension(:), pointer, contiguous :: thts => null()
20 real(DP), dimension(:), pointer, contiguous :: thti => null()
21 real(DP), dimension(:), pointer, contiguous :: eps => null()
22 type(CharacterStringType), dimension(:), pointer, contiguous :: &
23 bndname => null()
24 character(len=LINELENGTH) :: cellid_str
25 integer(I4B) :: ierr
26 integer(I4B) :: i
27 integer(I4B) :: n !< uzf cell number
28 integer(I4B) :: node !< gwf node number
29 integer(I4B) :: j, jcol
30 integer(I4B), dimension(:), allocatable :: rowmaxnnz
31 type(sparsematrix) :: sparse
32 integer(I4B), dimension(:), allocatable :: nboundchk
33 !
34 write (this%iout, '(/1x,3a)') 'PROCESSING ', trim(adjustl(this%text)), &
35 ' PACKAGEDATA'
36 !
37 ! -- get PACKAGEDATA arrays
38 call mem_setptr(ifno, 'PACKAGEDATA_IFNO', this%input_mempath)
39 call mem_setptr(cellid_idm, 'CELLID', this%input_mempath)
40 call mem_setptr(landflag, 'LANDFLAG', this%input_mempath)
41 call mem_setptr(ivertcon, 'IVERTCON', this%input_mempath)
42 call mem_setptr(surfdep, 'SURFDEP', this%input_mempath)
43 call mem_setptr(vks, 'VKS', this%input_mempath)
44 call mem_setptr(thtr, 'THTR', this%input_mempath)
45 call mem_setptr(thts, 'THTS', this%input_mempath)
46 call mem_setptr(thti, 'THTI', this%input_mempath)
47 call mem_setptr(eps, 'EPS', this%input_mempath)
48 if (this%inamedbound /= 0) then
49 call mem_setptr(bndname, 'BOUNDNAME', this%input_mempath)
50 end if
51 !
52 ! -- allocate local check arrays
53 allocate (rowmaxnnz(this%dis%nodes))
54 do node = 1, this%dis%nodes
55 rowmaxnnz(node) = 0
56 end do
57 allocate (nboundchk(this%nodes))
58 do n = 1, this%nodes
59 nboundchk(n) = 0
60 end do
61 !
62 ! -- loop over packagedata entries
63 do i = 1, this%nodes
64 n = this%validate_ifno(ifno(i), this%nodes, nboundchk, &
65 'IUZNO', 'PACKAGEDATA')
66 if (n == 0) cycle
67 !
68 ! -- convert CELLID to node number
69 write (cellid_str, '(10(i0,1x))') cellid_idm(1:this%dis%ndim, i)
70 node = this%dis%noder_from_cellid(cellid_str, this%inunit, this%iout)
71 this%igwfnode(n) = node
72 rowmaxnnz(node) = rowmaxnnz(node) + 1
73 !
74 ! -- validate landflag
75 if (landflag(i) < 0 .OR. landflag(i) > 1) then
76 write (errmsg, '(a,1x,i0,1x,a,1x,i0,a)') &
77 'LANDFLAG for uzf cell', n, &
78 'must be 0 or 1 (specified value is', landflag(i), ').'
79 call store_error(errmsg)
80 end if
81 !
82 ! -- validate ivertcon
83 if (ivertcon(i) < 0 .OR. ivertcon(i) > this%nodes) then
84 write (errmsg, '(a,1x,i0,1x,a,1x,i0,a)') &
85 'IVERTCON for uzf cell', n, &
86 'must be 0 or less than NUZFCELLS (specified value is', &
87 ivertcon(i), ').'
88 call store_error(errmsg)
89 end if
90 !
91 ! -- validate surfdep
92 if (surfdep(i) <= dzero .and. landflag(i) > 0) then
93 write (errmsg, '(a,1x,i0,1x,a,1x,g0,a)') &
94 'SURFDEP for uzf cell', n, &
95 'must be greater than 0 (specified value is', surfdep(i), ').'
96 call store_error(errmsg)
97 end if
98 if (surfdep(i) >= this%dis%top(node) - this%dis%bot(node)) then
99 write (errmsg, '(a,1x,i0,1x,a)') &
100 'SURFDEP for uzf cell', n, &
101 'cannot be greater than the cell thickness.'
102 call store_error(errmsg)
103 end if
104 !
105 ! -- validate vks
106 if (vks(i) <= dzero) then
107 write (errmsg, '(a,1x,i0,1x,a,1x,g0,a)') &
108 'VKS for uzf cell', n, &
109 'must be greater than 0 (specified value ia', vks(i), ').'
110 call store_error(errmsg)
111 end if
112 !
113 ! -- validate thtr
114 if (thtr(i) <= dzero) then
115 write (errmsg, '(a,1x,i0,1x,a,1x,g0,a)') &
116 'THTR for uzf cell', n, &
117 'must be greater than 0 (specified value is', thtr(i), ').'
118 call store_error(errmsg)
119 end if
120 !
121 ! -- validate thts
122 if (thts(i) <= thtr(i)) then
123 write (errmsg, '(a,1x,i0,1x,a,1x,g0,a)') &
124 'THTS for uzf cell', n, &
125 'must be greater than THTR (specified value is', thts(i), ').'
126 call store_error(errmsg)
127 end if
128 !
129 ! -- validate thti
130 if (thti(i) < thtr(i) .OR. thti(i) > thts(i)) then
131 write (errmsg, '(a,1x,i0,1x,a,1x,a,1x,g0,a)') &
132 'THTI for uzf cell', n, &
133 'must be greater than or equal to THTR AND less than THTS', &
134 '(specified value is', thti(i), ').'
135 call store_error(errmsg)
136 end if
137 !
138 ! -- validate eps
139 if (eps(i) < 3.5 .OR. eps(i) > 14) then
140 write (errmsg, '(a,1x,i0,1x,a,1x,g0,a)') &
141 'EPSILON for uzf cell', n, &
142 'must be between 3.5 and 14.0 (specified value is', eps(i), ').'
143 call store_error(errmsg)
144 end if
145 !
146 ! -- boundname
147 if (this%inamedbound == 1) then
148 this%uzfname(n) = bndname(i)
149 end if
150 !
151 ! -- set data if no errors
152 if (count_errors() == 0) then
153 call this%uzfobj%setdata(n, this%dis%area(node), &
154 this%dis%top(node), this%dis%bot(node), &
155 surfdep(i), vks(i), thtr(i), thts(i), &
156 thti(i), eps(i), this%ntrail_input, &
157 landflag(i), ivertcon(i))
158 if (ivertcon(i) > 0) then
159 this%iuzf2uzf = 1
160 end if
161 end if
162 end do
163 write (this%iout, '(1x,3a)') &
164 'END OF ', trim(adjustl(this%text)), ' PACKAGEDATA'
165 !
166 ! -- check for duplicate or missing uzf cells
167 call this%report_ifno_coverage(nboundchk, this%nodes, 'uzf cell', &
168 'PACKAGEDATA')
169 if (count_errors() > 0) then
170 call store_error_filename(this%input_fname)
171 end if
172 !
173 ! -- setup sparse for connectivity used to identify multiple uzf cells
174 ! per GWF model cell
175 call sparse%init(this%dis%nodes, this%dis%nodes, rowmaxnnz)
176 do n = 1, this%nodes
177 node = this%igwfnode(n)
178 call sparse%addconnection(node, n, 1)
179 end do
180 !
181 ! -- create ia and ja from sparse
182 call sparse%filliaja(this%ia, this%ja, ierr)
183 !
184 ! -- set imaxcellcnt
185 do i = 1, this%dis%nodes
186 jcol = 0
187 do j = this%ia(i), this%ia(i + 1) - 1
188 jcol = jcol + 1
189 end do
190 if (jcol > this%imaxcellcnt) then
191 this%imaxcellcnt = jcol
192 end if
193 end do
194 !
195 if (this%imaxcellcnt > 1 .and. this%iauxmultcol < 1) then
196 call this%check_cell_area()
197 end if
198 !
199 deallocate (rowmaxnnz)
200 deallocate (nboundchk)
201 !
202 ! -- release input context packagedata memory
203 call memorystore_release('PACKAGEDATA_IFNO', this%input_mempath)
204 call memorystore_release('CELLID', this%input_mempath)
205 call memorystore_release('LANDFLAG', this%input_mempath)
206 call memorystore_release('IVERTCON', this%input_mempath)
207 call memorystore_release('SURFDEP', this%input_mempath)
208 call memorystore_release('VKS', this%input_mempath)
209 call memorystore_release('THTR', this%input_mempath)
210 call memorystore_release('THTS', this%input_mempath)
211 call memorystore_release('THTI', this%input_mempath)
212 call memorystore_release('EPS', this%input_mempath)
213 call memorystore_release('BOUNDNAME', this%input_mempath)
214 end procedure uzf_source_packagedata
215
216 !> @brief Read UZF cell properties and set them for UZFCellGroup type
217 !<
218 module procedure print_cell_properties
219 ! -- local
220 character(len=20) :: cellid
221 character(len=LINELENGTH) :: title
222 character(len=LINELENGTH) :: tag
223 integer(I4B) :: ntabrows
224 integer(I4B) :: ntabcols
225 integer(I4B) :: n
226 integer(I4B) :: node
227 !
228 ntabrows = this%nodes
229 ntabcols = 10
230 if (this%inamedbound == 1) then
231 ntabcols = ntabcols + 1
232 end if
233 !
234 ! -- initialize table and define columns
235 title = trim(adjustl(this%text))//' PACKAGE ('// &
236 trim(adjustl(this%packName))//') STATIC UZF CELL DATA'
237 call table_cr(this%inputtab, this%packName, title)
238 call this%inputtab%table_df(ntabrows, ntabcols, this%iout)
239 tag = 'NUMBER'
240 call this%inputtab%initialize_column(tag, 10)
241 tag = 'CELLID'
242 call this%inputtab%initialize_column(tag, 20, alignment=tableft)
243 tag = 'LANDFLAG'
244 call this%inputtab%initialize_column(tag, 12)
245 tag = 'IVERTCON'
246 call this%inputtab%initialize_column(tag, 12)
247 tag = 'SURFDEP'
248 call this%inputtab%initialize_column(tag, 12)
249 tag = 'VKS'
250 call this%inputtab%initialize_column(tag, 12)
251 tag = 'THTR'
252 call this%inputtab%initialize_column(tag, 12)
253 tag = 'THTS'
254 call this%inputtab%initialize_column(tag, 12)
255 tag = 'THTI'
256 call this%inputtab%initialize_column(tag, 12)
257 tag = 'EPS'
258 call this%inputtab%initialize_column(tag, 12)
259 if (this%inamedbound == 1) then
260 tag = 'BOUNDNAME'
261 call this%inputtab%initialize_column(tag, lenboundname, alignment=tableft)
262 end if
263 !
264 ! -- write data for each cell
265 do n = 1, this%nodes
266 !
267 ! -- get cellid
268 node = this%igwfnode(n)
269 if (node > 0) then
270 call this%dis%noder_to_string(node, cellid)
271 else
272 cellid = 'none'
273 end if
274 !
275 ! -- add data
276 call this%inputtab%add_term(n)
277 call this%inputtab%add_term(cellid)
278 call this%inputtab%add_term(this%uzfobj%landflag(n))
279 call this%inputtab%add_term(this%uzfobj%cell_below(n))
280 call this%inputtab%add_term(this%uzfobj%surfdep(n))
281 call this%inputtab%add_term(this%uzfobj%vks(n))
282 call this%inputtab%add_term(this%uzfobj%theta_res(n))
283 call this%inputtab%add_term(this%uzfobj%theta_sat(n))
284 call this%inputtab%add_term(this%uzfobj%theta_init(n))
285 call this%inputtab%add_term(this%uzfobj%bc_eps(n))
286 if (this%inamedbound == 1) then
287 call this%inputtab%add_term(this%uzfname(n))
288 end if
289 end do
290 end procedure print_cell_properties
291
292 !> @brief Check UZF cell areas
293 !<
294 module procedure check_cell_area
295 ! -- modules
296 use inputoutputmodule, only: urword
298 ! -- local
299 character(len=16) :: cuzf
300 character(len=20) :: cellid
301 character(len=LINELENGTH) :: cuzfcells
302 integer(I4B) :: n
303 integer(I4B) :: n2
304 integer(I4B) :: j
305 integer(I4B) :: node
306 integer(I4B) :: i0
307 integer(I4B) :: i1
308 real(DP) :: area
309 real(DP) :: area2
310 real(DP) :: sumarea
311 real(DP) :: cellarea
312 real(DP) :: d
313 !
314 do n = 1, this%nodes
315 !
316 ! -- Initialize variables
317 n2 = this%uzfobj%cell_below(n)
318 area = this%uzfobj%uzfarea(n)
319 !
320 ! Create pointer to object below
321 if (n2 > 0) then
322 area2 = this%uzfobj%uzfarea(n2)
323 d = abs(area - area2)
324 if (d > dem6) then
325 write (errmsg, '(2(a,1x,g0,1x,a,1x,i0,1x),a)') &
326 'UZF cell area (', area, ') for cell ', n, &
327 'does not equal uzf cell area (', area2, ') for cell ', n2, '.'
328 call store_error(errmsg)
329 end if
330 end if
331 end do
332 !
333 ! -- check that the area of uzf cells in a GWF cell is less than or equal
334 ! to the GWF cell area
335 do node = 1, this%dis%nodes
336 i0 = this%ia(node)
337 i1 = this%ia(node + 1)
338 ! -- skip gwf cells with no UZF cells
339 if ((i1 - i0) < 1) cycle
340 sumarea = dzero
341 cellarea = dzero
342 cuzfcells = ''
343 do j = i0, i1 - 1
344 n = this%ja(j)
345 write (cuzf, '(i0)') n
346 cuzfcells = trim(adjustl(cuzfcells))//' '//trim(adjustl(cuzf))
347 sumarea = sumarea + this%uzfobj%uzfarea(n)
348 cellarea = this%uzfobj%cellarea(n)
349 end do
350 ! -- calculate the difference between the sum of UZF areas and GWF cell area
351 d = sumarea - cellarea
352 if (d > dem6) then
353 call this%dis%noder_to_string(node, cellid)
354 write (errmsg, '(a,1x,g0,1x,a,1x,g0,1x,a,1x,a,1x,a,a,a)') &
355 'Total uzf cell area (', sumarea, &
356 ') exceeds the gwf cell area (', cellarea, ') of cell', cellid, &
357 'which includes uzf cell(s): ', trim(adjustl(cuzfcells)), '.'
358 call store_error(errmsg)
359 end if
360 end do
361 !
362 ! -- terminate if errors were encountered
363 if (count_errors() > 0) then
364 call store_error_filename(this%input_fname)
365 end if
366 end procedure check_cell_area
367
368end submodule uzfmoduleinput
subroutine, public urword(line, icol, istart, istop, ncode, n, r, iout, in)
Extract a word from a string.
This module contains simulation methods.
Definition Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition Sim.f90:94
integer(i4b) function, public count_errors()
Return number of errors.
Definition Sim.f90:60
subroutine, public store_error_filename(filename, terminate)
Store the erroring file name.
Definition Sim.f90:208