diff --git a/autotest/framework.py b/autotest/framework.py index 262d53c65dd..b2d5f24390b 100644 --- a/autotest/framework.py +++ b/autotest/framework.py @@ -376,10 +376,19 @@ def _compare_heads(self, cpth=None, extensions="hds") -> bool: else: files2.append(None) - if self.cmp_namefile is None: + # todo: clean up namfile path detection? + nf = next(iter(get_namefiles(cpth)), None) + cmp_namefile = ( + None + if "mf6" in self.compare or "libmf6" in self.compare + else os.path.basename(nf) + if nf + else None + ) + if cmp_namefile is None: pth = None else: - pth = os.path.join(cpth, self.cmp_namefile) + pth = os.path.join(cpth, cmp_namefile) for i in range(len(files1)): file1 = files1[i] @@ -642,16 +651,6 @@ def run_sim_or_model( if self.verbose: print(f"Running {target} in {workspace}") - # needed in _compare_heads()... todo: inject explicitly? - nf = next(iter(get_namefiles(workspace)), None) - self.cmp_namefile = ( - None - if "mf6" in target.name or "libmf6" in target.name - else os.path.basename(nf) - if nf - else None - ) - # run the model try: # via MODFLOW API @@ -694,8 +693,13 @@ def run_sim_or_model( else: # non-MF6 model try: + nf_ext = ".mpsim" if "mp7" in target.name else ".nam" + namefile = next(iter(workspace.glob(f"*{nf_ext}")), None) + assert ( + namefile + ), f"Control file with extension {nf_ext} not found" success, buff = flopy.run_model( - target, self.cmp_namefile, workspace, report=True + target, namefile, workspace, report=True ) except Exception: warn(f"{target} model failed:\n{format_exc()}") diff --git a/autotest/prt/test_prt_disv.py b/autotest/prt/test_prt_disv.py index e7bb21c7385..7ab11f4680b 100644 --- a/autotest/prt/test_prt_disv.py +++ b/autotest/prt/test_prt_disv.py @@ -19,14 +19,9 @@ from flopy.utils import PathlineFile from flopy.utils.binaryfile import HeadFile from flopy.utils.gridutil import get_disv_kwargs -from prt_test_utils import ( - all_equal, - check_budget_data, - check_track_data, - get_partdata, - has_default_boundnames, - plot_nodes_and_vertices, -) +from prt_test_utils import (all_equal, check_budget_data, check_track_data, + get_partdata, has_default_boundnames, + plot_nodes_and_vertices) from framework import TestFramework @@ -72,9 +67,9 @@ def build_gwf_sim(idx, ws, mf6): - gwfname = f"{cases[idx]}_gwf" + gwf_name = f"{cases[idx]}_gwf" sim = flopy.mf6.MFSimulation( - sim_name=gwfname, version="mf6", exe_name=mf6, sim_ws=ws + sim_name=gwf_name, version="mf6", exe_name=mf6, sim_ws=ws ) # create tdis package @@ -84,7 +79,7 @@ def build_gwf_sim(idx, ws, mf6): # create gwf model gwf = flopy.mf6.ModflowGwf( - sim, modelname=gwfname, newtonoptions="NEWTON", save_flows=True + sim, modelname=gwf_name, newtonoptions="NEWTON", save_flows=True ) # create iterative model solution and register the gwf model with it @@ -133,12 +128,12 @@ def build_gwf_sim(idx, ws, mf6): # output control oc = flopy.mf6.ModflowGwfoc( gwf, - budget_filerecord="{}.cbc".format(gwfname), - head_filerecord="{}.hds".format(gwfname), + budget_filerecord="{}.cbc".format(gwf_name), + head_filerecord="{}.hds".format(gwf_name), headprintrecord=[("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL")], saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], printrecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], - filename="{}.oc".format(gwfname), + filename="{}.oc".format(gwf_name), ) # Print human-readable heads @@ -147,7 +142,7 @@ def build_gwf_sim(idx, ws, mf6): for i in np.arange(40, 50, 1): obs_lst.append(["obs_" + str(i + 1), "head", (k, i)]) - obs_dict = {f"{gwfname}.obs.csv": obs_lst} + obs_dict = {f"{gwf_name}.obs.csv": obs_lst} obs = flopy.mf6.ModflowUtlobs( gwf, pname="head_obs", digits=20, continuous=obs_dict ) @@ -171,8 +166,8 @@ def build_prt_sim(idx, gwf_ws, prt_ws, mf6): ) # create prt model - prtname = f"{cases[idx]}_prt" - prt = flopy.mf6.ModflowPrt(sim, modelname=prtname) + prt_name = f"{cases[idx]}_prt" + prt = flopy.mf6.ModflowPrt(sim, modelname=prt_name) # create prt discretization disv = flopy.mf6.ModflowGwfdisv(prt, **disvkwargs) @@ -188,12 +183,12 @@ def build_prt_sim(idx, gwf_ws, prt_ws, mf6): releasepts[0] = (0, (0, 1), 0.5, 9.5, 22.5) # create prp package - prp_track_file = f"{prtname}.prp.trk" - prp_track_csv_file = f"{prtname}.prp.trk.csv" + prp_track_file = f"{prt_name}.prp.trk" + prp_track_csv_file = f"{prt_name}.prp.trk.csv" flopy.mf6.ModflowPrtprp( prt, pname="prp1", - filename=f"{prtname}_1.prp", + filename=f"{prt_name}_1.prp", nreleasepts=len(releasepts), packagedata=releasepts, perioddata={0: ["FIRST"]}, @@ -204,8 +199,8 @@ def build_prt_sim(idx, gwf_ws, prt_ws, mf6): ) # create output control package - prt_track_file = f"{prtname}.trk" - prt_track_csv_file = f"{prtname}.trk.csv" + prt_track_file = f"{prt_name}.trk" + prt_track_csv_file = f"{prt_name}.trk.csv" flopy.mf6.ModflowPrtoc( prt, pname="oc", @@ -214,9 +209,9 @@ def build_prt_sim(idx, gwf_ws, prt_ws, mf6): ) # create the flow model interface - gwfname = f"{cases[idx]}_gwf" - gwf_budget_file = gwf_ws / f"{gwfname}.cbc" - gwf_head_file = gwf_ws / f"{gwfname}.hds" + gwf_name = f"{cases[idx]}_gwf" + gwf_budget_file = gwf_ws / f"{gwf_name}.cbc" + gwf_head_file = gwf_ws / f"{gwf_name}.hds" flopy.mf6.ModflowPrtfmi( prt, packagedata=[ @@ -229,7 +224,7 @@ def build_prt_sim(idx, gwf_ws, prt_ws, mf6): ems = flopy.mf6.ModflowEms( sim, pname="ems", - filename=f"{prtname}.ems", + filename=f"{prt_name}.ems", ) sim.register_solution_package(ems, [prt.name]) @@ -238,17 +233,19 @@ def build_prt_sim(idx, gwf_ws, prt_ws, mf6): def build_mp7_sim(idx, ws, mp7, gwf): partdata = get_partdata(gwf.modelgrid, releasepts_mp7) - mp7name = f"{cases[idx]}_mp7" + mp7_name = f"{cases[idx]}_mp7" pg = flopy.modpath.ParticleGroup( particlegroupname="G1", particledata=partdata, - filename=f"{mp7name}.sloc", + filename=f"{mp7_name}.sloc", ) mp = flopy.modpath.Modpath7( - modelname=mp7name, + modelname=mp7_name, flowmodel=gwf, exe_name=mp7, model_ws=ws, + headfilename=f"{gwf.name}.hds", + budgetfilename=f"{gwf.name}.cbc", ) mpbas = flopy.modpath.Modpath7Bas( mp, @@ -267,11 +264,14 @@ def build_mp7_sim(idx, ws, mp7, gwf): def build_models(idx, test): - gwfsim = build_gwf_sim(idx, test.workspace, test.targets.mf6) - prtsim = build_prt_sim( + gwf_sim = build_gwf_sim(idx, test.workspace, test.targets.mf6) + prt_sim = build_prt_sim( idx, test.workspace, test.workspace / "prt", test.targets.mf6 ) - return gwfsim, prtsim + mp7_sim = build_mp7_sim( + idx, test.workspace / "mp7", test.targets.mp7, gwf_sim.get_model() + ) + return gwf_sim, prt_sim, mp7_sim def check_output(idx, test): @@ -279,9 +279,14 @@ def check_output(idx, test): gwf_ws = test.workspace prt_ws = test.workspace / "prt" mp7_ws = test.workspace / "mp7" - gwfname = f"{name}_gwf" - prtname = f"{name}_prt" - mp7name = f"{name}_mp7" + gwf_name = f"{name}_gwf" + prt_name = f"{name}_prt" + mp7_name = f"{name}_mp7" + gwf_sim = test.sims[0] + prt_sim = test.sims[1] + gwf = gwf_sim.get_model(gwf_name) + prt = prt_sim.get_model(prt_name) + mg = gwf.modelgrid # if invalid release points, check for error message if "bprp" in name: @@ -289,28 +294,13 @@ def check_output(idx, test): assert any("Error: release point" in l for l in buff) return - # extract mf6 simulations/models and grid - gwfsim = test.sims[0] - prtsim = test.sims[1] - gwf = gwfsim.get_model(gwfname) - prt = prtsim.get_model(prtname) - mg = gwf.modelgrid - - # todo build mp7 model - mp7sim = build_mp7_sim(idx, mp7_ws, test.targets.mp7, gwf) - - # todo run mp7 model - mp7sim.write_input() - success, buff = mp7sim.run_model(report=True) - assert success, pformat(buff) - # check mf6 output files exist - gwf_budget_file = f"{gwfname}.cbc" - gwf_head_file = f"{gwfname}.hds" - prt_track_file = f"{prtname}.trk" - prt_track_csv_file = f"{prtname}.trk.csv" - prp_track_file = f"{prtname}.prp.trk" - prp_track_csv_file = f"{prtname}.prp.trk.csv" + gwf_budget_file = f"{gwf_name}.cbc" + gwf_head_file = f"{gwf_name}.hds" + prt_track_file = f"{prt_name}.trk" + prt_track_csv_file = f"{prt_name}.trk.csv" + prp_track_file = f"{prt_name}.prp.trk" + prp_track_csv_file = f"{prt_name}.prp.trk.csv" assert (gwf_ws / gwf_budget_file).is_file() assert (gwf_ws / gwf_head_file).is_file() assert (prt_ws / prt_track_file).is_file() @@ -319,7 +309,7 @@ def check_output(idx, test): assert (prt_ws / prp_track_csv_file).is_file() # check mp7 output files exist - mp7_pathline_file = f"{mp7name}.mppth" + mp7_pathline_file = f"{mp7_name}.mppth" assert (mp7_ws / mp7_pathline_file).is_file() # load mp7 pathline results @@ -446,6 +436,6 @@ def test_mf6model(idx, name, function_tmpdir, targets): check=lambda t: check_output(idx, t), targets=targets, compare=None, - xfail=[False, "bprp" in name], + xfail=[False, "bprp" in name, False], ) test.run() diff --git a/autotest/prt/test_prt_drape.py b/autotest/prt/test_prt_drape.py index 28089e85eb7..3314f6f04be 100644 --- a/autotest/prt/test_prt_drape.py +++ b/autotest/prt/test_prt_drape.py @@ -50,11 +50,11 @@ def build_gwf_sim(name, ws, mf6): ws = Path(ws) - gwfname = get_model_name(name, "gwf") + gwf_name = get_model_name(name, "gwf") # create simulation sim = flopy.mf6.MFSimulation( - sim_name=gwfname, version="mf6", exe_name=mf6, sim_ws=ws + sim_name=gwf_name, version="mf6", exe_name=mf6, sim_ws=ws ) # create tdis package tdis = flopy.mf6.ModflowTdis( @@ -62,8 +62,8 @@ def build_gwf_sim(name, ws, mf6): ) # set ims csv files - csv0 = f"{gwfname}.outer.ims.csv" - csv1 = f"{gwfname}.inner.ims.csv" + csv0 = f"{gwf_name}.outer.ims.csv" + csv1 = f"{gwf_name}.inner.ims.csv" # create iterative model solution and register the gwf model with it ims = flopy.mf6.ModflowIms( @@ -84,7 +84,7 @@ def build_gwf_sim(name, ws, mf6): ) # create gwf model - gwf = flopy.mf6.ModflowGwf(sim, modelname=gwfname, save_flows=True) + gwf = flopy.mf6.ModflowGwf(sim, modelname=gwf_name, save_flows=True) dis = flopy.mf6.ModflowGwfdis( gwf, @@ -126,12 +126,12 @@ def build_gwf_sim(name, ws, mf6): # output control oc = flopy.mf6.ModflowGwfoc( gwf, - budget_filerecord=f"{gwfname}.cbc", - head_filerecord=f"{gwfname}.hds", + budget_filerecord=f"{gwf_name}.cbc", + head_filerecord=f"{gwf_name}.hds", headprintrecord=[("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL")], saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], printrecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], - filename=f"{gwfname}.oc", + filename=f"{gwf_name}.oc", ) return sim @@ -139,12 +139,12 @@ def build_gwf_sim(name, ws, mf6): def build_prt_sim(name, gwf_ws, prt_ws, mf6): prt_ws = Path(prt_ws) - gwfname = get_model_name(name, "gwf") - prtname = get_model_name(name, "prt") + gwf_name = get_model_name(name, "gwf") + prt_name = get_model_name(name, "prt") # create simulation sim = flopy.mf6.MFSimulation( - sim_name=prtname, + sim_name=prt_name, exe_name=mf6, version="mf6", sim_ws=prt_ws, @@ -156,7 +156,7 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): ) # create prt model - prt = flopy.mf6.ModflowPrt(sim, modelname=prtname) + prt = flopy.mf6.ModflowPrt(sim, modelname=prt_name) # create prt discretization dis = flopy.mf6.ModflowGwfdis( @@ -174,12 +174,12 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): flopy.mf6.ModflowPrtmip(prt, pname="mip", porosity=porosity) # create prp package - prp_track_file = f"{prtname}.prp.trk" - prp_track_csv_file = f"{prtname}.prp.trk.csv" + prp_track_file = f"{prt_name}.prp.trk" + prp_track_csv_file = f"{prt_name}.prp.trk.csv" flopy.mf6.ModflowPrtprp( prt, pname="prp1", - filename=f"{prtname}_1.prp", + filename=f"{prt_name}_1.prp", nreleasepts=len(releasepts), packagedata=releasepts, perioddata={0: ["FIRST"]}, @@ -189,8 +189,8 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): ) # create output control package - prt_track_file = f"{prtname}.trk" - prt_track_csv_file = f"{prtname}.trk.csv" + prt_track_file = f"{prt_name}.trk" + prt_track_csv_file = f"{prt_name}.trk.csv" flopy.mf6.ModflowPrtoc( prt, pname="oc", @@ -199,8 +199,8 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): ) # create the flow model interface - gwf_budget_file = gwf_ws / f"{gwfname}.cbc" - gwf_head_file = gwf_ws / f"{gwfname}.hds" + gwf_budget_file = gwf_ws / f"{gwf_name}.cbc" + gwf_head_file = gwf_ws / f"{gwf_name}.hds" flopy.mf6.ModflowPrtfmi( prt, packagedata=[ @@ -213,7 +213,7 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): ems = flopy.mf6.ModflowEms( sim, pname="ems", - filename=f"{prtname}.ems", + filename=f"{prt_name}.ems", ) sim.register_solution_package(ems, [prt.name]) @@ -221,35 +221,31 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): def build_models(idx, test): - gwfsim = build_gwf_sim(test.name, test.workspace, test.targets.mf6) - prtsim = build_prt_sim( + gwf_sim = build_gwf_sim(test.name, test.workspace, test.targets.mf6) + prt_sim = build_prt_sim( test.name, test.workspace, test.workspace / "prt", test.targets.mf6 ) - return gwfsim, prtsim + return gwf_sim, prt_sim def check_output(idx, test): name = test.name gwf_ws = test.workspace prt_ws = test.workspace / "prt" - gwfname = get_model_name(name, "gwf") - prtname = get_model_name(name, "prt") - drape = "drp" in name - - # extract mf6 simulations/models and grid - gwfsim = test.sims[0] - prtsim = test.sims[1] - gwf = gwfsim.get_model(gwfname) - prt = prtsim.get_model(prtname) + gwf_name = get_model_name(name, "gwf") + prt_name = get_model_name(name, "prt") + gwf_sim = test.sims[0] + gwf = gwf_sim.get_model(gwf_name) mg = gwf.modelgrid + drape = "drp" in name # check mf6 output files exist - gwf_budget_file = f"{gwfname}.cbc" - gwf_head_file = f"{gwfname}.hds" - prt_track_file = f"{prtname}.trk" - prt_track_csv_file = f"{prtname}.trk.csv" - prp_track_file = f"{prtname}.prp.trk" - prp_track_csv_file = f"{prtname}.prp.trk.csv" + gwf_budget_file = f"{gwf_name}.cbc" + gwf_head_file = f"{gwf_name}.hds" + prt_track_file = f"{prt_name}.trk" + prt_track_csv_file = f"{prt_name}.trk.csv" + prp_track_file = f"{prt_name}.prp.trk" + prp_track_csv_file = f"{prt_name}.prp.trk.csv" assert (gwf_ws / gwf_budget_file).is_file() assert (gwf_ws / gwf_head_file).is_file() assert (prt_ws / prt_track_file).is_file() diff --git a/autotest/prt/test_prt_exg.py b/autotest/prt/test_prt_exg.py index b16846d48c3..3336be80e1d 100644 --- a/autotest/prt/test_prt_exg.py +++ b/autotest/prt/test_prt_exg.py @@ -37,14 +37,14 @@ def get_model_name(idx, mdl): return f"{cases[idx]}_{mdl}" -def build_models(idx, test): +def build_mf6_sim(idx, test): # create simulation name = cases[idx] sim = BasicDisCase.get_gwf_sim(name, test.workspace, test.targets.mf6) # create prt model - prtname = get_model_name(idx, "prt") - prt = flopy.mf6.ModflowPrt(sim, modelname=prtname) + prt_name = get_model_name(idx, "prt") + prt = flopy.mf6.ModflowPrt(sim, modelname=prt_name) # create prt discretization flopy.mf6.modflow.mfgwfdis.ModflowGwfdis( @@ -67,7 +67,7 @@ def build_models(idx, test): flopy.mf6.ModflowPrtprp( prt, pname="prp1", - filename=f"{prtname}_1.prp", + filename=f"{prt_name}_1.prp", nreleasepts=len(rpts), packagedata=rpts, perioddata={0: ["FIRST"]}, @@ -75,8 +75,8 @@ def build_models(idx, test): ) # create output control package - prt_track_file = f"{prtname}.trk" - prt_track_csv_file = f"{prtname}.trk.csv" + prt_track_file = f"{prt_name}.trk" + prt_track_csv_file = f"{prt_name}.trk.csv" flopy.mf6.ModflowPrtoc( prt, pname="oc", @@ -95,23 +95,22 @@ def build_models(idx, test): # ) # create exchange - gwfname = get_model_name(idx, "gwf") + gwf_name = get_model_name(idx, "gwf") flopy.mf6.ModflowGwfprt( sim, exgtype="GWF6-PRT6", - exgmnamea=gwfname, - exgmnameb=prtname, - filename=f"{gwfname}.gwfprt", + exgmnamea=gwf_name, + exgmnameb=prt_name, + filename=f"{gwf_name}.gwfprt", ) # add explicit model solution ems = flopy.mf6.ModflowEms( sim, pname="ems", - filename=f"{prtname}.ems", + filename=f"{prt_name}.ems", ) sim.register_solution_package(ems, [prt.name]) - return sim @@ -124,17 +123,19 @@ def build_mp7_sim(idx, ws, mp7, gwf): timeoffset=0, drape=0, ) - mp7name = get_model_name(idx, "mp7") + mp7_name = get_model_name(idx, "mp7") pg = flopy.modpath.ParticleGroup( particlegroupname="G1", particledata=partdata, - filename=f"{mp7name}.sloc", + filename=f"{mp7_name}.sloc", ) mp = flopy.modpath.Modpath7( - modelname=mp7name, + modelname=mp7_name, flowmodel=gwf, exe_name=mp7, model_ws=ws, + headfilename=f"{gwf.name}.hds", + budgetfilename=f"{gwf.name}.bud", ) mpbas = flopy.modpath.Modpath7Bas( mp, @@ -148,51 +149,51 @@ def build_mp7_sim(idx, ws, mp7, gwf): stoptimeoption="extend", particlegroups=[pg], ) - return mp +def build_models(idx, test): + mf6sim = build_mf6_sim(idx, test) + gwf_name = get_model_name(idx, "gwf") + gwf = mf6sim.get_model(gwf_name) + mp7sim = build_mp7_sim(idx, test.workspace / "mp7", test.targets.mp7, gwf) + return mf6sim, mp7sim + + def check_output(idx, test): name = test.name - ws = Path(test.workspace) + gwf_ws = Path(test.workspace) + mp7_ws = gwf_ws / "mp7" # model names - gwfname = get_model_name(idx, "gwf") - prtname = get_model_name(idx, "prt") - mp7name = get_model_name(idx, "mp7") + gwf_name = get_model_name(idx, "gwf") + prt_name = get_model_name(idx, "prt") + mp7_name = get_model_name(idx, "mp7") # extract model objects sim = test.sims[0] - gwf = sim.get_model(gwfname) - prt = sim.get_model(prtname) + gwf = sim.get_model(gwf_name) + prt = sim.get_model(prt_name) # extract model grid mg = gwf.modelgrid - # build mp7 model - mp7sim = build_mp7_sim(idx, ws, test.targets.mp7, gwf) - - # run mp7 model - mp7sim.write_input() - success, buff = mp7sim.run_model(report=True) - assert success, pformat(buff) - # check mf6 output files exist - gwf_budget_file = f"{gwfname}.bud" - gwf_head_file = f"{gwfname}.hds" - prt_track_file = f"{prtname}.trk" - prt_track_csv_file = f"{prtname}.trk.csv" - assert (ws / gwf_budget_file).is_file() - assert (ws / gwf_head_file).is_file() - assert (ws / prt_track_file).is_file() - assert (ws / prt_track_csv_file).is_file() + gwf_budget_file = f"{gwf_name}.bud" + gwf_head_file = f"{gwf_name}.hds" + prt_track_file = f"{prt_name}.trk" + prt_track_csv_file = f"{prt_name}.trk.csv" + assert (gwf_ws / gwf_budget_file).is_file() + assert (gwf_ws / gwf_head_file).is_file() + assert (gwf_ws / prt_track_file).is_file() + assert (gwf_ws / prt_track_csv_file).is_file() # check mp7 output files exist - mp7_pathline_file = f"{mp7name}.mppth" - assert (ws / mp7_pathline_file).is_file() + mp7_pathline_file = f"{mp7_name}.mppth" + assert (mp7_ws / mp7_pathline_file).is_file() # load mp7 pathline results - plf = PathlineFile(ws / mp7_pathline_file) + plf = PathlineFile(mp7_ws / mp7_pathline_file) mp7_pls = pd.DataFrame( plf.get_destination_pathline_data(range(mg.nnodes), to_recarray=True) ) @@ -202,7 +203,7 @@ def check_output(idx, test): mp7_pls["k"] = mp7_pls["k"] + 1 # load mf6 pathline results - mf6_pls = pd.read_csv(ws / prt_track_csv_file).replace( + mf6_pls = pd.read_csv(gwf_ws / prt_track_csv_file).replace( r"^\s*$", np.nan, regex=True ) @@ -221,19 +222,19 @@ def check_output(idx, test): # check budget data were written to mf6 prt list file check_budget_data( - ws / f"{name}_prt.lst", BasicDisCase.perlen, BasicDisCase.nper + gwf_ws / f"{name}_prt.lst", BasicDisCase.perlen, BasicDisCase.nper ) # check mf6 prt particle track data were written to binary/CSV files check_track_data( - track_bin=ws / prt_track_file, - track_hdr=ws / Path(prt_track_file.replace(".trk", ".trk.hdr")), - track_csv=ws / prt_track_csv_file, + track_bin=gwf_ws / prt_track_file, + track_hdr=gwf_ws / Path(prt_track_file.replace(".trk", ".trk.hdr")), + track_csv=gwf_ws / prt_track_csv_file, ) # extract head, budget, and specific discharge results from GWF model - gwf = sim.get_model(gwfname) - hds = HeadFile(ws / gwf_head_file).get_data() + gwf = sim.get_model(gwf_name) + hds = HeadFile(gwf_ws / gwf_head_file).get_data() bud = gwf.output.budget() spdis = bud.get_data(text="DATA-SPDIS")[0] qx, qy, qz = flopy.utils.postprocessing.get_specific_discharge(spdis, gwf) @@ -279,7 +280,7 @@ def check_output(idx, test): # view/save plot # plt.show() - plt.savefig(ws / f"test_{name}.png") + plt.savefig(gwf_ws / f"test_{name}.png") # convert mf6 pathlines to mp7 format mf6_pls = to_mp7_pathlines(mf6_pls) diff --git a/autotest/prt/test_prt_fmi.py b/autotest/prt/test_prt_fmi.py index 6e12dc0bd12..b80d043d3cc 100644 --- a/autotest/prt/test_prt_fmi.py +++ b/autotest/prt/test_prt_fmi.py @@ -26,7 +26,6 @@ from pathlib import Path -from pprint import pformat import flopy import matplotlib.cm as cm @@ -37,15 +36,9 @@ from flopy.plot.plotutil import to_mp7_pathlines from flopy.utils import PathlineFile from flopy.utils.binaryfile import HeadFile -from prt_test_utils import ( - BasicDisCase, - all_equal, - check_budget_data, - check_track_data, - get_model_name, - get_partdata, - has_default_boundnames, -) +from prt_test_utils import (BasicDisCase, all_equal, check_budget_data, + check_track_data, get_model_name, get_partdata, + has_default_boundnames) from framework import TestFramework @@ -74,8 +67,8 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): ) # create prt model - prtname = get_model_name(name, "prt") - prt = flopy.mf6.ModflowPrt(sim, modelname=prtname) + prt_name = get_model_name(name, "prt") + prt = flopy.mf6.ModflowPrt(sim, modelname=prt_name) # create prt discretization flopy.mf6.modflow.mfgwfdis.ModflowGwfdis( @@ -104,24 +97,24 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): assert np.allclose(BasicDisCase.releasepts_prt, releasepts) # create prp package - prp_track_file = f"{prtname}.prp.trk" - prp_track_csv_file = f"{prtname}.prp.trk.csv" + prp_track_file = f"{prt_name}.prp.trk" + prp_track_csv_file = f"{prt_name}.prp.trk.csv" flopy.mf6.ModflowPrtprp( prt, pname="prp1", - filename=f"{prtname}_1.prp", + filename=f"{prt_name}_1.prp", nreleasepts=len(releasepts), packagedata=releasepts, perioddata={0: ["FIRST"]}, track_filerecord=[prp_track_file], trackcsv_filerecord=[prp_track_csv_file], - stop_at_weak_sink="saws" in prtname, + stop_at_weak_sink="saws" in prt_name, boundnames=True, ) # create output control package - prt_track_file = f"{prtname}.trk" - prt_track_csv_file = f"{prtname}.trk.csv" + prt_track_file = f"{prt_name}.trk" + prt_track_csv_file = f"{prt_name}.trk.csv" flopy.mf6.ModflowPrtoc( prt, pname="oc", @@ -130,9 +123,9 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): ) # create the flow model interface - gwfname = get_model_name(name, "gwf") - gwf_budget_file = gwf_ws / f"{gwfname}.bud" - gwf_head_file = gwf_ws / f"{gwfname}.hds" + gwf_name = get_model_name(name, "gwf") + gwf_budget_file = gwf_ws / f"{gwf_name}.bud" + gwf_head_file = gwf_ws / f"{gwf_name}.hds" flopy.mf6.ModflowPrtfmi( prt, packagedata=[ @@ -145,7 +138,7 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): ems = flopy.mf6.ModflowEms( sim, pname="ems", - filename=f"{prtname}.ems", + filename=f"{prt_name}.ems", ) sim.register_solution_package(ems, [prt.name]) @@ -154,17 +147,19 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): def build_mp7_sim(name, ws, mp7, gwf): partdata = get_partdata(gwf.modelgrid, BasicDisCase.releasepts_mp7) - mp7name = get_model_name(name, "mp7") + mp7_name = get_model_name(name, "mp7") pg = flopy.modpath.ParticleGroup( particlegroupname="G1", particledata=partdata, - filename=f"{mp7name}.sloc", + filename=f"{mp7_name}.sloc", ) mp = flopy.modpath.Modpath7( - modelname=mp7name, + modelname=mp7_name, flowmodel=gwf, exe_name=mp7, model_ws=ws, + headfilename=f"{gwf.name}.hds", + budgetfilename=f"{gwf.name}.bud", ) mpbas = flopy.modpath.Modpath7Bas( mp, @@ -183,13 +178,19 @@ def build_mp7_sim(name, ws, mp7, gwf): def build_models(idx, test): - gwfsim = BasicDisCase.get_gwf_sim( + gwf_sim = BasicDisCase.get_gwf_sim( test.name, test.workspace, test.targets.mf6 ) - prtsim = build_prt_sim( + prt_sim = build_prt_sim( test.name, test.workspace, test.workspace / "prt", test.targets.mf6 ) - return gwfsim, prtsim + mp7_sim = build_mp7_sim( + test.name, + test.workspace / "mp7", + test.targets.mp7, + gwf_sim.get_model(), + ) + return gwf_sim, prt_sim, mp7_sim def check_output(idx, test): @@ -197,38 +198,25 @@ def check_output(idx, test): gwf_ws = test.workspace prt_ws = test.workspace / "prt" mp7_ws = test.workspace / "mp7" - gwfname = get_model_name(name, "gwf") - prtname = get_model_name(name, "prt") - mp7name = get_model_name(name, "mp7") + gwf_name = get_model_name(name, "gwf") + prt_name = get_model_name(name, "prt") + mp7_name = get_model_name(name, "mp7") + gwf_sim = test.sims[0] + gwf = gwf_sim.get_model(gwf_name) + mg = gwf.modelgrid if "bprp" in name: buff = test.buffs[1] assert any("Error: release point" in l for l in buff) return - # extract mf6 simulations/models and grid - gwfsim = test.sims[0] - prtsim = test.sims[1] - gwf = gwfsim.get_model(gwfname) - prt = prtsim.get_model(prtname) - mg = gwf.modelgrid - - # build/run mp7 model... can't run within framework as - # flopy needs gwf output files to write mp7 input files - mp7sim = build_mp7_sim(name, mp7_ws, test.targets.mp7, gwf) - - # run mp7 model - mp7sim.write_input() - success, buff = mp7sim.run_model(report=True) - assert success, pformat(buff) - # check mf6 output files exist - gwf_budget_file = f"{gwfname}.bud" - gwf_head_file = f"{gwfname}.hds" - prt_track_file = f"{prtname}.trk" - prt_track_csv_file = f"{prtname}.trk.csv" - prp_track_file = f"{prtname}.prp.trk" - prp_track_csv_file = f"{prtname}.prp.trk.csv" + gwf_budget_file = f"{gwf_name}.bud" + gwf_head_file = f"{gwf_name}.hds" + prt_track_file = f"{prt_name}.trk" + prt_track_csv_file = f"{prt_name}.trk.csv" + prp_track_file = f"{prt_name}.prp.trk" + prp_track_csv_file = f"{prt_name}.prp.trk.csv" assert (gwf_ws / gwf_budget_file).is_file() assert (gwf_ws / gwf_head_file).is_file() assert (prt_ws / prt_track_file).is_file() @@ -237,7 +225,7 @@ def check_output(idx, test): assert (prt_ws / prp_track_csv_file).is_file() # check mp7 output files exist - mp7_pathline_file = f"{mp7name}.mppth" + mp7_pathline_file = f"{mp7_name}.mppth" assert (mp7_ws / mp7_pathline_file).is_file() # load mp7 pathline results @@ -361,6 +349,6 @@ def test_mf6model(idx, name, function_tmpdir, targets): check=lambda t: check_output(idx, t), targets=targets, compare=None, - xfail=[False, "bprp" in name], + xfail=[False, "bprp" in name, False], ) test.run() diff --git a/autotest/prt/test_prt_notebooks.py b/autotest/prt/test_prt_notebooks.py index 610e9a7fb2d..7b611de8d59 100644 --- a/autotest/prt/test_prt_notebooks.py +++ b/autotest/prt/test_prt_notebooks.py @@ -89,7 +89,7 @@ def test_notebooks(notebook, function_tmpdir, targets): simname = Path(notebook).stem.replace("ex-prt-", "") gwfname = f"{simname}-gwf" prtname = f"{simname}-prt" - mp7name = f"{simname}-mp7" + mp7_name = f"{simname}-mp7" # if example working directory doesn't exist, return early example_ws = function_tmpdir.parent / "examples" / notebook.stem @@ -162,7 +162,7 @@ def test_notebooks(notebook, function_tmpdir, targets): # check mp7 pathline output file(s) if isinstance(mp7ws, Path): - mp7_pathline_file = mp7ws / f"{mp7name}.mppth" + mp7_pathline_file = mp7ws / f"{mp7_name}.mppth" assert mp7_pathline_file.is_file() mp7_pls = pd.DataFrame.from_records( PathlineFile(mp7_pathline_file).get_destination_pathline_data( @@ -172,8 +172,8 @@ def test_notebooks(notebook, function_tmpdir, targets): else: for ws in mp7ws: ll = ws.stem[-1] - mp7_pathline_file = ws / f"{mp7name}{ll}.mppth" - mp7_endpoint_file = ws / f"{mp7name}{ll}.mpend" + mp7_pathline_file = ws / f"{mp7_name}{ll}.mppth" + mp7_endpoint_file = ws / f"{mp7_name}{ll}.mpend" assert mp7_pathline_file.is_file() or mp7_endpoint_file.is_file() # if multiple mp7 dirs & pathline files, concatenate them into a single dataframe diff --git a/autotest/prt/test_prt_release_timing.py b/autotest/prt/test_prt_release_timing.py index 17b8737d4fb..e454414c0e8 100644 --- a/autotest/prt/test_prt_release_timing.py +++ b/autotest/prt/test_prt_release_timing.py @@ -37,14 +37,8 @@ from flopy.plot.plotutil import to_mp7_pathlines from flopy.utils import PathlineFile from flopy.utils.binaryfile import HeadFile -from prt_test_utils import ( - BasicDisCase, - all_equal, - check_budget_data, - check_track_data, - get_model_name, - get_partdata, -) +from prt_test_utils import (BasicDisCase, all_equal, check_budget_data, + check_track_data, get_model_name, get_partdata) from framework import TestFramework @@ -99,8 +93,8 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6, fraction=None): ) # create prt model - prtname = get_model_name(name, "prt") - prt = flopy.mf6.ModflowPrt(sim, modelname=prtname) + prt_name = get_model_name(name, "prt") + prt = flopy.mf6.ModflowPrt(sim, modelname=prt_name) # create prt discretization flopy.mf6.modflow.mfgwfdis.ModflowGwfdis( @@ -122,15 +116,15 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6, fraction=None): assert np.allclose(BasicDisCase.releasepts_prt, releasepts) # create prp package - prp_track_file = f"{prtname}.prp.trk" - prp_track_csv_file = f"{prtname}.prp.trk.csv" - pdat = get_perioddata(prtname, fraction=fraction) + prp_track_file = f"{prt_name}.prp.trk" + prp_track_csv_file = f"{prt_name}.prp.trk.csv" + pdat = get_perioddata(prt_name, fraction=fraction) # fraction 0.5 equiv. to release time 0.5 since 1 period 1 step with length 1 - trelease = fraction if "relt" in prtname else None + trelease = fraction if "relt" in prt_name else None flopy.mf6.ModflowPrtprp( prt, pname="prp1", - filename=f"{prtname}_1.prp", + filename=f"{prt_name}_1.prp", nreleasepts=len(releasepts), packagedata=releasepts, perioddata=pdat, @@ -140,8 +134,8 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6, fraction=None): ) # create output control package - prt_track_file = f"{prtname}.trk" - prt_track_csv_file = f"{prtname}.trk.csv" + prt_track_file = f"{prt_name}.trk" + prt_track_csv_file = f"{prt_name}.trk.csv" flopy.mf6.ModflowPrtoc( prt, pname="oc", @@ -150,9 +144,9 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6, fraction=None): ) # create the flow model interface - gwfname = get_model_name(name, "gwf") - gwf_budget_file = gwf_ws / f"{gwfname}.bud" - gwf_head_file = gwf_ws / f"{gwfname}.hds" + gwf_name = get_model_name(name, "gwf") + gwf_budget_file = gwf_ws / f"{gwf_name}.bud" + gwf_head_file = gwf_ws / f"{gwf_name}.hds" flopy.mf6.ModflowPrtfmi( prt, packagedata=[ @@ -165,7 +159,7 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6, fraction=None): ems = flopy.mf6.ModflowEms( sim, pname="ems", - filename=f"{prtname}.ems", + filename=f"{prt_name}.ems", ) sim.register_solution_package(ems, [prt.name]) @@ -174,17 +168,19 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6, fraction=None): def build_mp7_sim(name, ws, mp7, gwf): partdata = get_partdata(gwf.modelgrid, BasicDisCase.releasepts_mp7) - mp7name = get_model_name(name, "mp7") + mp7_name = get_model_name(name, "mp7") pg = flopy.modpath.ParticleGroup( particlegroupname="G1", particledata=partdata, - filename=f"{mp7name}.sloc", + filename=f"{mp7_name}.sloc", ) mp = flopy.modpath.Modpath7( - modelname=mp7name, + modelname=mp7_name, flowmodel=gwf, exe_name=mp7, model_ws=ws, + headfilename=f"{gwf.name}.hds", + budgetfilename=f"{gwf.name}.bud", ) mpbas = flopy.modpath.Modpath7Bas( mp, @@ -203,17 +199,23 @@ def build_mp7_sim(name, ws, mp7, gwf): def build_models(idx, test, fraction): - gwfsim = BasicDisCase.get_gwf_sim( + gwf_sim = BasicDisCase.get_gwf_sim( test.name, test.workspace, test.targets.mf6 ) - prtsim = build_prt_sim( + prt_sim = build_prt_sim( test.name, test.workspace, test.workspace / "prt", test.targets.mf6, fraction, ) - return gwfsim, prtsim + mp7_sim = build_mp7_sim( + test.name, + test.workspace / "mp7", + test.targets.mp7, + gwf_sim.get_model(), + ) + return gwf_sim, prt_sim, mp7_sim def check_output(idx, test, fraction): @@ -221,34 +223,20 @@ def check_output(idx, test, fraction): ws = test.workspace prt_ws = test.workspace / "prt" mp7_ws = test.workspace / "mp7" - gwfname = get_model_name(name, "gwf") - prtname = get_model_name(name, "prt") - mp7name = get_model_name(name, "mp7") - - # extract mf6 simulations/models and grid - gwfsim = test.sims[0] - prtsim = test.sims[1] - gwf = gwfsim.get_model(gwfname) - prt = prtsim.get_model(prtname) - - # extract model grid + gwf_name = get_model_name(name, "gwf") + prt_name = get_model_name(name, "prt") + mp7_name = get_model_name(name, "mp7") + gwf_sim = test.sims[0] + gwf = gwf_sim.get_model(gwf_name) mg = gwf.modelgrid - # build mp7 model - mp7sim = build_mp7_sim(name, mp7_ws, test.targets.mp7, gwf) - - # run mp7 model - mp7sim.write_input() - success, buff = mp7sim.run_model(report=True) - assert success, pformat(buff) - # check mf6 output files exist - gwf_budget_file = f"{gwfname}.bud" - gwf_head_file = f"{gwfname}.hds" - prt_track_file = f"{prtname}.trk" - prt_track_csv_file = f"{prtname}.trk.csv" - prp_track_file = f"{prtname}.prp.trk" - prp_track_csv_file = f"{prtname}.prp.trk.csv" + gwf_budget_file = f"{gwf_name}.bud" + gwf_head_file = f"{gwf_name}.hds" + prt_track_file = f"{prt_name}.trk" + prt_track_csv_file = f"{prt_name}.trk.csv" + prp_track_file = f"{prt_name}.prp.trk" + prp_track_csv_file = f"{prt_name}.prp.trk.csv" assert (ws / gwf_budget_file).is_file() assert (ws / gwf_head_file).is_file() assert (prt_ws / prt_track_file).is_file() @@ -257,7 +245,7 @@ def check_output(idx, test, fraction): assert (prt_ws / prp_track_csv_file).is_file() # check mp7 output files exist - mp7_pathline_file = f"{mp7name}.mppth" + mp7_pathline_file = f"{mp7_name}.mppth" assert (mp7_ws / mp7_pathline_file).is_file() # load mp7 pathline results diff --git a/autotest/prt/test_prt_stop_zones.py b/autotest/prt/test_prt_stop_zones.py index 28f7df8ef31..35ea0d6d198 100644 --- a/autotest/prt/test_prt_stop_zones.py +++ b/autotest/prt/test_prt_stop_zones.py @@ -24,7 +24,6 @@ from itertools import repeat from pathlib import Path -from pprint import pformat import flopy import matplotlib.cm as cm @@ -36,12 +35,8 @@ from flopy.utils import PathlineFile from flopy.utils.binaryfile import HeadFile from matplotlib.collections import LineCollection -from prt_test_utils import ( - BasicDisCase, - check_budget_data, - check_track_data, - get_model_name, -) +from prt_test_utils import (BasicDisCase, check_budget_data, check_track_data, + get_model_name) from framework import TestFramework @@ -78,8 +73,8 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): ) # create prt model - prtname = get_model_name(name, "prt") - prt = flopy.mf6.ModflowPrt(sim, modelname=prtname) + prt_name = get_model_name(name, "prt") + prt = flopy.mf6.ModflowPrt(sim, modelname=prt_name) # create prt discretization nlay = int(name[-1]) @@ -107,7 +102,7 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): flopy.mf6.ModflowPrtprp( prt, pname="prp1", - filename=f"{prtname}_1.prp", + filename=f"{prt_name}_1.prp", nreleasepts=len(BasicDisCase.releasepts_prt), packagedata=BasicDisCase.releasepts_prt, perioddata={0: ["FIRST"]}, @@ -115,8 +110,8 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): ) # create output control package - prt_track_file = f"{prtname}.trk" - prt_track_csv_file = f"{prtname}.trk.csv" + prt_track_file = f"{prt_name}.trk" + prt_track_csv_file = f"{prt_name}.trk.csv" flopy.mf6.ModflowPrtoc( prt, pname="oc", @@ -125,9 +120,9 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): ) # create the flow model interface - gwfname = get_model_name(name, "gwf") - gwf_budget_file = gwf_ws / f"{gwfname}.bud" - gwf_head_file = gwf_ws / f"{gwfname}.hds" + gwf_name = get_model_name(name, "gwf") + gwf_budget_file = gwf_ws / f"{gwf_name}.bud" + gwf_head_file = gwf_ws / f"{gwf_name}.hds" flopy.mf6.ModflowPrtfmi( prt, packagedata=[ @@ -140,7 +135,7 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): ems = flopy.mf6.ModflowEms( sim, pname="ems", - filename=f"{prtname}.ems", + filename=f"{prt_name}.ems", ) sim.register_solution_package(ems, [prt.name]) @@ -156,17 +151,19 @@ def build_mp7_sim(name, ws, mp7, gwf): timeoffset=0, drape=0, ) - mp7name = get_model_name(name, "mp7") + mp7_name = get_model_name(name, "mp7") pg = flopy.modpath.ParticleGroup( particlegroupname="G1", particledata=partdata, - filename=f"{mp7name}.sloc", + filename=f"{mp7_name}.sloc", ) mp = flopy.modpath.Modpath7( - modelname=mp7name, + modelname=mp7_name, flowmodel=gwf, exe_name=mp7, model_ws=ws, + headfilename=f"{gwf.name}.hds", + budgetfilename=f"{gwf.name}.bud", ) mpbas = flopy.modpath.Modpath7Bas( mp, @@ -190,10 +187,10 @@ def build_mp7_sim(name, ws, mp7, gwf): def build_models(idx, test): - gwfsim = BasicDisCase.get_gwf_sim( + gwf_sim = BasicDisCase.get_gwf_sim( test.name, test.workspace, test.targets.mf6 ) - gwf = gwfsim.get_model() + gwf = gwf_sim.get_model() dis = gwf.get_package("DIS") nlay = int(test.name[-1]) botm = [BasicDisCase.top - (k + 1) for k in range(nlay)] @@ -202,10 +199,13 @@ def build_models(idx, test): ).reshape((nlay, BasicDisCase.nrow, BasicDisCase.ncol)) dis.nlay = nlay dis.botm.set_data(botm_data) - prtsim = build_prt_sim( + prt_sim = build_prt_sim( test.name, test.workspace, test.workspace / "prt", test.targets.mf6 ) - return gwfsim, prtsim + mp7_sim = build_mp7_sim( + test.name, test.workspace / "mp7", test.targets.mp7, gwf + ) + return gwf_sim, prt_sim, mp7_sim def check_output(idx, test): @@ -213,39 +213,25 @@ def check_output(idx, test): gwf_ws = test.workspace prt_ws = test.workspace / "prt" mp7_ws = test.workspace / "mp7" - - # model names - gwfname = get_model_name(name, "gwf") - prtname = get_model_name(name, "prt") - mp7name = get_model_name(name, "mp7") - - # extract mf6 simulations/models and grid - gwfsim = test.sims[0] - prtsim = test.sims[1] - gwf = gwfsim.get_model(gwfname) - prt = prtsim.get_model(prtname) + gwf_name = get_model_name(name, "gwf") + prt_name = get_model_name(name, "prt") + mp7_name = get_model_name(name, "mp7") + gwf_sim = test.sims[0] + gwf = gwf_sim.get_model(gwf_name) mg = gwf.modelgrid - # build mp7 model - mp7sim = build_mp7_sim(name, mp7_ws, test.targets.mp7, gwf) - - # run mp7 model - mp7sim.write_input() - success, buff = mp7sim.run_model(report=True) - assert success, pformat(buff) - # check mf6 output files exist - gwf_budget_file = f"{gwfname}.bud" - gwf_head_file = f"{gwfname}.hds" - prt_track_file = f"{prtname}.trk" - prt_track_csv_file = f"{prtname}.trk.csv" + gwf_budget_file = f"{gwf_name}.bud" + gwf_head_file = f"{gwf_name}.hds" + prt_track_file = f"{prt_name}.trk" + prt_track_csv_file = f"{prt_name}.trk.csv" assert (gwf_ws / gwf_budget_file).is_file() assert (gwf_ws / gwf_head_file).is_file() assert (prt_ws / prt_track_file).is_file() assert (prt_ws / prt_track_csv_file).is_file() # check mp7 output files exist - mp7_pathline_file = f"{mp7name}.mppth" + mp7_pathline_file = f"{mp7_name}.mppth" assert (mp7_ws / mp7_pathline_file).is_file() # load mp7 pathline results diff --git a/autotest/prt/test_prt_track_events.py b/autotest/prt/test_prt_track_events.py index e26d4f68b49..2b0ee911960 100644 --- a/autotest/prt/test_prt_track_events.py +++ b/autotest/prt/test_prt_track_events.py @@ -24,7 +24,6 @@ from pathlib import Path -from pprint import pformat import flopy import matplotlib.cm as cm @@ -35,12 +34,8 @@ from flopy.plot.plotutil import to_mp7_pathlines from flopy.utils import PathlineFile from flopy.utils.binaryfile import HeadFile -from prt_test_utils import ( - BasicDisCase, - check_budget_data, - check_track_data, - get_model_name, -) +from prt_test_utils import (BasicDisCase, check_budget_data, check_track_data, + get_model_name) from framework import TestFramework @@ -125,8 +120,8 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): ) # create prt model - prtname = get_model_name(name, "prt") - prt = flopy.mf6.ModflowPrt(sim, modelname=prtname) + prt_name = get_model_name(name, "prt") + prt = flopy.mf6.ModflowPrt(sim, modelname=prt_name) # create prt discretization flopy.mf6.modflow.mfgwfdis.ModflowGwfdis( @@ -148,7 +143,7 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): flopy.mf6.ModflowPrtprp( prt, pname=f"prp_{grp}", - filename=f"{prtname}_{grp}.prp", + filename=f"{prt_name}_{grp}.prp", nreleasepts=len(releasepts_prt[grp]), packagedata=releasepts_prt[grp], perioddata={0: ["FIRST"]}, @@ -158,8 +153,8 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): # create output control package event = get_output_event(name) - prt_track_file = f"{prtname}.trk" - prt_track_csv_file = f"{prtname}.trk.csv" + prt_track_file = f"{prt_name}.trk" + prt_track_csv_file = f"{prt_name}.trk.csv" flopy.mf6.ModflowPrtoc( prt, pname="oc", @@ -169,9 +164,9 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): ) # create the flow model interface - gwfname = get_model_name(name, "gwf") - gwf_budget_file = gwf_ws / f"{gwfname}.bud" - gwf_head_file = gwf_ws / f"{gwfname}.hds" + gwf_name = get_model_name(name, "gwf") + gwf_budget_file = gwf_ws / f"{gwf_name}.bud" + gwf_head_file = gwf_ws / f"{gwf_name}.hds" flopy.mf6.ModflowPrtfmi( prt, packagedata=[ @@ -184,7 +179,7 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): ems = flopy.mf6.ModflowEms( sim, pname="ems", - filename=f"{prtname}.ems", + filename=f"{prt_name}.ems", ) sim.register_solution_package(ems, [prt.name]) @@ -192,8 +187,7 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): def build_mp7_sim(name, ws, mp7, gwf): - mp7name = get_model_name(name, "mp7") - mp7_pathline_file = f"{mp7name}.mppth" + mp7_name = get_model_name(name, "mp7") pgs = [ flopy.modpath.ParticleGroup( particlegroupname=f"group_{grp}", @@ -205,15 +199,17 @@ def build_mp7_sim(name, ws, mp7, gwf): timeoffset=0, drape=0, ), - filename=f"{mp7name}_{grp}.sloc", + filename=f"{mp7_name}_{grp}.sloc", ) for grp in ["a", "b"] ] mp = flopy.modpath.Modpath7( - modelname=mp7name, + modelname=mp7_name, flowmodel=gwf, exe_name=mp7, model_ws=ws, + headfilename=f"{gwf.name}.hds", + budgetfilename=f"{gwf.name}.bud", ) mpbas = flopy.modpath.Modpath7Bas( mp, @@ -233,21 +229,25 @@ def build_mp7_sim(name, ws, mp7, gwf): def build_models(idx, test): # build gwf model - gwfsim = BasicDisCase.get_gwf_sim( + gwf_sim = BasicDisCase.get_gwf_sim( test.name, test.workspace, test.targets.mf6 ) # add idomain - gwf = gwfsim.get_model() + gwf = gwf_sim.get_model() dis = gwf.get_package("DIS") dis.idomain = create_idomain( BasicDisCase.nlay, BasicDisCase.nrow, BasicDisCase.ncol ) # build prt model - prtsim = build_prt_sim( + prt_sim = build_prt_sim( test.name, test.workspace, test.workspace / "prt", test.targets.mf6 ) - return gwfsim, prtsim + # build mp7 model + mp7_sim = build_mp7_sim( + test.name, test.workspace / "mp7", test.targets.mp7, gwf + ) + return gwf_sim, prt_sim, mp7_sim def check_output(idx, test): @@ -255,35 +255,19 @@ def check_output(idx, test): gwf_ws = test.workspace prt_ws = test.workspace / "prt" mp7_ws = test.workspace / "mp7" - - # model names - gwfname = get_model_name(name, "gwf") - prtname = get_model_name(name, "prt") - mp7name = get_model_name(name, "mp7") - - # extract models - gwfsim = test.sims[0] - prtsim = test.sims[1] - gwf = gwfsim.get_model(gwfname) - prt = prtsim.get_model(prtname) - - # extract model grid + gwf_name = get_model_name(name, "gwf") + prt_name = get_model_name(name, "prt") + mp7_name = get_model_name(name, "mp7") + gwf_sim = test.sims[0] + gwf = gwf_sim.get_model(gwf_name) mg = gwf.modelgrid - # build mp7 model - mp7sim = build_mp7_sim(name, mp7_ws, test.targets.mp7, gwf) - - # run mp7 model - mp7sim.write_input() - success, buff = mp7sim.run_model(report=True) - assert success, pformat(buff) - # check mf6 output files exist - gwf_budget_file = f"{gwfname}.bud" - gwf_head_file = f"{gwfname}.hds" - prt_track_file = f"{prtname}.trk" - prt_track_csv_file = f"{prtname}.trk.csv" - mp7_pathline_file = f"{mp7name}.mppth" + gwf_budget_file = f"{gwf_name}.bud" + gwf_head_file = f"{gwf_name}.hds" + prt_track_file = f"{prt_name}.trk" + prt_track_csv_file = f"{prt_name}.trk.csv" + mp7_pathline_file = f"{mp7_name}.mppth" assert (gwf_ws / gwf_budget_file).is_file() assert (gwf_ws / gwf_head_file).is_file() assert (prt_ws / prt_track_file).is_file() diff --git a/autotest/prt/test_prt_triangle.py b/autotest/prt/test_prt_triangle.py index 57800f99eb7..30e1fe45696 100644 --- a/autotest/prt/test_prt_triangle.py +++ b/autotest/prt/test_prt_triangle.py @@ -204,38 +204,31 @@ def build_prt_sim(name, gwf_ws, prt_ws, targets): def build_models(idx, test): - gwfsim = build_gwf_sim(test.name, test.workspace, test.targets) - prtsim = build_prt_sim( + gwf_sim = build_gwf_sim(test.name, test.workspace, test.targets) + prt_sim = build_prt_sim( test.name, test.workspace, test.workspace / "prt", test.targets ) - return gwfsim, prtsim + return gwf_sim, prt_sim def check_output(idx, test): name = test.name - gwf_ws = test.workspace prt_ws = test.workspace / "prt" - gwfname = get_model_name(name, "gwf") - prtname = get_model_name(name, "prt") - drape = "drp" in name - - # extract mf6 simulations/models and grid - gwfsim = test.sims[0] - prtsim = test.sims[1] - gwf = gwfsim.get_model(gwfname) - prt = prtsim.get_model(prtname) - mg = gwf.modelgrid + gwf_name = get_model_name(name, "gwf") + prt_name = get_model_name(name, "prt") + gwf_sim = test.sims[0] + gwf = gwf_sim.get_model(gwf_name) # get gwf output - gwf = gwfsim.get_model() + gwf = gwf_sim.get_model() head = gwf.output.head().get_data() bdobj = gwf.output.budget() spdis = bdobj.get_data(text="DATA-SPDIS")[0] qx, qy, qz = flopy.utils.postprocessing.get_specific_discharge(spdis, gwf) # get prt output - prtname = get_model_name(name, "prt") - prt_track_csv_file = f"{prtname}.prp.trk.csv" + prt_name = get_model_name(name, "prt") + prt_track_csv_file = f"{prt_name}.prp.trk.csv" pls = pd.read_csv(prt_ws / prt_track_csv_file, na_filter=False) endpts = ( pls.sort_values("t") diff --git a/autotest/prt/test_prt_voronoi.py b/autotest/prt/test_prt_voronoi.py index ff12c7fefc6..ec48a30af06 100644 --- a/autotest/prt/test_prt_voronoi.py +++ b/autotest/prt/test_prt_voronoi.py @@ -21,7 +21,6 @@ from pathlib import Path import flopy -import matplotlib.cm as cm import matplotlib.pyplot as plt import numpy as np import pandas as pd @@ -82,7 +81,7 @@ def get_grid(workspace, targets): def build_gwf_sim(name, ws, targets): ws = Path(ws) - gwfname = get_model_name(name, "gwf") + gwf_name = get_model_name(name, "gwf") # create grid grid = get_grid(ws / "grid", targets) @@ -119,7 +118,7 @@ def build_gwf_sim(name, ws, targets): tdis = flopy.mf6.ModflowTdis( sim, time_units="DAYS", perioddata=[[1.0, 1, 1.0]] ) - gwf = flopy.mf6.ModflowGwf(sim, modelname=gwfname, save_flows=True) + gwf = flopy.mf6.ModflowGwf(sim, modelname=gwf_name, save_flows=True) ims = flopy.mf6.ModflowIms( sim, print_option="SUMMARY", @@ -158,8 +157,8 @@ def build_gwf_sim(name, ws, targets): chd = flopy.mf6.ModflowGwfchd(gwf, stress_period_data=chdlist) oc = flopy.mf6.ModflowGwfoc( gwf, - budget_filerecord=f"{gwfname}.bud", - head_filerecord=f"{gwfname}.hds", + budget_filerecord=f"{gwf_name}.bud", + head_filerecord=f"{gwf_name}.hds", saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], printrecord=[("HEAD", "LAST"), ("BUDGET", "LAST")], ) @@ -168,8 +167,8 @@ def build_gwf_sim(name, ws, targets): def build_prt_sim(name, gwf_ws, prt_ws, targets): prt_ws = Path(prt_ws) - gwfname = get_model_name(name, "gwf") - prtname = get_model_name(name, "prt") + gwf_name = get_model_name(name, "gwf") + prt_name = get_model_name(name, "prt") # create grid grid = get_grid(prt_ws / "grid", targets) @@ -201,7 +200,7 @@ def build_prt_sim(name, gwf_ws, prt_ws, targets): tdis = flopy.mf6.ModflowTdis( sim, time_units="DAYS", perioddata=[[1.0, 1, 1.0]] ) - prt = flopy.mf6.ModflowPrt(sim, modelname=prtname) + prt = flopy.mf6.ModflowPrt(sim, modelname=prt_name) disv = flopy.mf6.ModflowGwfdisv( prt, nlay=nlay, **grid.get_disv_gridprops(), top=top, botm=botm ) @@ -212,12 +211,12 @@ def build_prt_sim(name, gwf_ws, prt_ws, targets): (i, (0, vgrid.intersect(p[0], p[1])), p[0], p[1], p[2]) for i, p in enumerate(rpts) ] - prp_track_file = f"{prtname}.prp.trk" - prp_track_csv_file = f"{prtname}.prp.trk.csv" + prp_track_file = f"{prt_name}.prp.trk" + prp_track_csv_file = f"{prt_name}.prp.trk.csv" flopy.mf6.ModflowPrtprp( prt, pname="prp1", - filename=f"{prtname}_1.prp", + filename=f"{prt_name}_1.prp", nreleasepts=len(prpdata), packagedata=prpdata, perioddata={0: ["FIRST"]}, @@ -226,16 +225,16 @@ def build_prt_sim(name, gwf_ws, prt_ws, targets): boundnames=True, stop_at_weak_sink=True, # currently required for this problem ) - prt_track_file = f"{prtname}.trk" - prt_track_csv_file = f"{prtname}.trk.csv" + prt_track_file = f"{prt_name}.trk" + prt_track_csv_file = f"{prt_name}.trk.csv" flopy.mf6.ModflowPrtoc( prt, pname="oc", track_filerecord=[prt_track_file], trackcsv_filerecord=[prt_track_csv_file], ) - gwf_budget_file = gwf_ws / f"{gwfname}.bud" - gwf_head_file = gwf_ws / f"{gwfname}.hds" + gwf_budget_file = gwf_ws / f"{gwf_name}.bud" + gwf_head_file = gwf_ws / f"{gwf_name}.hds" flopy.mf6.ModflowPrtfmi( prt, packagedata=[ @@ -246,31 +245,25 @@ def build_prt_sim(name, gwf_ws, prt_ws, targets): ems = flopy.mf6.ModflowEms( sim, pname="ems", - filename=f"{prtname}.ems", + filename=f"{prt_name}.ems", ) sim.register_solution_package(ems, [prt.name]) return sim def build_models(idx, test): - gwfsim = build_gwf_sim(test.name, test.workspace, test.targets) - prtsim = build_prt_sim( + gwf_sim = build_gwf_sim(test.name, test.workspace, test.targets) + prt_sim = build_prt_sim( test.name, test.workspace, test.workspace / "prt", test.targets ) - return gwfsim, prtsim + return gwf_sim, prt_sim def check_output(idx, test): name = test.name - gwf_ws = test.workspace prt_ws = test.workspace / "prt" - gwfname = get_model_name(name, "gwf") - prtname = get_model_name(name, "prt") - mp7name = get_model_name(name, "mp7") - - # extract mf6 simulations/models and grid + prt_name = get_model_name(name, "prt") gwfsim = test.sims[0] - prtsim = test.sims[1] # get gwf output gwf = gwfsim.get_model() @@ -280,7 +273,7 @@ def check_output(idx, test): qx, qy, qz = flopy.utils.postprocessing.get_specific_discharge(spdis, gwf) # get prt output - prt_track_csv_file = f"{prtname}.prp.trk.csv" + prt_track_csv_file = f"{prt_name}.prp.trk.csv" pls = pd.read_csv(prt_ws / prt_track_csv_file, na_filter=False) plot_debug = False diff --git a/autotest/prt/test_prt_weak_sinks.py b/autotest/prt/test_prt_weak_sinks.py index b72573614f2..1e73c8d4253 100644 --- a/autotest/prt/test_prt_weak_sinks.py +++ b/autotest/prt/test_prt_weak_sinks.py @@ -35,13 +35,8 @@ from flopy.plot.plotutil import to_mp7_pathlines from flopy.utils import PathlineFile from flopy.utils.binaryfile import HeadFile -from prt_test_utils import ( - BasicDisCase, - check_budget_data, - check_track_data, - get_ireason_code, - get_model_name, -) +from prt_test_utils import (BasicDisCase, check_budget_data, check_track_data, + get_ireason_code, get_model_name) from framework import TestFramework @@ -131,7 +126,7 @@ def build_prt_sim(name, gwf_ws, prt_ws, mf6): def build_mp7_sim(name, ws, mp7, gwf): - mp7name = f"{name}_mp7" + mp7_name = f"{name}_mp7" partdata = flopy.modpath.ParticleData( partlocs=[p[0] for p in BasicDisCase.releasepts_mp7], localx=[p[1] for p in BasicDisCase.releasepts_mp7], @@ -143,13 +138,15 @@ def build_mp7_sim(name, ws, mp7, gwf): pg = flopy.modpath.ParticleGroup( particlegroupname="G1", particledata=partdata, - filename=f"{mp7name}.sloc", + filename=f"{mp7_name}.sloc", ) mp = flopy.modpath.Modpath7( - modelname=mp7name, + modelname=mp7_name, flowmodel=gwf, exe_name=mp7, model_ws=ws, + headfilename=f"{gwf.name}.hds", + budgetfilename=f"{gwf.name}.bud", ) mpbas = flopy.modpath.Modpath7Bas( mp, @@ -177,11 +174,11 @@ def get_different_rows(source_df, new_df): def build_models(idx, test): # build gwf model - gwfsim = BasicDisCase.get_gwf_sim( + gwf_sim = BasicDisCase.get_gwf_sim( test.name, test.workspace, test.targets.mf6 ) # add wel package - gwf = gwfsim.get_model() + gwf = gwf_sim.get_model() wells = [ # k, i, j, q (0, 4, 4, -0.1), @@ -194,10 +191,15 @@ def build_models(idx, test): ) # build prt model - prtsim = build_prt_sim( + prt_sim = build_prt_sim( test.name, test.workspace, test.workspace / "prt", test.targets.mf6 ) - return gwfsim, prtsim + + # build mp7 model + mp7_sim = build_mp7_sim( + test.name, test.workspace / "mp7", test.targets.mp7, gwf + ) + return gwf_sim, prt_sim, mp7_sim def check_output(idx, test): @@ -205,33 +207,19 @@ def check_output(idx, test): gwf_ws = test.workspace prt_ws = test.workspace / "prt" mp7_ws = test.workspace / "mp7" - - # model names - gwfname = get_model_name(name, "gwf") - prtname = get_model_name(name, "prt") - mp7name = get_model_name(name, "mp7") - - # extract mf6 models and grid - gwfsim = test.sims[0] - prtsim = test.sims[1] - gwf = gwfsim.get_model(gwfname) - prt = prtsim.get_model(prtname) + gwf_name = get_model_name(name, "gwf") + prt_name = get_model_name(name, "prt") + mp7_name = get_model_name(name, "mp7") + gwf_sim = test.sims[0] + gwf = gwf_sim.get_model(gwf_name) mg = gwf.modelgrid - # build mp7 model - mp7sim = build_mp7_sim(name, mp7_ws, test.targets.mp7, gwf) - - # run mp7 model - mp7sim.write_input() - success, buff = mp7sim.run_model(report=True) - assert success, pformat(buff) - # check mf6 output files exist - gwf_budget_file = f"{gwfname}.bud" - gwf_head_file = f"{gwfname}.hds" - prt_track_file = f"{prtname}.trk" - prt_track_csv_file = f"{prtname}.trk.csv" - mp7_pathline_file = f"{mp7name}.mppth" + gwf_budget_file = f"{gwf_name}.bud" + gwf_head_file = f"{gwf_name}.hds" + prt_track_file = f"{prt_name}.trk" + prt_track_csv_file = f"{prt_name}.trk.csv" + mp7_pathline_file = f"{mp7_name}.mppth" assert (gwf_ws / gwf_budget_file).is_file() assert (gwf_ws / gwf_head_file).is_file() assert (prt_ws / prt_track_file).is_file()