Ejemplo n.º 1
0
def test045_lake1ss_table():
    # init paths
    test_ex_name = 'test045_lake1ss_table'
    model_name = 'lakeex1b'

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder, 'lakeex1b_unch.hds')
    expected_head_file_b = os.path.join(expected_output_folder, 'lakeex1b_adj.hds')

    # load simulation
    sim = MFSimulation.load(model_name, 'mf6', exe_name, pth)

    # make temp folder to save simulation
    sim.simulation_data.mfpath.set_sim_path(run_folder)

    # write simulation to new location
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'lakeex1b.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

    # change some settings
    model = sim.get_model(model_name)
    laktbl = model.get_package('tab').table
    laktbl_data = laktbl.get_data()
    laktbl_data[-1][0] = 700.0
    laktbl.set_data(laktbl_data)

    # write simulation again
    sim.simulation_data.mfpath.set_sim_path(save_folder)
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_b)
        head_new = os.path.join(save_folder, 'lakeex1b.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

        # clean up
        sim.delete_output_files()

    return
Ejemplo n.º 2
0
def test001e_uzf_3lay():
    # init paths
    test_ex_name = 'test001e_UZF_3lay'
    model_name = 'gwf_1'

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder, 'test001e_UZF_3lay_unch.hds')
    expected_head_file_b = os.path.join(expected_output_folder, 'test001e_UZF_3lay_adj.hds')

    # load simulation
    sim = MFSimulation.load(model_name, 'mf6', exe_name, pth)

    # make temp folder to save simulation
    sim.simulation_data.mfpath.set_sim_path(run_folder)

    # write simulation to new location
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'test001e_UZF_3lay.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

    # change some settings
    model = sim.get_model(model_name)
    uzf = model.get_package('uzf')
    uzf_data = uzf.packagedata
    uzf_array = uzf_data.get_data()
    # increase initial water content
    for index in range(0, len(uzf_array)):
        uzf_array[index][7] = 0.3
    uzf_data.set_data(uzf_array)

    # write simulation again
    sim.simulation_data.mfpath.set_sim_path(save_folder)
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_b)
        head_new = os.path.join(save_folder, 'test001e_UZF_3lay.hds')
        outfile = os.path.join(save_folder, 'head_compare.dat')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new, outfile=outfile)
Ejemplo n.º 3
0
def test027_timeseriestest():
    # init paths
    test_ex_name = 'test027_TimeseriesTest'
    model_name = 'gwf_1'

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder, 'timeseriestest_unch.hds')
    expected_head_file_b = os.path.join(expected_output_folder, 'timeseriestest_adj.hds')

    # load simulation
    sim = MFSimulation.load(model_name, 'mf6', exe_name, pth)

    # make temp folder to save simulation
    sim.simulation_data.mfpath.set_sim_path(run_folder)

    # write simulation to new location
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'timeseriestest.hds')
        outfile = os.path.join(run_folder, 'head_compare.dat')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new, outfile=outfile)

    model = sim.get_model(model_name)
    rch = model.get_package('rcha')
    tas_rch = rch.get_package('tas')
    tas_array_data = tas_rch.tas_array.get_data(12.0)
    assert tas_array_data == 0.0003
    tas_array_data = 0.02
    tas_rch.tas_array.set_data(tas_array_data, key=12.0)

    # write simulation again
    sim.simulation_data.mfpath.set_sim_path(save_folder)
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_b)
        head_new = os.path.join(save_folder, 'timeseriestest.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)
Ejemplo n.º 4
0
def test045_lake2tr():
    # init paths
    test_ex_name = 'test045_lake2tr'
    model_name = 'lakeex2a'

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder, 'lakeex2a_unch.hds')
    expected_head_file_b = os.path.join(expected_output_folder, 'lakeex2a_adj.hds')

    # load simulation
    sim = MFSimulation.load(model_name, 'mf6', exe_name, pth)

    # write simulation to new location
    sim.simulation_data.mfpath.set_sim_path(run_folder)
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'lakeex2a.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

    # change some settings
    model = sim.get_model(model_name)
    evt = model.get_package('evt')
    evt.rate.set_data([0.05], key=0)

    lak = model.get_package('lak')
    lak_period = lak.lakeperioddata
    lak_period_data = lak_period.get_data()
    lak_period_data[2][2] = '0.05'
    lak_period.set_data(lak_period_data, 0)

    # write simulation again
    sim.simulation_data.mfpath.set_sim_path(save_folder)
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_b)
        head_new = os.path.join(save_folder, 'lakeex2a.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)
Ejemplo n.º 5
0
    def _compare_concentrations(self, msgall, extensions="ucn"):
        if isinstance(extensions, str):
            extensions = [extensions]
        success = True
        files0, files1 = self._regression_files(extensions)
        extension = "ucn"
        ipos = 0
        for idx, (fpth0, fpth1) in enumerate(zip(files0, files1)):
            outfile = os.path.splitext(os.path.basename(fpth0))[0]
            outfile = os.path.join(
                self.simpath, outfile + ".{}.cmp.out".format(extension)
            )
            success_tst = pymake.compare_heads(
                None,
                None,
                precision="double",
                htol=self.htol,
                text=extdict[extension],
                outfile=outfile,
                files1=fpth0,
                files2=fpth1,
                verbose=self.cmp_verbose,
            )
            msg = sfmt.format(
                "{} comparison {}".format(extdict[extension], ipos + 1),
                "{} ({})".format(self.name, os.path.basename(fpth0)),
            )
            ipos += 1
            print(msg)

            if not success_tst:
                success = False
                msgall += msg + " ... FAILED\n"

        return success, msgall
Ejemplo n.º 6
0
def test005_advgw_tidal():
    # init paths
    test_ex_name = 'test005_advgw_tidal'
    model_name = 'gwf_1'

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder,
                                        'AdvGW_tidal_unch.hds')
    expected_head_file_b = os.path.join(expected_output_folder,
                                        'AdvGW_tidal_adj.hds')

    # load simulation
    sim = MFSimulation.load(model_name,
                            'mf6',
                            exe_name,
                            pth,
                            verbosity_level=2)

    # test obs/ts package interface
    model = sim.get_model(model_name)
    ghb = model.get_package('ghb')
    obs = ghb.obs
    digits = obs.digits.get_data()
    assert (digits == 10)
    names = ghb.ts.time_series_namerecord.get_data()
    assert (names[0][0] == 'tides')

    # make temp folder to save simulation
    sim.simulation_data.mfpath.set_sim_path(run_folder)

    # write simulation to new location
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'advgw_tidal.hds')
        outfile = os.path.join(run_folder, 'head_compare.dat')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new,
                                    outfile=outfile)

    # change some settings
    """
Ejemplo n.º 7
0
def test005_advgw_tidal():
    # init paths
    test_ex_name = 'test005_advgw_tidal'
    model_name = 'gwf_1'

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder, 'AdvGW_tidal_unch.hds')
    expected_head_file_b = os.path.join(expected_output_folder, 'AdvGW_tidal_adj.hds')

    # load simulation
    sim = MFSimulation.load(model_name, 'mf6', exe_name, pth,
                            verbosity_level=2)

    # test obs/ts package interface
    model = sim.get_model(model_name)
    ghb = model.get_package('ghb')
    obs = ghb.obs
    digits = obs.digits.get_data()
    assert(digits == 10)
    names = ghb.ts.time_series_namerecord.get_data()
    assert(names[0][0] == 'tides')

    # make temp folder to save simulation
    sim.simulation_data.mfpath.set_sim_path(run_folder)

    # write simulation to new location
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'advgw_tidal.hds')
        outfile = os.path.join(run_folder, 'head_compare.dat')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new, outfile=outfile)

    # change some settings
    """
Ejemplo n.º 8
0
def runmodel(folder):
    f = os.path.basename(os.path.normpath(folder))
    print("\n\n")
    print("**** RUNNING TEST: {} ****".format(f))
    print("\n")

    # load the model into a flopy simulation
    print("loading {}".format(f))
    sim = flopy.mf6.MFSimulation.load(f, "mf6", exe_name, folder)
    assert isinstance(sim, flopy.mf6.MFSimulation)

    # run the simulation in folder if executable is available
    if run:
        success, buff = sim.run_simulation()
        assert success

        headfiles = [
            f for f in os.listdir(folder) if f.lower().endswith(".hds")
        ]

        folder2 = folder + "-RERUN"
        sim.simulation_data.mfpath.set_sim_path(folder2)
        sim.write_simulation()
        success, buff = sim.run_simulation()
        assert success

        headfiles1 = []
        headfiles2 = []
        for hf in headfiles:
            headfiles1.append(os.path.join(folder, hf))
            headfiles2.append(os.path.join(folder2, hf))

        outfile = os.path.join(folder, "head_compare.dat")
        success = pymake.compare_heads(
            None,
            None,
            precision="double",
            text="head",
            files1=headfiles1,
            files2=headfiles2,
            outfile=outfile,
        )
        assert success
Ejemplo n.º 9
0
def runmodel(f):

    print('\n\n')
    print('**** RUNNING TEST: {} ****'.format(f))
    print('\n')

    # load the model into a flopy simulation
    folder = os.path.join(out_dir, f)
    print('loading {}'.format(folder))
    sim = flopy.mf6.MFSimulation.load(f, 'mf6', exe_name, folder)
    assert isinstance(sim, flopy.mf6.MFSimulation)

    # run the simulation in folder if executable is available
    if run:
        success, buff = sim.run_simulation()
        assert success

        headfiles = [
            f for f in os.listdir(folder) if f.lower().endswith('.hds')
        ]

        folder2 = folder + '-RERUN'
        sim.simulation_data.mfpath.set_sim_path(folder2)
        sim.write_simulation()
        success, buff = sim.run_simulation()
        assert success

        headfiles1 = []
        headfiles2 = []
        for hf in headfiles:
            headfiles1.append(os.path.join(folder, hf))
            headfiles2.append(os.path.join(folder2, hf))

        outfile = os.path.join(folder, 'head_compare.dat')
        success = pymake.compare_heads(None,
                                       None,
                                       precision='double',
                                       text='head',
                                       files1=headfiles1,
                                       files2=headfiles2,
                                       outfile=outfile)
        assert success
Ejemplo n.º 10
0
def test005_advgw_tidal():
    # init paths
    test_ex_name = 'test005_advgw_tidal'
    model_name = 'gwf_1'

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder, 'AdvGW_tidal_unch.hds')
    expected_head_file_b = os.path.join(expected_output_folder, 'AdvGW_tidal_adj.hds')

    # load simulation
    sim = MFSimulation.load(model_name, 'mf6', exe_name, pth,
                            verbosity_level=VerbosityLevel.verbose)

    # make temp folder to save simulation
    sim.simulation_data.mfpath.set_sim_path(run_folder)

    # write simulation to new location
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'advgw_tidal.hds')
        outfile = os.path.join(run_folder, 'head_compare.dat')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new, outfile=outfile)

    # change some settings
    """
Ejemplo n.º 11
0
def test005_advgw_tidal():
    # init paths
    test_ex_name = 'test005_advgw_tidal'
    model_name = 'gwf_1'

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder, 'AdvGW_tidal_unch.hds')
    expected_head_file_b = os.path.join(expected_output_folder, 'AdvGW_tidal_adj.hds')

    # load simulation
    sim = MFSimulation.load(model_name, 'mf6', exe_name, pth)

    # make temp folder to save simulation
    sim.simulation_data.mfpath.set_sim_path(run_folder)

    # write simulation to new location
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'advgw_tidal.hds')
        outfile = os.path.join(run_folder, 'head_compare.dat')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new, outfile=outfile)

    # change some settings
    """
Ejemplo n.º 12
0
def runmodel(f):

    print('\n\n')
    print('**** RUNNING TEST: {} ****'.format(f))
    print('\n')

    # load the model into a flopy simulation
    folder = os.path.join(out_dir, f)
    print('loading {}'.format(folder))
    sim = flopy.mf6.MFSimulation.load(f, 'mf6', exe_name, folder)
    assert isinstance(sim, flopy.mf6.MFSimulation)

    # run the simulation in folder if executable is available
    if run:
        success, buff = sim.run_simulation()
        assert success

        headfiles = [f for f in os.listdir(folder)
                     if f.lower().endswith('.hds')]

        folder2 = folder + '-RERUN'
        sim.simulation_data.mfpath.set_sim_path(folder2)
        sim.write_simulation()
        success, buff = sim.run_simulation()
        assert success

        headfiles1 = []
        headfiles2 = []
        for hf in headfiles:
            headfiles1.append(os.path.join(folder, hf))
            headfiles2.append(os.path.join(folder2, hf))

        outfile = os.path.join(folder, 'head_compare.dat')
        success = pymake.compare_heads(None, None, precision='double',
                                       text='head', files1=headfiles1,
                                       files2=headfiles2, outfile=outfile)
        assert success
Ejemplo n.º 13
0
def test_simplelgr_load_and_write():
    """
    Test load and write of distributed MODFLOW-LGR example problem
    """
    pth = os.path.join('..', 'examples', 'data', 'mflgr_v2', 'ex3')
    opth = os.path.join(cpth, 'ex3', 'orig')
    # delete the directory if it exists
    if os.path.isdir(opth):
        shutil.rmtree(opth)
    os.makedirs(opth)
    # copy the original files
    files = os.listdir(pth)
    for file in files:
        src = os.path.join(pth, file)
        dst = os.path.join(opth, file)
        shutil.copyfile(src, dst)

    # load the lgr model
    lgr = flopy.modflowlgr.ModflowLgr.load('ex3.lgr',
                                           verbose=True,
                                           model_ws=opth,
                                           exe_name=exe_name)

    # get the namefiles of the parent and child
    namefiles = lgr.get_namefiles()
    msg = 'get_namefiles returned {} items instead of 2'.format(len(namefiles))
    assert len(namefiles) == 2, msg
    tpth = os.path.dirname(namefiles[0])
    msg = 'dir path is {} not {}'.format(tpth, opth)
    assert tpth == opth, msg

    # run the lgr model
    if run:
        success, buff = lgr.run_model(silent=False)
        assert success, 'could not run original modflow-lgr model'

    # check that a parent and child were read
    msg = 'modflow-lgr ex3 does not have 2 grids'
    assert lgr.ngrids == 2, msg

    npth = os.path.join(cpth, 'ex3', 'new')
    lgr.change_model_ws(new_pth=npth, reset_external=True)

    # get the namefiles of the parent and child
    namefiles = lgr.get_namefiles()
    msg = 'get_namefiles returned {} items instead of 2'.format(len(namefiles))
    assert len(namefiles) == 2, msg
    tpth = os.path.dirname(namefiles[0])
    msg = 'dir path is {} not {}'.format(tpth, npth)
    assert tpth == npth, msg

    # write the lgr model in to the new path
    lgr.write_input()

    # run the lgr model
    if run:
        success, buff = lgr.run_model(silent=False)
        assert success, 'could not run new modflow-lgr model'

        # compare parent results
        print('compare parent results')
        pth0 = os.path.join(opth, 'ex3_parent.nam')
        pth1 = os.path.join(npth, 'ex3_parent.nam')

        msg = 'parent heads do not match'
        success = pymake.compare_heads(pth0, pth1)
        assert success, msg

        # compare child results
        print('compare child results')
        pth0 = os.path.join(opth, 'ex3_child.nam')
        pth1 = os.path.join(npth, 'ex3_child.nam')

        msg = 'child heads do not match'
        success = pymake.compare_heads(pth0, pth1)
        assert success, msg

    # clean up
    shutil.rmtree(cpth)
Ejemplo n.º 14
0
def mfnwt_model(namfile, model_ws):
    # load MODFLOW-2005 models as MODFLOW-NWT models
    m = flopy.modflow.Modflow.load(namfile, model_ws=model_ws,
                                   version='mfnwt', verbose=True, check=False,
                                   exe_name=mfnwt_exe)
    assert m, 'Could not load namefile {}'.format(namfile)
    assert m.load_fail is False
    # convert to MODFLOW-NWT model
    m.set_version('mfnwt')
    # extract data from existing flow package
    flowpaks = ['LPF']
    for pak in m.get_package_list():
        if pak == 'LPF':
            lpf = m.get_package(pak)
            layavg = lpf.layavg
            laytyp = lpf.laytyp
            layvka = lpf.layvka
            ss = lpf.ss
            sy = lpf.sy
            hk = lpf.hk
            vka = lpf.vka
            hani = lpf.hani
            chani = lpf.chani
            ipakcb = lpf.ipakcb
            unitnumber = lpf.unit_number[0]
            # remove existing package
            m.remove_package(pak)
            break
    # create UPW file from existing flow package
    upw = flopy.modflow.ModflowUpw(m, layavg=layavg, laytyp=laytyp,
                                   ipakcb=ipakcb, unitnumber=unitnumber,
                                   layvka=layvka, hani=hani, chani=chani,
                                   hk=hk, vka=vka, ss=ss, sy=sy)
    # remove the existing solver
    solvers = ['SIP', 'PCG', 'PCGN', 'GMG', 'DE4']
    for pak in m.get_package_list():
        solv = m.get_package(pak)
        if pak in solvers:
            unitnumber = solv.unit_number[0]
            m.remove_package(pak)
    nwt = flopy.modflow.ModflowNwt(m, unitnumber=unitnumber)

    # add specify option to the well package
    wel = m.get_package('WEL')
    wel.specify = True
    wel.phiramp = 1.0e-5
    wel.phiramp_unit = 2

    # change workspace and write MODFLOW-NWT model
    tdir = os.path.splitext(namfile)[0]
    pth = os.path.join(tpth, tdir)
    m.change_model_ws(pth)
    m.write_input()
    if run:
        try:
            success, buff = m.run_model(silent=False)
        except:
            success = False
        assert success, 'base model run did not terminate successfully'
        fn0 = os.path.join(pth, namfile)

    # reload the model just written
    m = flopy.modflow.Modflow.load(namfile, model_ws=pth,
                                   version='mfnwt', verbose=True, check=False,
                                   exe_name=mfnwt_exe)
    assert m, 'Could not load namefile {}'.format(namfile)
    assert m.load_fail is False

    # change workspace and write MODFLOW-NWT model
    pthf = os.path.join(pth, 'flopy')
    m.change_model_ws(pthf)
    m.write_input()
    if run:
        try:
            success, buff = m.run_model(silent=False)
        except:
            success = False
        assert success, 'base model run did not terminate successfully'
        fn1 = os.path.join(pthf, namfile)

    if run:
        fsum = os.path.join(pth, '{}.head.out'.format(tdir))
        success = False
        try:
            success = pymake.compare_heads(fn0, fn1, outfile=fsum)
        except:
            success = False
            print('could not perform head comparison')

        assert success, 'head comparison failure'

        fsum = os.path.join(pth, '{}.budget.out'.format(tdir))
        success = False
        try:
            success = pymake.compare_budget(fn0, fn1,
                                            max_incpd=0.1, max_cumpd=0.1,
                                            outfile=fsum)
        except:
            success = False
            print('could not perform budget comparison')

        assert success, 'budget comparison failure'

    return
Ejemplo n.º 15
0
def test006_2models_mvr():
    # init paths
    test_ex_name = 'test006_2models_mvr'
    sim_name = 'test006_2models_mvr'
    model_names = ['parent', 'child']

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder,
                                        'model1_unch.hds')
    expected_head_file_aa = os.path.join(expected_output_folder,
                                         'model2_unch.hds')
    expected_cbc_file_a = os.path.join(expected_output_folder,
                                       'model1_unch.cbc')

    expected_head_file_b = os.path.join(expected_output_folder,
                                        'model1_adj.hds')
    expected_head_file_bb = os.path.join(expected_output_folder,
                                         'model2_adj.hds')

    # load simulation
    sim = MFSimulation.load(sim_name, 'mf6', exe_name, pth, verify_data=True)

    # make temp folder to save simulation
    sim.simulation_data.mfpath.set_sim_path(run_folder)

    # write simulation to new location
    sim.set_all_data_external()
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'model1.hds')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new)

        head_file = os.path.join(os.getcwd(), expected_head_file_aa)
        head_new = os.path.join(run_folder, 'model2.hds')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new)

        budget_file = os.path.join(os.getcwd(), expected_cbc_file_a)
        budget_obj = bf.CellBudgetFile(budget_file, precision='double')
        budget_obj.list_records()

    # test getting models
    model_dict = sim.model_dict
    assert len(model_dict) == 2
    for model in model_dict.values():
        assert model.name in model_names
    names = sim.model_names
    assert len(names) == 2
    for name in names:
        assert name in model_names
        model = sim.get_model(name)
        assert model.model_type == 'gwf'
    models = sim.gwf
    assert len(models) == 2
    for model in models:
        assert model.name in model_names
        assert model.model_type == 'gwf'

    # change some settings
    parent_model = sim.get_model(model_names[0])
    maw_pkg = parent_model.get_package('maw')
    period_data = maw_pkg.perioddata.get_data()
    period_data[0][0][2] = -1.0
    maw_pkg.perioddata.set_data(period_data[0], 0)
    well_rec_data = maw_pkg.packagedata.get_data()
    assert (well_rec_data[0][0] == 0)

    exg_pkg = sim.get_exchange_file('simulation.exg')
    exg_data = exg_pkg.exchangedata.get_data()
    for index in range(0, len(exg_data)):
        exg_data[index][6] = 500.0
    exg_pkg.exchangedata.set_data(exg_data)

    # test getting packages
    pkg_dict = parent_model.package_dict
    assert len(pkg_dict) == 6
    pkg_names = parent_model.package_names
    assert len(pkg_names) == 6
    # confirm that this is a copy of the original dictionary with references
    # to the packages
    del pkg_dict[pkg_names[0]]
    assert len(pkg_dict) == 5
    pkg_dict = parent_model.package_dict
    assert len(pkg_dict) == 6

    old_val = pkg_dict['dis'].nlay.get_data()
    pkg_dict['dis'].nlay = 22
    pkg_dict = parent_model.package_dict
    assert pkg_dict['dis'].nlay.get_data() == 22
    pkg_dict['dis'].nlay = old_val

    # write simulation again
    sim.simulation_data.mfpath.set_sim_path(save_folder)
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_b)
        head_new = os.path.join(save_folder, 'model1.hds')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new)

        head_file = os.path.join(os.getcwd(), expected_head_file_bb)
        head_new = os.path.join(save_folder, 'model2.hds')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new)

        # clean up
        sim.delete_output_files()

    # test load_only
    model_package_check = ['ic', 'maw', 'npf', 'oc']
    load_only_lists = [['ic6', 'npf6', 'oc', 'gwf6-gwf6', 'ims'],
                       ['ic', 'maw', 'npf', 'gwf-gwf', 'ims'],
                       ['ic', 'maw6', 'npf']]
    for load_only in load_only_lists:
        sim = MFSimulation.load(sim_name,
                                'mf6',
                                exe_name,
                                pth,
                                load_only=load_only)
        for model_name in model_names:
            model = sim.get_model(model_name)
            for package in model_package_check:
                assert (package in model.package_type_dict or
                        package in sim.package_type_dict) == \
                       (package in load_only or '{}6'.format(package) in
                        load_only)
        assert (len(sim._exchange_files) > 0) == ('gwf6-gwf6' in load_only
                                                  or 'gwf-gwf' in load_only)
        assert (len(sim._ims_files) > 0) == ('ims6' in load_only
                                             or 'ims' in load_only)

    # load package by name
    load_only_list = ['ic6', 'maw', 'npf_p1', 'oc_p2', 'ims']
    sim = MFSimulation.load(sim_name,
                            'mf6',
                            exe_name,
                            pth,
                            load_only=load_only_list)
    model_parent = sim.get_model('parent')
    model_child = sim.get_model('child')
    assert 'oc' not in model_parent.package_type_dict
    assert 'oc' in model_child.package_type_dict
    assert 'npf' in model_parent.package_type_dict
    assert 'npf' not in model_child.package_type_dict

    if run:
        # test running a runnable load_only case
        sim = MFSimulation.load(sim_name,
                                'mf6',
                                exe_name,
                                pth,
                                load_only=load_only_lists[0])
        assert sim.run_simulation()[0]

    return
Ejemplo n.º 16
0
def test036_twrihfb():
    # init paths
    test_ex_name = 'test036_twrihfb'
    model_name = 'twrihfb2015'

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder,
                                        'twrihfb2015_output_unch.hds')
    expected_head_file_b = os.path.join(expected_output_folder,
                                        'twrihfb2015_output_adj.hds')

    # load simulation
    sim = MFSimulation.load(model_name, 'mf6', exe_name, pth, verify_data=True)

    # make temp folder to save simulation
    sim.simulation_data.mfpath.set_sim_path(run_folder)

    # write simulation to new location
    sim.set_all_data_external()
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'twrihfb2015_output.hds')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new)

    # change some settings
    hydchr = sim.simulation_data.mfdata[(model_name, 'hfb', 'period',
                                         'stress_period_data')]
    hydchr_data = hydchr.get_data()
    hydchr_data[0][2][2] = 0.000002
    hydchr_data[0][3][2] = 0.000003
    hydchr_data[0][4][2] = 0.0000004
    hydchr.set_data(hydchr_data[0], 0)
    cond = sim.simulation_data.mfdata[(model_name, 'drn', 'period',
                                       'stress_period_data')]
    cond_data = cond.get_data()
    for index in range(0, len(cond_data[0])):
        cond_data[0][index][2] = 2.1
    cond.set_data(cond_data[0], 0)

    rch = sim.simulation_data.mfdata[(model_name, 'rcha', 'period',
                                      'recharge')]
    rch_data = rch.get_data()
    assert (rch_data[0][5, 1] == 0.00000003)

    # write simulation again
    sim.simulation_data.mfpath.set_sim_path(save_folder)
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_b)
        head_new = os.path.join(save_folder, 'twrihfb2015_output.hds')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new)
Ejemplo n.º 17
0
def test003_gwfs_disv():
    # init paths
    test_ex_name = 'test003_gwfs_disv'
    model_name = 'gwf_1'

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder,
                                        'model_unch.hds')
    expected_head_file_b = os.path.join(expected_output_folder,
                                        'model_adj.hds')
    expected_cbc_file_a = os.path.join(expected_output_folder,
                                       'model_unch.cbc')
    expected_cbc_file_b = os.path.join(expected_output_folder, 'model_adj.cbc')

    array_util = PyListUtil()

    # load simulation
    sim = MFSimulation.load(model_name, 'mf6', exe_name, pth, verify_data=True)

    # make temp folder to save simulation
    sim.simulation_data.mfpath.set_sim_path(run_folder)

    # write simulation to new location
    sim.simulation_data.max_columns_of_data = 10
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # get expected results
        budget_file = os.path.join(os.getcwd(), expected_cbc_file_a)
        budget_obj = bf.CellBudgetFile(budget_file, precision='auto')
        budget_fjf_valid = np.array(
            budget_obj.get_data(text='    FLOW JA FACE', full3D=True))

        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'model.hds')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new)

        budget_frf = sim.simulation_data.mfdata[(model_name, 'CBC',
                                                 'FLOW-JA-FACE')]
        assert array_util.array_comp(budget_fjf_valid, budget_frf)

    model = sim.get_model(model_name)
    if shapefile:
        model.export('{}/{}.shp'.format(pth, test_ex_name))

    # change some settings
    chd_head_left = model.get_package('CHD_LEFT')
    chd_left_period = chd_head_left.stress_period_data.get_data(0)
    chd_left_period[4][1] = 15.0
    chd_head_left.stress_period_data.set_data(chd_left_period, 0)

    chd_head_right = model.get_package('CHD_RIGHT')
    chd_right_period = chd_head_right.stress_period_data
    chd_right_data = chd_right_period.get_data(0)
    chd_right_data_slice = chd_right_data[3:10]
    chd_right_period.set_data(chd_right_data_slice, 0)

    # write simulation again
    sim.simulation_data.mfpath.set_sim_path(save_folder)
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # get expected results
        budget_file = os.path.join(os.getcwd(), expected_cbc_file_b)
        budget_obj = bf.CellBudgetFile(budget_file, precision='double')
        budget_fjf_valid = np.array(
            budget_obj.get_data(text='FLOW JA FACE', full3D=True))

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_b)
        head_new = os.path.join(save_folder, 'model.hds')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new)

        budget_frf = sim.simulation_data.mfdata[(model_name, 'CBC',
                                                 'FLOW-JA-FACE')]
        assert array_util.array_comp(budget_fjf_valid, budget_frf)

        # clean up
        sim.delete_output_files()

    return
Ejemplo n.º 18
0
def test006_gwf3():
    # init paths
    test_ex_name = 'test006_gwf3'
    model_name = 'gwf_1'

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder,
                                        'flow_unch.hds')
    expected_head_file_b = os.path.join(expected_output_folder, 'flow_adj.hds')
    expected_cbc_file_a = os.path.join(expected_output_folder, 'flow_unch.cbc')
    expected_cbc_file_b = os.path.join(expected_output_folder, 'flow_adj.cbc')

    array_util = PyListUtil()

    # load simulation
    sim = MFSimulation.load(model_name, 'mf6', exe_name, pth, verify_data=True)

    model = sim.get_model()
    disu = model.get_package('disu')
    # test switching disu array to internal array
    disu.ja = disu.ja.array
    # test writing hwva and cl12 arrays out to different locations
    disu.hwva = {
        'filename': 'flow.disu.hwva_new.dat',
        'factor': 1.0,
        'data': disu.hwva.array
    }
    disu.cl12 = {
        'filename': 'flow.disu.cl12_new.dat',
        'factor': 1.0,
        'data': disu.cl12.array
    }

    # make temp folder to save simulation
    sim.simulation_data.mfpath.set_sim_path(run_folder)
    # write simulation to new location
    sim.set_all_data_external()
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        budget_file = os.path.join(os.getcwd(), expected_cbc_file_a)
        budget_obj = bf.CellBudgetFile(budget_file, precision='double')
        budget_fjf_valid = np.array(
            budget_obj.get_data(text='    FLOW JA FACE', full3D=True))
        jaentries = budget_fjf_valid.shape[-1]
        budget_fjf_valid.shape = (-1, jaentries)

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'flow.hds')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new)

        budget_fjf = np.array(sim.simulation_data.mfdata[(model_name, 'CBC',
                                                          'FLOW-JA-FACE')])
        assert array_util.array_comp(np.array(budget_fjf_valid),
                                     np.array(budget_fjf))

    # change some settings
    model = sim.get_model(model_name)
    hk = model.get_package('npf').k
    hk_data = hk.get_data()
    hk_data[2] = 3.5
    hk.set_data(hk_data)
    ex_happened = False
    try:
        hk.make_layered()
    except:
        ex_happened = True
    assert (ex_happened)

    # write simulation again
    sim.simulation_data.mfpath.set_sim_path(save_folder)
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # get expected results
        budget_file = os.path.join(os.getcwd(), expected_cbc_file_b)
        budget_obj = bf.CellBudgetFile(budget_file, precision='auto')
        budget_fjf_valid = np.array(
            budget_obj.get_data(text='    FLOW JA FACE', full3D=True))
        jaentries = budget_fjf_valid.shape[-1]
        budget_fjf_valid.shape = (-1, jaentries)

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_b)
        head_new = os.path.join(save_folder, 'flow.hds')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new)

        budget_fjf = np.array(sim.simulation_data.mfdata[(model_name, 'CBC',
                                                          'FLOW-JA-FACE')])
        assert array_util.array_comp(np.array(budget_fjf_valid),
                                     np.array(budget_fjf))

    # confirm that files did move
    save_folder = os.path.join(run_folder, 'temp_two')
    sim.simulation_data.mfpath.set_sim_path(save_folder)

    # write with "copy_external_files" turned off so external files do not get copied to new location
    sim.write_simulation(
        ext_file_action=flopy.mf6.mfbase.ExtFileAction.copy_none)

    # store strt in an external binary file
    model = sim.get_model()
    ic = model.get_package('ic')
    ic.strt.store_as_external_file('initial_heads.bin', binary=True)

    strt_data = ic.strt.array
    # update packages
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # get expected results
        budget_file = os.path.join(os.getcwd(), expected_cbc_file_b)
        budget_obj = bf.CellBudgetFile(budget_file, precision='double')
        budget_fjf_valid = np.array(
            budget_obj.get_data(text='    FLOW JA FACE', full3D=True))
        jaentries = budget_fjf_valid.shape[-1]
        budget_fjf_valid.shape = (-1, jaentries)

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_b)
        head_new = os.path.join(save_folder, 'flow.hds')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new)

        budget_fjf = np.array(sim.simulation_data.mfdata[(model_name, 'CBC',
                                                          'FLOW-JA-FACE')])
        assert array_util.array_comp(np.array(budget_fjf_valid),
                                     np.array(budget_fjf))

        # confirm that files did not move
        assert not os.path.isfile(os.path.join(save_folder,
                                               'flow.disu.ja.dat'))
        assert not os.path.isfile(
            os.path.join(save_folder, 'flow.disu.iac.dat'))
        assert not os.path.isfile(
            os.path.join(save_folder, 'flow.disu.cl12.dat'))
        assert not os.path.isfile(
            os.path.join(save_folder, 'flow.disu.area.dat'))
        assert not os.path.isfile(
            os.path.join(save_folder, 'flow.disu.hwva.dat'))
        # confirm external binary file was created
        assert os.path.isfile(os.path.join(save_folder, 'initial_heads.bin'))

        # clean up
        sim.delete_output_files()

    return
Ejemplo n.º 19
0
def test_simplelgr_load_and_write():
    """
    Test load and write of distributed MODFLOW-LGR example problem
    """
    pth = os.path.join('..', 'examples', 'data', 'mflgr_v2', 'ex3')
    opth = os.path.join(cpth, 'ex3', 'orig')
    # delete the directory if it exists
    if os.path.isdir(opth):
        shutil.rmtree(opth)
    os.makedirs(opth)
    # copy the original files
    files = os.listdir(pth)
    for file in files:
        src = os.path.join(pth, file)
        dst = os.path.join(opth, file)
        shutil.copyfile(src, dst)

    # load the lgr model
    lgr = flopy.modflowlgr.ModflowLgr.load('ex3.lgr', verbose=True,
                                           model_ws=opth, exe_name=exe_name)

    # get the namefiles of the parent and child
    namefiles = lgr.get_namefiles()
    msg = 'get_namefiles returned {} items instead of 2'.format(len(namefiles))
    assert len(namefiles) == 2, msg
    tpth = os.path.dirname(namefiles[0])
    msg = 'dir path is {} not {}'.format(tpth, opth)
    assert tpth == opth, msg

    # run the lgr model
    if run:
        success, buff = lgr.run_model(silent=False)
        assert success, 'could not run original modflow-lgr model'

    # check that a parent and child were read
    msg = 'modflow-lgr ex3 does not have 2 grids'
    assert lgr.ngrids == 2, msg

    npth = os.path.join(cpth, 'ex3', 'new')
    lgr.change_model_ws(new_pth=npth, reset_external=True)

    # get the namefiles of the parent and child
    namefiles = lgr.get_namefiles()
    msg = 'get_namefiles returned {} items instead of 2'.format(len(namefiles))
    assert len(namefiles) == 2, msg
    tpth = os.path.dirname(namefiles[0])
    msg = 'dir path is {} not {}'.format(tpth, npth)
    assert tpth == npth, msg

    # write the lgr model in to the new path
    lgr.write_input()

    # run the lgr model
    if run:
        success, buff = lgr.run_model(silent=False)
        assert success, 'could not run new modflow-lgr model'

        # compare parent results
        pth0 = os.path.join(opth, 'ex3_parent.nam')
        pth1 = os.path.join(npth, 'ex3_parent.nam')
        try:
            msg = 'parent heads do not match'
            success = pymake.compare_heads(pth0, pth1)
            assert success, msg
        except:
            pass

        # compare child results
        pth0 = os.path.join(opth, 'ex3_child.nam')
        pth1 = os.path.join(npth, 'ex3_child.nam')
        try:
            msg = 'child heads do not match'
            success = pymake.compare_heads(pth0, pth1)
            assert success, msg
        except:
            pass
Ejemplo n.º 20
0
def mfnwt_model(namfile, model_ws):
    # load MODFLOW-2005 models as MODFLOW-NWT models
    m = flopy.modflow.Modflow.load(namfile, model_ws=model_ws,
                                   version='mfnwt', verbose=True, check=False,
                                   exe_name=mfnwt_exe)
    assert m, 'Could not load namefile {}'.format(namfile)
    assert m.load_fail is False
    # convert to MODFLOW-NWT model
    m.set_version('mfnwt')
    # extract data from existing flow package
    flowpaks = ['LPF']
    for pak in m.get_package_list():
        if pak == 'LPF':
            lpf = m.get_package(pak)
            layavg = lpf.layavg
            laytyp = lpf.laytyp
            layvka = lpf.layvka
            ss = lpf.ss
            sy = lpf.sy
            hk = lpf.hk
            vka = lpf.vka
            hani = lpf.hani
            chani = lpf.chani
            ipakcb = lpf.ipakcb
            unitnumber = lpf.unit_number[0]
            # remove existing package
            m.remove_package(pak)
            break
    # create UPW file from existing flow package
    upw = flopy.modflow.ModflowUpw(m, layavg=layavg, laytyp=laytyp,
                                   ipakcb=ipakcb, unitnumber=unitnumber,
                                   layvka=layvka, hani=hani, chani=chani,
                                   hk=hk, vka=vka, ss=ss, sy=sy)
    # remove the existing solver
    solvers = ['SIP', 'PCG', 'PCGN', 'GMG', 'DE4']
    for pak in m.get_package_list():
        solv = m.get_package(pak)
        if pak in solvers:
            unitnumber = solv.unit_number[0]
            m.remove_package(pak)
    nwt = flopy.modflow.ModflowNwt(m, unitnumber=unitnumber)

    # add specify option to the well package
    wel = m.get_package('WEL')
    wel.specify = True
    wel.phiramp = 1.0e-5
    wel.phiramp_unit = 2

    # change workspace and write MODFLOW-NWT model
    tdir = os.path.splitext(namfile)[0]
    pth = os.path.join(tpth, tdir)
    m.change_model_ws(pth)
    m.write_input()
    if run:
        try:
            success, buff = m.run_model(silent=False)
        except:
            success = False
        assert success, 'base model run did not terminate successfully'
        fn0 = os.path.join(pth, namfile)

    # reload the model just written
    m = flopy.modflow.Modflow.load(namfile, model_ws=pth,
                                   version='mfnwt', verbose=True, check=False,
                                   exe_name=mfnwt_exe)
    assert m, 'Could not load namefile {}'.format(namfile)
    assert m.load_fail is False

    # change workspace and write MODFLOW-NWT model
    pthf = os.path.join(pth, 'flopy')
    m.change_model_ws(pthf)
    m.write_input()
    if run:
        try:
            success, buff = m.run_model(silent=False)
        except:
            success = False
        assert success, 'base model run did not terminate successfully'
        fn1 = os.path.join(pthf, namfile)

    if run:
        fsum = os.path.join(pth, '{}.head.out'.format(tdir))
        success = False
        try:
            success = pymake.compare_heads(fn0, fn1, outfile=fsum)
        except:
            success = False
            print('could not perform head comparison')

        assert success, 'head comparison failure'

        fsum = os.path.join(pth, '{}.budget.out'.format(tdir))
        success = False
        try:
            success = pymake.compare_budget(fn0, fn1,
                                            max_incpd=0.1, max_cumpd=0.1,
                                            outfile=fsum)
        except:
            success = False
            print('could not perform budget comparison')

        assert success, 'budget comparison failure'

    return
Ejemplo n.º 21
0
def test006_2models_mvr():
    # init paths
    test_ex_name = 'test006_2models_mvr'
    sim_name = 'test006_2models_mvr'
    model_names = ['parent', 'child']

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder,
                                        'model1_unch.hds')
    expected_head_file_aa = os.path.join(expected_output_folder,
                                         'model2_unch.hds')
    expected_cbc_file_a = os.path.join(expected_output_folder,
                                       'model1_unch.cbc')

    expected_head_file_b = os.path.join(expected_output_folder,
                                        'model1_adj.hds')
    expected_head_file_bb = os.path.join(expected_output_folder,
                                         'model2_adj.hds')

    # load simulation
    sim = MFSimulation.load(sim_name, 'mf6', exe_name, pth)

    # make temp folder to save simulation
    sim.simulation_data.mfpath.set_sim_path(run_folder)

    # write simulation to new location
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'model1.hds')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new)

        head_file = os.path.join(os.getcwd(), expected_head_file_aa)
        head_new = os.path.join(run_folder, 'model2.hds')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new)

        budget_file = os.path.join(os.getcwd(), expected_cbc_file_a)
        budget_obj = bf.CellBudgetFile(budget_file, precision='double')
        budget_obj.list_records()

    # test getting models
    model_dict = sim.model_dict
    assert len(model_dict) == 2
    for model in model_dict.values():
        assert model.name in model_names
    names = sim.model_names
    assert len(names) == 2
    for name in names:
        assert name in model_names
        model = sim.get_model(name)
        assert model.model_type == 'gwf'
    models = sim.gwf
    assert len(models) == 2
    for model in models:
        assert model.name in model_names
        assert model.model_type == 'gwf'

    # change some settings
    parent_model = sim.get_model(model_names[0])
    maw_pkg = parent_model.get_package('maw')
    period_data = maw_pkg.perioddata.get_data()
    period_data[0][0][2] = -1.0
    maw_pkg.perioddata.set_data(period_data[0], 0)
    well_rec_data = maw_pkg.packagedata.get_data()
    assert (well_rec_data[0][0] == 0)

    exg_pkg = sim.get_exchange_file('simulation.exg')
    exg_data = exg_pkg.exchangedata.get_data()
    for index in range(0, len(exg_data)):
        exg_data[index][6] = 500.0
    exg_pkg.exchangedata.set_data(exg_data)

    # test getting packages
    pkg_dict = parent_model.package_dict
    assert len(pkg_dict) == 6
    pkg_names = parent_model.package_names
    assert len(pkg_names) == 6
    # confirm that this is a copy of the original dictionary with references
    # to the packages
    del pkg_dict[pkg_names[0]]
    assert len(pkg_dict) == 5
    pkg_dict = parent_model.package_dict
    assert len(pkg_dict) == 6

    old_val = pkg_dict['dis'].nlay.get_data()
    pkg_dict['dis'].nlay = 22
    pkg_dict = parent_model.package_dict
    assert pkg_dict['dis'].nlay.get_data() == 22
    pkg_dict['dis'].nlay = old_val

    # write simulation again
    sim.simulation_data.mfpath.set_sim_path(save_folder)
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_b)
        head_new = os.path.join(save_folder, 'model1.hds')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new)

        head_file = os.path.join(os.getcwd(), expected_head_file_bb)
        head_new = os.path.join(save_folder, 'model2.hds')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new)

        # clean up
        sim.delete_output_files()

    return
Ejemplo n.º 22
0
def test036_twrihfb():
    # init paths
    test_ex_name = 'test036_twrihfb'
    model_name = 'twrihfb2015'

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder, 'twrihfb2015_output_unch.hds')
    expected_head_file_b = os.path.join(expected_output_folder, 'twrihfb2015_output_adj.hds')

    # load simulation
    sim = MFSimulation.load(model_name, 'mf6', exe_name, pth)

    # make temp folder to save simulation
    sim.simulation_data.mfpath.set_sim_path(run_folder)

    # write simulation to new location
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'twrihfb2015_output.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

    # change some settings
    hydchr = sim.simulation_data.mfdata[(model_name, 'hfb', 'period', 'stress_period_data')]
    hydchr_data = hydchr.get_data()
    hydchr_data[2][2] = 0.000002
    hydchr_data[3][2] = 0.000003
    hydchr_data[4][2] = 0.0000004
    hydchr.set_data(hydchr_data, 0)
    cond = sim.simulation_data.mfdata[(model_name, 'drn', 'period', 'stress_period_data')]
    cond_data = cond.get_data()
    for index in range(0, len(cond_data)):
        cond_data[index][2] = 2.1
    cond.set_data(cond_data, 0)

    rch = sim.simulation_data.mfdata[(model_name, 'rcha', 'period', 'recharge')]
    rch_data = rch.get_data()
    assert(rch_data[5][1] == 0.00000003)

    # write simulation again
    sim.simulation_data.mfpath.set_sim_path(save_folder)
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_b)
        head_new = os.path.join(save_folder, 'twrihfb2015_output.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)
Ejemplo n.º 23
0
def eval_zdisplacement(sim):
    print("evaluating z-displacement...")

    # MODFLOW 6 total compaction results
    fpth = os.path.join(sim.simpath, "csub_obs.csv")
    try:
        tc = np.genfromtxt(fpth, names=True, delimiter=",")
    except:
        assert False, 'could not load data from "{}"'.format(fpth)

    # MODFLOW-2005 total compaction results
    fn = "{}.total_comp.hds".format(os.path.basename(sim.name))
    fpth = os.path.join(sim.simpath, "mfnwt", fn)
    try:
        sobj = flopy.utils.HeadFile(fpth, text="LAYER COMPACTION")
        tc0 = sobj.get_ts((2, wrp[0], wcp[0]))
    except:
        assert False, 'could not load data from "{}"'.format(fpth)

    # calculate maximum absolute error
    diff = tc["TCOMP3"] - tc0[:, 1]
    diffmax = np.abs(diff).max()
    msg = "maximum absolute total-compaction difference ({}) ".format(diffmax)

    if diffmax > dtol:
        sim.success = False
        msg += "exceeds {}".format(dtol)
        assert diffmax < dtol, msg
    else:
        sim.success = True
        print("    " + msg)

    # get results from listing file
    fpth = os.path.join(sim.simpath,
                        "{}.lst".format(os.path.basename(sim.name)))
    budl = flopy.utils.Mf6ListBudget(fpth)
    names = list(bud_lst)
    d0 = budl.get_budget(names=names)[0]
    dtype = d0.dtype
    nbud = d0.shape[0]

    # get results from cbc file
    cbc_bud = [
        "STO-SS",
        "STO-SY",
        "CSUB-CGELASTIC",
        "CSUB-ELASTIC",
        "CSUB-INELASTIC",
        "CSUB-WATERCOMP",
    ]
    d = np.recarray(nbud, dtype=dtype)
    for key in bud_lst:
        d[key] = 0.0
    fpth = os.path.join(sim.simpath,
                        "{}.cbc".format(os.path.basename(sim.name)))
    cobj = flopy.utils.CellBudgetFile(fpth, precision="double")
    kk = cobj.get_kstpkper()
    times = cobj.get_times()
    for idx, (k, t) in enumerate(zip(kk, times)):
        for text in cbc_bud:
            qin = 0.0
            qout = 0.0
            v = cobj.get_data(kstpkper=k, text=text)[0]
            if isinstance(v, np.recarray):
                vt = np.zeros(size3d, dtype=float)
                for jdx, node in enumerate(v["node"]):
                    vt[node - 1] += v["q"][jdx]
                v = vt.reshape(shape3d)
            for kk in range(v.shape[0]):
                for ii in range(v.shape[1]):
                    for jj in range(v.shape[2]):
                        vv = v[kk, ii, jj]
                        if vv < 0.0:
                            qout -= vv
                        else:
                            qin += vv
            d["totim"][idx] = t
            d["time_step"][idx] = k[0]
            d["stress_period"] = k[1]
            key = "{}_IN".format(text)
            d[key][idx] = qin
            key = "{}_OUT".format(text)
            d[key][idx] = qout

    diff = np.zeros((nbud, len(bud_lst)), dtype=float)
    for idx, key in enumerate(bud_lst):
        diff[:, idx] = d0[key] - d[key]
    diffmax = np.abs(diff).max()
    msg = "maximum absolute total-budget difference ({}) ".format(diffmax)

    # write summary
    fpth = os.path.join(sim.simpath,
                        "{}.bud.cmp.out".format(os.path.basename(sim.name)))
    f = open(fpth, "w")
    for i in range(diff.shape[0]):
        if i == 0:
            line = "{:>10s}".format("TIME")
            for idx, key in enumerate(bud_lst):
                line += "{:>25s}".format(key + "_LST")
                line += "{:>25s}".format(key + "_CBC")
                line += "{:>25s}".format(key + "_DIF")
            f.write(line + "\n")
        line = "{:10g}".format(d["totim"][i])
        for idx, key in enumerate(bud_lst):
            line += "{:25g}".format(d0[key][i])
            line += "{:25g}".format(d[key][i])
            line += "{:25g}".format(diff[i, idx])
        f.write(line + "\n")
    f.close()

    if diffmax > budtol:
        sim.success = False
        msg += "exceeds {}".format(dtol)
        assert diffmax < dtol, msg
    else:
        sim.success = True
        print("    " + msg)

    # compare z-displacement data
    fpth1 = os.path.join(
        sim.simpath,
        "{}.zdisplacement.gridbin".format(os.path.basename(sim.name)),
    )
    fpth2 = os.path.join(sim.simpath, cmppth, "csub_zdisp01.vert_disp.hds")
    text1 = "CSUB-ZDISPLACE"
    text2 = "Z DISPLACEMENT"
    fout = os.path.join(
        sim.simpath,
        "{}.z-displacement.bin.out".format(os.path.basename(sim.name)),
    )
    success_tst = pymake.compare_heads(
        None,
        None,
        text=text1,
        text2=text2,
        outfile=fout,
        files1=fpth1,
        files2=fpth2,
        difftol=True,
        verbose=True,
        exarr=iex,
    )
    msg = "z-displacement comparison success = {}".format(success_tst)
    if success_tst:
        sim.success = True
        print(msg)
    else:
        sim.success = False
        assert success_tst, msg

    return
Ejemplo n.º 24
0
def test006_2models_mvr():
    # init paths
    test_ex_name = 'test006_2models_mvr'
    sim_name = 'test006_2models_mvr'
    model_names = ['parent', 'child']

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder, 'model1_unch.hds')
    expected_head_file_aa = os.path.join(expected_output_folder, 'model2_unch.hds')
    expected_cbc_file_a = os.path.join(expected_output_folder, 'model1_unch.cbc')

    expected_head_file_b = os.path.join(expected_output_folder, 'model1_adj.hds')
    expected_head_file_bb = os.path.join(expected_output_folder, 'model2_adj.hds')

    # load simulation
    sim = MFSimulation.load(sim_name, 'mf6', exe_name, pth)

    # make temp folder to save simulation
    sim.simulation_data.mfpath.set_sim_path(run_folder)

    # write simulation to new location
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'model1.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

        head_file = os.path.join(os.getcwd(), expected_head_file_aa)
        head_new = os.path.join(run_folder, 'model2.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

        budget_file = os.path.join(os.getcwd(), expected_cbc_file_a)
        budget_obj = bf.CellBudgetFile(budget_file, precision='double')
        budget_obj.list_records()

    # change some settings
    parent_model = sim.get_model(model_names[0])
    maw_pkg = parent_model.get_package('maw')
    period_data = maw_pkg.perioddata.get_data()
    period_data[0][2] = -1.0
    maw_pkg.perioddata.set_data(period_data, 0)
    well_rec_data = maw_pkg.packagedata.get_data()
    assert(well_rec_data[0][0] == 0)

    exg_pkg = sim.get_exchange_file('simulation.exg')
    exg_data = exg_pkg.exchangedata.get_data()
    for index in range(0, len(exg_data)):
        exg_data[index][6] = 500.0
    exg_pkg.exchangedata.set_data(exg_data)

    # write simulation again
    sim.simulation_data.mfpath.set_sim_path(save_folder)
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_b)
        head_new = os.path.join(save_folder, 'model1.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

        head_file = os.path.join(os.getcwd(), expected_head_file_bb)
        head_new = os.path.join(save_folder, 'model2.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

        # clean up
        sim.delete_output_files()

    return
Ejemplo n.º 25
0
def test003_gwfs_disv():
    # init paths
    test_ex_name = 'test003_gwfs_disv'
    model_name = 'gwf_1'

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder, 'model_unch.hds')
    expected_head_file_b = os.path.join(expected_output_folder, 'model_adj.hds')
    expected_cbc_file_a = os.path.join(expected_output_folder, 'model_unch.cbc')
    expected_cbc_file_b = os.path.join(expected_output_folder, 'model_adj.cbc')

    array_util = ArrayUtil()

    # load simulation
    sim = MFSimulation.load(model_name, 'mf6', exe_name, pth)

    # make temp folder to save simulation
    sim.simulation_data.mfpath.set_sim_path(run_folder)

    # write simulation to new location
    sim.simulation_data.max_columns_of_data = 10
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # get expected results
        budget_file = os.path.join(os.getcwd(), expected_cbc_file_a)
        budget_obj = bf.CellBudgetFile(budget_file, precision='double')
        budget_fjf_valid = np.array(budget_obj.get_data(text='    FLOW JA FACE', full3D=True))

        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'model.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

        budget_frf = sim.simulation_data.mfdata[(model_name, 'CBC', 'FLOW-JA-FACE')]
        assert array_util.array_comp(budget_fjf_valid, budget_frf)

    # change some settings
    model = sim.get_model(model_name)
    chd_head_left = model.get_package('CHD_LEFT')
    chd_left_period = chd_head_left.stress_period_data.array
    chd_left_period[4][1] = 15.0

    chd_head_right = model.get_package('CHD_RIGHT')
    chd_right_period = chd_head_right.stress_period_data
    chd_right_data = chd_right_period.get_data(0)
    chd_right_data_slice = chd_right_data[3:10]
    chd_right_period.set_data(chd_right_data_slice, 0)

    # write simulation again
    sim.simulation_data.mfpath.set_sim_path(save_folder)
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # get expected results
        budget_file = os.path.join(os.getcwd(), expected_cbc_file_b)
        budget_obj = bf.CellBudgetFile(budget_file, precision='double')
        budget_fjf_valid = np.array(budget_obj.get_data(text='FLOW JA FACE', full3D=True))

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_b)
        head_new = os.path.join(save_folder, 'model.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

        budget_frf = sim.simulation_data.mfdata[(model_name, 'CBC', 'FLOW-JA-FACE')]
        assert array_util.array_comp(budget_fjf_valid, budget_frf)

        # clean up
        sim.delete_output_files()

    return
Ejemplo n.º 26
0
def test001a_tharmonic():
    # init paths
    test_ex_name = 'test001a_Tharmonic'
    model_name = 'flow15'

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder, 'flow15_flow_unch.hds')
    expected_head_file_b = os.path.join(expected_output_folder, 'flow15_flow_adj.hds')
    expected_cbc_file_a = os.path.join(expected_output_folder, 'flow15_flow_unch.cbc')
    expected_cbc_file_b = os.path.join(expected_output_folder, 'flow15_flow_adj.cbc')

    array_util = ArrayUtil()

    # load simulation
    sim = MFSimulation.load(model_name, 'mf6', exe_name, pth)
    sim.simulation_data.mfpath.set_sim_path(run_folder)

    # write simulation to new location
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # get expected results
        budget_file = os.path.join(os.getcwd(), expected_cbc_file_a)
        budget_obj = bf.CellBudgetFile(budget_file, precision='double')
        budget_obj.list_records()
        budget_frf_valid = np.array(budget_obj.get_data(text='    FLOW JA FACE', full3D=True))

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'flow15_flow.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

        budget_frf = sim.simulation_data.mfdata[(model_name, 'CBC', 'FLOW-JA-FACE')]
        assert array_util.array_comp(budget_frf_valid, budget_frf)

    # change some settings
    hk_data = sim.simulation_data.mfdata[(model_name, 'npf', 'griddata', 'k')]
    hk_array = hk_data.get_data()
    hk_array[0,0,1] = 20.0
    hk_data.set_data(hk_array)

    model = sim.get_model(model_name)
    ic = model.get_package('ic')
    ic_data = ic.strt
    ic_array = ic_data.get_data()
    ic_array[0,0,0] = 1.0
    ic_array[0,0,9] = 1.0
    ic_data.set_data(ic_array)

    get_test = hk_data[0,0,0]
    assert(get_test == 10.0)
    get_test = hk_data.array
    assert(array_util.array_comp(get_test, [[10.0, 20.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0]]))
    get_test = hk_data[:]
    assert(array_util.array_comp(get_test, [[[10.0, 20.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0]]]))

    # write simulation again
    sim.simulation_data.mfpath.set_sim_path(save_folder)
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # get expected results
        budget_file = os.path.join(os.getcwd(), expected_cbc_file_b)
        budget_obj = bf.CellBudgetFile(budget_file, precision='double')
        budget_frf_valid = np.array(budget_obj.get_data(text='    FLOW JA FACE', full3D=True))

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_b)
        head_new = os.path.join(save_folder, 'flow15_flow.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

        budget_frf = sim.simulation_data.mfdata[(model_name, 'CBC', 'FLOW-JA-FACE')]
        assert array_util.array_comp(budget_frf_valid, budget_frf)

        # clean up
        sim.delete_output_files()

    return
Ejemplo n.º 27
0
def load_and_write_gmg(mfnam, pth):
    """
    test045 load and write of MODFLOW-2005 GMG example problem
    """
    exe_name = "mf2005"
    v = flopy.which(exe_name)

    if pymake:
        run = v is not None
        lpth = os.path.join(cpth, os.path.splitext(mfnam)[0])
        apth = os.path.join(lpth, "flopy")
        compth = lpth
        pymake.setup(os.path.join(pth, mfnam), lpth)
    else:
        run = False
        lpth = pth
        apth = cpth
        compth = cpth

    m = flopy.modflow.Modflow.load(
        mfnam, model_ws=lpth, verbose=True, exe_name=exe_name
    )
    assert m.load_fail is False

    if run:
        try:
            success, buff = m.run_model(silent=False)
        except:
            success = False
        assert success, "base model run did not terminate successfully"
        fn0 = os.path.join(lpth, mfnam)

    # rewrite files
    m.change_model_ws(apth)
    m.write_input()
    if run:
        try:
            success, buff = m.run_model(silent=False)
        except:
            success = False
        assert success, "new model run did not terminate successfully"
        fn1 = os.path.join(apth, mfnam)

    if run:
        fsum = os.path.join(
            compth, "{}.head.out".format(os.path.splitext(mfnam)[0])
        )
        success = False
        try:
            success = pymake.compare_heads(fn0, fn1, outfile=fsum)
        except:
            success = False
            print("could not perform head comparison")

        assert success, "head comparison failure"

        fsum = os.path.join(
            compth, "{}.budget.out".format(os.path.splitext(mfnam)[0])
        )
        success = False
        try:
            success = pymake.compare_budget(
                fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum
            )
        except:
            success = False
            print("could not perform budget comparison")

        assert success, "budget comparison failure"

    return
Ejemplo n.º 28
0
    def compare(self):
        """
        Compare the model results

        """
        self.success = True
        msgall = ''
        msg = sfmt.format('Comparison test', self.name)
        print(msg)

        extdict = {
            'hds': 'head',
            'hed': 'head',
            'bhd': 'head',
            'ucn': 'concentration'
        }

        success_tst = False
        if self.action is not None:
            cpth = os.path.join(self.simpath, self.action)
            files_cmp = None
            if self.action.lower() == 'compare':
                files_cmp = []
                files = os.listdir(cpth)
                for file in files:
                    files_cmp.append(file)

            files1 = []
            files2 = []
            exfiles = []
            ipos = 0
            for file1 in self.outp:
                ext = os.path.splitext(file1)[1][1:]

                if ext.lower() in ['hds', 'hed', 'bhd', 'ahd']:

                    # simulation file
                    pth = os.path.join(self.simpath, file1)
                    files1.append(pth)

                    # look for an exclusion file
                    pth = os.path.join(self.simpath, file1 + '.ex')
                    if os.path.isfile(pth):
                        exfiles.append(pth)
                    else:
                        exfiles.append(None)

                    # Check to see if there is a corresponding compare file
                    if files_cmp is not None:

                        if file1 + '.cmp' in files_cmp:
                            # compare file
                            idx = files_cmp.index(file1 + '.cmp')
                            pth = os.path.join(cpth, files_cmp[idx])
                            files2.append(pth)
                            txt = sfmt.format(
                                'Comparison file {}'.format(ipos + 1),
                                os.path.basename(pth))
                            print(txt)
                    else:
                        files2.append(None)

            if self.nam_cmp is None:
                pth = None
            else:
                pth = os.path.join(cpth, self.nam_cmp)

            for ipos in range(len(files1)):
                file1 = files1[ipos]
                ext = os.path.splitext(file1)[1][1:].lower()
                outfile = os.path.splitext(os.path.basename(file1))[0]
                outfile = os.path.join(self.simpath,
                                       outfile + '.' + ext + '.cmp.out')
                if files2 is None:
                    file2 = None
                else:
                    file2 = files2[ipos]

                # set exfile
                exfile = None
                if file2 is None:
                    if len(exfiles) > 0:
                        exfile = exfiles[ipos]
                        if exfile is not None:
                            txt = sfmt.format(
                                'Exclusion file {}'.format(ipos + 1),
                                os.path.basename(exfile))
                            print(txt)

                # make comparison
                success_tst = pymake.compare_heads(
                    None,
                    pth,
                    precision='double',
                    text=extdict[ext],
                    outfile=outfile,
                    files1=file1,
                    files2=file2,
                    htol=self.htol,
                    difftol=False,
                    # Change to true to have list of all nodes exceeding htol
                    verbose=True,
                    exfile=exfile)
                msg = sfmt.format(
                    '{} comparison {}'.format(extdict[ext], ipos + 1),
                    self.name)
                if success_tst:
                    print(msg)
                else:
                    print(msg)

                if not success_tst:
                    self.success = False
                    msgall += msg + '\n'

        assert self.success, msgall
        return
Ejemplo n.º 29
0
def test006_2models_mvr():
    # init paths
    test_ex_name = 'test006_2models_mvr'
    sim_name = 'test006_2models_mvr'
    model_names = ['parent', 'child']

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder, 'model1_unch.hds')
    expected_head_file_aa = os.path.join(expected_output_folder, 'model2_unch.hds')
    expected_cbc_file_a = os.path.join(expected_output_folder, 'model1_unch.cbc')

    expected_head_file_b = os.path.join(expected_output_folder, 'model1_adj.hds')
    expected_head_file_bb = os.path.join(expected_output_folder, 'model2_adj.hds')

    # load simulation
    sim = MFSimulation.load(sim_name, 'mf6', exe_name, pth)

    # make temp folder to save simulation
    sim.simulation_data.mfpath.set_sim_path(run_folder)

    # write simulation to new location
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'model1.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

        head_file = os.path.join(os.getcwd(), expected_head_file_aa)
        head_new = os.path.join(run_folder, 'model2.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

        budget_file = os.path.join(os.getcwd(), expected_cbc_file_a)
        budget_obj = bf.CellBudgetFile(budget_file, precision='double')
        budget_obj.list_records()

    # test getting models
    model_dict = sim.model_dict
    assert len(model_dict) == 2
    for model in model_dict.values():
        assert model.name in model_names
    names = sim.model_names
    assert len(names) == 2
    for name in names:
        assert name in model_names
        model = sim.get_model(name)
        assert model.model_type == 'gwf'
    models = sim.gwf
    assert len(models) == 2
    for model in models:
        assert model.name in model_names
        assert model.model_type == 'gwf'

    # change some settings
    parent_model = sim.get_model(model_names[0])
    maw_pkg = parent_model.get_package('maw')
    period_data = maw_pkg.perioddata.get_data()
    period_data[0][0][2] = -1.0
    maw_pkg.perioddata.set_data(period_data[0], 0)
    well_rec_data = maw_pkg.packagedata.get_data()
    assert(well_rec_data[0][0] == 0)

    exg_pkg = sim.get_exchange_file('simulation.exg')
    exg_data = exg_pkg.exchangedata.get_data()
    for index in range(0, len(exg_data)):
        exg_data[index][6] = 500.0
    exg_pkg.exchangedata.set_data(exg_data)

    # test getting packages
    pkg_dict = parent_model.package_dict
    assert len(pkg_dict) == 6
    pkg_names = parent_model.package_names
    assert len(pkg_names) == 6
    # confirm that this is a copy of the original dictionary with references
    # to the packages
    del pkg_dict[pkg_names[0]]
    assert len(pkg_dict) == 5
    pkg_dict = parent_model.package_dict
    assert len(pkg_dict) == 6

    old_val = pkg_dict['dis'].nlay.get_data()
    pkg_dict['dis'].nlay = 22
    pkg_dict = parent_model.package_dict
    assert pkg_dict['dis'].nlay.get_data() == 22
    pkg_dict['dis'].nlay = old_val

    # write simulation again
    sim.simulation_data.mfpath.set_sim_path(save_folder)
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_b)
        head_new = os.path.join(save_folder, 'model1.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

        head_file = os.path.join(os.getcwd(), expected_head_file_bb)
        head_new = os.path.join(save_folder, 'model2.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

        # clean up
        sim.delete_output_files()

    return
Ejemplo n.º 30
0
def load_and_write_fhb(mfnam, pth):

    exe_name = 'mf2005'
    v = flopy.which(exe_name)

    run = True
    if v is None:
        run = False
    try:
        import pymake
        lpth = os.path.join(cpth, os.path.splitext(mfnam)[0])
        apth = os.path.join(lpth, 'flopy')
        compth = lpth
        pymake.setup(os.path.join(pth, mfnam), lpth)
    except:
        run = False
        lpth = pth
        apth = cpth
        compth = cpth

    m = flopy.modflow.Modflow.load(mfnam,
                                   model_ws=lpth,
                                   verbose=True,
                                   exe_name=exe_name)
    assert m.load_fail is False

    if run:
        try:
            success, buff = m.run_model(silent=False)
        except:
            success = False
        assert success, 'base model run did not terminate successfully'
        fn0 = os.path.join(lpth, mfnam)

    # rewrite files
    m.change_model_ws(apth, reset_external=True)
    m.write_input()
    if run:
        try:
            success, buff = m.run_model(silent=False)
        except:
            success = False
        assert success, 'new model run did not terminate successfully'
        fn1 = os.path.join(apth, mfnam)

    if run:
        fsum = os.path.join(compth,
                            '{}.head.out'.format(os.path.splitext(mfnam)[0]))
        success = False
        try:
            success = pymake.compare_heads(fn0, fn1, outfile=fsum)
        except:
            success = False
            print('could not perform head comparison')

        assert success, 'head comparison failure'

        fsum = os.path.join(compth,
                            '{}.budget.out'.format(os.path.splitext(mfnam)[0]))
        success = False
        try:
            success = pymake.compare_budget(fn0,
                                            fn1,
                                            max_incpd=0.1,
                                            max_cumpd=0.1,
                                            outfile=fsum)
        except:
            success = False
            print('could not perform budget comparison')

        assert success, 'budget comparison failure'

    return
Ejemplo n.º 31
0
def eval_zdisplacement(sim):
    print('evaluating z-displacement...')

    # MODFLOW 6 total compaction results
    fpth = os.path.join(sim.simpath, 'csub_obs.csv')
    try:
        tc = np.genfromtxt(fpth, names=True, delimiter=',')
    except:
        assert False, 'could not load data from "{}"'.format(fpth)

    # MODFLOW-2005 total compaction results
    fn = '{}.total_comp.hds'.format(os.path.basename(sim.name))
    fpth = os.path.join(sim.simpath, 'mfnwt', fn)
    try:
        sobj = flopy.utils.HeadFile(fpth, text='LAYER COMPACTION')
        tc0 = sobj.get_ts((2, wrp[0], wcp[0]))
    except:
        assert False, 'could not load data from "{}"'.format(fpth)

    # calculate maximum absolute error
    diff = tc['TCOMP3'] - tc0[:, 1]
    diffmax = np.abs(diff).max()
    msg = 'maximum absolute total-compaction difference ({}) '.format(diffmax)

    if diffmax > dtol:
        sim.success = False
        msg += 'exceeds {}'.format(dtol)
        assert diffmax < dtol, msg
    else:
        sim.success = True
        print('    ' + msg)

    # get results from listing file
    fpth = os.path.join(sim.simpath,
                        '{}.lst'.format(os.path.basename(sim.name)))
    budl = flopy.utils.Mf6ListBudget(fpth)
    names = list(bud_lst)
    d0 = budl.get_budget(names=names)[0]
    dtype = d0.dtype
    nbud = d0.shape[0]

    # get results from cbc file
    cbc_bud = [
        'STO-SS', 'STO-SY', 'CSUB-CGELASTIC', 'CSUB-ELASTIC', 'CSUB-INELASTIC',
        'CSUB-WATERCOMP'
    ]
    d = np.recarray(nbud, dtype=dtype)
    for key in bud_lst:
        d[key] = 0.
    fpth = os.path.join(sim.simpath,
                        '{}.cbc'.format(os.path.basename(sim.name)))
    cobj = flopy.utils.CellBudgetFile(fpth, precision='double')
    kk = cobj.get_kstpkper()
    times = cobj.get_times()
    for idx, (k, t) in enumerate(zip(kk, times)):
        for text in cbc_bud:
            qin = 0.
            qout = 0.
            v = cobj.get_data(kstpkper=k, text=text)[0]
            if isinstance(v, np.recarray):
                vt = np.zeros(size3d, dtype=np.float)
                for jdx, node in enumerate(v['node']):
                    vt[node - 1] += v['q'][jdx]
                v = vt.reshape(shape3d)
            for kk in range(v.shape[0]):
                for ii in range(v.shape[1]):
                    for jj in range(v.shape[2]):
                        vv = v[kk, ii, jj]
                        if vv < 0.:
                            qout -= vv
                        else:
                            qin += vv
            d['totim'][idx] = t
            d['time_step'][idx] = k[0]
            d['stress_period'] = k[1]
            key = '{}_IN'.format(text)
            d[key][idx] = qin
            key = '{}_OUT'.format(text)
            d[key][idx] = qout

    diff = np.zeros((nbud, len(bud_lst)), dtype=np.float)
    for idx, key in enumerate(bud_lst):
        diff[:, idx] = d0[key] - d[key]
    diffmax = np.abs(diff).max()
    msg = 'maximum absolute total-budget difference ({}) '.format(diffmax)

    # write summary
    fpth = os.path.join(sim.simpath,
                        '{}.bud.cmp.out'.format(os.path.basename(sim.name)))
    f = open(fpth, 'w')
    for i in range(diff.shape[0]):
        if i == 0:
            line = '{:>10s}'.format('TIME')
            for idx, key in enumerate(bud_lst):
                line += '{:>25s}'.format(key + '_LST')
                line += '{:>25s}'.format(key + '_CBC')
                line += '{:>25s}'.format(key + '_DIF')
            f.write(line + '\n')
        line = '{:10g}'.format(d['totim'][i])
        for idx, key in enumerate(bud_lst):
            line += '{:25g}'.format(d0[key][i])
            line += '{:25g}'.format(d[key][i])
            line += '{:25g}'.format(diff[i, idx])
        f.write(line + '\n')
    f.close()

    if diffmax > budtol:
        sim.success = False
        msg += 'exceeds {}'.format(dtol)
        assert diffmax < dtol, msg
    else:
        sim.success = True
        print('    ' + msg)

    # compare z-displacement data
    fpth1 = os.path.join(
        sim.simpath, '{}.zdisplacement.bin'.format(os.path.basename(sim.name)))
    fpth2 = os.path.join(sim.simpath, cmppth, 'csub_zdisp01.vert_disp.hds')
    text1 = 'CSUB-ZDISPLACE'
    text2 = 'Z DISPLACEMENT'
    fout = os.path.join(
        sim.simpath,
        '{}.z-displacement.bin.out'.format(os.path.basename(sim.name)))
    success_tst = pymake.compare_heads(None,
                                       None,
                                       text=text1,
                                       text2=text2,
                                       outfile=fout,
                                       files1=fpth1,
                                       files2=fpth2,
                                       difftol=True,
                                       verbose=True,
                                       exarr=iex)
    msg = 'z-displacement comparison success = {}'.format(success_tst)
    if success_tst:
        sim.success = True
        print(msg)
    else:
        sim.success = False
        assert success_tst, msg

    return
Ejemplo n.º 32
0
def test005_advgw_tidal():
    # init paths
    test_ex_name = 'test005_advgw_tidal'
    model_name = 'gwf_1'

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder,
                                        'AdvGW_tidal_unch.hds')
    expected_head_file_b = os.path.join(expected_output_folder,
                                        'AdvGW_tidal_adj.hds')

    # load simulation
    sim = MFSimulation.load(model_name,
                            'mf6',
                            exe_name,
                            pth,
                            verbosity_level=2,
                            verify_data=True)

    # test obs/ts package interface
    model = sim.get_model(model_name)
    time = model.modeltime
    assert (time.steady_state[0] == True and time.steady_state[1] == False
            and time.steady_state[2] == False
            and time.steady_state[3] == False)
    ghb = model.get_package('ghb')
    obs = ghb.obs
    digits = obs.digits.get_data()
    assert (digits == 10)
    names = ghb.ts.time_series_namerecord.get_data()
    assert (names[0][0] == 'tides')

    # add a stress period beyond nper
    spd = ghb.stress_period_data.get_data()
    spd[20] = copy.deepcopy(spd[0])
    ghb.stress_period_data.set_data(spd)

    # make temp folder to save simulation
    sim.simulation_data.mfpath.set_sim_path(run_folder)

    # write simulation to new location
    sim.set_all_data_external()
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'advgw_tidal.hds')
        outfile = os.path.join(run_folder, 'head_compare.dat')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new,
                                    outfile=outfile)
Ejemplo n.º 33
0
def test_str_free():
    m = flopy.modflow.Modflow.load(
        str_items[0]["mfnam"],
        exe_name=mfexe,
        model_ws=path,
        verbose=False,
        check=False,
    )
    ws = os.path.join(tpth, "fixed")
    m.change_model_ws(ws)

    # get pointer to str package
    str = m.str
    str.istcb2 = -1

    # add aux variables to str
    aux_names = ["aux iface", "aux xyz"]
    names = ["iface", "xyz"]
    current, current_seg = flopy.modflow.ModflowStr.get_empty(23,
                                                              7,
                                                              aux_names=names)

    # copy data from existing stress period data
    for name in str.stress_period_data[0].dtype.names:
        current[:][name] = str.stress_period_data[0][:][name]

    # fill aux variable data
    for idx, c in enumerate(str.stress_period_data[0]):
        for jdx, name in enumerate(names):
            current[idx][name] = idx + jdx * 10

    # replace str data with updated str data
    str = flopy.modflow.ModflowStr(
        m,
        mxacts=str.mxacts,
        nss=str.nss,
        ntrib=str.ntrib,
        ndiv=str.ndiv,
        icalc=str.icalc,
        const=str.const,
        ipakcb=str.ipakcb,
        istcb2=str.istcb2,
        iptflg=str.iptflg,
        irdflg=str.irdflg,
        stress_period_data={0: current},
        segment_data=str.segment_data,
        options=aux_names,
    )

    # add head output to oc file
    oclst = ["PRINT HEAD", "PRINT BUDGET", "SAVE HEAD", "SAVE BUDGET"]
    spd = {(0, 0): oclst, (0, 1): oclst, (0, 2): oclst}
    oc = flopy.modflow.ModflowOc(m, stress_period_data=spd)
    oc.reset_budgetunit()

    # reset ipakcb for str package to get ascii output in lst file
    str.ipakcb = -1

    m.write_input()
    if run:
        try:
            success, buff = m.run_model()
        except:
            success = False
        assert success, "base model run did not terminate successfully"

    # load the fixed format model with aux variables
    try:
        m2 = flopy.modflow.Modflow.load(
            str_items[0]["mfnam"],
            exe_name=mfexe,
            model_ws=ws,
            verbose=False,
            check=False,
        )
    except:
        m2 = None

    msg = "could not load the fixed format model with aux variables"
    assert m2 is not None, msg

    ws = os.path.join(tpth, "free")
    m.change_model_ws(ws)
    m.set_ifrefm()
    m.write_input()
    if run:
        try:
            success, buff = m.run_model()
        except:
            success = False
        assert success, "free format model run did not terminate successfully"

    # load the free format model
    try:
        m2 = flopy.modflow.Modflow.load(
            str_items[0]["mfnam"],
            exe_name=mfexe,
            model_ws=ws,
            verbose=False,
            check=False,
        )
    except:
        m2 = None

    msg = "could not load the free format model with aux variables"
    assert m2 is not None, msg

    # compare the fixed and free format head files
    if run:
        if pymake is not None:
            fn1 = os.path.join(tpth, "fixed", "str.nam")
            fn2 = os.path.join(ws, "str.nam")
            success = pymake.compare_heads(fn1, fn2, verbose=True)
            msg = "fixed and free format input output head files are different"
            assert success, msg
Ejemplo n.º 34
0
def test001a_tharmonic():
    # init paths
    test_ex_name = 'test001a_Tharmonic'
    model_name = 'flow15'

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder,
                                        'flow15_flow_unch.hds')
    expected_head_file_b = os.path.join(expected_output_folder,
                                        'flow15_flow_adj.hds')
    expected_cbc_file_a = os.path.join(expected_output_folder,
                                       'flow15_flow_unch.cbc')
    expected_cbc_file_b = os.path.join(expected_output_folder,
                                       'flow15_flow_adj.cbc')

    array_util = PyListUtil()

    # load simulation
    sim = MFSimulation.load(model_name,
                            'mf6',
                            exe_name,
                            pth,
                            verbosity_level=0,
                            verify_data=True,
                            write_headers=False)
    sim.simulation_data.mfpath.set_sim_path(run_folder)

    # write simulation to new location
    sim.set_all_data_external()
    sim.write_simulation(silent=True)

    model = sim.get_model(model_name)
    model.export('{}/tharmonic.nc'.format(model.model_ws))
    model.export('{}/tharmonic.shp'.format(model.model_ws))
    model.dis.botm.export('{}/botm.shp'.format(model.model_ws))

    mg = model.modelgrid

    if run:
        # run simulation
        sim.run_simulation()

        # get expected results
        budget_file = os.path.join(os.getcwd(), expected_cbc_file_a)
        budget_obj = bf.CellBudgetFile(budget_file, precision='auto')
        budget_obj.list_records()
        budget_frf_valid = np.array(
            budget_obj.get_data(text='    FLOW JA FACE', full3D=True))

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'flow15_flow.hds')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new)

        budget_frf = sim.simulation_data.mfdata[(model_name, 'CBC',
                                                 'FLOW-JA-FACE')]
        assert array_util.array_comp(budget_frf_valid, budget_frf)

    # change some settings
    hk_data = sim.simulation_data.mfdata[(model_name, 'npf', 'griddata', 'k')]
    hk_array = hk_data.get_data()
    hk_array[0, 0, 1] = 20.0
    hk_data.set_data(hk_array)

    model = sim.get_model(model_name)
    ic = model.get_package('ic')
    ic_data = ic.strt
    ic_array = ic_data.get_data()
    ic_array[0, 0, 0] = 1.0
    ic_array[0, 0, 9] = 1.0
    ic_data.set_data(ic_array)

    get_test = hk_data[0, 0, 0]
    assert (get_test == 10.0)
    get_test = hk_data.array
    assert (array_util.array_comp(
        get_test,
        [[10.0, 20.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0]]))
    get_test = hk_data[:]
    assert (array_util.array_comp(
        get_test,
        [[[10.0, 20.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0]]]))

    # write simulation again
    sim.simulation_data.mfpath.set_sim_path(save_folder)
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # get expected results
        budget_file = os.path.join(os.getcwd(), expected_cbc_file_b)
        budget_obj = bf.CellBudgetFile(budget_file, precision='auto')
        budget_frf_valid = np.array(
            budget_obj.get_data(text='    FLOW JA FACE', full3D=True))

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_b)
        head_new = os.path.join(save_folder, 'flow15_flow.hds')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new)

        budget_frf = sim.simulation_data.mfdata[(model_name, 'CBC',
                                                 'FLOW-JA-FACE')]
        assert array_util.array_comp(budget_frf_valid, budget_frf)

        # clean up
        sim.delete_output_files()

    return
Ejemplo n.º 35
0
def test_binary_well():

    nlay = 3
    nrow = 3
    ncol = 3
    mfnam = "t1"
    ml = flopy.modflow.Modflow(modelname=mfnam,
                               model_ws=cpth,
                               verbose=True,
                               exe_name=exe_name)
    dis = flopy.modflow.ModflowDis(ml,
                                   nlay=nlay,
                                   nrow=nrow,
                                   ncol=ncol,
                                   top=0,
                                   botm=[-1.0, -2.0, -3.0])
    ibound = np.ones((nlay, nrow, ncol), dtype=int)
    ibound[0, 1, 1] = 0
    ibound[0, 0, -1] = -1
    bas = flopy.modflow.ModflowBas(ml, ibound=ibound)
    lpf = flopy.modflow.ModflowLpf(ml, ipakcb=102)
    wd = flopy.modflow.ModflowWel.get_empty(ncells=2, aux_names=["v1", "v2"])
    wd["k"][0] = 2
    wd["i"][0] = 2
    wd["j"][0] = 2
    wd["flux"][0] = -1000.0
    wd["v1"][0] = 1.0
    wd["v2"][0] = 2.0
    wd["k"][1] = 2
    wd["i"][1] = 1
    wd["j"][1] = 1
    wd["flux"][1] = -500.0
    wd["v1"][1] = 200.0
    wd["v2"][1] = 100.0
    wel_data = {0: wd}
    wel = flopy.modflow.ModflowWel(ml,
                                   stress_period_data=wel_data,
                                   dtype=wd.dtype)
    oc = flopy.modflow.ModflowOc(ml)
    pcg = flopy.modflow.ModflowPcg(ml)

    ml.write_input()

    # run the modflow-2005 model
    if run:
        success, buff = ml.run_model(silent=False)
        assert success, "could not run MODFLOW-2005 model"
        fn0 = os.path.join(cpth, mfnam + ".nam")

    # load the model
    m = flopy.modflow.Modflow.load(mfnam + ".nam",
                                   model_ws=cpth,
                                   verbose=True,
                                   exe_name=exe_name)

    wl = m.wel.stress_period_data[0]
    msg = ("previous well package stress period data does not match " +
           "stress period data loaded.")
    assert np.array_equal(wel.stress_period_data[0], wl), msg

    # change model work space
    pth = os.path.join(cpth, "flopy")
    m.change_model_ws(new_pth=pth)

    # remove the existing well package
    m.remove_package("WEL")

    # recreate well package with binary output
    wel = flopy.modflow.ModflowWel(m,
                                   stress_period_data=wel_data,
                                   binary=True,
                                   dtype=wd.dtype)

    # write the model to the new path
    m.write_input()

    # run the new modflow-2005 model
    if run:
        success, buff = m.run_model(silent=False)
        assert success, "could not run the new MODFLOW-2005 model"
        fn1 = os.path.join(pth, mfnam + ".nam")

    # compare the files
    if run:
        fsum = os.path.join(cpth,
                            "{}.head.out".format(os.path.splitext(mfnam)[0]))
        success = False
        try:
            success = pymake.compare_heads(fn0, fn1, outfile=fsum)
        except:
            print("could not perform head comparison")

        assert success, "head comparison failure"

        fsum = os.path.join(cpth,
                            "{}.budget.out".format(os.path.splitext(mfnam)[0]))
        success = False
        try:
            success = pymake.compare_budget(fn0,
                                            fn1,
                                            max_incpd=0.1,
                                            max_cumpd=0.1,
                                            outfile=fsum)
        except:
            print("could not perform budget comparison")

        assert success, "budget comparison failure"

    # clean up
    shutil.rmtree(cpth)
Ejemplo n.º 36
0
def test001e_uzf_3lay():
    # init paths
    test_ex_name = 'test001e_UZF_3lay'
    model_name = 'gwf_1'

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder,
                                        'test001e_UZF_3lay_unch.hds')
    expected_head_file_b = os.path.join(expected_output_folder,
                                        'test001e_UZF_3lay_adj.hds')

    # load simulation
    sim = MFSimulation.load(model_name, 'mf6', exe_name, pth, verify_data=True)

    # make temp folder to save simulation
    sim.simulation_data.mfpath.set_sim_path(run_folder)

    # write simulation to new location
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'test001e_UZF_3lay.hds')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new)

    # change some settings
    model = sim.get_model(model_name)
    uzf = model.get_package('uzf')
    uzf_data = uzf.packagedata
    uzf_array = uzf_data.get_data()
    # increase initial water content
    for index in range(0, len(uzf_array)):
        uzf_array[index][7] = 0.3
    uzf_data.set_data(uzf_array)

    # write simulation again
    sim.simulation_data.mfpath.set_sim_path(save_folder)
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_b)
        head_new = os.path.join(save_folder, 'test001e_UZF_3lay.hds')
        outfile = os.path.join(save_folder, 'head_compare.dat')
        assert pymake.compare_heads(None,
                                    None,
                                    files1=head_file,
                                    files2=head_new,
                                    outfile=outfile)

    # test load_only
    model_package_check = ['chd', 'ic', 'npf', 'oc', 'sto', 'uzf']
    load_only_lists = [['chd6', 'ic6', 'ims', 'npf6', 'obs', 'oc', 'sto'],
                       ['chd6', 'ims', 'npf6', 'obs', 'oc', 'sto', 'uzf6'],
                       ['chd', 'ic', 'npf', 'obs', 'sto'],
                       ['ic6', 'ims', 'obs6', 'oc6']]
    for load_only in load_only_lists:
        sim = MFSimulation.load(model_name,
                                'mf6',
                                exe_name,
                                pth,
                                load_only=load_only)
        model = sim.get_model()
        for package in model_package_check:
            assert (package in model.package_type_dict) == \
                   (package in load_only or '{}6'.format(package) in load_only)
    if run:
        # test running a runnable load_only case
        sim = MFSimulation.load(model_name,
                                'mf6',
                                exe_name,
                                pth,
                                load_only=load_only_lists[0])
        assert sim.run_simulation()[0]
Ejemplo n.º 37
0
def load_and_write(mfnam, pth):
    """
    test045 load and write of MODFLOW-2005 GMG example problem
    """
    exe_name = 'mf2005'
    v = flopy.which(exe_name)

    run = True
    if v is None:
        run = False
    try:
        import pymake
        lpth = os.path.join(cpth, os.path.splitext(mfnam)[0])
        apth = os.path.join(lpth, 'flopy')
        compth = lpth
        pymake.setup(os.path.join(pth, mfnam), lpth)
    except:
        run = False
        lpth = pth
        apth = cpth
        compth = cpth

    m = flopy.modflow.Modflow.load(mfnam,
                                   model_ws=lpth,
                                   verbose=True,
                                   exe_name=exe_name)
    assert m.load_fail is False

    if run:
        try:
            success, buff = m.run_model(silent=False)
        except:
            success = False
        assert success, 'base model run did not terminate successfully'
        fn0 = os.path.join(lpth, mfnam)

    # change model workspace
    m.change_model_ws(apth)

    # recreate oc file
    oc = m.oc
    unitnumber = [oc.unit_number[0], oc.iuhead, oc.iuddn, 0, 0]
    spd = {(0, 0): ['save head', 'save drawdown']}
    chedfm = '(10(1X1PE13.5))'
    cddnfm = '(10(1X1PE13.5))'
    oc = flopy.modflow.ModflowOc(m,
                                 stress_period_data=spd,
                                 chedfm=chedfm,
                                 cddnfm=cddnfm,
                                 unitnumber=unitnumber)

    # rewrite files
    m.write_input()

    if run:
        try:
            success, buff = m.run_model(silent=False)
        except:
            success = False
        assert success, 'new model run did not terminate successfully'
        fn1 = os.path.join(apth, mfnam)

    if run:
        # compare heads
        fsum = os.path.join(compth,
                            '{}.head.out'.format(os.path.splitext(mfnam)[0]))
        success = False
        try:
            success = pymake.compare_heads(fn0, fn1, outfile=fsum)
        except:
            success = False
            print('could not perform head comparison')

        assert success, 'head comparison failure'

        # compare heads
        fsum = os.path.join(compth,
                            '{}.ddn.out'.format(os.path.splitext(mfnam)[0]))
        success = False
        try:
            success = pymake.compare_heads(fn0,
                                           fn1,
                                           outfile=fsum,
                                           text='drawdown')
        except:
            success = False
            print('could not perform drawdown comparison')

        assert success, 'head comparison failure'

        # compare budgets
        fsum = os.path.join(compth,
                            '{}.budget.out'.format(os.path.splitext(mfnam)[0]))
        success = False
        try:
            success = pymake.compare_budget(fn0,
                                            fn1,
                                            max_incpd=0.1,
                                            max_cumpd=0.1,
                                            outfile=fsum)
        except:
            success = False
            print('could not perform budget comparison')

        assert success, 'budget comparison failure'

    return
Ejemplo n.º 38
0
def load_and_write_fhb(mfnam, pth):

    exe_name = 'mf2005'
    v = flopy.which(exe_name)

    run = True
    if v is None:
        run = False
    try:
        import pymake
        lpth = os.path.join(cpth, os.path.splitext(mfnam)[0])
        apth = os.path.join(lpth, 'flopy')
        compth = lpth
        pymake.setup(os.path.join(pth, mfnam), lpth)
    except:
        run = False
        lpth = pth
        apth = cpth
        compth = cpth

    m = flopy.modflow.Modflow.load(mfnam, model_ws=lpth, verbose=True,
                                   exe_name=exe_name)
    assert m.load_fail is False

    if run:
        try:
            success, buff = m.run_model(silent=False)
        except:
            pass
        assert success, 'base model run did not terminate successfully'
        fn0 = os.path.join(lpth, mfnam)

    # rewrite files
    m.change_model_ws(apth, reset_external=True)
    m.write_input()
    if run:
        try:
            success, buff = m.run_model(silent=False)
        except:
            pass
        assert success, 'new model run did not terminate successfully'
        fn1 = os.path.join(apth, mfnam)

    if run:
        fsum = os.path.join(compth,
                            '{}.head.out'.format(os.path.splitext(mfnam)[0]))
        success = False
        try:
            success = pymake.compare_heads(fn0, fn1, outfile=fsum)
        except:
            print('could not perform head comparison')

        assert success, 'head comparison failure'

        fsum = os.path.join(compth,
                            '{}.budget.out'.format(os.path.splitext(mfnam)[0]))
        success = False
        try:
            success = pymake.compare_budget(fn0, fn1,
                                            max_incpd=0.1, max_cumpd=0.1,
                                            outfile=fsum)
        except:
            print('could not perform budget comparison')

        assert success, 'budget comparison failure'

    return
Ejemplo n.º 39
0
def test_binary_well():

    nlay = 3
    nrow = 3
    ncol = 3
    mfnam = 't1'
    ml = flopy.modflow.Modflow(modelname=mfnam, model_ws=cpth, verbose=True,
                               exe_name=exe_name)
    dis = flopy.modflow.ModflowDis(ml, nlay=nlay, nrow=nrow, ncol=ncol, top=0,
                                   botm=[-1., -2., -3.])
    ibound = np.ones((nlay, nrow, ncol), dtype=np.int)
    ibound[0, 1, 1] = 0
    ibound[0, 0, -1] = -1
    bas = flopy.modflow.ModflowBas(ml, ibound=ibound)
    lpf = flopy.modflow.ModflowLpf(ml, ipakcb=102)
    wd = flopy.modflow.ModflowWel.get_empty(ncells=2,
                                            aux_names=['aux1', 'aux2'])
    wd['k'][0] = 2
    wd['i'][0] = 2
    wd['j'][0] = 2
    wd['flux'][0] = -1000.
    wd['aux1'][0] = 1.
    wd['aux2'][0] = 2.
    wd['k'][1] = 2
    wd['i'][1] = 1
    wd['j'][1] = 1
    wd['flux'][1] = -500.
    wd['aux1'][1] = 200.
    wd['aux2'][1] = 100.
    wel_data = {0: wd}
    wel = flopy.modflow.ModflowWel(ml, stress_period_data=wel_data,
                                   binary=True, dtype=wd.dtype)
    oc = flopy.modflow.ModflowOc(ml)
    pcg = flopy.modflow.ModflowPcg(ml)

    ml.write_input()

    # run the modflow-2005 model
    if run:
        success, buff = ml.run_model(silent=False)
        assert success, 'could not run MODFLOW-2005 model'
        fn0 = os.path.join(cpth, mfnam+'.nam')


    # load the model
    m = flopy.modflow.Modflow.load(mfnam+'.nam', model_ws=cpth,
                                   verbose=True, exe_name=exe_name)

    wl = m.wel.stress_period_data[0]
    msg = 'previous well package stress period data does not match ' + \
          'stress period data loaded.'
    assert np.array_equal(wel.stress_period_data[0], wl), msg

    # change model work space
    pth = os.path.join(cpth, 'flopy')
    m.change_model_ws(new_pth=pth)

    # temporary fix to save wel data as binary file
    m.wel.stress_period_data._MfList__binary = True

    # write the lgr model in to the new path
    m.write_input()

    # run the new modflow-2005 model
    if run:
        success, buff = m.run_model(silent=False)
        assert success, 'could not run the new MODFLOW-2005 model'
        fn1 = os.path.join(pth, mfnam+'.nam')

    # compare the files
    if run:
        fsum = os.path.join(cpth,
                            '{}.head.out'.format(os.path.splitext(mfnam)[0]))
        success = False
        try:
            success = pymake.compare_heads(fn0, fn1, outfile=fsum)
        except:
            print('could not perform head comparison')

        assert success, 'head comparison failure'

        fsum = os.path.join(cpth,
                            '{}.budget.out'.format(os.path.splitext(mfnam)[0]))
        success = False
        try:
            success = pymake.compare_budget(fn0, fn1,
                                            max_incpd=0.1, max_cumpd=0.1,
                                            outfile=fsum)
        except:
            print('could not perform budget comparison')

        assert success, 'budget comparison failure'
Ejemplo n.º 40
0
def load_and_write(mfnam, pth):
    """
    test045 load and write of MODFLOW-2005 GMG example problem
    """
    exe_name = 'mf2005'
    v = flopy.which(exe_name)

    run = True
    if v is None:
        run = False
    try:
        import pymake
        lpth = os.path.join(cpth, os.path.splitext(mfnam)[0])
        apth = os.path.join(lpth, 'flopy')
        compth = lpth
        pymake.setup(os.path.join(pth, mfnam), lpth)
    except:
        run = False
        lpth = pth
        apth = cpth
        compth = cpth

    m = flopy.modflow.Modflow.load(mfnam, model_ws=lpth, verbose=True,
                                   exe_name=exe_name)
    assert m.load_fail is False

    if run:
        try:
            success, buff = m.run_model(silent=False)
        except:
            success = False
        assert success, 'base model run did not terminate successfully'
        fn0 = os.path.join(lpth, mfnam)

    # change model workspace
    m.change_model_ws(apth)

    # recreate oc file
    oc = m.oc
    unitnumber = [oc.unit_number[0], oc.iuhead, oc.iuddn, 0, 0]
    spd = {(0,0): ['save head', 'save drawdown']}
    chedfm = '(10(1X1PE13.5))'
    cddnfm = '(10(1X1PE13.5))'
    oc = flopy.modflow.ModflowOc(m, stress_period_data=spd,
                                 chedfm=chedfm, cddnfm=cddnfm,
                                 unitnumber=unitnumber)

    # rewrite files
    m.write_input()

    if run:
        try:
            success, buff = m.run_model(silent=False)
        except:
            success = False
        assert success, 'new model run did not terminate successfully'
        fn1 = os.path.join(apth, mfnam)

    if run:
        # compare heads
        fsum = os.path.join(compth,
                            '{}.head.out'.format(os.path.splitext(mfnam)[0]))
        success = False
        try:
            success = pymake.compare_heads(fn0, fn1, outfile=fsum)
        except:
            success = False
            print('could not perform head comparison')

        assert success, 'head comparison failure'

        # compare heads
        fsum = os.path.join(compth,
                            '{}.ddn.out'.format(os.path.splitext(mfnam)[0]))
        success = False
        try:
            success = pymake.compare_heads(fn0, fn1, outfile=fsum,
                                           text='drawdown')
        except:
            success = False
            print('could not perform drawdown comparison')

        assert success, 'head comparison failure'

        # compare budgets
        fsum = os.path.join(compth,
                            '{}.budget.out'.format(os.path.splitext(mfnam)[0]))
        success = False
        try:
            success = pymake.compare_budget(fn0, fn1,
                                            max_incpd=0.1, max_cumpd=0.1,
                                            outfile=fsum)
        except:
            success = False
            print('could not perform budget comparison')

        assert success, 'budget comparison failure'

    return
Ejemplo n.º 41
0
def load_and_write_pcgn(mfnam, pth):
    """
    test044 load and write of MODFLOW-2005 PCGN example problem
    """
    exe_name = 'mf2005'
    v = flopy.which(exe_name)

    run = True
    if v is None:
        run = False
    try:
        import pymake
        lpth = os.path.join(cpth, os.path.splitext(mfnam)[0])
        apth = os.path.join(lpth, 'flopy')
        compth = lpth
        pymake.setup(os.path.join(pth, mfnam), lpth)
    except:
        run = False
        lpth = pth
        apth = cpth
        compth = cpth

    m = flopy.modflow.Modflow.load(mfnam, model_ws=lpth, verbose=True,
                                   exe_name=exe_name)
    assert m.load_fail is False
    if mfnam in ['twri.nam']:  # update this list for fixed models
        assert m.free_format_input is False
    else:
        assert m.free_format_input is True

    if run:
        try:
            success, buff = m.run_model(silent=False)
        except:
            success = False
        assert success, 'base model run did not terminate successfully'
        fn0 = os.path.join(lpth, mfnam)

    # rewrite files
    m.change_model_ws(apth)
    m.write_input()
    if run:
        try:
            success, buff = m.run_model(silent=False)
        except:
            success = False
        assert success, 'new model run did not terminate successfully'
        fn1 = os.path.join(apth, mfnam)

    if run:
        fsum = os.path.join(compth,
                            '{}.head.out'.format(os.path.splitext(mfnam)[0]))
        success = False
        try:
            success = pymake.compare_heads(fn0, fn1, outfile=fsum, htol=0.005)
        except:
            success = False
            print('could not perform head comparison')

        assert success, 'head comparison failure'

        fsum = os.path.join(compth,
                            '{}.budget.out'.format(os.path.splitext(mfnam)[0]))
        success = False
        try:
            success = pymake.compare_budget(fn0, fn1,
                                            max_incpd=0.1, max_cumpd=0.1,
                                            outfile=fsum)
        except:
            success = False
            print('could not perform budget comparison')

        assert success, 'budget comparison failure'

    return
Ejemplo n.º 42
0
def load_and_write_pcgn(mfnam, pth):
    """
    test044 load and write of MODFLOW-2005 PCGN example problem
    """
    exe_name = 'mf2005'
    v = flopy.which(exe_name)

    run = True
    if v is None:
        run = False
    try:
        import pymake
        lpth = os.path.join(cpth, os.path.splitext(mfnam)[0])
        apth = os.path.join(lpth, 'flopy')
        compth = lpth
        pymake.setup(os.path.join(pth, mfnam), lpth)
    except:
        run = False
        lpth = pth
        apth = cpth
        compth = cpth

    m = flopy.modflow.Modflow.load(mfnam,
                                   model_ws=lpth,
                                   verbose=True,
                                   exe_name=exe_name)
    assert m.load_fail is False
    if mfnam in ['twri.nam']:  # update this list for fixed models
        assert m.free_format_input is False
    else:
        assert m.free_format_input is True

    if run:
        try:
            success, buff = m.run_model(silent=False)
        except:
            pass
        assert success, 'base model run did not terminate successfully'
        fn0 = os.path.join(lpth, mfnam)

    # rewrite files
    m.change_model_ws(apth)
    m.write_input()
    if run:
        try:
            success, buff = m.run_model(silent=False)
        except:
            pass
        assert success, 'new model run did not terminate successfully'
        fn1 = os.path.join(apth, mfnam)

    if run:
        fsum = os.path.join(compth,
                            '{}.head.out'.format(os.path.splitext(mfnam)[0]))
        success = False
        try:
            success = pymake.compare_heads(fn0, fn1, outfile=fsum)
        except:
            print('could not perform head comparison')

        assert success, 'head comparison failure'

        fsum = os.path.join(compth,
                            '{}.budget.out'.format(os.path.splitext(mfnam)[0]))
        success = False
        try:
            success = pymake.compare_budget(fn0,
                                            fn1,
                                            max_incpd=0.1,
                                            max_cumpd=0.1,
                                            outfile=fsum)
        except:
            print('could not perform budget comparison')

        assert success, 'budget comparison failure'

    return
Ejemplo n.º 43
0
def test006_gwf3():
    from flopy.mf6.utils.binaryfile_utils import _reshape_binary_data

    # init paths
    test_ex_name = 'test006_gwf3'
    model_name = 'gwf_1'

    pth = os.path.join('..', 'examples', 'data', 'mf6', test_ex_name)
    run_folder = os.path.join(cpth, test_ex_name)
    if not os.path.isdir(run_folder):
        os.makedirs(run_folder)
    save_folder = os.path.join(run_folder, 'temp')
    if not os.path.isdir(save_folder):
        os.makedirs(save_folder)

    expected_output_folder = os.path.join(pth, 'expected_output')
    expected_head_file_a = os.path.join(expected_output_folder, 'flow_unch.hds')
    expected_head_file_b = os.path.join(expected_output_folder, 'flow_adj.hds')
    expected_cbc_file_a = os.path.join(expected_output_folder, 'flow_unch.cbc')
    expected_cbc_file_b = os.path.join(expected_output_folder, 'flow_adj.cbc')

    array_util = ArrayUtil()

    # load simulation
    sim = MFSimulation.load(model_name, 'mf6', exe_name, pth)

    # make temp folder to save simulation
    sim.simulation_data.mfpath.set_sim_path(run_folder)
    # write simulation to new location
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        budget_file = os.path.join(os.getcwd(), expected_cbc_file_a)
        budget_obj = bf.CellBudgetFile(budget_file, precision='double')
        budget_fjf_valid = np.array(budget_obj.get_data(text='    FLOW JA FACE', full3D=True))
        jaentries = budget_fjf_valid.shape[-1]
        budget_fjf_valid.shape = (-1, jaentries)

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_a)
        head_new = os.path.join(run_folder, 'flow.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

        budget_fjf = np.array(sim.simulation_data.mfdata[(model_name, 'CBC', 'FLOW-JA-FACE')])
        assert array_util.array_comp(np.array(budget_fjf_valid), np.array(budget_fjf))

    # change some settings
    model = sim.get_model(model_name)
    hk = model.get_package('npf').k
    hk_data = hk.get_data()
    hk_data[2] = 3.5
    hk.set_data(hk_data)
    ex_happened = False
    try:
        hk.make_layered()
    except:
        ex_happened = True
    assert(ex_happened)

    # write simulation again
    sim.simulation_data.mfpath.set_sim_path(save_folder)
    sim.write_simulation()

    if run:
        # run simulation
        sim.run_simulation()

        # get expected results
        budget_file = os.path.join(os.getcwd(), expected_cbc_file_b)
        budget_obj = bf.CellBudgetFile(budget_file, precision='double')
        budget_fjf_valid = np.array(budget_obj.get_data(text='    FLOW JA FACE', full3D=True))
        jaentries = budget_fjf_valid.shape[-1]
        budget_fjf_valid.shape = (-1, jaentries)

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_b)
        head_new = os.path.join(save_folder, 'flow.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

        budget_fjf = np.array(sim.simulation_data.mfdata[(model_name, 'CBC', 'FLOW-JA-FACE')])
        assert array_util.array_comp(np.array(budget_fjf_valid), np.array(budget_fjf))

    # confirm that files did move
    save_folder = os.path.join(run_folder, 'temp_two')
    sim.simulation_data.mfpath.set_sim_path(save_folder)

    # write with "copy_external_files" turned off so external files do not get copied to new location
    sim.write_simulation(ext_file_action=flopy.mf6.mfbase.ExtFileAction.copy_none)

    if run:
        # run simulation
        sim.run_simulation()

        # get expected results
        budget_file = os.path.join(os.getcwd(), expected_cbc_file_b)
        budget_obj = bf.CellBudgetFile(budget_file, precision='double')
        budget_fjf_valid = np.array(budget_obj.get_data(text='    FLOW JA FACE', full3D=True))
        jaentries = budget_fjf_valid.shape[-1]
        budget_fjf_valid.shape = (-1, jaentries)

        # compare output to expected results
        head_file = os.path.join(os.getcwd(), expected_head_file_b)
        head_new = os.path.join(save_folder, 'flow.hds')
        assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)

        budget_fjf = np.array(sim.simulation_data.mfdata[(model_name, 'CBC', 'FLOW-JA-FACE')])
        assert array_util.array_comp(np.array(budget_fjf_valid), np.array(budget_fjf))

        # confirm that files did not move
        assert not os.path.isfile(os.path.join(save_folder, 'flow.disu.ja.dat'))
        assert not os.path.isfile(os.path.join(save_folder, 'flow.disu.iac.dat'))
        assert not os.path.isfile(os.path.join(save_folder, 'flow.disu.cl12.dat'))
        assert not os.path.isfile(os.path.join(save_folder, 'flow.disu.area.dat'))
        assert not os.path.isfile(os.path.join(save_folder, 'flow.disu.hwva.dat'))

        # clean up
        sim.delete_output_files()

    return