@@ -656,3 +656,105 @@ def test_read_mf6_budgetfile(example_data_path):
656
656
assert len (rch_zone_1 ) == 120 * 3 + 1
657
657
assert len (rch_zone_2 ) == 120 * 3 + 1
658
658
assert len (rch_zone_3 ) == 120 * 3 + 1
659
+
660
+
661
+ def test_cellbudgetfile_get_ts_auxiliary_variables (example_data_path ):
662
+ from flopy .discretization import StructuredGrid
663
+
664
+ mf2005_model_path = example_data_path / "mf2005_test"
665
+ cbc_fname = mf2005_model_path / "test1tr.gitcbc"
666
+
667
+ # modelgrid for test1tr (1 layer, 15 rows, 10 cols)
668
+ modelgrid = StructuredGrid (nrow = 15 , ncol = 10 , nlay = 1 )
669
+
670
+ with CellBudgetFile (cbc_fname , modelgrid = modelgrid ) as v :
671
+ node = 54 - 1
672
+ k = node // (15 * 10 )
673
+ i = (node % (15 * 10 )) // 10
674
+ j = node % 10
675
+
676
+ ts_default = v .get_ts (idx = (k , i , j ), text = "WELLS" )
677
+ ts_q_explicit = v .get_ts (idx = (k , i , j ), text = "WELLS" , variable = "q" )
678
+ assert ts_default .shape [1 ] == 2 # time + 1 data column
679
+ np .testing .assert_array_equal (ts_default , ts_q_explicit )
680
+
681
+ ts_iface = v .get_ts (idx = (k , i , j ), text = "WELLS" , variable = "IFACE" )
682
+ assert ts_iface .shape [1 ] == 2 # time + 1 data column
683
+ assert not np .array_equal (ts_default [:, 1 ], ts_iface [:, 1 ])
684
+ np .testing .assert_array_equal (ts_default [:, 0 ], ts_iface [:, 0 ])
685
+
686
+
687
+ @pytest .mark .requires_exe ("mf6" )
688
+ def test_cellbudgetfile_get_ts_spdis_auxiliary_variables (function_tmpdir ):
689
+ from flopy .mf6 import (
690
+ MFSimulation ,
691
+ ModflowGwf ,
692
+ ModflowGwfchd ,
693
+ ModflowGwfdis ,
694
+ ModflowGwfic ,
695
+ ModflowGwfnpf ,
696
+ ModflowGwfoc ,
697
+ ModflowIms ,
698
+ ModflowTdis ,
699
+ )
700
+
701
+ sim_name = "spdis_test"
702
+ sim = MFSimulation (sim_name = sim_name , sim_ws = function_tmpdir , exe_name = "mf6" )
703
+ tdis = ModflowTdis (sim , nper = 2 , perioddata = [(1.0 , 1 , 1.0 ), (1.0 , 1 , 1.0 )])
704
+ ims = ModflowIms (sim )
705
+ gwf = ModflowGwf (sim , modelname = sim_name , save_flows = True )
706
+ nrow , ncol , nlay = 5 , 5 , 1
707
+ dis = ModflowGwfdis (
708
+ gwf ,
709
+ nrow = nrow ,
710
+ ncol = ncol ,
711
+ nlay = nlay ,
712
+ delr = 10.0 ,
713
+ delc = 10.0 ,
714
+ top = 10.0 ,
715
+ botm = [0.0 ],
716
+ )
717
+ ic = ModflowGwfic (gwf , strt = 5.0 )
718
+ npf = ModflowGwfnpf (gwf , k = 1.0 , save_specific_discharge = True )
719
+ chd_spd = [[(0 , 0 , 0 ), 10.0 ], [(0 , 4 , 4 ), 0.0 ]]
720
+ chd = ModflowGwfchd (gwf , stress_period_data = chd_spd )
721
+ budget_file = f"{ sim_name } .cbc"
722
+ head_file = f"{ sim_name } .hds"
723
+ oc = ModflowGwfoc (
724
+ gwf ,
725
+ budget_filerecord = budget_file ,
726
+ head_filerecord = head_file ,
727
+ saverecord = [("HEAD" , "ALL" ), ("BUDGET" , "ALL" )],
728
+ )
729
+
730
+ sim .write_simulation ()
731
+ success , _ = sim .run_simulation (silent = True )
732
+
733
+ cbc_file = function_tmpdir / budget_file
734
+ with CellBudgetFile (cbc_file , modelgrid = gwf .modelgrid ) as cbc :
735
+ spdis_data = cbc .get_data (text = "DATA-SPDIS" )
736
+ if len (spdis_data ) == 0 :
737
+ pytest .skip ("No DATA-SPDIS records found" )
738
+
739
+ available_fields = list (spdis_data [0 ].dtype .names )
740
+ expected_fields = ["node" , "q" , "qx" , "qy" , "qz" ]
741
+
742
+ for field in ["qx" , "qy" , "qz" ]:
743
+ assert field in available_fields , (
744
+ f"Expected field '{ field } ' not found in { available_fields } "
745
+ )
746
+
747
+ test_cell = (0 , 2 , 2 )
748
+ ts_q = cbc .get_ts (idx = test_cell , text = "DATA-SPDIS" , variable = "q" )
749
+ ts_qx = cbc .get_ts (idx = test_cell , text = "DATA-SPDIS" , variable = "qx" )
750
+ ts_qy = cbc .get_ts (idx = test_cell , text = "DATA-SPDIS" , variable = "qy" )
751
+ ts_qz = cbc .get_ts (idx = test_cell , text = "DATA-SPDIS" , variable = "qz" )
752
+
753
+ assert ts_q .shape [1 ] == 2 # time + 1 data column
754
+ assert ts_qx .shape [1 ] == 2
755
+ assert ts_qy .shape [1 ] == 2
756
+ assert ts_qz .shape [1 ] == 2
757
+
758
+ np .testing .assert_array_equal (ts_q [:, 0 ], ts_qx [:, 0 ])
759
+ np .testing .assert_array_equal (ts_q [:, 0 ], ts_qy [:, 0 ])
760
+ np .testing .assert_array_equal (ts_q [:, 0 ], ts_qz [:, 0 ])
0 commit comments