MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
gwf-csub-budget.f90
Go to the documentation of this file.
1!> @brief CSUB package convergence check and budget
2!<
3submodule(gwfcsubmodule) gwfcsubmodulebudget
4
5 character(len=LENBUDTXT), dimension(4) :: budtxt = & !< text labels for budget terms
6 [' CSUB-CGELASTIC', &
7 ' CSUB-ELASTIC', &
8 ' CSUB-INELASTIC', &
9 ' CSUB-WATERCOMP']
10
11contains
12
13 ! -- documented on the GwfCsubType type-bound procedure in gwf-csub.f90
14 module subroutine csub_cc(this, innertot, kiter, iend, icnvgmod, nodes, &
15 hnew, hold, cpak, ipak, dpak)
16 ! -- modules
17 use tdismodule, only: totim, kstp, kper, delt
18 ! -- dummy variables
19 class(GwfCsubType) :: this
20 integer(I4B), intent(in) :: innertot !< total number of inner iterations
21 integer(I4B), intent(in) :: kiter !< outer iteration number
22 integer(I4B), intent(in) :: iend !< flag indicating if it is the last iteration
23 integer(I4B), intent(in) :: icnvgmod !< flag indicating if the solution is considered converged
24 integer(I4B), intent(in) :: nodes !< number of active nodes
25 real(DP), dimension(nodes), intent(in) :: hnew !< current gwf head
26 real(DP), dimension(nodes), intent(in) :: hold !< gwf for previous time step
27 character(len=LENPAKLOC), intent(inout) :: cpak !< string location of the maximum change in csub package
28 integer(I4B), intent(inout) :: ipak !< node with the maximum change in csub package
29 real(DP), intent(inout) :: dpak !< maximum change in csub package
30 ! local variables
31 character(len=LENPAKLOC) :: cloc
32 integer(I4B) :: icheck
33 integer(I4B) :: ipakfail
34 integer(I4B) :: ib
35 integer(I4B) :: node
36 integer(I4B) :: idelay
37 integer(I4B) :: locdhmax
38 integer(I4B) :: locrmax
39 integer(I4B) :: ifirst
40 real(DP) :: dhmax
41 real(DP) :: rmax
42 real(DP) :: dh
43 real(DP) :: area
44 real(DP) :: hcell
45 real(DP) :: hcellold
46 real(DP) :: snnew
47 real(DP) :: snold
48 real(DP) :: stoe
49 real(DP) :: stoi
50 real(DP) :: dwc
51 real(DP) :: tled
52 real(DP) :: hcof
53 real(DP) :: rhs
54 real(DP) :: v1
55 real(DP) :: v2
56 real(DP) :: df
57 !
58 ! -- initialize local variables
59 icheck = this%iconvchk
60 ipakfail = 0
61 locdhmax = 0
62 locrmax = 0
63 ifirst = 1
64 dhmax = dzero
65 rmax = dzero
66 !
67 ! -- additional checks to see if convergence needs to be checked
68 ! -- no convergence check for steady-state stress periods
69 if (this%gwfiss /= 0) then
70 icheck = 0
71 else
72 if (icnvgmod == 0) then
73 icheck = 0
74 end if
75 end if
76 !
77 ! -- perform package convergence check
78 if (icheck /= 0) then
79 if (delt > dzero) then
80 tled = done / delt
81 else
82 tled = dzero
83 end if
84 final_check: do ib = 1, this%ninterbeds
85 idelay = this%idelay(ib)
86 node = this%nodelist(ib)
87 !
88 ! -- skip nodelay interbeds
89 if (idelay == 0) cycle
90 !
91 ! -- skip inactive cells
92 if (this%ibound(node) < 1) cycle
93 !
94 ! -- evaluate the maximum head change in the interbed
95 dh = this%dbdhmax(idelay)
96 !
97 ! -- evaluate difference between storage changes
98 ! in the interbed and exchange between the interbed
99 ! and the gwf cell
100 area = this%dis%get_area(node)
101 hcell = hnew(node)
102 hcellold = hold(node)
103 !
104 ! -- calculate cell saturation
105 call this%csub_calc_sat(node, hcell, hcellold, snnew, snold)
106 !
107 ! -- calculate the change in storage
108 call this%csub_delay_calc_dstor(ib, hcell, stoe, stoi)
109 v1 = (stoe + stoi) * area * this%rnb(ib) * tled
110 !
111 ! -- add water compressibility to storage term
112 call this%csub_delay_calc_wcomp(ib, dwc)
113 v1 = v1 + dwc * area * this%rnb(ib)
114 !
115 ! -- calculate the flow between the interbed and the cell
116 call this%csub_delay_fc(ib, hcof, rhs)
117 v2 = (-hcof * hcell - rhs) * area * this%rnb(ib)
118 !
119 ! -- calculate the difference between the interbed change in
120 ! storage and the flow between the interbed and the cell
121 df = v2 - v1
122 !
123 ! -- normalize by cell area and convert to a depth
124 df = df * delt / area
125 !
126 ! -- evaluate magnitude of differences
127 if (ifirst == 1) then
128 ifirst = 0
129 locdhmax = ib
130 dhmax = dh
131 locrmax = ib
132 rmax = df
133 else
134 if (abs(dh) > abs(dhmax)) then
135 locdhmax = ib
136 dhmax = dh
137 end if
138 if (abs(df) > abs(rmax)) then
139 locrmax = ib
140 rmax = df
141 end if
142 end if
143 end do final_check
144 !
145 ! -- set dpak and cpak
146 ! -- update head error
147 if (abs(dhmax) > abs(dpak)) then
148 ipak = locdhmax
149 dpak = dhmax
150 write (cloc, "(a,'-',a)") trim(this%packName), 'head'
151 cpak = cloc
152 end if
153 !
154 ! -- update storage error
155 if (abs(rmax) > abs(dpak)) then
156 ipak = locrmax
157 dpak = rmax
158 write (cloc, "(a,'-',a)") trim(this%packName), 'storage'
159 cpak = cloc
160 end if
161 !
162 ! -- write convergence data to package csv
163 if (this%ipakcsv /= 0) then
164 !
165 ! -- write the data
166 call this%pakcsvtab%add_term(innertot)
167 call this%pakcsvtab%add_term(totim)
168 call this%pakcsvtab%add_term(kper)
169 call this%pakcsvtab%add_term(kstp)
170 call this%pakcsvtab%add_term(kiter)
171 if (this%ndelaybeds > 0) then
172 call this%pakcsvtab%add_term(dhmax)
173 call this%pakcsvtab%add_term(locdhmax)
174 call this%pakcsvtab%add_term(rmax)
175 call this%pakcsvtab%add_term(locrmax)
176 else
177 call this%pakcsvtab%add_term('--')
178 call this%pakcsvtab%add_term('--')
179 call this%pakcsvtab%add_term('--')
180 call this%pakcsvtab%add_term('--')
181 end if
182 !
183 ! -- finalize the package csv
184 if (iend == 1) then
185 call this%pakcsvtab%finalize_table()
186 end if
187 end if
188 end if
189 end subroutine csub_cc
190
191 ! -- documented on the GwfCsubType type-bound procedure in gwf-csub.f90
192 module subroutine csub_cq(this, nodes, hnew, hold, isuppress_output, flowja)
193 ! -- modules
194 use tdismodule, only: delt
196 ! -- dummy variables
197 class(GwfCsubType) :: this
198 integer(I4B), intent(in) :: nodes !< number of active model nodes
199 real(DP), intent(in), dimension(nodes) :: hnew !< current head
200 real(DP), intent(in), dimension(nodes) :: hold !< head for the previous time step
201 integer(I4B), intent(in) :: isuppress_output !< flag indicating if budget output should be suppressed
202 real(DP), dimension(:), contiguous, intent(inout) :: flowja
203 ! -- local variables
204 integer(I4B) :: ib
205 integer(I4B) :: idelay
206 integer(I4B) :: ielastic
207 integer(I4B) :: iconvert
208 integer(I4B) :: node
209 integer(I4B) :: nn
210 integer(I4B) :: n
211 integer(I4B) :: idiag
212 real(DP) :: es
213 real(DP) :: pcs
214 real(DP) :: rho1
215 real(DP) :: rho2
216 real(DP) :: tled
217 real(DP) :: tledm
218 real(DP) :: es0
219 real(DP) :: rrate
220 real(DP) :: ratein
221 real(DP) :: rateout
222 real(DP) :: comp
223 real(DP) :: compi
224 real(DP) :: compe
225 real(DP) :: area
226 real(DP) :: h
227 real(DP) :: h0
228 real(DP) :: snnew
229 real(DP) :: snold
230 real(DP) :: hcof
231 real(DP) :: rhs
232 real(DP) :: stoe
233 real(DP) :: stoi
234 real(DP) :: b
235 real(DP) :: q
236 real(DP) :: rratewc
237 ! -- for observations
238 integer(I4B) :: iprobslocal
239 ! -- formats
240 !
241 ! -- Suppress saving of simulated values; they
242 ! will be saved at end of this procedure.
243 iprobslocal = 0
244 ratein = dzero
245 rateout = dzero
246 !
247 ! -- coarse-grained coarse-grained storage
248 do node = 1, this%dis%nodes
249 idiag = this%dis%con%ia(node)
250 area = this%dis%get_area(node)
251 comp = dzero
252 rrate = dzero
253 rratewc = dzero
254 if (this%gwfiss == 0) then
255 if (delt > dzero) then
256 tled = done / delt
257 else
258 tled = dzero
259 end if
260 if (this%ibound(node) > 0 .and. this%cg_thickini(node) > dzero) then
261 !
262 ! -- calculate coarse-grained storage terms
263 call this%csub_cg_fc(node, tled, area, hnew(node), hold(node), &
264 hcof, rhs)
265 rrate = hcof * hnew(node) - rhs
266 !
267 ! -- calculate compaction
268 call this%csub_cg_calc_comp(node, hnew(node), hold(node), comp)
269 !
270 ! -- calculate coarse-grained water compressibility storage terms
271 call this%csub_cg_wcomp_fc(node, tled, area, hnew(node), hold(node), &
272 hcof, rhs)
273 rratewc = hcof * hnew(node) - rhs
274 end if
275 end if
276 !
277 ! -- update coarse-grained storage and water
278 ! compression variables
279 this%cg_stor(node) = rrate
280 this%cell_wcstor(node) = rratewc
281 this%cell_thick(node) = this%cg_thick(node)
282 !
283 ! -- update incremental coarse-grained compaction
284 this%cg_comp(node) = comp
285 !
286 !
287 ! -- update states if required
288 if (isuppress_output == 0) then
289 !
290 ! -- calculate strain and change in coarse-grained void ratio and thickness
291 ! todo: consider moving error check in csub_cg_update to ot()
292 if (this%iupdatematprop /= 0) then
293 call this%csub_cg_update(node)
294 end if
295 !
296 ! -- update total compaction
297 this%cg_tcomp(node) = this%cg_tcomp(node) + comp
298 end if
299 !
300 ! -- update flowja
301 flowja(idiag) = flowja(idiag) + rrate
302 flowja(idiag) = flowja(idiag) + rratewc
303 end do
304 !
305 ! -- interbed storage
306 !
307 ! -- reset delay bed counters for the current time step
308 if (this%ndelaybeds > 0) then
309 this%idb_nconv_count(1) = 0
310 end if
311 !
312 ! -- initialize tled
313 tled = done
314 !
315 ! -- calculate budget terms for each interbed
316 do ib = 1, this%ninterbeds
317 rratewc = dzero
318 idelay = this%idelay(ib)
319 ielastic = this%ielastic(ib)
320 !
321 ! -- calculate interbed thickness
322 ! -- no delay interbeds
323 if (idelay == 0) then
324 b = this%thick(ib)
325 ! -- delay interbeds
326 else
327 b = this%thick(ib) * this%rnb(ib)
328 end if
329 !
330 ! -- set variables required for no-delay and delay interbeds
331 node = this%nodelist(ib)
332 idiag = this%dis%con%ia(node)
333 area = this%dis%get_area(node)
334 !
335 ! -- add interbed thickness to cell thickness
336 this%cell_thick(node) = this%cell_thick(node) + b
337 !
338 ! -- update budget terms if transient stress period
339 if (this%gwfiss == 0) then
340 if (delt > dzero) then
341 tledm = done / delt
342 else
343 tledm = dzero
344 end if
345 !
346 ! -- skip inactive and constant head cells
347 if (this%ibound(node) < 1) cycle
348 !
349 ! -- no delay interbeds
350 if (idelay == 0) then
351 iconvert = this%iconvert(ib)
352 stoi = dzero
353 !
354 ! -- calculate compaction
355 call this%csub_nodelay_calc_comp(ib, hnew(node), hold(node), comp, &
356 rho1, rho2)
357 !
358 ! -- interbed stresses
359 es = this%cg_es(node)
360 pcs = this%pcs(ib)
361 es0 = this%cg_es0(node)
362 !
363 ! -- calculate inelastic and elastic compaction
364 if (ielastic > 0 .or. iconvert == 0) then
365 stoe = comp
366 else
367 stoi = -pcs * rho2 + (rho2 * es)
368 stoe = pcs * rho1 - (rho1 * es0)
369 end if
370 compe = stoe
371 compi = stoi
372 stoe = stoe * area
373 stoi = stoi * area
374 this%storagee(ib) = stoe * tledm
375 this%storagei(ib) = stoi * tledm
376 !
377 ! -- update compaction
378 this%comp(ib) = comp
379 !
380 ! -- update states if required
381 if (isuppress_output == 0) then
382 !
383 ! -- calculate strain and change in interbed void ratio and thickness
384 if (this%iupdatematprop /= 0) then
385 call this%csub_nodelay_update(ib)
386 end if
387 !
388 ! -- update total compaction
389 this%tcomp(ib) = this%tcomp(ib) + comp
390 this%tcompe(ib) = this%tcompe(ib) + compe
391 this%tcompi(ib) = this%tcompi(ib) + compi
392 end if
393 !
394 ! -- delay interbeds
395 else
396 h = hnew(node)
397 h0 = hold(node)
398 !
399 ! -- calculate cell saturation
400 call this%csub_calc_sat(node, h, h0, snnew, snold)
401 !
402 ! -- calculate inelastic and elastic storage contributions
403 call this%csub_delay_calc_dstor(ib, h, stoe, stoi)
404 this%storagee(ib) = stoe * area * this%rnb(ib) * tledm
405 this%storagei(ib) = stoi * area * this%rnb(ib) * tledm
406 !
407 ! -- calculate flow across the top and bottom of the delay interbed
408 q = this%csub_calc_delay_flow(ib, 1, h) * area * this%rnb(ib)
409 this%dbflowtop(idelay) = q
410 nn = this%ndelaycells
411 q = this%csub_calc_delay_flow(ib, nn, h) * area * this%rnb(ib)
412 this%dbflowbot(idelay) = q
413 !
414 ! -- update states if required
415 if (isuppress_output == 0) then
416 !
417 ! -- calculate sum of compaction in delay interbed
418 call this%csub_delay_calc_comp(ib, h, h0, comp, compi, compe)
419 !
420 ! - calculate strain and change in interbed void ratio and thickness
421 ! todo: consider moving error check in csub_delay_update to ot()
422 if (this%iupdatematprop /= 0) then
423 call this%csub_delay_update(ib)
424 end if
425 !
426 ! -- update total compaction for interbed
427 this%tcomp(ib) = this%tcomp(ib) + comp
428 this%tcompi(ib) = this%tcompi(ib) + compi
429 this%tcompe(ib) = this%tcompe(ib) + compe
430 !
431 ! -- update total compaction for each delay bed cell
432 do n = 1, this%ndelaycells
433 this%dbtcomp(n, idelay) = this%dbtcomp(n, idelay) + &
434 this%dbcomp(n, idelay)
435 end do
436 !
437 ! -- check delay bed heads relative to the top and bottom of each
438 ! delay bed cell for convertible and non-convertible gwf cells
439 call this%csub_delay_head_check(ib)
440 end if
441 end if
442 !
443 ! -- interbed water compressibility
444 !
445 ! -- no-delay interbed
446 if (idelay == 0) then
447 call this%csub_nodelay_wcomp_fc(ib, node, tledm, area, &
448 hnew(node), hold(node), hcof, rhs)
449 rratewc = hcof * hnew(node) - rhs
450 !
451 ! -- delay interbed
452 else
453 call this%csub_delay_calc_wcomp(ib, q)
454 rratewc = q * area * this%rnb(ib)
455 end if
456 this%cell_wcstor(node) = this%cell_wcstor(node) + rratewc
457 !
458 ! -- flowja
459 flowja(idiag) = flowja(idiag) + rratewc
460 else
461 this%storagee(ib) = dzero
462 this%storagei(ib) = dzero
463 if (idelay /= 0) then
464 this%dbflowtop(idelay) = dzero
465 this%dbflowbot(idelay) = dzero
466 end if
467 end if
468 !
469 ! -- flowja
470 flowja(idiag) = flowja(idiag) + this%storagee(ib)
471 flowja(idiag) = flowja(idiag) + this%storagei(ib)
472 end do
473 !
474 ! -- terminate if errors encountered when updating material properties
475 if (this%iupdatematprop /= 0) then
476 if (count_errors() > 0) then
477 call store_error_filename(this%input_fname)
478 end if
479 end if
480 end subroutine csub_cq
481
482 ! -- documented on the GwfCsubType type-bound procedure in gwf-csub.f90
483 module subroutine csub_bd(this, isuppress_output, model_budget)
484 ! -- modules
485 use tdismodule, only: delt
488 ! -- dummy variables
489 class(GwfCsubType) :: this
490 integer(I4B), intent(in) :: isuppress_output
491 type(BudgetType), intent(inout) :: model_budget !< model budget object
492 ! -- local
493 real(DP) :: rin
494 real(DP) :: rout
495 !
496 ! -- interbed elastic storage (this%cg_stor)
497 call rate_accumulator(this%cg_stor, rin, rout)
498 call model_budget%addentry(rin, rout, delt, budtxt(1), &
499 isuppress_output, ' CSUB')
500 if (this%ninterbeds > 0) then
501 !
502 ! -- interbed elastic storage (this%storagee)
503 call rate_accumulator(this%storagee, rin, rout)
504 call model_budget%addentry(rin, rout, delt, budtxt(2), &
505 isuppress_output, ' CSUB')
506 !
507 ! -- interbed elastic storage (this%storagei)
508 call rate_accumulator(this%storagei, rin, rout)
509 call model_budget%addentry(rin, rout, delt, budtxt(3), &
510 isuppress_output, ' CSUB')
511 end if
512 call rate_accumulator(this%cell_wcstor, rin, rout)
513 call model_budget%addentry(rin, rout, delt, budtxt(4), &
514 isuppress_output, ' CSUB')
515 return
516 end subroutine csub_bd
517
518 ! -- documented on the GwfCsubType type-bound procedure in gwf-csub.f90
519 module subroutine csub_save_model_flows(this, icbcfl, icbcun)
520 ! -- dummy variables
521 class(GwfCsubType) :: this
522 integer(I4B), intent(in) :: icbcfl !< flag to output budget data
523 integer(I4B), intent(in) :: icbcun !< unit number for cell-by-cell file
524 ! -- local variables
525 character(len=1) :: cdatafmp = ' '
526 character(len=1) :: editdesc = ' '
527 integer(I4B) :: ibinun
528 integer(I4B) :: iprint
529 integer(I4B) :: nvaluesp
530 integer(I4B) :: nwidthp
531 integer(I4B) :: ib
532 integer(I4B) :: node
533 integer(I4B) :: naux
534 real(DP) :: dinact
535 real(DP) :: Q
536 ! -- formats
537 !
538 ! -- Set unit number for binary output
539 if (this%ipakcb < 0) then
540 ibinun = icbcun
541 elseif (this%ipakcb == 0) then
542 ibinun = 0
543 else
544 ibinun = this%ipakcb
545 end if
546 if (icbcfl == 0) ibinun = 0
547 !
548 ! -- Record the storage rates if requested
549 if (ibinun /= 0) then
550 iprint = 0
551 dinact = dzero
552 !
553 ! -- coarse-grained storage (sske)
554 call this%dis%record_array(this%cg_stor, this%iout, iprint, -ibinun, &
555 budtxt(1), cdatafmp, nvaluesp, &
556 nwidthp, editdesc, dinact)
557 if (this%ninterbeds > 0) then
558 naux = 0
559 !
560 ! -- interbed elastic storage
561 call this%dis%record_srcdst_list_header(budtxt(2), &
562 this%name_model, &
563 this%name_model, &
564 this%name_model, &
565 this%packName, &
566 naux, &
567 this%auxname, &
568 ibinun, &
569 this%ninterbeds, &
570 this%iout)
571 do ib = 1, this%ninterbeds
572 q = this%storagee(ib)
573 node = this%nodelist(ib)
574 call this%dis%record_mf6_list_entry(ibinun, node, node, q, naux, &
575 this%auxvar(:, ib))
576 end do
577 !
578 ! -- interbed inelastic storage
579 call this%dis%record_srcdst_list_header(budtxt(3), &
580 this%name_model, &
581 this%name_model, &
582 this%name_model, &
583 this%packName, &
584 naux, &
585 this%auxname, &
586 ibinun, &
587 this%ninterbeds, &
588 this%iout)
589 do ib = 1, this%ninterbeds
590 q = this%storagei(ib)
591 node = this%nodelist(ib)
592 call this%dis%record_mf6_list_entry(ibinun, node, node, q, naux, &
593 this%auxvar(:, ib))
594 end do
595 end if
596 !
597 ! -- water compressibility
598 call this%dis%record_array(this%cell_wcstor, this%iout, iprint, -ibinun, &
599 budtxt(4), cdatafmp, nvaluesp, &
600 nwidthp, editdesc, dinact)
601 end if
602 end subroutine csub_save_model_flows
603
604end submodule gwfcsubmodulebudget
This module contains the BudgetModule.
Definition Budget.f90:20
subroutine, public rate_accumulator(flow, rin, rout)
Rate accumulator subroutine.
Definition Budget.f90:634
This module contains simulation constants.
Definition Constants.f90:9
integer(i4b), parameter lenboundname
maximum length of a bound name
Definition Constants.f90:36
real(dp), parameter dzero
real constant zero
Definition Constants.f90:65
real(dp), parameter done
real constant 1
Definition Constants.f90:76
This module contains the CSUB package methods.
Definition gwf-csub.f90:23
real(dp), pointer, public totim
time relative to start of simulation
Definition tdis.f90:35
integer(i4b), pointer, public kstp
current time step number
Definition tdis.f90:27
integer(i4b), pointer, public kper
current stress period number
Definition tdis.f90:26
real(dp), pointer, public delt
length of the current time step
Definition tdis.f90:32
Derived type for the Budget object.
Definition Budget.f90:40