-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathprint.R
1816 lines (1574 loc) · 73.7 KB
/
print.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#' @export
print.rmf_2d_array <- function(obj, ...) {
cat(paste('RMODFLOW 2d array with', dim(obj)[1], ifelse(dim(obj)[1] > 1, 'rows', 'row'), 'and',
dim(obj)[2], ifelse(dim(obj)[2] > 1, 'columns,', 'column,'), 'representing the',
paste(attr(obj, 'dimlabels'), collapse = ' & '), 'dimensions.', '\n'))
if(is.null(attr(obj, 'kper'))) {
cat('Not representing stress period data', '\n')
} else {
cat('Active during', ifelse(length(unique(attr(obj, 'kper'))) > 1, 'stress periods:', 'stress period:'),
unique(attr(obj, 'kper')), '\n')
}
print(as.array(obj), ...)
}
#' @export
print.rmf_3d_array <- function(obj, ...) {
cat(paste('RMODFLOW 3d array with', dim(obj)[1], ifelse(dim(obj)[1] > 1, 'rows,', 'row,'),
dim(obj)[2], ifelse(dim(obj)[2] > 1, 'columns', 'column'), 'and', dim(obj)[3],
ifelse(dim(obj)[3] > 1, 'layers,', 'layer,'), 'representing the',
paste(attr(obj, 'dimlabels')[1:2], collapse = ', '), paste('&', attr(obj, 'dimlabels')[3]),
'dimensions.', '\n'))
if(is.null(attr(obj, 'kper'))) {
cat('Not representing stress period data', '\n')
} else {
cat('Active during', ifelse(length(unique(attr(obj, 'kper'))) > 1, 'stress periods:', 'stress period:'),
unique(attr(obj, 'kper')), '\n')
}
print(as.array(obj), ...)
}
#' @export
print.rmf_4d_array <- function(obj, ...) {
cat(paste('RMODFLOW 4d array with', dim(obj)[1], ifelse(dim(obj)[1] > 1, 'rows,', 'row,'),
dim(obj)[2], ifelse(dim(obj)[2] > 1, 'columns,', 'column'), dim(obj)[3],
ifelse(dim(obj)[3] > 1, 'layers', 'layer'), 'and', dim(obj)[4],
ifelse(dim(obj)[4] > 1, 'timesteps,', 'timestep'), 'representing the',
paste(attr(obj, 'dimlabels')[1:3], collapse = ', '), paste('&', attr(obj, 'dimlabels')[4]),
'dimensions.', '\n'))
if(is.null(attr(obj, 'kper'))) {
cat('Not representing stress period data', '\n')
} else {
cat('Active during', ifelse(length(unique(attr(obj, 'kper'))) > 1, 'stress periods:', 'stress period:'),
unique(attr(obj, 'kper')), '\n')
}
print(as.array(obj), ...)
}
#' @export
print.rmf_list <- function(obj, ...) {
cat('RMODFLOW list with', nrow(obj), 'features', 'and', ncol(obj) - 3,
ifelse(ncol(obj) - 3 > 1, 'variables', 'variable'), '\n')
if(is.null(attr(obj, 'kper'))) {
cat('Not representing stress period data', '\n')
} else {
cat('Active during', ifelse(length(unique(attr(obj, 'kper'))) > 1, 'stress periods:', 'stress period:'),
unique(attr(obj, 'kper')), '\n')
}
print(as.data.frame(obj), ...)
}
#' @export
print.rmf_package <- function(obj) cat('A undefined RMODFLOW package')
#' @export
print.nam <- function(nam) {
cat('RMODFLOW Name File object with:', '\n')
cat(nrow(nam), 'files with', length(which(!nam$ftype %in% c('DATA', 'DATA(BINARY)', 'LIST', 'GLOBAL', 'DATAGLO', 'DATAGLO(BINARY)'))), 'packages', '\n')
cat('\n')
print.data.frame(nam)
}
#' @export
print.dis <- function(dis, n = 5) {
# dimensions
cat('RMODFLOW Discretization File object with:', '\n')
cat(paste(dis$nrow, ifelse(dis$nrow > 1, 'rows,', 'row,'), dis$ncol, ifelse(dis$ncol > 1, 'columns', 'column'),
'and', dis$nlay, ifelse(dis$nlay > 1, 'layers', 'layer'), 'totalling', dis$nrow*dis$ncol*dis$nlay, 'cells' ,'\n'))
cat('\n')
# units
cat(paste('Time units:', c('undefined', 'seconds', 'minutes', 'hours', 'days', 'years')[dis$itmuni+1], '\n'))
cat(paste('Length units:', c('undefined', 'feet', 'meters', 'centimeters')[dis$lenuni+1], '\n'))
# cbd
if(any(dis$laycbd != 0)) {
cat('\n')
cat('Confining beds present below layer(s)', which(dis$laycbd != 0), '\n')
} # else {
# cat('No confining beds present', '\n')
# }
# delr & delc
cnst_delr <- isTRUE(do.call(all.equal, as.list(range(dis$delr) / mean(dis$delr))))
cnst_delc <- isTRUE(do.call(all.equal, as.list(range(dis$delc) / mean(dis$delc))))
if(cnst_delr) {
delr <- c(dis$delr[1], '(constant)')
} else {
if(dis$ncol > n) {
delr <- c(dis$delr[1:n], '...')
} else {
delr <- dis$delr
}
}
if(cnst_delc) {
delc <- c(dis$delc[1], '(constant)')
} else {
if(dis$nrow > n) {
delc <- c(dis$delc[1:n], '...')
} else {
delc <- dis$delc
}
}
cat('\n')
cat('Spacing along rows (DELR): ', delr, '\n')
cat('Spacing along columns (DELC): ', delc, '\n')
cat('\n')
# top
cat('Summary of top elevations:', '\n')
c(dis$top) %>% as.data.frame() %>% setNames('Top') %>% summary() %>% print
cat('\n')
# botm
if(dis$nlay > n) {
cat('Summary of bottom elevations (first', n,'layers):', '\n')
nlay <- n
} else {
cat('Summary of bottom elevations: \n')
nlay <- dis$nlay
}
if(any(dis$laycbd != 0)) {
cbd <- rmfi_confining_beds(dis)
nnlay <- dis$nlay + sum(cbd)
names_botm <- vapply(1:nnlay,
function(i) rmfi_ifelse0(cbd[i], paste('Confining bed', cumsum(cbd)[i]),
paste('Layer', i - cumsum(cbd)[i])),
'text')
} else {
names_botm <- paste('Layer', 1:dis$nlay)
}
apply(dis$botm, 3, function(i) summary(c(i))) %>% as.data.frame() %>%
setNames(names_botm) %>% subset(select = 1:nlay) %>% print()
cat('\n')
# stress periods
sp_names <- setNames(c('Steady-state', 'Transient'), c('SS', 'TR'))
sp <- data.frame(kper = 1:dis$nper, perlen = dis$perlen, nstp = dis$nstp, tsmult = dis$tsmult, sstr = sp_names[toupper(dis$sstr)])
names(sp) <- c('Period', 'Length', 'Timesteps', 'Multiplier', 'Type')
if(dis$nper > n) {
cat('Information for', dis$nper, if(dis$nper > 1) 'stress-periods' else 'stress-period', '(first', n, 'shown):', '\n')
nper <- n
} else {
cat('Information for', dis$nper, if(dis$nper > 1) 'stress-periods:' else 'stress-period:', '\n')
nper <- dis$nper
}
print(sp[1:nper,], row.names = FALSE)
if(rmf_has_prj(dis)) {
cat('\n')
print(rmf_get_prj(dis))
}
}
#' @export
print.bas <- function(bas, n = 5) {
cat('RMODFLOW Basic Package object with:', '\n')
cat(length(which(bas$ibound == -1)), 'constant head cells,', length(which(bas$ibound == 0)), 'inactive cells and',
length(which(bas$ibound == 1)), 'active cells', '\n')
cat('\n')
if(bas$xsection) cat('Model is a 1-row cross-section; strt & ibound have dimensions ncol*nlay.', '\n')
if(bas$chtoch) cat('Flow between adjacent constant head cells is calculated.', '\n')
if(bas$free) cat('Free format is used for reading and writing input variables.', '\n')
if(bas$printtime) cat('Start, end and elapsed execution time is written to the listing file.', '\n')
if(bas$showprogress) cat('Stress period, time step and equation being solved are written to the monitor.', '\n')
if(bas$stoperror) cat('When failing to converge, execution will continue as long as the budget discrepancy is smaller than', bas$stoper, '\n')
cat('\n')
cat('Inactive cells are assigned a head value of', bas$hnoflo, '\n')
cat('\n')
if(dim(bas$strt)[3] > n) {
cat('Summary of initial head values (first', n,'layers):', '\n')
nlay <- n
} else {
cat('Summary of initial head values:', '\n')
nlay <- dim(bas$strt)[3]
}
apply(bas$strt, 3, function(i) summary(c(i))) %>% as.data.frame() %>%
setNames(paste('Layer', 1:dim(bas$strt)[3])) %>% subset(select = 1:nlay) %>% print()
}
#' @export
print.pval <- function(pval, n = 30) {
cat('RMODFLOW Parameter Value File object with:', '\n')
df <- data.frame(parnam = pval$data$parnam, parval = pval$data$parval)
if(pval$np > n) {
cat(pval$np, 'parameter values', '(first', n, 'shown):', '\n')
nlay <- n
} else {
cat(pval$np, 'parameter values:', '\n')
nlay <- pval$np
}
cat('\n')
print(df[1:nlay, ])
}
#' @export
print.zon <- function(zon, n = 5) {
cat('RMODFLOW Zone File object with:', '\n')
cat(zon$nzn, ifelse(zon$nzn > 1, 'zone arrays', 'zone array'), '\n')
cat('\n')
nlay <- ifelse(zon$nzn > n, n, zon$nzn)
cat(rmfi_ifelse0(zon$nzn > n, c('Overview of zone arrays (first', n, 'arrays):'), 'Overview of zone arrays:'), '\n')
obj <- abind::abind(zon$izon[1:nlay], along = 3) %>%
apply(3, table)
for(i in 1:nlay) {
w <- max(nchar(obj[[i]]), nchar(names(obj[[i]])))
cat('\n')
cat(zon$zonnam[i], '\n')
cat('IZ: ', format(as.character(names(obj[[i]])), width = w, justify = 'right'), '\n')
cat('Freq: ', format(c(obj[[i]]), width = w, justify = 'right'), '\n')
}
}
#' @export
print.mlt <- function(mlt, n = 5) {
cat('RMODFLOW Multipler File object with:', '\n')
cat(mlt$nml, ifelse(mlt$nml > 1, 'multiplier arrays', 'mutliplier array'), '\n')
cat('\n')
nlay <- ifelse(mlt$nml > n, n, mlt$nml)
cat(rmfi_ifelse0(mlt$nml > n, c('Summary of multiplier arrays (first', n, 'arrays):'), 'Summary of multiplier arrays:'), '\n')
abind::abind(mlt$rmlt, along = 3) %>% apply(3, function(i) summary(c(i))) %>% as.data.frame() %>%
setNames(mlt$mltnam) %>% subset(select = 1:nlay) %>% print()
}
#' @export
print.huf <- function(huf, n = 5) {
cat('RMODFLOW Hydrogeologic-Unit Flow object with:', '\n')
cat(huf$nhuf, ifelse(huf$nhuf > 1, 'hydrogeological units', 'hydrogeological unit'), 'and', huf$nphuf, ifelse(huf$nphuf > 1, 'flow parameters', 'flow parameter'), '\n')
cat('\n')
cat('Cell-by-cell flow terms are', ifelse(huf$ihufcb == 0, 'not written',
ifelse(huf$ihufcb > 0, paste('written to file number', huf$ihufcb),
'(only flow between constant-head cells) printed to the listing file')), '\n')
cat('Dry cells are assigned a head value of', huf$hdry, '\n')
cat('\n')
cat('Heads interpolated to hydrogeological units are', ifelse(huf$iohufheads == 0, 'not written', paste('written to file number', huf$iohufheads)), '\n')
cat('Flow terms interpolated to hydrogeological units are', ifelse(huf$iohufflows == 0, 'not written', paste('written to file number', huf$iohufflows)), '\n')
cat('\n')
# Layer overview
ll <- data.frame('Layer' = 1:length(huf$lthuf), 'Type' = 'Confined', 'Wetting' = 'Inactive', stringsAsFactors = FALSE)
ll$Type[which(huf$lthuf != 0)] <- 'Convertible'
ll$Wetting[which(huf$laywt != 0)] <- 'Active'
if(length(huf$lthuf) > n) {
cat('Layer overview (first', n, 'layers): ', '\n')
nlay <- n
} else {
cat('Layer overview:', '\n')
nlay <- length(huf$lthuf)
}
print(ll[1:nlay,], row.names = FALSE)
cat('\n')
# Wetting
if(any(huf$latwt != 0)) {
cat('Wetting factor:', huf$wetfct, '\n')
cat('Wetting is attempted every', ifelse(huf$iwetit == 1, 'interval', paste(huf$iwetit, 'intervals')), '\n')
cat('Initial heads at cells that become wet are defined using equation', ifelse(huf$ihdwet == 0, '3a', '3b'), '(see MODFLOW manual)', '\n')
# wetdry
wetdry <- huf$wetdry[,,which(huf$laywt != 0)]
if(length(dim(wetdry)) == 2) wetdry <- rmf_create_array(wetdry, dim = c(dim(wetdry), 1))
if(dim(wetdry)[3] > n) {
cat('Summary of wetdry values (first', n ,'layers):', '\n')
nlay <- n
} else {
cat('Summary of wetdry values:', '\n')
nlay <- dim(wetdry)[3]
}
names_wetdry <- paste('Layer', which(huf$laywt != 0))
apply(wetdry, 3, function(i) summary(c(i))) %>% as.data.frame() %>%
setNames(names_wetdry) %>% subset(select = 1:nlay) %>% print()
cat('\n')
}
# HGU overview
un <- data.frame('Index' = 1:huf$nhuf, 'Unit' = huf$hgunam, 'HANI' = 'Parameter', 'VANI' = 'VK', stringsAsFactors = FALSE)
un$HANI <- replace(un$HANI, which(huf$hguhani != 0), huf$hguhani[which(huf$hguhani != 0)])
un$VANI <- replace(un$VANI, which(huf$hguvani != 0), huf$hguvani[which(huf$hguvani != 0)])
df <- cbind(hgu = vapply(huf$parameters, function(i) attr(i, 'hgunam'), 'txt'),
type = vapply(huf$parameters, function(i) attr(i, 'partyp'), 'txt')) %>%
as.data.frame(stringsAsFactors = FALSE)
if('VANI' %in% df$type) {
df <- subset(df, type == 'VANI')
df$unit <- vapply(df$hgu, function(i) which(huf$hgunam == i), 1)
un$VANI <- replace(un$VANI, unique(df$unit), 'Parameter')
}
if(huf$nhuf > n) {
cat('HGU overview (first', n, 'hgu\'s): ', '\n')
nlay <- n
} else {
cat('HGU overview:', '\n')
nlay <- huf$nhuf
}
print(un[1:nlay,], row.names = FALSE)
cat('\n')
# Parameters
pdf <- data.frame('Name' = vapply(huf$parameters, function(i) attr(i, 'parnam'), 'txt'),
'Type' = vapply(huf$parameters, function(i) attr(i, 'partyp'), 'txt'),
'Unit' = vapply(huf$parameters, function(i) attr(i, 'hgunam'), 'txt'),
'Value' = vapply(huf$parameters, function(i) attr(i, 'parval'), 1),
stringsAsFactors = FALSE)
if(nrow(pdf) > n) {
cat('Parameter overview (first', n, 'parameters): ', '\n')
nlay <- n
} else {
cat('Parameter overview:', '\n')
nlay <- nrow(pdf)
}
print(pdf[1:nlay,], row.names = FALSE)
cat('\n')
# top
if(huf$nhuf > n) {
cat('Summary of top elevations (first', n ,'units):', '\n')
nlay <- n
} else {
cat('Summary of top elevations:', '\n')
nlay <- huf$nhuf
}
apply(huf$top, 3, function(i) summary(c(i))) %>% as.data.frame() %>%
setNames(huf$hgunam) %>% subset(select = 1:nlay) %>% print()
cat('\n')
# thck
if(huf$nhuf > n) {
cat('Summary of thicknesses (first', n, 'units):', '\n')
nlay <- n
} else {
cat('Summary of thicknesses:', '\n')
nlay <- huf$nhuf
}
apply(huf$thck, 3, function(i) summary(c(i))) %>% as.data.frame() %>%
setNames(huf$hgunam) %>% subset(select = 1:nlay) %>% print()
}
#' @export
print.oc <- function(oc, n = 500) {
cat('RMODFLOW Output Control Option file using:', '\n')
cat(ifelse(is.null(oc$incode), 'words', 'numeric codes'), 'to specify output', '\n')
cat('\n')
# words
if(is.null(oc$incode)) {
# save
if(!is.na(oc$ihedun) && any(c(oc$save_head))) {
if(is.matrix(oc$save_head)) {
df <- cbind('Time step' = 1:nrow(oc$save_head), setNames(as.data.frame(oc$save_head), paste('Layer', 1:ncol(oc$save_head))))
cat('Simulated heads are written to a', if(oc$head_label) {'labelled'}, ifelse(is.na(oc$chedfm), 'binary', 'formatted'), 'file on unit number', oc$ihedun, 'at following',
ifelse(nrow(df) > n, paste('time steps (first', n, 'shown)'), 'time steps'), 'and', ifelse(ncol(df) > n, paste('layers (first', n, 'shown):'), 'layers:'), '\n')
nr <- ifelse(nrow(df) > n, n, nrow(df))
nc <- ifelse(ncol(df) > n, n, ncol(df))
print(df[1:nr, 1:nc], row.names = FALSE)
} else {
vc <- which(oc$save_head)
cat('Simulated heads are written to a', if(oc$head_label) {'labelled'}, ifelse(is.na(oc$chedfm), 'binary', 'formatted'), 'file on unit number', oc$ihedun, 'at following',
ifelse(length(vc) > n, paste('time steps (first', n, 'shown):'), 'time steps:'), '\n')
cat(' ', rmfi_ifelse0(length(vc) > n, c(vc[1:n], '...'), vc), '\n')
}
cat('\n')
}
if(!is.na(oc$iddnun) && any(c(oc$save_drawdown))) {
if(is.matrix(oc$save_drawdown)) {
df <- cbind('Time step' = 1:nrow(oc$save_drawdown), setNames(as.data.frame(oc$save_drawdown), paste('Layer', 1:ncol(oc$save_drawdown))))
cat('Simulated drawdowns are written to a', if(oc$drawdown_label) {'labelled'}, ifelse(is.na(oc$cddnfm), 'binary', 'formatted'), 'file on unit number', oc$iddnun, 'at following',
ifelse(nrow(df) > n, paste('time steps (first', n, 'shown)'), 'time steps'), 'and', ifelse(ncol(df) > n, paste('layers (first', n, 'shown):'), 'layers:'), '\n')
nr <- ifelse(nrow(df) > n, n, nrow(df))
nc <- ifelse(ncol(df) > n, n, ncol(df))
print(df[1:nr, 1:nc], row.names = FALSE)
} else {
vc <- which(oc$save_drawdown)
cat('Simulated drawdowns are written to a', if(oc$drawdown_label) {'labelled'}, ifelse(is.na(oc$cddnfm), 'binary', 'formatted'), 'file on unit number', oc$iddnun, 'at following',
ifelse(length(vc) > n, paste('time steps (first', n, 'shown):'), 'time steps:'), '\n')
cat(' ', rmfi_ifelse0(length(vc) > n, c(vc[1:n], '...'), vc), '\n')
}
cat('\n')
}
if(!is.na(oc$ibouun) && any(c(oc$save_ibound))) {
if(is.matrix(oc$save_ibound)) {
df <- cbind('Time step' = 1:nrow(oc$save_ibound), setNames(as.data.frame(oc$save_ibound), paste('Layer', 1:ncol(oc$save_ibound))))
cat('The ibound array is written to a', if(oc$ibound_label) {'labelled'}, ifelse(is.na(oc$cddnfm), 'binary', 'formatted'), 'file on unit number', oc$iddnun, 'at following',
ifelse(nrow(df) > n, paste('time steps (first', n, 'shown)'), 'time steps'), 'and', ifelse(ncol(df) > n, paste('layers (first', n, 'shown):'), 'layers:'), '\n')
nr <- ifelse(nrow(df) > n, n, nrow(df))
nc <- ifelse(ncol(df) > n, n, ncol(df))
print(df[1:nr, 1:nc], row.names = FALSE)
} else {
vc <- which(oc$save_ibound)
cat('The ibound array is written to a', if(oc$ibound_label) {'labelled'}, ifelse(is.na(oc$cddnfm), 'binary', 'formatted'), 'file on unit number', oc$iddnun, 'at following',
ifelse(length(vc) > n, paste('time steps (first', n, 'shown):'), 'time steps:'), '\n')
cat(' ', rmfi_ifelse0(length(vc) > n, c(vc[1:n], '...'), vc), '\n')
}
cat('\n')
}
if(any(c(oc$save_budget))) {
vc <- which(oc$save_budget)
cat('The', if(oc$compact_budget) {'compacted'}, 'cell-by-cell flow budget', if(oc$aux){'including auxiliary data'}, 'is saved to the binary file(s) specified in the flow and/or stress-packages', 'at following',
ifelse(length(vc) > n, paste('time steps (first', n, 'shown):'), 'time steps:'), '\n')
cat(' ', rmfi_ifelse0(length(vc) > n, c(vc[1:n], '...'), vc), '\n')
cat('\n')
}
# print
if(!is.na(oc$ihedfm) && any(c(oc$print_head))) {
if(is.matrix(oc$print_head)) {
df <- cbind('Time step' = 1:nrow(oc$print_head), setNames(as.data.frame(oc$print_head), paste('Layer', 1:ncol(oc$print_head))))
cat('Simulated heads are printed to the listing file', 'at following',
ifelse(nrow(df) > n, paste('time steps (first', n, 'shown)'), 'time steps'), 'and', ifelse(ncol(df) > n, paste('layers (first', n, 'shown):'), 'layers:'), '\n')
nr <- ifelse(nrow(df) > n, n, nrow(df))
nc <- ifelse(ncol(df) > n, n, ncol(df))
print(df[1:nr, 1:nc], row.names = FALSE)
} else {
vc <- which(oc$print_head)
cat('Simulated heads are printed to the listing file', 'at following',
ifelse(length(vc) > n, paste('time steps (first', n, 'shown):'), 'time steps:'), '\n')
cat(' ', rmfi_ifelse0(length(vc) > n, c(vc[1:n], '...'), vc), '\n')
}
cat('\n')
}
if(!is.na(oc$iddnfm) && any(c(oc$print_drawdown))) {
if(is.matrix(oc$print_drawdown)) {
df <- cbind('Time step' = 1:nrow(oc$print_drawdown), setNames(as.data.frame(oc$print_drawdown), paste('Layer', 1:ncol(oc$print_drawdown))))
cat('Simulated drawdowns are printed to the listing file', 'at following',
ifelse(nrow(df) > n, paste('time steps (first', n, 'shown)'), 'time steps'), 'and', ifelse(ncol(df) > n, paste('layers (first', n, 'shown):'), 'layers:'), '\n')
nr <- ifelse(nrow(df) > n, n, nrow(df))
nc <- ifelse(ncol(df) > n, n, ncol(df))
print(df[1:nr, 1:nc], row.names = FALSE)
} else {
vc <- which(oc$print_drawdown)
cat('Simulated drawdowns are printed to the listing file', 'at following',
ifelse(length(vc) > n, paste('time steps (first', n, 'shown):'), 'time steps:'), '\n')
cat(' ', rmfi_ifelse0(length(vc) > n, c(vc[1:n], '...'), vc), '\n')
}
cat('\n')
}
if(any(c(oc$print_budget))) {
vc <- which(oc$print_budget)
cat('The volumetric budget is printed to the listing file', 'at following',
ifelse(length(vc) > n, paste('time steps (first', n, 'shown):'), 'time steps:'), '\n')
cat(' ', rmfi_ifelse0(length(vc) > n, c(vc[1:n], '...'), vc), '\n')
cat('\n')
}
} else { # codes
# save
if(!is.na(oc$ihedun) && oc$ihedun > 0 && sum(oc$ihddfl) != 0 && any(c(oc$hdsv) != 0, na.rm = TRUE)) {
if(sum(oc$incode) > 0) {
df <- cbind('Time step' = 1:nrow(oc$hdsv), setNames(as.data.frame(oc$hdsv), paste('Layer', 1:ncol(oc$hdsv))))
cat('Simulated heads are written to a binary file on unit number', oc$ihedun, 'at following',
ifelse(nrow(df) > n, paste('time steps (first', n, 'shown)'), 'time steps'), 'and', ifelse(ncol(df) > n, paste('layers (first', n, 'shown):'), 'layers:'), '\n')
nr <- ifelse(nrow(df) > n, n, nrow(df))
nc <- ifelse(ncol(df) > n, n, ncol(df))
print(df[1:nr, 1:nc], row.names = FALSE)
} else {
vc <- which(oc$hdsv[,1] != 0)
cat('Simulated heads are written to a binary file on unit number', oc$ihedun, 'at following',
ifelse(length(vc) > n, paste('time steps (first', n, 'shown):'), 'time steps:'), '\n')
cat(' ', rmfi_ifelse0(length(vc) > n, c(vc[1:n], '...'), vc), '\n')
}
cat('\n')
}
if(!is.na(oc$iddnun) && oc$iddnun > 0 && sum(oc$ihddfl) != 0 && any(c(oc$ddsv) != 0, na.rm = TRUE)) {
if(sum(oc$incode) > 0) {
df <- cbind('Time step' = 1:nrow(oc$ddsv), setNames(as.data.frame(oc$ddsv), paste('Layer', 1:ncol(oc$ddsv))))
cat('Simulated heads are written to a binary file on unit number', oc$iddnun, 'at following',
ifelse(nrow(df) > n, paste('time steps (first', n, 'shown)'), 'time steps'), 'and', ifelse(ncol(df) > n, paste('layers (first', n, 'shown):'), 'layers:'), '\n')
nr <- ifelse(nrow(df) > n, n, nrow(df))
nc <- ifelse(ncol(df) > n, n, ncol(df))
print(df[1:nr, 1:nc], row.names = FALSE)
} else {
vc <- which(oc$ddsv[,1] != 0)
cat('Simulated heads are written to a binary file on unit number', oc$iddnun, 'at following',
ifelse(length(vc) > n, paste('time steps (first', n, 'shown):'), 'time steps:'), '\n')
cat(' ', rmfi_ifelse0(length(vc) > n, c(vc[1:n], '...'), vc), '\n')
}
cat('\n')
}
if(sum(oc$icbcfl) != 0) {
vc <- which(oc$icbcfl != 0)
cat('The cell-by-cell flow budget is saved to the binary file(s) specified in the flow and/or stress-packages', 'at following',
ifelse(length(vc) > n, paste('time steps (first', n, 'shown):'), 'time steps:'), '\n')
cat(' ', rmfi_ifelse0(length(vc) > n, c(vc[1:n], '...'), vc), '\n')
cat('\n')
}
# print
if(sum(oc$ihddfl, na.rm = TRUE) != 0 && any(c(oc$hdpr) != 0, na.rm = TRUE)) {
if(sum(oc$incode) > 0) {
df <- cbind('Time step' = 1:nrow(oc$hdpr), setNames(as.data.frame(oc$hdpr), paste('Layer', 1:ncol(oc$hdpr))))
cat('Simulated heads are printed to the listing file', 'at following',
ifelse(nrow(df) > n, paste('time steps (first', n, 'shown)'), 'time steps'), 'and', ifelse(ncol(df) > n, paste('layers (first', n, 'shown):'), 'layers:'), '\n')
nr <- ifelse(nrow(df) > n, n, nrow(df))
nc <- ifelse(ncol(df) > n, n, ncol(df))
print(df[1:nr, 1:nc], row.names = FALSE)
} else {
vc <- which(oc$hdpr[,1] != 0)
cat('Simulated heads are printed to the listing file', 'at following',
ifelse(length(vc) > n, paste('time steps (first', n, 'shown):'), 'time steps:'), '\n')
cat(' ', rmfi_ifelse0(length(vc) > n, c(vc[1:n], '...'), vc), '\n')
}
cat('\n')
}
if(sum(oc$ihddfl) != 0 && any(c(oc$ddpr) != 0, na.rm = TRUE)) {
if(sum(oc$incode) > 0) {
df <- cbind('Time step' = 1:nrow(oc$ddpr), setNames(as.data.frame(oc$ddpr), paste('Layer', 1:ncol(oc$ddpr))))
cat('Simulated drawdowns are printed to the listing file', 'at following',
ifelse(nrow(df) > n, paste('time steps (first', n, 'shown)'), 'time steps'), 'and', ifelse(ncol(df) > n, paste('layers (first', n, 'shown):'), 'layers:'), '\n')
nr <- ifelse(nrow(df) > n, n, nrow(df))
nc <- ifelse(ncol(df) > n, n, ncol(df))
print(df[1:nr, 1:nc], row.names = FALSE)
} else {
vc <- which(oc$ddpr[,1] != 0)
cat('Simulated drawdowns are printed to the listing file', 'at following',
ifelse(length(vc) > n, paste('time steps (first', n, 'shown):'), 'time steps:'), '\n')
cat(' ', rmfi_ifelse0(length(vc) > n, c(vc[1:n], '...'), vc), '\n')
}
cat('\n')
}
if(sum(oc$ibudfl) != 0) {
vc <- which(oc$ibudfl != 0)
cat('The volumetric budget is printed to the listing file', 'at following',
ifelse(length(vc) > n, paste('time steps (first', n, 'shown):'), 'time steps:'), '\n')
cat(' ', rmfi_ifelse0(length(vc) > n, c(vc[1:n], '...'), vc), '\n')
cat('\n')
}
}
}
#' @export
print.wel <- function(wel, n = 15) {
i_parm <- nrow(subset(wel$data, parameter == TRUE))
i_noparm <- nrow(subset(wel$data, parameter == FALSE))
cat('RMODFLOW Well object with:', '\n')
if(wel$np > 0) cat(wel$np, if(!is.null(wel$instances)) {'time-varying'}, 'parameters representing', i_parm, 'wells', '\n')
cat(i_noparm, 'non-parameter wells', '\n')
if(!is.null(wel$aux)) cat('Auxiliary variables defined:', wel$aux, '\n')
cat('\n')
cat(rmfi_ifelse0(wel$iwelcb == 0, 'WEL fluxes are not saved to a cell-by-cell flow budget file', c('WELs fluxes are saved to the cell-by-cell flow budget file on unit number', wel$iwelcb)), '\n')
cat('\n')
cat(rmfi_ifelse0(nrow(wel$data) > n, c('Summary of the first', n, 'defined wells:'), 'Summary of the defined wells:'), '\n')
rmfi_ifelse0(nrow(wel$data) > n, print(as.data.frame(wel$data)[1:n, ]), print(as.data.frame(wel$data)))
cat('\n')
cat('Summary of the stress-period', rmfi_ifelse0(nrow(wel$kper) > n, c('information (first', n, 'stress-periods shown):'), 'information:'), '\n')
rmfi_ifelse0(nrow(wel$kper) > n, print(wel$kper[1:n, ]), print(wel$kper))
}
#' @export
print.ghb <- function(ghb, n = 15) {
i_parm <- nrow(subset(ghb$data, parameter == TRUE))
i_noparm <- nrow(subset(ghb$data, parameter == FALSE))
cat('RMODFLOW General-Head Boundary object with:', '\n')
if(ghb$np > 0) cat(ghb$np, if(!is.null(ghb$instances)) {'time-varying'}, 'parameters representing', i_parm, 'general-head boundaries', '\n')
cat(i_noparm, 'non-parameter general-head boundaries', '\n')
if(!is.null(ghb$aux)) cat('Auxiliary variables defined:', ghb$aux, '\n')
cat('\n')
cat(rmfi_ifelse0(ghb$ighbcb == 0, 'GHB fluxes are not saved to a cell-by-cell flow budget file', c('GHB fluxes are saved to the cell-by-cell flow budget file on unit number', ghb$ighbcb)), '\n')
cat('\n')
cat(rmfi_ifelse0(nrow(ghb$data) > n, c('Summary of the first', n, 'defined general-head boundaries:'), 'Summary of the defined general-head boundaries:'), '\n')
rmfi_ifelse0(nrow(ghb$data) > n, print(as.data.frame(ghb$data)[1:n, ]), print(as.data.frame(ghb$data)))
cat('\n')
cat('Summary of the stress-period', rmfi_ifelse0(nrow(ghb$kper) > n, c('information (first', n, 'stress-periods shown):'), 'information:'), '\n')
rmfi_ifelse0(nrow(ghb$kper) > n, print(ghb$kper[1:n, ]), print(ghb$kper))
}
#' @export
print.pcg <- function(pcg) {
cat('RMODFLOW Preconditioned Conjugate-Gradient Package object with:', '\n')
cat('A maximum of', pcg$mxiter, 'outer iterations with', pcg$iter1, 'inner iterations using the', '\n')
cat(ifelse(pcg$npcond == 1, 'Modified Incomplete Cholesky', 'Polynomial'), 'matrix conditioning method.', '\n')
cat('\n')
cat('Head change criterion for convergence:', pcg$hclose, '\n')
cat('Residual criterion for convergence:', pcg$rclose, '\n')
cat('\n')
if(pcg$npcond == 1) {
cat('The relaxation parameter for the matrix conditioning is', pcg$relax, '\n')
} else {
cat('The upper bound on the maximum eigenvalue for the matrix conditioning', ifelse(pcg$nbpol == 2, 'is 2.0', 'will be calculated'), '\n')
}
cat('Maximum head change and residual change are printed to the listing file at every', ifelse(pcg$iprpcg == 0, '999', pcg$iprpcg), 'time steps', '\n')
cat('The damping factor', ifelse(pcg$damppcg > 0, 'for steady-state & transient stress periods is', 'for steady-state stress periods is'), abs(pcg$damppcg), '\n')
if(pcg$damppcg < 0 && !is.null(pcg$damppcgt)) cat('The damping factor for transient stress periods is', pcg$damppcgt, '\n')
}
#' @export
print.kdep <- function(kdep, n = 10) {
cat('RMODFLOW Hydraulic-Conductivity Depth-Dependence Capability object with:', '\n')
cat(kdep$npkdep, ifelse(kdep$npkdep > 1, 'parameters', 'parameter'), '\n')
cat('Parameters represent depth-dependence coefficients used to modify horizontal hydraulic conductivity with depth for the hydrogeologic unit(s) specified in the HUF package', '\n')
cat('The reference surface elevation is specified by', ifelse(kdep$ifkdep == 0, 'the TOP array in the dis object', 'the RS array specified below'), '\n')
cat('\n')
if(kdep$ifkdep > 0) {
cat('Summary of the reference surface elevations:', '\n')
c(kdep$rs) %>% as.data.frame() %>% setNames('RS') %>% summary() %>% print
cat('\n')
}
# Parameters
pdf <- data.frame('Name' = vapply(kdep$parameters, function(i) attr(i, 'parnam'), 'txt'),
'Unit' = vapply(kdep$parameters, function(i) attr(i, 'hgunam'), 'txt'),
'Value' = vapply(kdep$parameters, function(i) attr(i, 'parval'), 1),
stringsAsFactors = FALSE)
if(nrow(pdf) > n) {
cat('Parameter overview (first', n, 'parameters): ', '\n')
nlay <- n
} else {
cat('Parameter overview:', '\n')
nlay <- nrow(pdf)
}
print(pdf[1:nlay,], row.names = FALSE)
cat('\n')
}
#' @export
print.lpf <- function(lpf, n = 5) {
cat('RMODFLOW Layer-Property Flow Package object with:', '\n')
if(lpf$nplpf > 0) cat(lpf$nplpf, ifelse(lpf$nplpf > 1 , 'flow parameters', 'flow parameter'), '\n')
cat('Cell-by-cell flow terms', ifelse(lpf$ilpfcb == 0, 'not written',
ifelse(lpf$ilpfcb > 0, paste('written to file number', lpf$ilpfcb),
'(only flow between constant-head cells) printed to the listing file')), '\n')
cat('Dry cells are assigned a head value of', lpf$hdry, '\n')
cat('\n')
# options
if(lpf$storagecoefficient) cat('Ss values are read as storage coefficients rather than specific storage', '\n')
if(lpf$constantcv) cat('Vertical conductance for an unconfined cell is computed from the cell thickness rather than the saturated thickness', '\n')
if(lpf$thickstrt) cat('Layers with a negative LAYTYP are confined and have their cell thickness for conductance calculations computed from STRT-BOTM rather than TOP-BOTM', '\n')
if(lpf$nocvcorrection | lpf$constantcv) cat('Vertical conductance is not corrected when the vertical flow correction is applied', '\n')
if(lpf$novfc) cat('The vertical flow correction under dewatered conditions is turned off', '\n')
if(lpf$noparcheck) cat('There is no check to see if a variable is defined for all cells when parameters are used', '\n')
if(lpf$storagecoefficient + lpf$constantcv + lpf$thickstrt + lpf$nocvcorrection + lpf$novfc + lpf$noparcheck > 0) cat('\n')
# Layer overview
ll <- data.frame('Layer' = 1:length(lpf$laytyp), 'Type' = 'Confined', 'Averaging' = 'Harmonic',
'CHANI' = 'HANI', 'VKA' = 'VK', 'Wetting' = 'Inactive', stringsAsFactors = FALSE)
ll$Type[which(lpf$laytyp != 0)] <- 'Convertible'
if(lpf$thickstrt) {
ll$Type[which(lpf$laytyp < 0)] <- 'Confined (thickstrt)'
lpf$laytyp[which(lpf$laytyp < 0)] <- 0
}
avg <- c('Harmonic', 'Logarithmic', 'Arithmetic THCK + Log K')
ll$Averaging <- avg[lpf$layavg + 1]
ll$CHANI <- replace(ll$CHANI, which(lpf$chani > 0), lpf$chani[which(lpf$chani > 0)])
ll$VKA <- replace(ll$VKA, which(lpf$layvka != 0), 'VANI')
ll$Wetting[which(lpf$laywet != 0)] <- 'Active'
if(length(lpf$laytyp) > n) {
cat('Layer overview (first', n, 'layers): ', '\n')
nlay <- n
} else {
cat('Layer overview:', '\n')
nlay <- length(lpf$laytyp)
}
print(ll[1:nlay,], row.names = FALSE)
cat('\n')
# Wetting
if(any(lpf$laywet != 0)) {
cat('Wetting factor:', lpf$wetfct, '\n')
cat('Wetting is attempted every', ifelse(lpf$iwetit == 1, 'interval', paste(lpf$iwetit, 'intervals')), '\n')
cat('Initial heads at cells that become wet are defined using equation', ifelse(lpf$ihdwet == 0, '3a', '3b'), '(see MODFLOW manual)', '\n')
cat('\n')
}
# Parameters
if(lpf$nplpf > 0) {
pdf <- data.frame('Name' = vapply(lpf$parameters, function(i) attr(i, 'parnam'), 'txt'),
'Type' = vapply(lpf$parameters, function(i) attr(i, 'partyp'), 'txt'),
'Layer' = vapply(lpf$parameters, function(i) paste(attr(i, 'layer'), collapse = ' '), 'text'),
'Value' = vapply(lpf$parameters, function(i) attr(i, 'parval'), 1),
stringsAsFactors = FALSE)
if(nrow(pdf) > n) {
cat('Parameter overview (first', n, 'parameters): ', '\n')
nlay <- n
} else {
cat('Parameter overview:', '\n')
nlay <- nrow(pdf)
}
print(pdf[1:nlay,], row.names = FALSE)
cat('\n')
}
# HK
if(length(lpf$laytyp) > n) {
cat('Summary of HK (first', n, 'layers):', '\n')
nlay <- n
} else {
cat('Summary of HK:', '\n')
nlay <- length(lpf$laytyp)
}
apply(lpf$hk, 3, function(i) summary(c(i))) %>% as.data.frame() %>%
setNames(paste('Layer', 1:length(lpf$laytyp))) %>% subset(select = 1:nlay) %>% print()
cat('\n')
# HANI
if(!is.null(lpf$hani)) {
if(length(lpf$laytyp) > n) {
cat('Summary of HANI (first', n, 'layers):', '\n')
nlay <- n
} else {
cat('Summary of HANI:', '\n')
nlay <- length(lpf$laytyp)
}
apply(lpf$hani, 3, function(i) summary(c(i))) %>% as.data.frame() %>%
setNames(paste('Layer', 1:length(lpf$laytyp))) %>% subset(select = 1:nlay) %>% print()
cat('\n')
}
# VKA
if(!is.null(lpf$vka)) {
if(length(lpf$laytyp) > n) {
cat('Summary of VKA (first', n, 'layers):', '\n')
nlay <- n
} else {
cat('Summary of VKA:', '\n')
nlay <- length(lpf$laytyp)
}
apply(lpf$vka, 3, function(i) summary(c(i))) %>% as.data.frame() %>%
setNames(paste('Layer', 1:length(lpf$laytyp))) %>% subset(select = 1:nlay) %>% print()
cat('\n')
}
# SS
if(!is.null(lpf$ss)) {
if(length(lpf$laytyp) > n) {
cat('Summary of SS (first', n, 'layers):', '\n')
nlay <- n
} else {
cat('Summary of SS:', '\n')
nlay <- length(lpf$laytyp)
}
apply(lpf$ss, 3, function(i) summary(c(i))) %>% as.data.frame() %>%
setNames(paste('Layer', 1:length(lpf$laytyp))) %>% subset(select = 1:nlay) %>% print()
cat('\n')
}
# SY
if(!is.null(lpf$sy)) {
sy <- lpf$sy[,,which(lpf$laytyp != 0)]
if(length(dim(sy)) == 2) sy <- rmf_create_array(sy, dim = c(dim(sy), 1))
if(dim(sy)[3] > n) {
cat('Summary of SY (first', n, 'layers):', '\n')
nlay <- n
} else {
cat('Summary of SY:', '\n')
nlay <- dim(sy)[3]
}
names_sy <- paste('Layer', which(lpf$laytyp != 0))
apply(sy, 3, function(i) summary(c(i))) %>% as.data.frame() %>%
setNames(names_sy) %>% subset(select = 1:nlay) %>% print()
cat('\n')
}
# VKCB
if(!is.null(lpf$vkcb)) {
if(length(lpf$laytyp) > n) {
cat('Summary of VKCB (first', n, 'layers):', '\n')
nlay <- n
} else {
cat('Summary of VKCB:', '\n')
nlay <- length(lpf$laytyp)
}
apply(lpf$vkcb, 3, function(i) summary(c(i))) %>% as.data.frame() %>%
setNames(paste('Layer', 1:length(lpf$laytyp))) %>% subset(select = 1:nlay) %>% print()
cat('\n')
}
# WETDRY
if(!is.null(lpf$wetdry)) {
wetdry <- lpf$wetdry[,,which(lpf$laywet != 0)]
if(length(dim(wetdry)) == 2) wetdry <- rmf_create_array(wetdry, dim = c(dim(wetdry), 1))
if(dim(wetdry)[3] > n) {
cat('Summary of WETDRY (first', n ,'layers):', '\n')
nlay <- n
} else {
cat('Summary of WETDRY:', '\n')
nlay <- dim(wetdry)[3]
}
names_wetdry <- paste('Layer', which(lpf$laywet != 0))
apply(wetdry, 3, function(i) summary(c(i))) %>% as.data.frame() %>%
setNames(names_wetdry) %>% subset(select = 1:nlay) %>% print()
cat('\n')
}
}
#' @export
print.rch <- function(rch, n = 5) {
cat('RMODFLOW Recharge Package object with:', '\n')
cat(length(rch$recharge), 'recharge', ifelse(length(rch$recharge) > 1, 'arrays', 'array'), '\n')
if(rch$np > 0) cat('including', rch$np, if(!is.null(rch$instances)) {'time-varying'}, ifelse(rch$np == 1, 'parameter', 'parameters'), '\n')
if(rch$nrchop == 1) {
nrchop <- 'the top grid layer'
} else if(rch$nrchop == 2) {
nrchop <- 'the cells defined by layer variable irch'
} else if(rch$nrchop == 3) {
nrchop <- 'the highest active cell in each vertical column'
}
cat('Recharge applied to', nrchop, '\n')
cat('\n')
cat(rmfi_ifelse0(rch$irchcb == 0, 'RCH fluxes are not saved to a cell-by-cell flow budget file', c('RCH fluxes are saved to the cell-by-cell flow budget file on unit number', rch$irchcb)), '\n')
cat('\n')
# for time-varing parameters
list_arrays <- function(i) {
if(is.list(i) && !is.null(attr(i[[1]], 'instnam'))) {
return(i)
} else {
return(list(i))
}
}
rmf_arrays <- lapply(rch$recharge, list_arrays)
rmf_arrays <- do.call(c, rmf_arrays)
# recharge
if(length(rmf_arrays) > n) {
cat('Summary of recharge (first', n, 'arrays):', '\n')
nlay <- n
} else {
cat('Summary of recharge arrays:', '\n')
nlay <- length(rmf_arrays)
}
abind::abind(rmf_arrays, along = 3) %>%
apply(3, function(i) summary(c(i))) %>% as.data.frame() %>%
setNames(names(rmf_arrays)) %>% subset(select = 1:nlay) %>% print()
# irch
if(rch$nrchop == 2) {
cat('\n')
if(length(rch$irch) > n) {
cat('Summary of irch (first', n, 'arrays):', '\n')
nlay <- n
} else {
cat('Summary of irch arrays:', '\n')
nlay <- length(rch$irch)
}
abind::abind(rch$irch, along = 3) %>%
apply(3, function(i) summary(c(i))) %>% as.data.frame() %>%
setNames(names(rch$irch)) %>% subset(select = 1:nlay) %>% print()
}
cat('\n')
cat('Summary of the stress-period', rmfi_ifelse0(nrow(rch$kper) > n, c('information (first', n, 'stress-periods shown):'), 'information:'), '\n')
rmfi_ifelse0(nrow(rch$kper) > n, print(rch$kper[1:n, ]), print(rch$kper))
}
#' @export
print.chd <- function(chd, n = 15) {
i_parm <- nrow(subset(chd$data, parameter == TRUE))
i_noparm <- nrow(subset(chd$data, parameter == FALSE))
cat('RMODFLOW Time-Varying Specified Head object with:', '\n')
if(chd$np > 0) cat(chd$np, if(!is.null(chd$instances)) {'time-varying'}, 'parameters representing', i_parm, 'specified-heads', '\n')
cat(i_noparm, 'non-parameter specified-heads', '\n')
if(!is.null(chd$aux)) cat('Auxiliary variables defined:', chd$aux, '\n')
cat('\n')
# cat(rmfi_ifelse0(chd$ichdcb == 0, 'CHD fluxes are not saved to a cell-by-cell flow budget file', c('CHD fluxes are saved to the cell-by-cell flow budget file on unit number', chd$ichdcb)), '\n')
# cat('\n')
cat(rmfi_ifelse0(nrow(chd$data) > n, c('Summary of the first', n, 'defined specified-heads:'), 'Summary of the defined specified-heads:'), '\n')
rmfi_ifelse0(nrow(chd$data) > n, print(as.data.frame(chd$data)[1:n, ]), print(as.data.frame(chd$data)))
cat('\n')
cat('Summary of the stress-period', rmfi_ifelse0(nrow(chd$kper) > n, c('information (first', n, 'stress-periods shown):'), 'information:'), '\n')
rmfi_ifelse0(nrow(chd$kper) > n, print(chd$kper[1:n, ]), print(chd$kper))
}
#' @export
print.bcf <- function(bcf, n = 5) {
cat('RMODFLOW Block-Centered Flow Package object with:', '\n')
cat('Cell-by-cell flow terms', ifelse(bcf$ibcfcb == 0, 'not written',
ifelse(bcf$ibcfcb > 0, paste('written to file number', bcf$ibcfcb),
'(only flow between constant-head cells) printed to the listing file')), '\n')
cat('Dry cells are assigned a head value of', bcf$hdry, '\n')
cat('Wetting is', ifelse(bcf$iwdflg == 0, 'inactive', 'active'), '\n')
if(bcf$iwdflg != 0) {
cat('Wetting factor:', bcf$wetfct, '\n')
cat('Wetting is attempted every', ifelse(bcf$iwetit == 1, 'interval', paste(bcf$iwetit, 'intervals')), '\n')
cat('Initial heads at cells that become wet are defined using equation', ifelse(bcf$ihdwet == 0, '3a', '3b'), '(see MODFLOW manual)', '\n')
}
cat('\n')
# Layer overview
ll <- data.frame('Layer' = 1:length(bcf$layavg), 'Type' = 'Confined', 'Averaging' = 'Harmonic', 'TRPY' = bcf$trpy, stringsAsFactors = FALSE)
type <- c('Confined', 'Unconfined', 'Confined/unconfined (constant T)', 'Confined/unconfined (T varies)')
ll$Type <- type[bcf$laycon + 1]
avg <- c('Harmonic', 'Arithmetic', 'Logarithmic', 'Arithmetic THCK + Log K')
ll$Averaging <- avg[bcf$layavg + 1]
if(length(bcf$layavg) > n) {
cat('Layer overview (first', n, 'layers): ', '\n')
nlay <- n
} else {
cat('Layer overview:', '\n')
nlay <- length(bcf$layavg)
}
print(ll[1:nlay,], row.names = FALSE)
cat('\n')
# HY
if(!is.null(bcf$hy)) {
hy <- bcf$hy[,,which(bcf$laycon %in% c(1,3))]
if(length(dim(hy)) == 2) hy <- rmf_create_array(hy, dim = c(dim(hy), 1))
if(dim(hy)[3] > n) {
cat('Summary of HY (first', n, 'layers):', '\n')
nlay <- n
} else {
cat('Summary of HY:', '\n')
nlay <- dim(hy)[3]
}
names <- paste('Layer', which(bcf$laycon %in% c(1,3)))
apply(hy, 3, function(i) summary(c(i))) %>% as.data.frame() %>%
setNames(names) %>% subset(select = 1:nlay) %>% print()
cat('\n')
}
# TRAN
if(!is.null(bcf$tran)) {
tran <- bcf$tran[,,which(bcf$laycon %in% c(0,2))]
if(length(dim(tran)) == 2) tran <- rmf_create_array(tran, dim = c(dim(tran), 1))
if(dim(tran)[3] > n) {
cat('Summary of TRAN (first', n, 'layers):', '\n')
nlay <- n
} else {
cat('Summary of TRAN:', '\n')
nlay <- dim(tran)[3]
}
names <- paste('Layer', which(bcf$laycon %in% c(0,2)))
apply(tran, 3, function(i) summary(c(i))) %>% as.data.frame() %>%
setNames(names) %>% subset(select = 1:nlay) %>% print()