41 integer(I4B),
pointer :: msum => null()
42 integer(I4B),
pointer :: maxsize => null()
43 real(dp),
pointer :: budperc => null()
44 logical,
pointer :: written_once => null()
45 real(dp),
dimension(:, :),
pointer :: vbvl => null()
46 character(len=LENBUDTXT),
dimension(:),
pointer,
contiguous :: vbnm => null()
47 character(len=20),
pointer :: bdtype => null()
48 character(len=5),
pointer :: bddim => null()
49 character(len=LENBUDROWLABEL), &
50 dimension(:),
pointer,
contiguous :: rowlabel => null()
51 character(len=16),
pointer :: labeltitle => null()
52 character(len=20),
pointer :: bdzone => null()
53 logical,
pointer :: labeled => null()
56 integer(I4B),
pointer :: ibudcsv => null()
57 integer(I4B),
pointer :: icsvheader => null()
88 character(len=*),
intent(in) :: name_model
94 call this%allocate_scalars(name_model)
102 subroutine budget_df(this, maxsize, bdtype, bddim, labeltitle, bdzone)
104 integer(I4B),
intent(in) :: maxsize
105 character(len=*),
optional :: bdtype
106 character(len=*),
optional :: bddim
107 character(len=*),
optional :: labeltitle
108 character(len=*),
optional :: bdzone
111 this%maxsize = maxsize
114 call this%allocate_arrays()
117 if (
present(bdtype))
then
120 this%bdtype =
'VOLUME'
124 if (
present(bddim))
then
131 if (
present(bdzone))
then
134 this%bdzone =
'ENTIRE MODEL'
138 if (
present(labeltitle))
then
139 this%labeltitle = labeltitle
141 this%labeltitle =
'PACKAGE NAME'
152 real(dp),
intent(in) :: val
153 character(len=*),
intent(out) :: string
154 real(dp),
intent(in) :: big
155 real(dp),
intent(in) :: small
159 if (val /=
dzero .and. (absval >= big .or. absval < small))
then
160 if (absval >= 9.99995d99 .or. absval < 1.d-99)
then
164 write (string,
'(es17.4E3)') val
166 write (string,
'(1pe17.4)') val
170 write (string,
'(f17.4)') val
182 integer(I4B),
intent(in) :: kstp
183 integer(I4B),
intent(in) :: kper
184 integer(I4B),
intent(in) :: iout
185 character(len=17) :: val1, val2
186 integer(I4B) :: msum1, l
187 real(DP) :: two, hund, bigvl1, bigvl2, small, &
188 totrin, totrot, totvin, totvot, diffr, adiffr, &
189 pdiffr, pdiffv, avgrat, diffv, adiffv, avgvol
200 msum1 = this%msum - 1
201 if (msum1 <= 0)
return
211 totrin = totrin + this%vbvl(3, l)
212 totrot = totrot + this%vbvl(4, l)
213 totvin = totvin + this%vbvl(1, l)
214 totvot = totvot + this%vbvl(2, l)
218 if (this%labeled)
then
219 write (iout, 261) trim(adjustl(this%bdtype)), trim(adjustl(this%bdzone)), &
221 write (iout, 266) trim(adjustl(this%bdtype)), trim(adjustl(this%bddim)), &
222 trim(adjustl(this%bddim)), this%labeltitle
224 write (iout, 260) trim(adjustl(this%bdtype)), trim(adjustl(this%bdzone)), &
226 write (iout, 265) trim(adjustl(this%bdtype)), trim(adjustl(this%bddim)), &
227 trim(adjustl(this%bddim))
234 if (this%labeled)
then
235 write (iout, 276) this%vbnm(l), val1, this%vbnm(l), val2, this%rowlabel(l)
237 write (iout, 275) this%vbnm(l), val1, this%vbnm(l), val2
242 write (iout, 286) val1, val2
249 if (this%labeled)
then
250 write (iout, 276) this%vbnm(l), val1, this%vbnm(l), val2, this%rowlabel(l)
252 write (iout, 275) this%vbnm(l), val1, this%vbnm(l), val2
257 write (iout, 298) val1, val2
262 diffr = totrin - totrot
267 avgrat = (totrin + totrot) / two
268 if (avgrat /=
dzero) pdiffr = hund * diffr / avgrat
269 this%budperc = pdiffr
272 diffv = totvin - totvot
277 avgvol = (totvin + totvot) / two
278 if (avgvol /=
dzero) pdiffv = hund * diffv / avgvol
284 write (iout, 299) val1, val2
285 write (iout, 300) pdiffv, pdiffr
291 this%written_once = .true.
294 260
FORMAT(//2x, a,
' BUDGET FOR ', a,
' AT END OF' &
295 ,
' TIME STEP', i5,
', STRESS PERIOD', i4 / 2x, 78(
'-'))
296 261
FORMAT(//2x, a,
' BUDGET FOR ', a,
' AT END OF' &
297 ,
' TIME STEP', i5,
', STRESS PERIOD', i4 / 2x, 99(
'-'))
298 265
FORMAT(1x, /5x,
'CUMULATIVE ', a, 6x, a, 7x &
299 ,
'RATES FOR THIS TIME STEP', 6x, a,
'/T'/5x, 18(
'-'), 17x, 24(
'-') &
300 //11x,
'IN:', 38x,
'IN:'/11x,
'---', 38x,
'---')
301 266
FORMAT(1x, /5x,
'CUMULATIVE ', a, 6x, a, 7x &
302 ,
'RATES FOR THIS TIME STEP', 6x, a,
'/T', 10x, a16, &
303 /5x, 18(
'-'), 17x, 24(
'-'), 21x, 16(
'-') &
304 //11x,
'IN:', 38x,
'IN:'/11x,
'---', 38x,
'---')
305 275
FORMAT(1x, 3x, a16,
' =', a17, 6x, a16,
' =', a17)
306 276
FORMAT(1x, 3x, a16,
' =', a17, 6x, a16,
' =', a17, 5x, a)
307 286
FORMAT(1x, /12x,
'TOTAL IN =', a, 14x,
'TOTAL IN =', a)
308 287
FORMAT(1x, /10x,
'OUT:', 37x,
'OUT:'/10x, 4(
'-'), 37x, 4(
'-'))
309 298
FORMAT(1x, /11x,
'TOTAL OUT =', a, 13x,
'TOTAL OUT =', a)
310 299
FORMAT(1x, /12x,
'IN - OUT =', a, 14x,
'IN - OUT =', a)
311 300
FORMAT(1x, /1x,
'PERCENT DISCREPANCY =', f15.2 &
312 , 5x,
'PERCENT DISCREPANCY =', f15.2/)
324 deallocate (this%msum)
325 deallocate (this%maxsize)
326 deallocate (this%budperc)
327 deallocate (this%written_once)
328 deallocate (this%labeled)
329 deallocate (this%bdtype)
330 deallocate (this%bddim)
331 deallocate (this%labeltitle)
332 deallocate (this%bdzone)
333 deallocate (this%ibudcsv)
334 deallocate (this%icsvheader)
337 deallocate (this%vbvl)
338 deallocate (this%vbnm)
339 deallocate (this%rowlabel)
355 do i = 1, this%maxsize
356 this%vbvl(3, i) =
dzero
357 this%vbvl(4, i) =
dzero
376 isupress_accumulate, rowlabel)
379 real(DP),
intent(in) :: rin
380 real(DP),
intent(in) :: rout
381 real(DP),
intent(in) :: delt
382 character(len=LENBUDTXT),
intent(in) :: text
383 integer(I4B),
optional,
intent(in) :: isupress_accumulate
384 character(len=*),
optional,
intent(in) :: rowlabel
386 character(len=LINELENGTH) :: errmsg
387 character(len=*),
parameter :: fmtbuderr = &
388 &
"('Error in MODFLOW 6.', 'Entries do not match: ', (a), (a) )"
390 integer(I4B) :: maxsize
393 if (
present(isupress_accumulate))
then
394 iscv = isupress_accumulate
399 if (maxsize > this%maxsize)
then
400 call this%resize(maxsize)
405 if (this%written_once)
then
406 if (trim(adjustl(this%vbnm(this%msum))) /= trim(adjustl(text)))
then
407 write (errmsg, fmtbuderr) trim(adjustl(this%vbnm(this%msum))), &
413 this%vbvl(3, this%msum) = rin
414 this%vbvl(4, this%msum) = rout
415 this%vbnm(this%msum) = adjustr(text)
416 if (
present(rowlabel))
then
417 this%rowlabel(this%msum) = adjustl(rowlabel)
418 this%labeled = .true.
420 this%msum = this%msum + 1
438 isupress_accumulate, rowlabel)
441 real(DP),
dimension(:, :),
intent(in) :: budterm
442 real(DP),
intent(in) :: delt
443 character(len=LENBUDTXT),
dimension(:),
intent(in) :: budtxt
444 integer(I4B),
optional,
intent(in) :: isupress_accumulate
445 character(len=*),
optional,
intent(in) :: rowlabel
447 character(len=LINELENGTH) :: errmsg
448 character(len=*),
parameter :: fmtbuderr = &
449 &
"('Error in MODFLOW 6.', 'Entries do not match: ', (a), (a) )"
450 integer(i4b) :: iscv, i
451 integer(I4B) :: nbudterms, maxsize
454 if (
present(isupress_accumulate))
then
455 iscv = isupress_accumulate
459 nbudterms =
size(budtxt)
460 maxsize = this%msum - 1 + nbudterms
461 if (maxsize > this%maxsize)
then
462 call this%resize(maxsize)
466 do i = 1,
size(budtxt)
470 if (this%written_once)
then
471 if (trim(adjustl(this%vbnm(this%msum))) /= &
472 trim(adjustl(budtxt(i))))
then
473 write (errmsg, fmtbuderr) trim(adjustl(this%vbnm(this%msum))), &
474 trim(adjustl(budtxt(i)))
479 this%vbvl(3, this%msum) = budterm(1, i)
480 this%vbvl(4, this%msum) = budterm(2, i)
481 this%vbnm(this%msum) = adjustr(budtxt(i))
482 if (
present(rowlabel))
then
483 this%rowlabel(this%msum) = adjustl(rowlabel)
484 this%labeled = .true.
486 this%msum = this%msum + 1
492 call store_error(
'Could not add multi-entry', terminate=.true.)
506 real(DP),
intent(in) :: delt
510 do i = 1, this%msum - 1
511 this%vbvl(1, i) = this%vbvl(1, i) + this%vbvl(3, i) * delt
512 this%vbvl(2, i) = this%vbvl(2, i) + this%vbvl(4, i) * delt
525 character(len=*),
intent(in) :: name_model
528 allocate (this%maxsize)
529 allocate (this%budperc)
530 allocate (this%written_once)
531 allocate (this%labeled)
532 allocate (this%bdtype)
533 allocate (this%bddim)
534 allocate (this%labeltitle)
535 allocate (this%bdzone)
536 allocate (this%ibudcsv)
537 allocate (this%icsvheader)
542 this%written_once = .false.
543 this%labeled = .false.
563 if (
associated(this%vbvl))
then
564 deallocate (this%vbvl)
567 if (
associated(this%vbnm))
then
568 deallocate (this%vbnm)
571 if (
associated(this%rowlabel))
then
572 deallocate (this%rowlabel)
573 nullify (this%rowlabel)
577 allocate (this%vbvl(4, this%maxsize))
578 allocate (this%vbnm(this%maxsize))
579 allocate (this%rowlabel(this%maxsize))
582 this%vbvl(:, :) =
dzero
584 this%rowlabel(:) =
''
597 integer(I4B),
intent(in) :: maxsize
599 real(DP),
dimension(:, :),
allocatable :: vbvl
600 character(len=LENBUDTXT),
dimension(:),
allocatable :: vbnm
601 character(len=LENBUDROWLABEL),
dimension(:),
allocatable :: rowlabel
602 integer(I4B) :: maxsizeold
605 maxsizeold = this%maxsize
606 allocate (vbvl(4, maxsizeold))
607 allocate (vbnm(maxsizeold))
608 allocate (rowlabel(maxsizeold))
609 vbvl(:, :) = this%vbvl(:, :)
610 vbnm(:) = this%vbnm(:)
611 rowlabel(:) = this%rowlabel(:)
614 this%maxsize = maxsize
615 call this%allocate_arrays()
618 this%vbvl(:, 1:maxsizeold) = vbvl(:, 1:maxsizeold)
619 this%vbnm(1:maxsizeold) = vbnm(1:maxsizeold)
620 this%rowlabel(1:maxsizeold) = rowlabel(1:maxsizeold)
625 deallocate (rowlabel)
636 real(dp),
dimension(:),
contiguous,
intent(in) :: flow
637 real(dp),
intent(out) :: rin
638 real(dp),
intent(out) :: rout
644 if (flow(n) <
dzero)
then
645 rout = rout - flow(n)
662 integer(I4B),
intent(in) :: ibudcsv
663 this%ibudcsv = ibudcsv
677 real(DP),
intent(in) :: totim
686 if (this%ibudcsv > 0)
then
689 if (this%icsvheader == 0)
then
690 call this%write_csv_header()
697 do i = 1, this%msum - 1
698 totrin = totrin + this%vbvl(3, i)
699 totrout = totrout + this%vbvl(4, i)
703 diffr = totrin - totrout
705 avgrat = (totrin + totrout) /
dtwo
706 if (avgrat /=
dzero)
then
711 write (this%ibudcsv,
'(*(G0,:,","))') &
713 (this%vbvl(3, i), i=1, this%msum - 1), &
714 (this%vbvl(4, i), i=1, this%msum - 1), &
715 totrin, totrout, pdiffr
734 character(len=LINELENGTH) :: txt, txtl
735 write (this%ibudcsv,
'(a)', advance=
'NO')
'time,'
738 do l = 1, this%msum - 1
741 if (this%labeled)
then
742 txtl =
'('//trim(adjustl(this%rowlabel(l)))//
')'
744 txt = trim(adjustl(txt))//trim(adjustl(txtl))//
'_IN,'
745 write (this%ibudcsv,
'(a)', advance=
'NO') trim(adjustl(txt))
749 do l = 1, this%msum - 1
752 if (this%labeled)
then
753 txtl =
'('//trim(adjustl(this%rowlabel(l)))//
')'
755 txt = trim(adjustl(txt))//trim(adjustl(txtl))//
'_OUT,'
756 write (this%ibudcsv,
'(a)', advance=
'NO') trim(adjustl(txt))
758 write (this%ibudcsv,
'(a)')
'TOTAL_IN,TOTAL_OUT,PERCENT_DIFFERENCE'
This module contains the BudgetModule.
subroutine budget_ot(this, kstp, kper, iout)
@ brief Output the budget table
subroutine budget_da(this)
@ brief Deallocate memory
subroutine, public budget_cr(this, name_model)
@ brief Create a new budget object
subroutine allocate_scalars(this, name_model)
@ brief allocate scalar variables
subroutine add_single_entry(this, rin, rout, delt, text, isupress_accumulate, rowlabel)
@ brief Add a single row of information
subroutine writecsv(this, totim)
@ brief Write csv output
subroutine write_csv_header(this)
@ brief Write csv header
subroutine resize(this, maxsize)
@ brief Resize the budget object
subroutine, public rate_accumulator(flow, rin, rout)
@ brief Rate accumulator subroutine
subroutine, public value_to_string(val, string, big, small)
@ brief Convert a number to a string
subroutine allocate_arrays(this)
@ brief allocate array variables
subroutine budget_df(this, maxsize, bdtype, bddim, labeltitle, bdzone)
@ brief Define information for this object
subroutine add_multi_entry(this, budterm, delt, budtxt, isupress_accumulate, rowlabel)
@ brief Add multiple rows of information
subroutine finalize_step(this, delt)
@ brief Update accumulators
subroutine reset(this)
@ brief Reset the budget object
subroutine set_ibudcsv(this, ibudcsv)
@ brief Set unit number for csv output file
This module contains simulation constants.
integer(i4b), parameter linelength
maximum length of a standard line
integer(i4b), parameter lenbudrowlabel
maximum length of the rowlabel string used in the budget table
real(dp), parameter dhundred
real constant 100
real(dp), parameter dzero
real constant zero
real(dp), parameter dtwo
real constant 2
integer(i4b), parameter lenbudtxt
maximum length of a budget component names
This module defines variable data types.
This module contains simulation methods.
subroutine, public store_error(msg, terminate)
Store an error message.
integer(i4b) function, public count_errors()
Return number of errors.
Derived type for the Budget object.