def load_swi(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) # write free format files - # won't run without resetting to free format - evt external file issue m.free_format_input = True # rewrite files m.change_model_ws(apth, reset_external=True) # l1b2k_bath wont run without this m.write_input() if run: try: success, buff = m.run_model(silent=False) except: pass assert success, 'base model run did not terminate successfully' fn1 = os.path.join(apth, mfnam) if run: fsum = os.path.join(compth, '{}.budget.out'.format(os.path.splitext(mfnam)[0])) 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
def load_lak(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=True) except: pass assert success, 'base model run did not terminate successfully' fn0 = os.path.join(lpth, mfnam) # write free format files - wont run without resetting to free format - evt externa file issue m.free_format_input = True # rewrite files m.change_model_ws(apth, reset_external=True) # l1b2k_bath wont run without this m.write_input() if run: try: success, buff = m.run_model(silent=True) except: pass assert success, 'base model run did not terminate successfully' fn1 = os.path.join(apth, mfnam) fsum = os.path.join(compth, '{}.budget.out'.format(os.path.splitext(mfnam)[0])) success = pymake.compare_budget(fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum) assert success, 'budget comparison failure' return
def load_lak(mfnam, pth, run): 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=True) except: msg = 'could not run base model ' + \ '{}'.format(os.path.splitext(mfnam)[0]) print(msg) pass msg = 'base model {} '.format(os.path.splitext(mfnam)[0]) + \ 'run did not terminate successfully' assert success, msg msg = 'base model {} '.format(os.path.splitext(mfnam)[0]) + \ 'run terminated successfully' print(msg) fn0 = os.path.join(lpth, mfnam) # write free format files - wont run without resetting to free format - evt externa file issue m.free_format_input = True # rewrite files m.change_model_ws(apth, reset_external=True) # l1b2k_bath wont run without this m.write_input() if run: try: success, buff = m.run_model(silent=False) except: msg = 'could not run new model ' + \ '{}'.format(os.path.splitext(mfnam)[0]) print(msg) pass msg = 'new model {} '.format(os.path.splitext(mfnam)[0]) + \ 'run did not terminate successfully' assert success, msg msg = 'new model {} '.format(os.path.splitext(mfnam)[0]) + \ 'run terminated successfully' print(msg) fn1 = os.path.join(apth, mfnam) fsum = os.path.join(compth, '{}.budget.out'.format(os.path.splitext(mfnam)[0])) if run: 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
def test_unitnums_load_and_write(): exe_name = 'mf2005' v = flopy.which(exe_name) run = True if v is None: run = False mfnam = 'testsfr2_tab.nam' # copy files 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, verbose=True, model_ws=lpth, exe_name=exe_name) assert m.load_fail is False, 'failed to load all packages' msg = 'modflow-2005 testsfr2_tab does not have ' + \ '1 layer, 7 rows, and 100 colummns' v = (m.nlay, m.nrow, m.ncol, m.nper) assert v == (1, 7, 100, 50), msg 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, 'base model run did not terminate successfully' fn1 = os.path.join(apth, mfnam) if run: fsum = os.path.join(compth, '{}.budget.out'.format(os.path.splitext(mfnam)[0])) try: success = pymake.compare_budget(fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum) except: print('could not perform ls' 'budget comparison') assert success, 'budget comparison failure' return
def test_uzf_unit_numbers(): exe_name = 'mf2005' v = flopy.which(exe_name) run = True if v is None: run = False mfnam = 'UZFtest2.nam' pt = os.path.join('..', 'examples', 'data', 'uzf_examples') # copy files 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(pt, mfnam), lpth) except: run = False lpth = pth apth = cpth compth = cpth m = flopy.modflow.Modflow.load(mfnam, verbose=True, model_ws=lpth, forgive=False, exe_name=exe_name) assert m.load_fail is False, 'failed to load all packages' 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) # change uzf iuzfcb2 and add binary uzf output file m.uzf.iuzfcb2 = 61 m.add_output_file(m.uzf.iuzfcb2, extension='uzfcb2.bin', package='UZF') # change the model work space m.change_model_ws(apth, reset_external=True) # rewrite files m.write_input() # run and compare the output files if run: try: success, buff = m.run_model(silent=False) except: pass assert success, 'base model run did not terminate successfully' fn1 = os.path.join(apth, mfnam) if run: fsum = os.path.join(compth, '{}.budget.out'.format(os.path.splitext(mfnam)[0])) try: success = pymake.compare_budget(fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum) except: print('could not perform ls' 'budget comparison') assert success, 'budget comparison failure' return
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'
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
def test_unitnums_load_and_write(): exe_name = "mf2005" v = flopy.which(exe_name) run = True if v is None: run = False mfnam = "testsfr2_tab.nam" # copy files 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, verbose=True, model_ws=lpth, exe_name=exe_name) assert m.load_fail is False, "failed to load all packages" msg = ("modflow-2005 testsfr2_tab does not have " + "1 layer, 7 rows, and 100 columns") v = (m.nlay, m.nrow, m.ncol, m.nper) assert v == (1, 7, 100, 50), msg 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, "base model run did not terminate successfully" fn1 = os.path.join(apth, mfnam) if run: fsum = os.path.join(compth, "{}.budget.out".format(os.path.splitext(mfnam)[0])) try: success = pymake.compare_budget(fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum) except: success = False print("could not perform ls" "budget comparison") assert success, "budget comparison failure" # clean up shutil.rmtree(lpth) return
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
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)
def test_unitnums_load_and_write(): exe_name = 'mf2005' v = flopy.which(exe_name) run = True if v is None: run = False mfnam = 'testsfr2_tab.nam' # copy files 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, verbose=True, model_ws=lpth, exe_name=exe_name) assert m.load_fail is False, 'failed to load all packages' msg = 'modflow-2005 testsfr2_tab does not have ' + \ '1 layer, 7 rows, and 100 colummns' v = (m.nlay, m.nrow, m.ncol, m.nper) assert v == (1, 7, 100, 50), msg 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, 'base model run did not terminate successfully' fn1 = os.path.join(apth, mfnam) if run: fsum = os.path.join(compth, '{}.budget.out'.format(os.path.splitext(mfnam)[0])) try: success = pymake.compare_budget(fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum) except: print('could not perform ls' 'budget comparison') assert success, 'budget comparison failure' return
def test_uzf_unit_numbers(): exe_name = 'mf2005' v = flopy.which(exe_name) run = True if v is None: run = False mfnam = 'UZFtest2.nam' pt = os.path.join('..', 'examples', 'data', 'uzf_examples') # copy files 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(pt, mfnam), lpth) except: run = False lpth = pth apth = cpth compth = cpth m = flopy.modflow.Modflow.load(mfnam, verbose=True, model_ws=lpth, exe_name=exe_name) assert m.load_fail is False, 'failed to load all packages' 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) # change uzf iuzfcb2 and add binary uzf output file m.uzf.iuzfcb2 = 61 m.add_output_file(m.uzf.iuzfcb2, extension='uzfcb2.bin', package='UZF') # change the model work space m.change_model_ws(apth, reset_external=True) # rewrite files m.write_input() # run and compare the output files if run: try: success, buff = m.run_model(silent=False) except: pass assert success, 'base model run did not terminate successfully' fn1 = os.path.join(apth, mfnam) if run: fsum = os.path.join(compth, '{}.budget.out'.format(os.path.splitext(mfnam)[0])) try: success = pymake.compare_budget(fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum) except: print('could not perform ls' 'budget comparison') assert success, 'budget comparison failure' return
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
def test_uzf_unit_numbers(): exe_name = 'mf2005' v = flopy.which(exe_name) run = True if v is None: run = False mfnam = 'UZFtest2.nam' pt = os.path.join('..', 'examples', 'data', 'uzf_examples') # copy files 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(pt, mfnam), lpth) except: run = False lpth = pth apth = cpth compth = cpth m = flopy.modflow.Modflow.load(mfnam, verbose=True, model_ws=lpth, forgive=False, exe_name=exe_name) assert m.load_fail is False, 'failed to load all packages' # reset the oc file m.remove_package('OC') output = ['save head', 'print budget'] spd = {} for iper in range(1, m.dis.nper): for istp in [0, 4, 9, 14]: spd[(iper, istp)] = output spd[(0, 0)] = output spd[(1, 1)] = output spd[(1, 2)] = output spd[(1, 3)] = output oc = flopy.modflow.ModflowOc(m, stress_period_data=spd) oc.write_file() 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 uzf iuzfcb2 and add binary uzf output file m.uzf.iuzfcb2 = 61 m.add_output_file(m.uzf.iuzfcb2, extension='uzfcb2.bin', package='UZF') # change the model work space m.change_model_ws(apth, reset_external=True) # rewrite files m.write_input() # run and compare the output files 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) # compare budget terms if run: fsum = os.path.join(compth, '{}.budget.out'.format(os.path.splitext(mfnam)[0])) try: success = pymake.compare_budget(fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum) except: success = False print('could not perform ls' 'budget comparison') assert success, 'budget comparison failure' # clean up shutil.rmtree(lpth) return
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
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
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
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'
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
def test_uzf_unit_numbers(): exe_name = "mf2005" v = flopy.which(exe_name) run = True if v is None: run = False mfnam = "UZFtest2.nam" pt = os.path.join("..", "examples", "data", "uzf_examples") # copy files 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(pt, mfnam), lpth) except: run = False lpth = pth apth = cpth compth = cpth m = flopy.modflow.Modflow.load(mfnam, verbose=True, model_ws=lpth, forgive=False, exe_name=exe_name) assert m.load_fail is False, "failed to load all packages" # reset the oc file m.remove_package("OC") output = ["save head", "print budget"] spd = {} for iper in range(1, m.dis.nper): for istp in [0, 4, 9, 14]: spd[(iper, istp)] = output spd[(0, 0)] = output spd[(1, 1)] = output spd[(1, 2)] = output spd[(1, 3)] = output oc = flopy.modflow.ModflowOc(m, stress_period_data=spd) oc.write_file() 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 uzf iuzfcb2 and add binary uzf output file m.uzf.iuzfcb2 = 61 m.add_output_file(m.uzf.iuzfcb2, extension="uzfcb2.bin", package="UZF") # change the model work space m.change_model_ws(apth, reset_external=True) # rewrite files m.write_input() # run and compare the output files 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) # compare budget terms if run: fsum = os.path.join(compth, "{}.budget.out".format(os.path.splitext(mfnam)[0])) try: success = pymake.compare_budget(fn0, fn1, max_incpd=0.1, max_cumpd=0.1, outfile=fsum) except: success = False print("could not perform ls" "budget comparison") assert success, "budget comparison failure" # clean up shutil.rmtree(lpth) return
def load_lak(mfnam, pth, run): 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, forgive=False, exe_name=exe_name) assert m.load_fail is False if run: try: success, buff = m.run_model(silent=True) except: msg = 'could not run base model ' + \ '{}'.format(os.path.splitext(mfnam)[0]) print(msg) pass msg = 'base model {} '.format(os.path.splitext(mfnam)[0]) + \ 'run did not terminate successfully' assert success, msg msg = 'base model {} '.format(os.path.splitext(mfnam)[0]) + \ 'run terminated successfully' print(msg) fn0 = os.path.join(lpth, mfnam) # write free format files - wont run without resetting to free format - evt externa file issue m.free_format_input = True # rewrite files m.change_model_ws(apth, reset_external=True) # l1b2k_bath wont run without this m.write_input() if run: try: success, buff = m.run_model(silent=False) except: msg = 'could not run new model ' + \ '{}'.format(os.path.splitext(mfnam)[0]) print(msg) pass msg = 'new model {} '.format(os.path.splitext(mfnam)[0]) + \ 'run did not terminate successfully' assert success, msg msg = 'new model {} '.format(os.path.splitext(mfnam)[0]) + \ 'run terminated successfully' print(msg) fn1 = os.path.join(apth, mfnam) fsum = os.path.join(compth, '{}.budget.out'.format(os.path.splitext(mfnam)[0])) if run: 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
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
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