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
def setup(self, src, dst): msg = sfmt.format('Setup test', self.name) print(msg) self.originpath = src self.simpath = dst # write message print('running pymake.setup_mf6 from ' + '{}'.format(os.path.abspath(os.getcwd()))) try: self.inpt, self.outp = pymake.setup_mf6(src=src, dst=dst) print('waiting...') time.sleep(0.5) success = True except: success = False print('source: {}'.format(src)) print('destination: {}'.format(dst)) assert success, 'did not run pymake.setup_mf6' # Copy comparison simulations if available if success: action = pymake.setup_mf6_comparison(src, dst, remove_existing=self.delFiles) self.action = action return
def setup(self, src, dst): msg = sfmt.format("Setup test", self.name) print(msg) self.originpath = src self.simpath = dst # write message print( "running pymake.setup_mf6 from " + "{}".format(os.path.abspath(os.getcwd())) ) try: self.inpt, self.outp = pymake.setup_mf6(src=src, dst=dst) print("waiting...") time.sleep(0.5) success = True except: success = False print("source: {}".format(src)) print("destination: {}".format(dst)) assert success, "did not run pymake.setup_mf6" if success: self.setup_comparison(src, dst) return
def setup(self, src, dst): msg = sfmt.format("Setup test", self.name) print(msg) self.originpath = src self.simpath = dst # write message print("running pymake.setup_mf6 from " + "{}".format(os.path.abspath(os.getcwd()))) try: self.inpt, self.outp = pymake.setup_mf6(src=src, dst=dst) print("waiting...") time.sleep(0.5) success = True except: success = False print("source: {}".format(src)) print("destination: {}".format(dst)) assert success, "did not run pymake.setup_mf6" # adjust htol if it is smaller than IMS outer_dvclose dvclose = self._get_dvclose(dst) if dvclose is not None: dvclose *= 5.0 if self.htol < dvclose: self.htol = dvclose # Copy comparison simulations if available if success: if self.mf6_regression and not self.name.endswith("_dev"): action = "mf6-regression" shutil.copytree(dst, os.path.join(dst, "mf6-regression")) else: action = pymake.setup_mf6_comparison( src, dst, remove_existing=self.delFiles) self.action = action return
def setup_examples(srcdir, dstdir, win_target_os=True): examples_dict = load_examples_df() # Create a runall.bat file in examples if win_target_os: frunallbat = open(os.path.join(dstdir, 'runall.bat'), 'w') else: frunallbat = None for k in examples_dict: v = examples_dict[k] # For each example, copy the necessary files from the development directory # into the distribution directory. print('Copying examples') for i, exdest in enumerate(examples_dict): exd = examples_dict[exdest] exsrc = exd['examples_name'] # name in modflow6-examples repo srcpath = os.path.join(srcdir, exsrc) # path to modflow6-examples repo prefix = 'ex{:02d}-'.format(i + 1) destfoldername = prefix + exdest dstpath = os.path.join(dstdir, prefix + exdest) print(' {:<35} ===> {:<20}'.format(exsrc, prefix + exdest)) # Copy all of the mf6 input from srcpath to dstpath pymake.setup_mf6(srcpath, dstpath) # Create a description.txt file in the example folder fname = os.path.join(dstpath, 'description.txt') with open(fname, 'w') as f: f.write(exd['description_text'] + '\n') if win_target_os: # Create a batch file for running the model fname = os.path.join(dstpath, 'run.bat') with open(fname, 'w') as f: s = '@echo off' f.write(s + '\n') s = r'..\..\bin\mf6.exe' f.write(s + '\n') s = 'echo.' f.write(s + '\n') s = 'echo Run complete. Press any key to continue.' f.write(s + '\n') s = 'pause>nul' f.write(s + '\n') if frunallbat is not None: frunallbat.write('cd ' + destfoldername + '\n') frunallbat.write(r'..\..\bin\mf6.exe' + '\n') frunallbat.write('cd ..' + '\n\n') print('\n') if frunallbat is not None: frunallbat.write('pause' + '\n') frunallbat.close() return
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
frunallbat = None # For each example, copy the necessary files from the development directory # into the distribution directory. print('Copying examples') for i, (exsrc, exdest) in enumerate(examplelist): srcpath = os.path.join(exsrcpath, exsrc) prefix = 'ex{:02d}-'.format(i + 1) destfoldername = prefix + exdest dstpath = os.path.join(expath, prefix + exdest) print(' {:<35} ===> {:<20}'.format(exsrc, prefix + exdest)) # Copy all of the mf6 input from srcpath to dstpath extrafiles = ['description.txt'] pymake.setup_mf6(srcpath, dstpath, extrafiles=extrafiles) if win_target_os: # Create a batch file for running the model fname = os.path.join(dstpath, 'run.bat') with open(fname, 'w') as f: s = '@echo off' f.write(s + '\n') s = r'..\..\bin\mf6.exe' f.write(s + '\n') s = 'echo.' f.write(s + '\n') s = 'echo Run complete. Press any key to continue.' f.write(s + '\n') s = 'pause>nul' f.write(s + '\n')