Пример #1
0
def run_gridgen(d):
    print('running...{}'.format(d))

    biscayne_cmds = [
        'buildqtg action01_buildqtg.dfn',
        'grid02qtg-to-usgdata action02_writeusgdata.dfn',
        'grid01mfg-to-polyshapefile action03_shapefile.dfn',
        'grid02qtg-to-polyshapefile action03_shapefile.dfn',
        'grid01mfg-to-pointshapefile action03_shapefile.dfn',
        'grid02qtg-to-pointshapefile action03_shapefile.dfn',
        'canal_grid02qtg_lay1_intersect action04_intersect.dfn',
        'chd_grid02qtg_lay1_intersect action04_intersect.dfn',
        'grid01mfg-to-vtkfile action05_vtkfile.dfn',
        'grid02qtg-to-vtkfile action05_vtkfile.dfn',
        'grid02qtg-to-vtkfilesv action05_vtkfile.dfn', ]

    testpth = os.path.join(expth, d)
    testpth = os.path.abspath(testpth)
    prog = os.path.abspath(target)

    for cmd in biscayne_cmds:
        cmdlist = [prog] + cmd.split()
        print('running ', cmdlist)
        retcode = run_command(cmdlist, testpth)
        success = False
        if retcode == 0:
            success = True
        assert success

    if success:
        pymake.teardown(testpth)
    assert success is True

    return
Пример #2
0
def run_gridgen(d):
    print('running...{}'.format(d))

    biscayne_cmds = [
        'buildqtg action01_buildqtg.dfn',
        'grid02qtg-to-usgdata action02_writeusgdata.dfn',
        'grid01mfg-to-polyshapefile action03_shapefile.dfn',
        'grid02qtg-to-polyshapefile action03_shapefile.dfn',
        'grid01mfg-to-pointshapefile action03_shapefile.dfn',
        'grid02qtg-to-pointshapefile action03_shapefile.dfn',
        'canal_grid02qtg_lay1_intersect action04_intersect.dfn',
        'chd_grid02qtg_lay1_intersect action04_intersect.dfn',
        'grid01mfg-to-vtkfile action05_vtkfile.dfn',
        'grid02qtg-to-vtkfile action05_vtkfile.dfn',
        'grid02qtg-to-vtkfilesv action05_vtkfile.dfn',]


    testpth = os.path.join(expth, d)
    testpth = os.path.abspath(testpth)
    prog = os.path.abspath(target)

    for cmd in biscayne_cmds:
        cmdlist = [prog] + cmd.split()
        print('running ', cmdlist)
        retcode = run_command(cmdlist, testpth)
        success = False
        if retcode == 0:
            success = True
        assert success

    if success:
        pymake.teardown(testpth)
    assert success is True

    return
Пример #3
0
def run_mf2005(namefile, regression=True):
    """
    Run the simulation.

    """

    # Set root as the directory name where namefile is located
    testname = pymake.get_sim_name(namefile, rootpth=config.testpaths[0])[0]

    # Set nam as namefile name without path
    nam = os.path.basename(namefile)

    # Setup
    testpth = os.path.join(config.testdir, testname)
    pymake.setup(namefile, testpth)

    # run test models
    print('running model...{}'.format(testname))
    exe_name = os.path.abspath(config.target)
    success, buff = flopy.run_model(exe_name,
                                    nam,
                                    model_ws=testpth,
                                    silent=True)

    # If it is a regression run, then setup and run the model with the
    # release target and the reference target
    success_reg = True
    if regression:
        testname_reg = os.path.basename(config.target_release)
        testpth_reg = os.path.join(testpth, testname_reg)
        pymake.setup(namefile, testpth_reg)
        print('running regression model...{}'.format(testname_reg))
        exe_name = os.path.abspath(config.target_release)
        success_reg, buff = flopy.run_model(exe_name,
                                            nam,
                                            model_ws=testpth_reg,
                                            silent=True)

        if success_reg:
            outfile1 = os.path.join(
                os.path.split(os.path.join(testpth, nam))[0], 'bud.cmp')
            outfile2 = os.path.join(
                os.path.split(os.path.join(testpth, nam))[0], 'hds.cmp')
            success_reg = pymake.compare(os.path.join(testpth, nam),
                                         os.path.join(testpth_reg, nam),
                                         precision='single',
                                         max_cumpd=0.01,
                                         max_incpd=0.01,
                                         htol=0.001,
                                         outfile1=outfile1,
                                         outfile2=outfile2)

    # Clean things up
    if success and success_reg and not config.retain:
        pymake.teardown(testpth)
    assert success, 'model did not run'
    assert success_reg, 'regression model did not meet comparison criteria'

    return
Пример #4
0
def run_mf2005(namefile, regression=True):
    """
    Run the simulation.

    """

    # Set root as the directory name where namefile is located
    testname = pymake.get_sim_name(namefile, rootpth=testpaths[0])[0]

    # Set nam as namefile name without path
    nam = os.path.basename(namefile)

    # Setup
    testpth = os.path.join(testdir, testname)
    pymake.setup(namefile, testpth)

    # run test models
    print('running model...{}'.format(testname))
    exe_name = os.path.abspath(target_release)
    success, buff = flopy.run_model(exe_name, nam, model_ws=testpth,
                                    silent=True)

    assert success, 'base model {} '.format(nam) + 'did not run.'

    # If it is a regression run, then setup and run the model with the
    # release target and the reference target
    success_reg = True
    if regression:
        testname_reg = os.path.basename(target_previous)
        testpth_reg = os.path.join(testpth, testname_reg)
        pymake.setup(namefile, testpth_reg)
        print('running regression model...{}'.format(testname_reg))
        exe_name = os.path.abspath(target_previous)
        success_reg, buff = flopy.run_model(exe_name, nam,
                                            model_ws=testpth_reg,
                                            silent=False)

        assert success_reg, 'regression model {} '.format(nam) + 'did not run.'

        # compare results
        outfile1 = os.path.join(os.path.split(os.path.join(testpth, nam))[0],
                                'bud.cmp')
        outfile2 = os.path.join(os.path.split(os.path.join(testpth, nam))[0],
                                'hds.cmp')
        success_reg = pymake.compare(os.path.join(testpth, nam),
                                     os.path.join(testpth_reg, nam),
                                     precision='single',
                                     max_cumpd=0.01, max_incpd=0.01,
                                     htol=0.001,
                                     outfile1=outfile1, outfile2=outfile2)

    # Clean things up
    if not retain:
        pymake.teardown(testpth)

    return
Пример #5
0
def run_mfusg(namepth, dst):
    print('running...{}'.format(dst))
    # setup
    testpth = os.path.join(dstpth, dst)
    pymake.setup(namepth, testpth)

    # run test models
    print('running model...{}'.format(os.path.basename(namepth)))
    success, buff = flopy.run_model(epth, os.path.basename(namepth),
                                    model_ws=testpth, silent=True)
    if success:
        pymake.teardown(testpth)
    assert success is True

    return
Пример #6
0
def run_mf6(d):
    print('running...{}'.format(d))
    # setup
    epth = os.path.join(expth, d)
    testpth = os.path.join(dstpth, d)
    pymake.setup_mf6(epth, testpth)

    # run test models
    print('running model...{}'.format(os.path.basename(d)))
    epth = os.path.abspath(target)
    success, buff = flopy.run_model(epth, None, model_ws=testpth, silent=False)
    if success:
        pymake.teardown(testpth)
    assert success is True

    return
Пример #7
0
def run_mf6(d):
    print('running...{}'.format(d))
    # setup
    epth = os.path.join(expth, d)
    testpth = os.path.join(dstpth, d)
    pymake.setup_mf6(epth, testpth)

    # run test models
    print('running model...{}'.format(os.path.basename(d)))
    epth = os.path.abspath(target)
    success, buff = flopy.run_model(epth, None,
                                    model_ws=testpth, silent=False)
    if success:
        pymake.teardown(testpth)
    assert success is True

    return
Пример #8
0
def run_mf2005(namefile, regression=True):
    """
    Run the simulation.

    """
    if namefile is not None:
        # Set root as the directory name where namefile is located
        testname = pymake.get_sim_name(namefile, rootpth=expth)[0]

        # Set nam as namefile name without path
        nam = os.path.basename(namefile)

        # Setup
        testpth = os.path.join(dstpth, testname)
        pymake.setup(namefile, testpth)

        # run test models
        exe_name = os.path.abspath(epth)
        msg = "running model...{}".format(testname) + " using {}".format(
            exe_name)
        print(msg)
        if os.path.exists(exe_name):
            success, buff = flopy.run_model(exe_name,
                                            nam,
                                            model_ws=testpth,
                                            silent=True)
        else:
            success = False

        assert success, "base model {} ".format(nam) + "did not run."

        # If it is a regression run, then setup and run the model with the
        # release target and the reference target
        success_reg = True
        if regression:
            testname_reg = os.path.basename(mfpth)
            testpth_reg = os.path.join(testpth, testname_reg)
            pymake.setup(namefile, testpth_reg)
            # exe_name = os.path.abspath(target_previous)
            msg = "running regression model...{}".format(
                testname_reg) + " using {}".format(exe_name)
            print(msg)

            if os.path.exists(exe_name):
                success_reg, buff = flopy.run_model(exe_name,
                                                    nam,
                                                    model_ws=testpth_reg,
                                                    silent=False)
            else:
                success_reg = False

            assert success_reg, ("regression model {} ".format(nam) +
                                 "did not run.")

        # compare results
        if success and success_reg:
            fpth = os.path.split(os.path.join(testpth, nam))[0]
            outfile1 = os.path.join(fpth, "bud.cmp")
            fpth = os.path.split(os.path.join(testpth, nam))[0]
            outfile2 = os.path.join(fpth, "hds.cmp")
            success_reg = pymake.compare(
                os.path.join(testpth, nam),
                os.path.join(testpth_reg, nam),
                precision="single",
                max_cumpd=0.01,
                max_incpd=0.01,
                htol=0.001,
                outfile1=outfile1,
                outfile2=outfile2,
            )
        # Clean things up
        if success_reg:
            pymake.teardown(testpth)
        else:
            success = False
            errmsg = "could not run...{}".format(os.path.basename(nam))
    else:
        success = False
        errmsg = "{} does not exist".format(target)

    assert success, errmsg

    return
Пример #9
0
def run_mt3d(mf5namefile, mf6namefile, mtnamefile, regression=True):
    """
    Run the simulations.

    """

    # Set root as the directory name where namefile is located
    flowexe = config.target_dict['mfnwt']
    if '_mf2k' in mf5namefile:
        crep = '_mf2k'
        flowexe = config.target_dict['mf2000']
    elif '_mf2005' in mf5namefile:
        crep = '_mf2005'
        flowexe = config.target_dict['mf2005']
    else:
        crep = '_mf'
        flowexe = config.target_dict['mfnwt']
    testname = pymake.get_sim_name(mf5namefile.replace(crep, ''),
                                   rootpth=os.path.dirname(mf5namefile))[0]

    # Setup modflow
    testpth = os.path.join(config.testdir, testname)
    pymake.setup(mf5namefile, testpth)

    # run modflow5-variant (whether NWT or 2k5) to generate flow field for mt3d-usgs
    print('running modflow5 model...{}'.format(testname))
    nam = os.path.basename(mf5namefile)
    exe_name = flowexe
    success, buff = flopy.run_model(exe_name,
                                    nam,
                                    model_ws=testpth,
                                    silent=False,
                                    report=True)

    # Setup and run MF6 files for comparing with MF5-linked results
    flowexe = config.target_dict['mf6']
    exe_name = flowexe
    nam = os.path.basename(mf6namefile)
    pymake.setup_mf6(os.path.dirname(mf6namefile),
                     testpth,
                     remove_existing=False)

    cwd = os.getcwd()
    os.chdir(os.path.join(testpth))
    os.system(os.path.join('..', 'bin', 'mf6.exe'))
    os.chdir(cwd)

    # Setup mt3d
    pymake.setup(mtnamefile[0],
                 testpth,
                 remove_existing=False,
                 extrafiles=mtnamefile[1])

    # if modflow ran successfully, then run mt3d-usgs
    success_mf5 = success_mf6 = False
    if success:
        for i, nmfile in enumerate(mtnamefile):
            print('running mt3d-usgs model...{}'.format(nmfile))
            nam = os.path.basename(nmfile)
            exe_name = os.path.abspath(config.target)
            success, buff = flopy.run_model(exe_name,
                                            nam,
                                            model_ws=testpth,
                                            silent=False,
                                            report=True,
                                            normal_msg='program completed')
            if i == 0:
                success_mf5 = success
            elif i > 0:
                success_mf6 = success

    # run ucn comparison
    if success_mf5 and success_mf6:
        success_cmp = True
    else:
        success_cmp = False

    success_reg = False
    if regression:
        if success_cmp:
            # if mt3d-usgs ran, then time to do a comparison
            #ucnfile1 = os.path.join(testpth, os.path.split(testpth)[-1] + '_Comp1_4mf5.ucn')
            #ucnfile2 = os.path.join(testpth, os.path.split(testpth)[-1] + '_Comp1_4mf6.ucn')
            namefile1 = os.path.join(testpth, os.path.split(mtnamefile[0])[-1])
            namefile2 = os.path.join(testpth, os.path.split(mtnamefile[1])[-1])
            outfileucn = os.path.join(
                testpth,
                os.path.split(testpth)[-1] + '_UCNcompareResults.txt')
            success_ucn = pymake.compare_concs(namefile1,
                                               namefile2,
                                               ctol=0.001,
                                               outfile=outfileucn)
            if success_ucn:
                success_reg = True
            else:
                success_reg = False

    # Clean things up
    if success and success_reg and not config.retain:
        pymake.teardown(testpth)
    assert success, 'model did not run'
    assert success_cmp, 'comparison model did not meet comparison criteria'
    return
Пример #10
0
def run_mt3d(spth, comparison=True):
    """
    Run the simulations.

    """

    # Path to folder containing tests
    pth = config.testpaths[0]

    # -- get modflow name files
    tpth = os.path.join(pth, spth)
    namefilesmf = []
    namefilesmf += get_namefiles(tpth, exclude='mt')

    # -- get mt3d name files
    tpth = os.path.join(pth, spth)
    namefilesmt = []
    namefilesmt += get_namefiles(tpth, exclude='mf')

    mfnamefile = namefilesmf[0]
    mtnamefile = namefilesmt[0]
    print(mfnamefile, mtnamefile)

    # Set root as the directory name where namefile is located
    testname = pymake.get_sim_name(mfnamefile.replace('_mf', ''),
                                   rootpth=os.path.dirname(mfnamefile))[0]

    # Setup modflow
    testpth = os.path.join(config.testdir, testname)
    pymake.setup(mfnamefile, testpth)
    # Setup mt3d
    pymake.setup(mtnamefile, testpth, remove_existing=False)

    # Remove HSS file reference line from MT3D-USGS name file
    f = open(mtnamefile, 'r')
    lines = f.read()
    f.close()

    lines = lines.splitlines()
    f = open(os.path.join(testpth, testname + '_mt.nam'), 'w')
    for line in lines:
        if ('hss_source' in line):
            f.write('\n')
        else:
            f.write(line + '\n')
    f.close()

    # run modflow to generate flow field for mt3d-usgs
    print('running modflow-nwt model...{}'.format(testname))
    nam = os.path.basename(mfnamefile)
    exe_name = config.target_dict['mfnwt']
    success, buff = flopy.run_model(exe_name,
                                    nam,
                                    model_ws=testpth,
                                    silent=False,
                                    report=True)

    # if modflow ran successfully, then run mt3d-usgs
    if success:
        print('running mt3d-usgs model...{}'.format(testname))
        nam = os.path.basename(mtnamefile)
        exe_name = os.path.abspath(config.target)
        success, buff = flopy.run_model(exe_name,
                                        nam,
                                        model_ws=testpth,
                                        silent=False,
                                        report=True,
                                        normal_msg='program completed')

    success_cmp = True
    if success and comparison:
        action = pymake.setup_comparison(mfnamefile, testpth)
        action = pymake.setup_comparison(mtnamefile,
                                         testpth,
                                         remove_existing=False)
        testpth_cmp = os.path.join(testpth, action)
        if action is not None:
            files_cmp = None
            if action.lower() == '.cmp':
                files_cmp = []
                files = os.listdir(testpth_cmp)

                # Go through all files in the .cmp folder and do a separate
                # comparison for each one.  This will ensure that the
                # individual ucn files for sorbed and multi-species will be
                # compared.
                for file in files:
                    files1 = os.path.join(testpth, file[:-4])
                    files2 = os.path.join(testpth_cmp, file)
                    outfileucn = os.path.join(testpth, file + '.txt')
                    success_ucn = pymake.compare_concs(None,
                                                       None,
                                                       ctol=0.002,
                                                       outfile=outfileucn,
                                                       files1=files1,
                                                       files2=files2)
                    if not success_ucn:
                        success_cmp = False

            else:
                print('running comparison modflow-nwt model...{}'.format(
                    testpth_cmp))
                key = action.lower().replace('.cmp', '')
                nam = os.path.basename(mfnamefile)
                exe_name = os.path.abspath(config.target_dict['mfnwt'])
                success_cmp, buff = flopy.run_model(exe_name,
                                                    nam,
                                                    model_ws=testpth_cmp,
                                                    silent=False,
                                                    report=True)
                if success_cmp:
                    print('running comparison mt3dms model...{}'.format(
                        testpth_cmp))
                    key = action.lower().replace('.cmp', '')
                    nam = os.path.basename(mtnamefile)
                    exe_name = os.path.abspath(config.target_release)
                    success_cmp, buff = flopy.run_model(
                        exe_name,
                        nam,
                        model_ws=testpth_cmp,
                        silent=False,
                        report=True,
                        normal_msg='program completed')

                if success_cmp:
                    nam = os.path.basename(mtnamefile)
                    namefile1 = os.path.join(testpth, nam)
                    namefile2 = os.path.join(testpth_cmp, nam)
                    outfileucn = os.path.join(
                        os.path.split(os.path.join(testpth, nam))[0],
                        'ucn.cmp')
                    success_ucn = pymake.compare_concs(namefile1,
                                                       namefile2,
                                                       ctol=0.002,
                                                       outfile=outfileucn,
                                                       files2=files_cmp)

                if success_cmp and success_ucn:
                    success_cmp = True
                else:
                    success_cmp = False
    # Clean things up
    if success and success_cmp and not config.retain:
        pymake.teardown(testpth)
    assert success, 'model did not run'
    assert success_cmp, 'comparison model did not meet comparison criteria'
    return
Пример #11
0
def run_mfusg(namefile, comparison=True):
    """
    Run the simulation.

    """

    # Set root as the directory name where namefile is located
    testname = pymake.get_sim_name(namefile, rootpth=config.testpaths[2])[0]

    # Set nam as namefile name without path
    nam = os.path.basename(namefile)

    # Setup
    testpth = os.path.join(config.testdir, testname)
    pymake.setup(namefile, testpth)

    # run test models
    print('running model...{}'.format(testname))
    exe_name = os.path.abspath(config.target)
    success, buff = flopy.run_model(exe_name,
                                    nam,
                                    model_ws=testpth,
                                    silent=True)
    success_cmp = True
    if comparison:
        action = pymake.setup_comparison(namefile, testpth)
        testpth_cmp = os.path.join(testpth, action)
        if action is not None:
            files_cmp = None
            if action.lower() == '.cmp':
                files_cmp = []
                files = os.listdir(testpth_cmp)
                for file in files:
                    files_cmp.append(
                        os.path.abspath(os.path.join(testpth_cmp, file)))
                success_cmp = True
                print(files_cmp)
            else:
                print('running comparison model...{}'.format(testpth_cmp))
                key = action.lower().replace('.cmp', '')
                exe_name = config.target_dict[key]
                success_cmp, buff = flopy.run_model(exe_name,
                                                    nam,
                                                    model_ws=testpth_cmp,
                                                    silent=True)
            if success_cmp:
                outfile1 = os.path.join(
                    os.path.split(os.path.join(testpth, nam))[0], 'bud.cmp')
                outfile2 = os.path.join(
                    os.path.split(os.path.join(testpth, nam))[0], 'hds.cmp')
                success_cmp = pymake.compare(os.path.join(testpth, nam),
                                             os.path.join(testpth_cmp, nam),
                                             precision='single',
                                             max_cumpd=0.01,
                                             max_incpd=0.01,
                                             htol=0.001,
                                             outfile1=outfile1,
                                             outfile2=outfile2,
                                             files2=files_cmp)

    # Clean things up
    if success and success_cmp and not config.retain:
        pymake.teardown(testpth)
    assert success, 'model did not run'
    assert success_cmp, 'comparison model did not meet comparison criteria'

    return
Пример #12
0
def run_mt3d(spth, comparison=True):
    """
    Run the simulations.

    """

    # Path to folder containing tests
    pth = config.testpaths[0]

    # -- get modflow name files
    tpth = os.path.join(pth, spth)
    namefilesmf = []
    namefilesmf += get_namefiles(tpth, exclude='mt')

    # -- get mt3d name files
    tpth = os.path.join(pth, spth)
    namefilesmt = []
    namefilesmt += get_namefiles(tpth, exclude='mf')

    mfnamefile = namefilesmf[0]
    mtnamefile = namefilesmt[0]
    print(mfnamefile, mtnamefile)

    # Set root as the directory name where namefile is located
    testname = pymake.get_sim_name(mfnamefile.replace('_mf', ''), 
                                   rootpth=os.path.dirname(mfnamefile))[0]

    # Setup modflow
    testpth = os.path.join(config.testdir, testname)
    pymake.setup(mfnamefile, testpth)
    # Setup mt3d
    pymake.setup(mtnamefile, testpth, remove_existing=False)

    # run test models
    print('running modflow-nwt model...{}'.format(testname))
    nam = os.path.basename(mfnamefile)
    exe_name = config.target_dict['mfnwt']
    success, buff = flopy.run_model(exe_name, nam, model_ws=testpth,
                                    silent=True)

    if success:
        print('running mt3d-usgs model...{}'.format(testname))
        nam = os.path.basename(mtnamefile)
        exe_name = os.path.abspath(config.target)
        success, buff = flopy.run_model(exe_name, nam, model_ws=testpth,
                                        silent=True,
                                        normal_msg='program completed')

    success_cmp = True
    if success and comparison:
        action = pymake.setup_comparison(mfnamefile, testpth)
        action = pymake.setup_comparison(mtnamefile, testpth, 
                                         remove_existing=False)
        testpth_cmp = os.path.join(testpth, action)
        if action is not None:
            files_cmp = None
            if action.lower() == '.cmp':
                files_cmp = []
                files = os.listdir(testpth_cmp)
                for file in files:
                    files1 = os.path.join(testpth, file[:-4])
                    files2 = os.path.join(testpth_cmp, file)
                    outfileucn = os.path.join(testpth, file + '.txt')
                    success_ucn = pymake.compare_concs(None, None,
                                                       ctol=0.002,
                                                       outfile=outfileucn,
                                                       files1=files1,
                                                       files2=files2)
                    if not success_ucn:
                        success_cmp = False

            else:
                print('running comparison modflow-nwt model...{}'.format(testpth_cmp))
                key = action.lower().replace('.cmp', '')
                nam = os.path.basename(mfnamefile)
                exe_name = os.path.abspath(config.target_dict['mfnwt'])
                success_cmp, buff = flopy.run_model(exe_name, nam,
                                                    model_ws=testpth_cmp,
                                                    silent=True)
                if success_cmp:
                    print('running comparison mt3dms model...{}'.format(testpth_cmp))
                    key = action.lower().replace('.cmp', '')
                    nam = os.path.basename(mtnamefile)
                    exe_name = os.path.abspath(config.target_release)
                    success_cmp, buff = flopy.run_model(exe_name, nam,
                                                        model_ws=testpth_cmp,
                                                        silent=True,
                                                        normal_msg='program completed')

                if success_cmp:
                    nam = os.path.basename(mtnamefile)
                    namefile1 = os.path.join(testpth, nam)
                    namefile2 = os.path.join(testpth_cmp, nam)
                    outfileucn = os.path.join(
                                 os.path.split(os.path.join(testpth, nam))[0],
                                 'ucn.cmp')
                    success_ucn = pymake.compare_concs(namefile1, namefile2,
                                                       ctol=0.002,
                                                       outfile=outfileucn,
                                                       files2=files_cmp)

                if success_cmp and success_ucn:
                    success_cmp = True
                else:
                    success_cmp = False
    # Clean things up
    if success and success_cmp and not config.retain:
        pymake.teardown(testpth)
    assert success, 'model did not run'
    assert success_cmp, 'comparison model did not meet comparison criteria'
    return
Пример #13
0
def run_mfusg(regression=True):
    """
    Download run and compare biscayne quadtree problem

    """

    # Set the testname
    testname = '02_quadtree'
    testpth = os.path.join(config.testdir, testname)

    # Delete folder if exists, then download the MODFLOW-USG distribution
    if os.path.isdir(testpth):
        shutil.rmtree(testpth)
    url = "http://water.usgs.gov/ogw/mfusg/02_quadtree.zip"
    pymake.download_and_unzip(url, pth=config.testdir)

    # Go through name file and replace \ with /
    oldnam = os.path.join(testpth, 'biscayne.nam')
    newnam = os.path.join(testpth, 'biscayne.new.nam')
    fold = open(oldnam, 'r')
    fnew = open(newnam, 'w')
    for i, line in enumerate(fold):
        line = line.replace('\\', '/')
        line = line.replace('biscayne.disu', 'biscayne.new.disu')
        line = line.replace('biscayne.oc', 'biscayne.new.oc')
        fnew.write(line)
    fold.close()
    fnew.close()

    # Change the number of stress periods from 1000 to 10
    olddis = os.path.join(testpth, 'input', 'biscayne.disu')
    newdis = os.path.join(testpth, 'input', 'biscayne.new.disu')
    fold = open(olddis, 'r')
    fnew = open(newdis, 'w')
    for i, line in enumerate(fold):
        if i == 1:
            line = line.replace('1000', '10')
        fnew.write(line)
    fold.close()
    fnew.close()

    # Write oc so that head and budget are always saved.
    newoc = os.path.join(testpth, 'input', 'biscayne.new.oc')
    fnew = open(newoc, 'w')
    fnew.write('HEAD SAVE UNIT 51' + '\n')
    fnew.write('COMPACT BUDGET' + '\n')
    for kper in range(10):
        fnew.write('PERIOD {} STEP 1'.format(kper + 1) + '\n')
        fnew.write('  PRINT BUDGET' + '\n')
        fnew.write('  SAVE BUDGET' + '\n')
        fnew.write('  SAVE HEAD' + '\n')
    fnew.close()

    # run test models
    print('running model...{}'.format(testname))
    nam = 'biscayne.new.nam'
    exe_name = os.path.abspath(config.target)
    success, buff = flopy.run_model(exe_name,
                                    nam,
                                    model_ws=testpth,
                                    silent=True)
    assert success, 'biscayne model did not run successfully.'

    # If it is a regression run, then setup and run the model with the
    # release target
    if regression:
        testname_reg = testname + '_reg'
        testpth_reg = os.path.join(config.testdir, testname_reg)
        pymake.setup(os.path.join(testpth, nam), testpth_reg)
        outdir = os.path.join(testpth_reg, 'output')
        if not os.path.isdir(outdir):
            os.mkdir(outdir)
        print('running regression model...{}'.format(testname_reg))
        exe_name = os.path.abspath(config.target_release)
        success, buff = flopy.run_model(exe_name,
                                        nam,
                                        model_ws=testpth_reg,
                                        silent=True)

        # Make comparison
        success = compare(os.path.join(testpth, nam),
                          os.path.join(testpth_reg, nam))
        assert success, 'Biscayne regression test did not pass'

    # Clean things up
    if success and not config.retain:
        pymake.teardown(testpth)
        if regression:
            pymake.teardown(testpth_reg)

    return
Пример #14
0
def run_mt3d(spth, comparison=True):
    """
    Run the simulations.

    """

    # Path to folder containing tests
    pth = config.testpaths[0]

    # -- get modflow name files
    tpth = os.path.join(pth, spth)
    namefilesmf = []
    namefilesmf += get_namefiles(tpth, exclude='mt')

    # -- get mt3d name files
    tpth = os.path.join(pth, spth)
    namefilesmt = []
    namefilesmt += get_namefiles(tpth, exclude='mf')

    mfnamefile = namefilesmf[0]
    mtnamefile = namefilesmt[0]
    print(mfnamefile, mtnamefile)

    # Set root as the directory name where namefile is located
    testname = pymake.get_sim_name(mfnamefile.replace('_mf', ''),
                                   rootpth=os.path.dirname(mfnamefile))[0]

    # Setup modflow
    testpth = os.path.join(config.testdir, testname)
    pymake.setup(mfnamefile, testpth)
    # Setup mt3d
    pymake.setup(mtnamefile, testpth, remove_existing=False)

    # run test models
    print('running modflow-nwt model...{}'.format(testname))
    nam = os.path.basename(mfnamefile)
    exe_name = config.target_dict['mfnwt']
    success, buff = flopy.run_model(exe_name,
                                    nam,
                                    model_ws=testpth,
                                    silent=False,
                                    report=True)

    if success:
        # For this particular test, a lengthy period of "stop flow"
        # needs to be inserted into the linker file for simulating
        # a period of equilibration.
        print('running insert_stopflow_period.py...{}'.format(testname))
        insert_stopflow_period.InsStpFlw()

        print('running mt3d-usgs model...{}'.format(testname))
        nam = os.path.basename(mtnamefile)
        exe_name = os.path.abspath(config.target)
        success, buff = flopy.run_model(exe_name,
                                        nam,
                                        model_ws=testpth,
                                        silent=False,
                                        report=True,
                                        normal_msg='program completed')

    success_cmp = True
    if success and comparison:
        action = pymake.setup_comparison(mfnamefile, testpth)
        action = pymake.setup_comparison(mtnamefile,
                                         testpth,
                                         remove_existing=False)
        testpth_cmp = os.path.join(testpth, action)
        if action is not None:
            files_cmp = None
            if action.lower() == '.cmp':
                files_cmp = []
                files = os.listdir(testpth_cmp)

                # Go through all files in the .cmp folder and do a separate
                # comparison for each one.  This will ensure that the
                # individual ucn files for sorbed and multi-species will be
                # compared.
                for file in files:
                    files1 = os.path.join(testpth, file[:-4])
                    files2 = os.path.join(testpth_cmp, file)
                    outfileucn = os.path.join(testpth, file + '.txt')
                    success_ucn = pymake.compare_concs(None,
                                                       None,
                                                       ctol=0.002,
                                                       outfile=outfileucn,
                                                       files1=files1,
                                                       files2=files2)
                    if not success_ucn:
                        success_cmp = False

            else:
                print('running comparison modflow-nwt model...{}'.format(
                    testpth_cmp))
                key = action.lower().replace('.cmp', '')
                nam = os.path.basename(mfnamefile)
                exe_name = os.path.abspath(config.target_dict['mfnwt'])
                success_cmp, buff = flopy.run_model(exe_name,
                                                    nam,
                                                    model_ws=testpth_cmp,
                                                    silent=False,
                                                    report=True)
                if success_cmp:
                    print('running comparison mt3dms model...{}'.format(
                        testpth_cmp))
                    key = action.lower().replace('.cmp', '')
                    nam = os.path.basename(mtnamefile)
                    exe_name = os.path.abspath(config.target_release)
                    success_cmp, buff = flopy.run_model(
                        exe_name,
                        nam,
                        model_ws=testpth_cmp,
                        silent=False,
                        report=True,
                        normal_msg='program completed')

                if success_cmp:
                    nam = os.path.basename(mtnamefile)
                    namefile1 = os.path.join(testpth, nam)
                    namefile2 = os.path.join(testpth_cmp, nam)
                    outfileucn = os.path.join(
                        os.path.split(os.path.join(testpth, nam))[0],
                        'ucn.cmp')
                    success_ucn = pymake.compare_concs(namefile1,
                                                       namefile2,
                                                       ctol=0.002,
                                                       outfile=outfileucn,
                                                       files2=files_cmp)

                if success_cmp and success_ucn:
                    success_cmp = True
                else:
                    success_cmp = False
    # Clean things up
    if success and success_cmp and not config.retain:
        pymake.teardown(testpth)
    assert success, 'model did not run'
    assert success_cmp, 'comparison model did not meet comparison criteria'
    return
Пример #15
0
def run_mt3d(mfnamefile, mtnamefile, regression=True):
    """
    Run the simulations.

    """

    # Set root as the directory name where namefile is located
    flowexe = config.target_dict['mfnwt']
    if '_mf2k' in mfnamefile:
        crep = '_mf2k'
        flowexe = config.target_dict['mf2k']
    elif '_mf2005' in mfnamefile:
        crep = '_mf2005'
        flowexe = config.target_dict['mf2005']
    else:
        crep = '_mf'
        flowexe = config.target_dict['mfnwt']
    testname = pymake.get_sim_name(mfnamefile.replace(crep, ''),
                                   rootpth=os.path.dirname(mfnamefile))[0]

    # Setup modflow
    testpth = os.path.join(config.testdir, testname)
    pymake.setup(mfnamefile, testpth)
    # Setup mt3d
    pymake.setup(mtnamefile, testpth, remove_existing=False)

    # run test models
    print('running modflow-nwt model...{}'.format(testname))
    nam = os.path.basename(mfnamefile)
    exe_name = config.target_dict['mfnwt']
    success, buff = flopy.run_model(exe_name,
                                    nam,
                                    model_ws=testpth,
                                    silent=True)

    if success:
        print('running mt3d-usgs model...{}'.format(testname))
        nam = os.path.basename(mtnamefile)
        exe_name = os.path.abspath(config.target)
        success, buff = flopy.run_model(exe_name,
                                        nam,
                                        model_ws=testpth,
                                        silent=True,
                                        normal_msg='program completed')

    success_cmp = True
    if regression:
        testname_reg = os.path.basename(config.target_release)
        testpth_reg = os.path.join(testpth, testname_reg)
        pymake.setup(mfnamefile, testpth_reg)
        pymake.setup(mtnamefile, testpth_reg, remove_existing=False)
        print('running regression {} model...{}'.format(
            os.path.basename(flowexe), testpth_reg))
        nam = os.path.basename(mfnamefile)
        exe_name = flowexe  #config.target_dict['mfnwt']
        success_reg, buff = flopy.run_model(exe_name,
                                            nam,
                                            model_ws=testpth_reg,
                                            silent=True)
        if success_reg:
            print('running regression mt3dms model...{}'.format(testpth_reg))
            nam = os.path.basename(mtnamefile)
            exe_name = os.path.abspath(config.target_release)
            success_reg, buff = flopy.run_model(exe_name,
                                                nam,
                                                model_ws=testpth_reg,
                                                silent=True,
                                                normal_msg='program completed')
            if success_reg:
                nam = os.path.basename(mtnamefile)
                namefile1 = os.path.join(testpth, nam)
                namefile2 = os.path.join(testpth_reg, nam)
                outfileucn = os.path.join(
                    os.path.split(os.path.join(testpth, nam))[0], 'ucn.cmp')
                success_ucn = pymake.compare_concs(namefile1,
                                                   namefile2,
                                                   ctol=0.001,
                                                   outfile=outfileucn)
                if success_reg and success_ucn:
                    success_reg = True
                else:
                    success_reg = False
    # Clean things up
    if success and success_reg and not config.retain:
        pymake.teardown(testpth)
    assert success, 'model did not run'
    assert success_cmp, 'comparison model did not meet comparison criteria'
    return
Пример #16
0
def run_mfusg(namefile, regression=True):
    """
    Run the simulation.

    """

    # Set root as the directory name where namefile is located
    testname = os.path.dirname(namefile).split(os.sep)[-1]

    # Set nam as namefile name without path
    nam = os.path.basename(namefile)

    # Setup
    testpth = os.path.join(config.testdir, testname)
    pymake.setup(namefile, testpth)

    # run test models
    print('running model...{}'.format(testname))
    exe_name = os.path.abspath(config.target)
    success, buff = flopy.run_model(exe_name,
                                    nam,
                                    model_ws=testpth,
                                    silent=True,
                                    report=True)
    f = open(os.path.join(testpth, 'output.dat'), 'w')
    for line in buff:
        f.write(line + '\n')
    f.close()
    assert success, 'model did not run successfully: {}'.format(testname)

    # If it is a regression run, then setup and run the model with the
    # release target
    success_reg = True
    if regression:
        testname_reg = os.path.basename(config.target_release)
        testpth_reg = os.path.join(testpth, testname_reg)
        pymake.setup(namefile, testpth_reg)
        print('running regression model...{}'.format(testname_reg))
        exe_name = os.path.abspath(config.target_release)
        success, buff = flopy.run_model(exe_name,
                                        nam,
                                        model_ws=testpth_reg,
                                        silent=True,
                                        report=True)
        f = open(os.path.join(testpth_reg, 'output.dat'), 'w')
        for line in buff:
            f.write(line + '\n')
        f.close()
        assert success, 'model did not run successfully: {}'.format(
            testname_reg)

        # Make comparison
        success = compare(os.path.join(testpth, nam),
                          os.path.join(testpth_reg, nam))
        assert success, 'Models do not compare: {} and {}'.format(
            testname, testname_reg)

    # Clean things up
    if success and not config.retain:
        pymake.teardown(testpth)
    assert success and success_reg

    return