@@ -687,6 +687,47 @@ def test_cellbudgetfile_get_ts_aux_vars_mf2005(example_data_path):
687687 assert np .array_equal (ts_default [:, 0 ], ts_iface [:, 0 ], equal_nan = True )
688688
689689
690+ def test_cellbudgetfile_get_ts_aux_vars_mf6_readme_example (function_tmpdir ):
691+ from flopy .mf6 import (
692+ MFSimulation ,
693+ ModflowGwf ,
694+ ModflowGwfchd ,
695+ ModflowGwfdis ,
696+ ModflowGwfic ,
697+ ModflowGwfnpf ,
698+ ModflowGwfoc ,
699+ ModflowIms ,
700+ ModflowTdis ,
701+ )
702+
703+ name = 'mymodel'
704+ sim = MFSimulation (sim_name = name , sim_ws = function_tmpdir , exe_name = 'mf6' )
705+ tdis = ModflowTdis (sim )
706+ ims = ModflowIms (sim )
707+ gwf = ModflowGwf (sim , modelname = name , save_flows = True )
708+ dis = ModflowGwfdis (gwf , nrow = 10 , ncol = 10 )
709+ ic = ModflowGwfic (gwf )
710+ npf = ModflowGwfnpf (gwf , save_specific_discharge = True )
711+ chd = ModflowGwfchd (gwf , stress_period_data = [[(0 , 0 , 0 ), 1. ],
712+ [(0 , 9 , 9 ), 0. ]])
713+ budget_file = name + '.bud'
714+ head_file = name + '.hds'
715+ oc = ModflowGwfoc (gwf ,
716+ budget_filerecord = budget_file ,
717+ head_filerecord = head_file ,
718+ saverecord = [('HEAD' , 'ALL' ), ('BUDGET' , 'ALL' )])
719+ sim .write_simulation (silent = True )
720+ sim .run_simulation (silent = True )
721+
722+ hds = gwf .output .head ().get_data ()
723+ cbc = gwf .output .budget ()
724+
725+ cellid = (0 ,5 ,5 )
726+
727+ head = hds .get_ts (idx = cellid )
728+ spdis = cbc .get_ts (idx = cellid , text = 'DATA-SPDIS' )
729+
730+
690731@pytest .fixture
691732def dis_sim (function_tmpdir ):
692733 from flopy .mf6 import (
@@ -742,54 +783,61 @@ def test_cellbudgetfile_get_ts_aux_vars_mf6_dis(dis_sim):
742783
743784 gwf = sim .get_model ()
744785 cbc = gwf .output .budget ()
745- spdis = cbc .get_data (text = "DATA-SPDIS" )
746- available_fields = list (spdis [0 ].dtype .names )
747- expected_fields = ["node" , "q" , "qx" , "qy" , "qz" ]
748- for field in expected_fields :
749- assert field in available_fields
750786
751787 cellid = (0 , 2 , 2 )
752788 nn = gwf .modelgrid .get_node (cellid )[0 ]
753789
754- ts_q = cbc . get_ts ( idx = cellid , text = "DATA-SPDIS" , variable = "q" )
755- ts_qx = cbc .get_ts ( idx = cellid , text = "DATA-SPDIS" , variable = "qx" )
756- ts_qy = cbc . get_ts ( idx = cellid , text = "DATA-SPDIS " , variable = " qy")
757- ts_qz = cbc . get_ts ( idx = cellid , text = "DATA-SPDIS" , variable = "qz" )
790+ text = "DATA-SPDIS"
791+ spdis = cbc .get_data ( text = text )
792+ for field in [ "node" , "q " , "qx" , " qy", "qz" ]:
793+ assert field in spdis [ 0 ]. dtype . names
758794
759- assert ts_q .shape == ts_qx .shape == ts_qy .shape == ts_qz .shape
760- assert ts_q .shape [1 ] == 2 # time + 1 data column
761- assert ts_qx .shape [1 ] == 2
762- assert ts_qy .shape [1 ] == 2
763- assert ts_qz .shape [1 ] == 2
795+ text = "CHD"
796+ chd = cbc .get_data (text = text )
797+ for field in ["node" , "node2" , "q" ]:
798+ assert field in chd [0 ].dtype .names
799+
800+ spdis_q = cbc .get_ts (idx = cellid , text = text , variable = "q" )
801+ spdis_qx = cbc .get_ts (idx = cellid , text = text , variable = "qx" )
802+ spdis_qy = cbc .get_ts (idx = cellid , text = text , variable = "qy" )
803+ spdis_qz = cbc .get_ts (idx = cellid , text = text , variable = "qz" )
804+
805+ chd_q = cbc .get_ts (idx = cellid , )
806+
807+ assert spdis_q .shape == spdis_qx .shape == spdis_qy .shape == spdis_qz .shape
808+ assert spdis_q .shape [1 ] == 2 # time + 1 data column
809+ assert spdis_qx .shape [1 ] == 2
810+ assert spdis_qy .shape [1 ] == 2
811+ assert spdis_qz .shape [1 ] == 2
764812
765- assert np .array_equal (ts_q [:, 0 ], ts_qx [:, 0 ])
766- assert np .array_equal (ts_q [:, 0 ], ts_qy [:, 0 ])
767- assert np .array_equal (ts_q [:, 0 ], ts_qz [:, 0 ])
813+ assert np .array_equal (spdis_q [:, 0 ], spdis_qx [:, 0 ])
814+ assert np .array_equal (spdis_q [:, 0 ], spdis_qy [:, 0 ])
815+ assert np .array_equal (spdis_q [:, 0 ], spdis_qz [:, 0 ])
768816
769817 # check get_ts() values match get_data() for each time step
770818 for i , rec in enumerate (spdis ):
771819 mask = rec ["node" ] == nn + 1 # 1-based
772820 assert np .allclose (
773- ts_q [i , 1 ],
821+ spdis_q [i , 1 ],
774822 rec ["q" ][mask ][0 ],
775823 ), f"get_ts() q value doesn't match get_data() at time { i } "
776824 assert np .allclose (
777- ts_qx [i , 1 ],
825+ spdis_qx [i , 1 ],
778826 rec ["qx" ][mask ][0 ],
779827 ), f"get_ts() qx value doesn't match get_data() at time { i } "
780828 assert np .allclose (
781- ts_qy [i , 1 ],
829+ spdis_qy [i , 1 ],
782830 rec ["qy" ][mask ][0 ],
783831 ), f"get_ts() qy value doesn't match get_data() at time { i } "
784832 assert np .allclose (
785- ts_qz [i , 1 ],
833+ spdis_qz [i , 1 ],
786834 rec ["qz" ][mask ][0 ],
787835 ), f"get_ts() qz value doesn't match get_data() at time { i } "
788836
789- assert not np .allclose (ts_qx [:, 1 ], 0.0 ), "qx should have non-zero flow"
790- assert not np .allclose (ts_qy [:, 1 ], 0.0 ), "qy should have non-zero flow"
791- assert np .allclose (ts_q [:, 1 ], 0.0 ), "q should be zero for internal cells"
792- assert np .allclose (ts_qz [:, 1 ], 0.0 ), "qz should be zero for single layer"
837+ assert not np .allclose (spdis_qx [:, 1 ], 0.0 ), "qx should have non-zero flow"
838+ assert not np .allclose (spdis_qy [:, 1 ], 0.0 ), "qy should have non-zero flow"
839+ assert np .allclose (spdis_q [:, 1 ], 0.0 ), "q should be zero for internal cells"
840+ assert np .allclose (spdis_qz [:, 1 ], 0.0 ), "qz should be zero for single layer"
793841
794842
795843@pytest .mark .requires_exe ("mf6" )
@@ -822,12 +870,10 @@ def test_cellbudgetfile_get_ts_aux_vars_mf6_disv(dis_sim):
822870
823871 cbc = gwf .output .budget ()
824872 spdis = cbc .get_data (text = "DATA-SPDIS" )
825- available_fields = list (spdis [0 ].dtype .names )
826- expected_fields = ["node" , "q" , "qx" , "qy" , "qz" ]
827- for field in expected_fields :
828- assert field in available_fields
873+ for field in ["node" , "q" , "qx" , "qy" , "qz" ]:
874+ assert field in spdis [0 ].dtype .names
829875
830- cellid = (0 , 4 ) # cell in center of layer 0
876+ cellid = (0 , 4 )
831877 nn = 4
832878
833879 ts_q = cbc .get_ts (idx = cellid , text = "DATA-SPDIS" , variable = "q" )
@@ -866,6 +912,10 @@ def test_cellbudgetfile_get_ts_aux_vars_mf6_disv(dis_sim):
866912 assert np .allclose (ts_q [:, 1 ], 0.0 ), "q should be zero for internal cells"
867913 assert np .allclose (ts_qz [:, 1 ], 0.0 ), "qz should be zero for single layer"
868914
915+ chd = cbc .get_data (text = "CHD" )
916+ for field in ["node" , "node2" , "q" ]:
917+ assert field in chd [0 ].dtype .names
918+
869919
870920@pytest .mark .requires_exe ("mf6" )
871921def test_cellbudgetfile_get_ts_aux_vars_mf6_disu (dis_sim ):
@@ -898,10 +948,8 @@ def test_cellbudgetfile_get_ts_aux_vars_mf6_disu(dis_sim):
898948
899949 cbc = gwf .output .budget ()
900950 spdis = cbc .get_data (text = "DATA-SPDIS" )
901- available_fields = list (spdis [0 ].dtype .names )
902- expected_fields = ["node" , "q" , "qx" , "qy" , "qz" ]
903- for field in expected_fields :
904- assert field in available_fields
951+ for field in ["node" , "q" , "qx" , "qy" , "qz" ]:
952+ assert field in spdis [0 ].dtype .names
905953
906954 ts_q = cbc .get_ts (idx = nn , text = "DATA-SPDIS" , variable = "q" )
907955 ts_qx = cbc .get_ts (idx = nn , text = "DATA-SPDIS" , variable = "qx" )
@@ -938,3 +986,7 @@ def test_cellbudgetfile_get_ts_aux_vars_mf6_disu(dis_sim):
938986 assert not np .allclose (ts_qy [:, 1 ], 0.0 ), "qy should have non-zero flow"
939987 assert np .allclose (ts_q [:, 1 ], 0.0 ), "q should be zero for internal cells"
940988 assert np .allclose (ts_qz [:, 1 ], 0.0 ), "qz should be zero for single layer"
989+
990+ chd = cbc .get_data (text = "CHD" )
991+ for field in ["node" , "node2" , "q" ]:
992+ assert field in chd [0 ].dtype .names
0 commit comments