40 integer(I4B),
pointer :: msum => null()
41 integer(I4B),
pointer :: maxsize => null()
42 real(dp),
pointer :: budperc => null()
43 logical,
pointer :: written_once => null()
44 real(dp),
dimension(:, :),
pointer :: vbvl => null()
45 character(len=LENBUDTXT),
dimension(:),
pointer,
contiguous :: vbnm => null()
46 character(len=20),
pointer :: bdtype => null()
47 character(len=5),
pointer :: bddim => null()
48 character(len=LENBUDROWLABEL), &
49 dimension(:),
pointer,
contiguous :: rowlabel => null()
50 character(len=16),
pointer :: labeltitle => null()
51 character(len=20),
pointer :: bdzone => null()
52 logical,
pointer :: labeled => null()
55 integer(I4B),
pointer :: ibudcsv => null()
56 integer(I4B),
pointer :: icsvheader => null()
87 character(len=*),
intent(in) :: name_model
93 call this%allocate_scalars(name_model)
101 subroutine budget_df(this, maxsize, bdtype, bddim, labeltitle, bdzone)
103 integer(I4B),
intent(in) :: maxsize
104 character(len=*),
optional :: bdtype
105 character(len=*),
optional :: bddim
106 character(len=*),
optional :: labeltitle
107 character(len=*),
optional :: bdzone
110 this%maxsize = maxsize
113 call this%allocate_arrays()
116 if (
present(bdtype))
then
119 this%bdtype =
'VOLUME'
123 if (
present(bddim))
then
130 if (
present(bdzone))
then
133 this%bdzone =
'ENTIRE MODEL'
137 if (
present(labeltitle))
then
138 this%labeltitle = labeltitle
140 this%labeltitle =
'PACKAGE NAME'
151 real(DP),
intent(in) :: val
152 character(len=*),
intent(out) :: string
153 real(DP),
intent(in) :: big
154 real(DP),
intent(in) :: small
158 if (val /=
dzero .and. (absval >= big .or. absval < small))
then
159 if (absval >= 1.d100 .or. absval <= 1.d-100)
then
162 write (string,
'(es17.4E3)') val
164 write (string,
'(1pe17.4)') val
168 write (string,
'(f17.4)') val
180 integer(I4B),
intent(in) :: kstp
181 integer(I4B),
intent(in) :: kper
182 integer(I4B),
intent(in) :: iout
183 character(len=17) :: val1, val2
184 integer(I4B) :: msum1, l
185 real(DP) :: two, hund, bigvl1, bigvl2, small, &
186 totrin, totrot, totvin, totvot, diffr, adiffr, &
187 pdiffr, pdiffv, avgrat, diffv, adiffv, avgvol
198 msum1 = this%msum - 1
199 if (msum1 <= 0)
return
209 totrin = totrin + this%vbvl(3, l)
210 totrot = totrot + this%vbvl(4, l)
211 totvin = totvin + this%vbvl(1, l)
212 totvot = totvot + this%vbvl(2, l)
216 if (this%labeled)
then
217 write (iout, 261) trim(adjustl(this%bdtype)), trim(adjustl(this%bdzone)), &
219 write (iout, 266) trim(adjustl(this%bdtype)), trim(adjustl(this%bddim)), &
220 trim(adjustl(this%bddim)), this%labeltitle
222 write (iout, 260) trim(adjustl(this%bdtype)), trim(adjustl(this%bdzone)), &
224 write (iout, 265) trim(adjustl(this%bdtype)), trim(adjustl(this%bddim)), &
225 trim(adjustl(this%bddim))
232 if (this%labeled)
then
233 write (iout, 276) this%vbnm(l), val1, this%vbnm(l), val2, this%rowlabel(l)
235 write (iout, 275) this%vbnm(l), val1, this%vbnm(l), val2
240 write (iout, 286) val1, val2
247 if (this%labeled)
then
248 write (iout, 276) this%vbnm(l), val1, this%vbnm(l), val2, this%rowlabel(l)
250 write (iout, 275) this%vbnm(l), val1, this%vbnm(l), val2
255 write (iout, 298) val1, val2
260 diffr = totrin - totrot
265 avgrat = (totrin + totrot) / two
266 if (avgrat /=
dzero) pdiffr = hund * diffr / avgrat
267 this%budperc = pdiffr
270 diffv = totvin - totvot
275 avgvol = (totvin + totvot) / two
276 if (avgvol /=
dzero) pdiffv = hund * diffv / avgvol
282 write (iout, 299) val1, val2
283 write (iout, 300) pdiffv, pdiffr
289 this%written_once = .true.
292 260
FORMAT(//2x, a,
' BUDGET FOR ', a,
' AT END OF' &
293 ,
' TIME STEP', i5,
', STRESS PERIOD', i4 / 2x, 78(
'-'))
294 261
FORMAT(//2x, a,
' BUDGET FOR ', a,
' AT END OF' &
295 ,
' TIME STEP', i5,
', STRESS PERIOD', i4 / 2x, 99(
'-'))
296 265
FORMAT(1x, /5x,
'CUMULATIVE ', a, 6x, a, 7x &
297 ,
'RATES FOR THIS TIME STEP', 6x, a,
'/T'/5x, 18(
'-'), 17x, 24(
'-') &
298 //11x,
'IN:', 38x,
'IN:'/11x,
'---', 38x,
'---')
299 266
FORMAT(1x, /5x,
'CUMULATIVE ', a, 6x, a, 7x &
300 ,
'RATES FOR THIS TIME STEP', 6x, a,
'/T', 10x, a16, &
301 /5x, 18(
'-'), 17x, 24(
'-'), 21x, 16(
'-') &
302 //11x,
'IN:', 38x,
'IN:'/11x,
'---', 38x,
'---')
303 275
FORMAT(1x, 3x, a16,
' =', a17, 6x, a16,
' =', a17)
304 276
FORMAT(1x, 3x, a16,
' =', a17, 6x, a16,
' =', a17, 5x, a)
305 286
FORMAT(1x, /12x,
'TOTAL IN =', a, 14x,
'TOTAL IN =', a)
306 287
FORMAT(1x, /10x,
'OUT:', 37x,
'OUT:'/10x, 4(
'-'), 37x, 4(
'-'))
307 298
FORMAT(1x, /11x,
'TOTAL OUT =', a, 13x,
'TOTAL OUT =', a)
308 299
FORMAT(1x, /12x,
'IN - OUT =', a, 14x,
'IN - OUT =', a)
309 300
FORMAT(1x, /1x,
'PERCENT DISCREPANCY =', f15.2 &
310 , 5x,
'PERCENT DISCREPANCY =', f15.2/)
322 deallocate (this%msum)
323 deallocate (this%maxsize)
324 deallocate (this%budperc)
325 deallocate (this%written_once)
326 deallocate (this%labeled)
327 deallocate (this%bdtype)
328 deallocate (this%bddim)
329 deallocate (this%labeltitle)
330 deallocate (this%bdzone)
331 deallocate (this%ibudcsv)
332 deallocate (this%icsvheader)
335 deallocate (this%vbvl)
336 deallocate (this%vbnm)
337 deallocate (this%rowlabel)
353 do i = 1, this%maxsize
354 this%vbvl(3, i) =
dzero
355 this%vbvl(4, i) =
dzero
374 isupress_accumulate, rowlabel)
377 real(DP),
intent(in) :: rin
378 real(DP),
intent(in) :: rout
379 real(DP),
intent(in) :: delt
380 character(len=LENBUDTXT),
intent(in) :: text
381 integer(I4B),
optional,
intent(in) :: isupress_accumulate
382 character(len=*),
optional,
intent(in) :: rowlabel
384 character(len=LINELENGTH) :: errmsg
385 character(len=*),
parameter :: fmtbuderr = &
386 &
"('Error in MODFLOW 6.', 'Entries do not match: ', (a), (a) )"
388 integer(I4B) :: maxsize
391 if (
present(isupress_accumulate))
then
392 iscv = isupress_accumulate
397 if (maxsize > this%maxsize)
then
398 call this%resize(maxsize)
403 if (this%written_once)
then
404 if (trim(adjustl(this%vbnm(this%msum))) /= trim(adjustl(text)))
then
405 write (errmsg, fmtbuderr) trim(adjustl(this%vbnm(this%msum))), &
411 this%vbvl(3, this%msum) = rin
412 this%vbvl(4, this%msum) = rout
413 this%vbnm(this%msum) = adjustr(text)
414 if (
present(rowlabel))
then
415 this%rowlabel(this%msum) = adjustl(rowlabel)
416 this%labeled = .true.
418 this%msum = this%msum + 1
436 isupress_accumulate, rowlabel)
439 real(DP),
dimension(:, :),
intent(in) :: budterm
440 real(DP),
intent(in) :: delt
441 character(len=LENBUDTXT),
dimension(:),
intent(in) :: budtxt
442 integer(I4B),
optional,
intent(in) :: isupress_accumulate
443 character(len=*),
optional,
intent(in) :: rowlabel
445 character(len=LINELENGTH) :: errmsg
446 character(len=*),
parameter :: fmtbuderr = &
447 &
"('Error in MODFLOW 6.', 'Entries do not match: ', (a), (a) )"
448 integer(i4b) :: iscv, i
449 integer(I4B) :: nbudterms, maxsize
452 if (
present(isupress_accumulate))
then
453 iscv = isupress_accumulate
457 nbudterms =
size(budtxt)
458 maxsize = this%msum - 1 + nbudterms
459 if (maxsize > this%maxsize)
then
460 call this%resize(maxsize)
464 do i = 1,
size(budtxt)
468 if (this%written_once)
then
469 if (trim(adjustl(this%vbnm(this%msum))) /= &
470 trim(adjustl(budtxt(i))))
then
471 write (errmsg, fmtbuderr) trim(adjustl(this%vbnm(this%msum))), &
472 trim(adjustl(budtxt(i)))
477 this%vbvl(3, this%msum) = budterm(1, i)
478 this%vbvl(4, this%msum) = budterm(2, i)
479 this%vbnm(this%msum) = adjustr(budtxt(i))
480 if (
present(rowlabel))
then
481 this%rowlabel(this%msum) = adjustl(rowlabel)
482 this%labeled = .true.
484 this%msum = this%msum + 1
490 call store_error(
'Could not add multi-entry', terminate=.true.)
504 real(DP),
intent(in) :: delt
508 do i = 1, this%msum - 1
509 this%vbvl(1, i) = this%vbvl(1, i) + this%vbvl(3, i) * delt
510 this%vbvl(2, i) = this%vbvl(2, i) + this%vbvl(4, i) * delt
523 character(len=*),
intent(in) :: name_model
526 allocate (this%maxsize)
527 allocate (this%budperc)
528 allocate (this%written_once)
529 allocate (this%labeled)
530 allocate (this%bdtype)
531 allocate (this%bddim)
532 allocate (this%labeltitle)
533 allocate (this%bdzone)
534 allocate (this%ibudcsv)
535 allocate (this%icsvheader)
540 this%written_once = .false.
541 this%labeled = .false.
561 if (
associated(this%vbvl))
then
562 deallocate (this%vbvl)
565 if (
associated(this%vbnm))
then
566 deallocate (this%vbnm)
569 if (
associated(this%rowlabel))
then
570 deallocate (this%rowlabel)
571 nullify (this%rowlabel)
575 allocate (this%vbvl(4, this%maxsize))
576 allocate (this%vbnm(this%maxsize))
577 allocate (this%rowlabel(this%maxsize))
580 this%vbvl(:, :) =
dzero
582 this%rowlabel(:) =
''
595 integer(I4B),
intent(in) :: maxsize
597 real(DP),
dimension(:, :),
allocatable :: vbvl
598 character(len=LENBUDTXT),
dimension(:),
allocatable :: vbnm
599 character(len=LENBUDROWLABEL),
dimension(:),
allocatable :: rowlabel
600 integer(I4B) :: maxsizeold
603 maxsizeold = this%maxsize
604 allocate (vbvl(4, maxsizeold))
605 allocate (vbnm(maxsizeold))
606 allocate (rowlabel(maxsizeold))
607 vbvl(:, :) = this%vbvl(:, :)
608 vbnm(:) = this%vbnm(:)
609 rowlabel(:) = this%rowlabel(:)
612 this%maxsize = maxsize
613 call this%allocate_arrays()
616 this%vbvl(:, 1:maxsizeold) = vbvl(:, 1:maxsizeold)
617 this%vbnm(1:maxsizeold) = vbnm(1:maxsizeold)
618 this%rowlabel(1:maxsizeold) = rowlabel(1:maxsizeold)
623 deallocate (rowlabel)
634 real(dp),
dimension(:),
contiguous,
intent(in) :: flow
635 real(dp),
intent(out) :: rin
636 real(dp),
intent(out) :: rout
642 if (flow(n) <
dzero)
then
643 rout = rout - flow(n)
660 integer(I4B),
intent(in) :: ibudcsv
661 this%ibudcsv = ibudcsv
675 real(DP),
intent(in) :: totim
684 if (this%ibudcsv > 0)
then
687 if (this%icsvheader == 0)
then
688 call this%write_csv_header()
695 do i = 1, this%msum - 1
696 totrin = totrin + this%vbvl(3, i)
697 totrout = totrout + this%vbvl(4, i)
701 diffr = totrin - totrout
703 avgrat = (totrin + totrout) /
dtwo
704 if (avgrat /=
dzero)
then
709 write (this%ibudcsv,
'(*(G0,:,","))') &
711 (this%vbvl(3, i), i=1, this%msum - 1), &
712 (this%vbvl(4, i), i=1, this%msum - 1), &
713 totrin, totrout, pdiffr
732 character(len=LINELENGTH) :: txt, txtl
733 write (this%ibudcsv,
'(a)', advance=
'NO')
'time,'
736 do l = 1, this%msum - 1
739 if (this%labeled)
then
740 txtl =
'('//trim(adjustl(this%rowlabel(l)))//
')'
742 txt = trim(adjustl(txt))//trim(adjustl(txtl))//
'_IN,'
743 write (this%ibudcsv,
'(a)', advance=
'NO') trim(adjustl(txt))
747 do l = 1, this%msum - 1
750 if (this%labeled)
then
751 txtl =
'('//trim(adjustl(this%rowlabel(l)))//
')'
753 txt = trim(adjustl(txt))//trim(adjustl(txtl))//
'_OUT,'
754 write (this%ibudcsv,
'(a)', advance=
'NO') trim(adjustl(txt))
756 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 value_to_string(val, string, big, small)
@ brief Convert a number to a string
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 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.