MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
budgetobjectmodule Module Reference

Data Types

type  budgetobjecttype

Functions/Subroutines

subroutine, public budgetobject_cr (this, name)
 Create a new budget object.
subroutine budgetobject_df (this, ncv, nbudterm, iflowja, nsto, bddim_opt, labeltitle_opt, bdzone_opt, ibudcsv)
 Define the new budget object.
subroutine flowtable_df (this, iout, cellids)
 Define the new flow table object.
subroutine accumulate_terms (this)
 Add up accumulators and submit to budget table.
subroutine write_flowtable (this, dis, kstp, kper, cellidstr)
 Write the flow table for each advanced package control volume.
subroutine write_budtable (this, kstp, kper, iout, ibudfl, totim, delt)
 Write the budget table.
subroutine save_flows (this, dis, ibinun, kstp, kper, delt, pertim, totim, iout)
 Write the budget table.
subroutine read_flows (this, dis, ibinun)
 Read from a binary file into this BudgetObjectType.
subroutine budgetobject_da (this)
 Deallocate.
subroutine, public budgetobject_cr_bfr (this, name, ibinun, iout, colconv1, colconv2)
 Create a new budget object from a binary flow file.
subroutine bfr_init (this, ibinun, ncv, nbudterm, iout)
 Initialize the budget file reader.
subroutine bfr_advance (this, dis, iout)
 Advance the binary file readers for setting the budget terms of the next time step.
subroutine fill_from_bfr (this, dis, iout)
 Copy the information from the binary file into budterms.

Function/Subroutine Documentation

◆ accumulate_terms()

subroutine budgetobjectmodule::accumulate_terms ( class(budgetobjecttype) this)

Definition at line 277 of file BudgetObject.f90.

278 ! -- modules
279 use tdismodule, only: delt
280 ! -- dummy
281 class(BudgetObjectType) :: this
282 ! -- local
283 character(len=LENBUDTXT) :: flowtype
284 integer(I4B) :: i
285 real(DP) :: ratin, ratout
286 !
287 ! -- Reset the budget table
288 call this%budtable%reset()
289 !
290 ! -- Calculate the budget table terms
291 do i = 1, this%nbudterm
292 !
293 ! -- Accumulate positive and negative flows for each budget term
294 flowtype = this%budterm(i)%flowtype
295 select case (trim(adjustl(flowtype)))
296 case ('FLOW-JA-FACE')
297 ! -- Skip
298 case default
299 !
300 ! -- Calculate sum of positive and negative flows
301 call this%budterm(i)%accumulate_flow(ratin, ratout)
302 !
303 ! -- Pass accumulators into the budget table
304 call this%budtable%addentry(ratin, ratout, delt, flowtype)
305 end select
306 end do
real(dp), pointer, public delt
length of the current time step
Definition tdis.f90:32

◆ bfr_advance()

subroutine budgetobjectmodule::bfr_advance ( class(budgetobjecttype) this,
class(disbasetype), intent(in) dis,
integer(i4b), intent(in) iout )

Definition at line 620 of file BudgetObject.f90.

621 ! -- modules
622 use tdismodule, only: kstp, kper
623 ! -- dummy
624 class(BudgetObjectType) :: this
625 class(DisBaseType), intent(in) :: dis
626 integer(I4B), intent(in) :: iout
627 ! -- local
628 logical :: readnext
629 ! -- formats
630 character(len=*), parameter :: fmtkstpkper = &
631 &"(1x,/1x, a, ' READING BUDGET TERMS FOR KSTP ', i0, ' KPER ', i0)"
632 character(len=*), parameter :: fmtbudkstpkper = &
633 "(1x,/1x, a, ' SETTING BUDGET TERMS FOR KSTP ', i0, ' AND KPER ', &
634 &i0, ' TO BUDGET FILE TERMS FROM KSTP ', i0, ' AND KPER ', i0)"
635 !
636 ! -- Do not read the budget if the budget is at end of file or if the next
637 ! record in the budget file is the first timestep of the next stress
638 ! period. Also do not read if it is the very first time step because
639 ! the first chunk of data is read as part of the initialization
640 readnext = .true.
641 if (kstp * kper == 1) then
642 readnext = .false.
643 else if (kstp * kper > 1) then
644 if (this%bfr%endoffile) then
645 readnext = .false.
646 else
647 if (this%bfr%headernext%kper == kper + 1 .and. &
648 this%bfr%headernext%kstp == 1) &
649 readnext = .false.
650 end if
651 end if
652 !
653 ! -- Read the next record
654 if (readnext) then
655 !
656 ! -- Write the current time step and stress period
657 if (iout > 0) &
658 write (iout, fmtkstpkper) this%name, kstp, kper
659 !
660 ! -- Read flows from the binary file and copy them into this%budterm(:)
661 call this%fill_from_bfr(dis, iout)
662 else
663 if (iout > 0) &
664 write (iout, fmtbudkstpkper) trim(this%name), kstp, kper, &
665 this%bfr%header%kstp, this%bfr%header%kper
666 end if
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

◆ bfr_init()

subroutine budgetobjectmodule::bfr_init ( class(budgetobjecttype) this,
integer(i4b), intent(in) ibinun,
integer(i4b), intent(inout) ncv,
integer(i4b), intent(inout) nbudterm,
integer(i4b), intent(in) iout )

Definition at line 603 of file BudgetObject.f90.

604 ! -- dummy
605 class(BudgetObjectType) :: this
606 integer(I4B), intent(in) :: ibinun
607 integer(I4B), intent(inout) :: ncv
608 integer(I4B), intent(inout) :: nbudterm
609 integer(I4B), intent(in) :: iout
610 !
611 ! -- Initialize budget file reader
612 allocate (this%bfr)
613 call this%bfr%initialize(ibinun, iout, ncv)
614 nbudterm = this%bfr%nbudterms

◆ budgetobject_cr()

subroutine, public budgetobjectmodule::budgetobject_cr ( type(budgetobjecttype), pointer this,
character(len=*), intent(in) name )

Definition at line 82 of file BudgetObject.f90.

83 ! -- dummy
84 type(BudgetObjectType), pointer :: this
85 character(len=*), intent(in) :: name
86 !
87 ! -- Create the object
88 allocate (this)
89 !
90 ! -- Initialize variables
91 this%name = name
92 this%ncv = 0
93 this%nbudterm = 0
94 this%iflowja = 0
95 this%nsto = 0
96 this%iterm = 0
97 !
98 ! -- Initialize budget table
99 call budget_cr(this%budtable, name)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ budgetobject_cr_bfr()

subroutine, public budgetobjectmodule::budgetobject_cr_bfr ( type(budgetobjecttype), pointer this,
character(len=*), intent(in) name,
integer(i4b), intent(in) ibinun,
integer(i4b), intent(in) iout,
character(len=16), dimension(:), optional colconv1,
character(len=16), dimension(:), optional colconv2 )

Definition at line 552 of file BudgetObject.f90.

553 ! -- dummy
554 type(BudgetObjectType), pointer :: this
555 character(len=*), intent(in) :: name
556 integer(I4B), intent(in) :: ibinun
557 integer(I4B), intent(in) :: iout
558 character(len=16), dimension(:), optional :: colconv1
559 character(len=16), dimension(:), optional :: colconv2
560 ! -- local
561 integer(I4B) :: ncv, nbudterm
562 integer(I4B) :: iflowja, nsto
563 integer(I4B) :: i, j
564 !
565 ! -- Create the object
566 call budgetobject_cr(this, name)
567 !
568 ! -- Initialize the budget file reader
569 call this%bfr_init(ibinun, ncv, nbudterm, iout)
570 !
571 ! -- Define this budget object using number of control volumes and number
572 ! of budget terms read from ibinun
573 iflowja = 0
574 nsto = 0
575 call this%budgetobject_df(ncv, nbudterm, iflowja, nsto)
576 !
577 ! -- Set the conversion flags, which cause id1 or id2 to be converted from
578 ! user node numbers to reduced node numbers
579 if (present(colconv1)) then
580 do i = 1, nbudterm
581 do j = 1, size(colconv1)
582 if (colconv1(j) == adjustl(this%bfr%budtxtarray(i))) then
583 this%budterm(i)%olconv1 = .true.
584 exit
585 end if
586 end do
587 end do
588 end if
589 if (present(colconv2)) then
590 do i = 1, nbudterm
591 do j = 1, size(colconv2)
592 if (colconv2(j) == adjustl(this%bfr%budtxtarray(i))) then
593 this%budterm(i)%olconv2 = .true.
594 exit
595 end if
596 end do
597 end do
598 end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ budgetobject_da()

subroutine budgetobjectmodule::budgetobject_da ( class(budgetobjecttype) this)

Definition at line 519 of file BudgetObject.f90.

520 ! -- dummy
521 class(BudgetObjectType) :: this
522 ! -- local
523 integer(I4B) :: i
524 !
525 ! -- Save flows for each budget term
526 do i = 1, this%nbudterm
527 call this%budterm(i)%deallocate_arrays()
528 end do
529 !
530 ! -- Destroy the flow table
531 if (associated(this%flowtab)) then
532 deallocate (this%add_cellids)
533 deallocate (this%icellid)
534 deallocate (this%nflowterms)
535 deallocate (this%istart)
536 deallocate (this%iflowterms)
537 call this%flowtab%table_da()
538 deallocate (this%flowtab)
539 nullify (this%flowtab)
540 end if
541 !
542 ! -- Destroy the budget object table
543 if (associated(this%budtable)) then
544 call this%budtable%budget_da()
545 deallocate (this%budtable)
546 nullify (this%budtable)
547 end if

◆ budgetobject_df()

subroutine budgetobjectmodule::budgetobject_df ( class(budgetobjecttype) this,
integer(i4b), intent(in) ncv,
integer(i4b), intent(in) nbudterm,
integer(i4b), intent(in) iflowja,
integer(i4b), intent(in) nsto,
character(len=*), optional bddim_opt,
character(len=*), optional labeltitle_opt,
character(len=*), optional bdzone_opt,
integer(i4b), intent(in), optional ibudcsv )

Definition at line 104 of file BudgetObject.f90.

107 ! -- dummy
108 class(BudgetObjectType) :: this
109 integer(I4B), intent(in) :: ncv
110 integer(I4B), intent(in) :: nbudterm
111 integer(I4B), intent(in) :: iflowja
112 integer(I4B), intent(in) :: nsto
113 character(len=*), optional :: bddim_opt
114 character(len=*), optional :: labeltitle_opt
115 character(len=*), optional :: bdzone_opt
116 integer(I4B), intent(in), optional :: ibudcsv
117 ! -- local
118 character(len=20) :: bdtype
119 character(len=5) :: bddim
120 character(len=16) :: labeltitle
121 character(len=20) :: bdzone
122 !
123 ! -- Set values
124 this%ncv = ncv
125 this%nbudterm = nbudterm
126 this%iflowja = iflowja
127 this%nsto = nsto
128 !
129 ! -- Allocate space for budterm
130 allocate (this%budterm(nbudterm))
131 !
132 ! -- Set the budget type to name
133 bdtype = this%name
134 !
135 ! -- Set the budget dimension
136 if (present(bddim_opt)) then
137 bddim = bddim_opt
138 else
139 bddim = 'L**3'
140 end if
141 !
142 ! -- Set the budget zone
143 if (present(bdzone_opt)) then
144 bdzone = bdzone_opt
145 else
146 bdzone = 'ENTIRE MODEL'
147 end if
148 !
149 ! -- Set the label title
150 if (present(labeltitle_opt)) then
151 labeltitle = labeltitle_opt
152 else
153 labeltitle = 'PACKAGE NAME'
154 end if
155 !
156 ! -- Setup the budget table object
157 call this%budtable%budget_df(nbudterm, bdtype, bddim, labeltitle, bdzone)
158 !
159 ! -- Trigger csv output
160 if (present(ibudcsv)) then
161 call this%budtable%set_ibudcsv(ibudcsv)
162 end if

◆ fill_from_bfr()

subroutine budgetobjectmodule::fill_from_bfr ( class(budgetobjecttype) this,
class(disbasetype), intent(in) dis,
integer(i4b), intent(in) iout )

Definition at line 671 of file BudgetObject.f90.

672 ! -- dummy
673 class(BudgetObjectType) :: this
674 class(DisBaseType), intent(in) :: dis
675 integer(I4B), intent(in) :: iout
676 ! -- local
677 integer(I4B) :: i
678 logical :: success
679 !
680 ! -- Read flows from the binary file and copy them into this%budterm(:)
681 do i = 1, this%nbudterm
682 call this%bfr%read_record(success, iout)
683 call this%budterm(i)%fill_from_bfr(this%bfr, dis)
684 end do

◆ flowtable_df()

subroutine budgetobjectmodule::flowtable_df ( class(budgetobjecttype) this,
integer(i4b), intent(in) iout,
character(len=*), intent(in), optional cellids )

Definition at line 167 of file BudgetObject.f90.

168 ! -- dummy
169 class(BudgetObjectType) :: this
170 integer(I4B), intent(in) :: iout
171 character(len=*), intent(in), optional :: cellids
172 ! -- local
173 character(len=LINELENGTH) :: title
174 character(len=LINELENGTH) :: text
175 character(len=LENBUDTXT) :: flowtype
176 character(len=LENBUDTXT) :: tag
177 character(len=LENBUDTXT) :: coupletype
178 logical :: lfound
179 logical :: add_cellids
180 integer(I4B) :: maxcol
181 integer(I4B) :: idx
182 integer(I4B) :: ipos
183 integer(I4B) :: i
184 !
185 ! -- Process optional variables
186 if (present(cellids)) then
187 add_cellids = .true.
188 coupletype = cellids
189 else
190 add_cellids = .false.
191 end if
192 !
193 ! -- Allocate scalars
194 allocate (this%add_cellids)
195 allocate (this%icellid)
196 allocate (this%nflowterms)
197 !
198 ! -- Initialize scalars
199 this%add_cellids = add_cellids
200 this%nflowterms = 0
201 this%icellid = 0
202 !
203 ! -- Determine the number of columns in the table
204 maxcol = 3
205 if (add_cellids) then
206 maxcol = maxcol + 1
207 end if
208 do i = 1, this%nbudterm
209 lfound = .false.
210 flowtype = this%budterm(i)%get_flowtype()
211 if (trim(adjustl(flowtype)) == 'FLOW-JA-FACE') then
212 lfound = .true.
213 maxcol = maxcol + 2
214 else if (trim(adjustl(flowtype)) /= 'AUXILIARY') then
215 lfound = .true.
216 maxcol = maxcol + 1
217 end if
218 if (lfound) then
219 this%nflowterms = this%nflowterms + 1
220 if (add_cellids) then
221 if (trim(adjustl(flowtype)) == trim(adjustl(coupletype))) then
222 this%icellid = i
223 end if
224 end if
225 end if
226 end do
227 !
228 ! -- Allocate arrays
229 allocate (this%istart(this%nflowterms))
230 allocate (this%iflowterms(this%nflowterms))
231 !
232 ! -- Set up flow tableobj
233 title = trim(this%name)//' PACKAGE - SUMMARY OF FLOWS FOR '// &
234 'EACH CONTROL VOLUME'
235 call table_cr(this%flowtab, this%name, title)
236 call this%flowtab%table_df(this%ncv, maxcol, iout, transient=.true.)
237 !
238 ! -- Go through and set up flow table budget terms
239 text = 'NUMBER'
240 call this%flowtab%initialize_column(text, 10, alignment=tabcenter)
241 if (add_cellids) then
242 text = 'CELLID'
243 call this%flowtab%initialize_column(text, 20, alignment=tableft)
244 end if
245 idx = 1
246 do i = 1, this%nbudterm
247 lfound = .false.
248 flowtype = this%budterm(i)%get_flowtype()
249 tag = trim(adjustl(flowtype))
250 ipos = index(tag, '-')
251 if (ipos > 0) then
252 tag(ipos:ipos) = ' '
253 end if
254 if (trim(adjustl(flowtype)) == 'FLOW-JA-FACE') then
255 lfound = .true.
256 text = 'INFLOW'
257 call this%flowtab%initialize_column(text, 12, alignment=tabcenter)
258 text = 'OUTFLOW'
259 call this%flowtab%initialize_column(text, 12, alignment=tabcenter)
260 else if (trim(adjustl(flowtype)) /= 'AUXILIARY') then
261 lfound = .true.
262 call this%flowtab%initialize_column(tag, 12, alignment=tabcenter)
263 end if
264 if (lfound) then
265 this%iflowterms(idx) = i
266 idx = idx + 1
267 end if
268 end do
269 text = 'IN - OUT'
270 call this%flowtab%initialize_column(text, 12, alignment=tabcenter)
271 text = 'PERCENT DIFFERENCE'
272 call this%flowtab%initialize_column(text, 12, alignment=tabcenter)
Here is the call graph for this function:

◆ read_flows()

subroutine budgetobjectmodule::read_flows ( class(budgetobjecttype) this,
class(disbasetype), intent(in) dis,
integer(i4b), intent(in) ibinun )

Definition at line 497 of file BudgetObject.f90.

498 ! -- dummy
499 class(BudgetObjectType) :: this
500 class(DisBaseType), intent(in) :: dis
501 integer(I4B), intent(in) :: ibinun
502 ! -- local
503 integer(I4B) :: kstp
504 integer(I4B) :: kper
505 real(DP) :: delt
506 real(DP) :: pertim
507 real(DP) :: totim
508 integer(I4B) :: i
509 !
510 ! -- Read flows for each budget term
511 do i = 1, this%nbudterm
512 call this%budterm(i)%read_flows(dis, ibinun, kstp, kper, delt, &
513 pertim, totim)
514 end do

◆ save_flows()

subroutine budgetobjectmodule::save_flows ( class(budgetobjecttype) this,
class(disbasetype), intent(in) dis,
integer(i4b), intent(in) ibinun,
integer(i4b), intent(in) kstp,
integer(i4b), intent(in) kper,
real(dp), intent(in) delt,
real(dp), intent(in) pertim,
real(dp), intent(in) totim,
integer(i4b), intent(in) iout )

Definition at line 473 of file BudgetObject.f90.

475 ! -- dummy
476 class(BudgetObjectType) :: this
477 class(DisBaseType), intent(in) :: dis
478 integer(I4B), intent(in) :: ibinun
479 integer(I4B), intent(in) :: kstp
480 integer(I4B), intent(in) :: kper
481 real(DP), intent(in) :: delt
482 real(DP), intent(in) :: pertim
483 real(DP), intent(in) :: totim
484 integer(I4B), intent(in) :: iout
485 ! -- dummy
486 integer(I4B) :: i
487 !
488 ! -- Save flows for each budget term
489 do i = 1, this%nbudterm
490 call this%budterm(i)%save_flows(dis, ibinun, kstp, kper, delt, &
491 pertim, totim, iout)
492 end do

◆ write_budtable()

subroutine budgetobjectmodule::write_budtable ( class(budgetobjecttype) this,
integer(i4b), intent(in) kstp,
integer(i4b), intent(in) kper,
integer(i4b), intent(in) iout,
integer(i4b), intent(in) ibudfl,
real(dp), intent(in) totim,
real(dp), intent(in) delt )

Definition at line 453 of file BudgetObject.f90.

454 ! -- dummy
455 class(BudgetObjectType) :: this
456 integer(I4B), intent(in) :: kstp
457 integer(I4B), intent(in) :: kper
458 integer(I4B), intent(in) :: iout
459 integer(I4B), intent(in) :: ibudfl
460 real(DP), intent(in) :: totim
461 real(DP), intent(in) :: delt
462 !
463 ! -- Write the table
464 call this%budtable%finalize_step(delt)
465 if (ibudfl /= 0) then
466 call this%budtable%budget_ot(kstp, kper, iout)
467 end if
468 call this%budtable%writecsv(totim)

◆ write_flowtable()

subroutine budgetobjectmodule::write_flowtable ( class(budgetobjecttype) this,
class(disbasetype), intent(in) dis,
integer(i4b), intent(in) kstp,
integer(i4b), intent(in) kper,
character(len=20), dimension(:), optional cellidstr )

Definition at line 311 of file BudgetObject.f90.

312 ! -- dummy
313 class(BudgetObjectType) :: this
314 class(DisBaseType), intent(in) :: dis
315 integer(I4B), intent(in) :: kstp
316 integer(I4B), intent(in) :: kper
317 character(len=20), dimension(:), optional :: cellidstr
318 ! -- local
319 character(len=LENBUDTXT) :: flowtype
320 character(len=20) :: cellid
321 integer(I4B) :: nlist
322 integer(I4B) :: id1
323 integer(I4B) :: id2
324 integer(I4B) :: icv
325 integer(I4B) :: idx
326 integer(I4B) :: i
327 integer(I4B) :: j
328 real(DP) :: v
329 real(DP) :: qin
330 real(DP) :: qout
331 real(DP) :: q
332 real(DP) :: qinflow
333 real(DP) :: qoutflow
334 real(DP) :: qerr
335 real(DP) :: qavg
336 real(DP) :: qpd
337 !
338 ! -- Reset starting position
339 do j = 1, this%nflowterms
340 this%istart(j) = 1
341 end do
342 !
343 ! -- Set table kstp and kper
344 call this%flowtab%set_kstpkper(kstp, kper)
345 !
346 ! -- Write the table
347 do icv = 1, this%ncv
348 call this%flowtab%add_term(icv)
349 !
350 ! -- Initialize flow terms for the control volume
351 qin = dzero
352 qout = dzero
353 !
354 ! -- Add cellid if required
355 if (this%add_cellids) then
356 if (present(cellidstr)) then
357 !
358 ! -- If there are not maxbound entries for this%budterm(idx),
359 ! which can happen for sfr, for example, if 'none' connections
360 ! are specified, then cellidstr should be passed in if the flow
361 ! table needs a cellid label.
362 cellid = cellidstr(icv)
363 else
364 !
365 ! -- Determine the cellid for this entry. The cellid, such as
366 ! (1, 10, 10), is assumed to be in the id2 column of this budterm.
367 j = this%icellid
368 idx = this%iflowterms(j)
369 i = this%istart(j)
370 id2 = this%budterm(idx)%get_id2(i)
371 if (id2 > 0) then
372 call dis%noder_to_string(id2, cellid)
373 else
374 cellid = 'NONE'
375 end if
376 end if
377 call this%flowtab%add_term(cellid)
378 end if
379 !
380 ! -- Iterate over the flow terms
381 do j = 1, this%nflowterms
382 !
383 ! -- Initialize flow terms for the row
384 q = dzero
385 qinflow = dzero
386 qoutflow = dzero
387 !
388 ! -- Determine the index, flowtype and length of
389 ! the flowterm
390 idx = this%iflowterms(j)
391 flowtype = this%budterm(idx)%get_flowtype()
392 nlist = this%budterm(idx)%get_nlist()
393 !
394 ! -- Iterate over the entries in the flowtype. If id1 is not ordered
395 ! then need to look through the entire list each time
396 colterm: do i = this%istart(j), nlist
397 id1 = this%budterm(idx)%get_id1(i)
398 if (this%budterm(idx)%ordered_id1) then
399 if (id1 > icv) then
400 this%istart(j) = i
401 exit colterm
402 end if
403 else
404 if (id1 /= icv) then
405 cycle colterm
406 end if
407 end if
408 if (id1 /= icv) then
409 v = dzero
410 else
411 v = this%budterm(idx)%get_flow(i)
412 end if
413 if (trim(adjustl(flowtype)) == 'FLOW-JA-FACE') then
414 if (v < dzero) then
415 qoutflow = qoutflow + v
416 else
417 qinflow = qinflow + v
418 end if
419 end if
420 !
421 ! -- Accumulators
422 q = q + v
423 if (v < dzero) then
424 qout = qout + v
425 else
426 qin = qin + v
427 end if
428 end do colterm
429 !
430 ! -- Add entry to table
431 if (trim(adjustl(flowtype)) == 'FLOW-JA-FACE') then
432 call this%flowtab%add_term(qinflow)
433 call this%flowtab%add_term(qoutflow)
434 else
435 call this%flowtab%add_term(q)
436 end if
437 end do
438 !
439 ! -- Calculate in-out and percent difference
440 qerr = qin + qout
441 qavg = dhalf * (qin - qout)
442 qpd = dzero
443 if (qavg > dzero) then
444 qpd = dhundred * qerr / qavg
445 end if
446 call this%flowtab%add_term(qerr)
447 call this%flowtab%add_term(qpd)
448 end do