コード例 #1
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
コード例 #2
0
ファイル: t014_test.py プロジェクト: wjqiu/mt3d-usgs
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
コード例 #3
0
ファイル: t003_test.py プロジェクト: mwtoews/mt3d-usgs
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
コード例 #4
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
コード例 #5
0
ファイル: t002_test.py プロジェクト: torvalds2010/mt3d-usgs
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