Skip to content

Commit

Permalink
feat(mfusg_gsi): add gsi version of MODFLOW-USG (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhughes-usgs authored Mar 27, 2023
1 parent 4095375 commit 077adec
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 8 deletions.
28 changes: 23 additions & 5 deletions autotest/test_mfusg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

# define program data
target = "mfusg"
target_gsi = "mfusg_gsi"
if sys.platform.lower() == "win32":
target += ".exe"
target_gsi += ".exe"

# get program dictionary
prog_dict = pymake.usgs_program_data.get_target(target)
Expand All @@ -25,6 +27,7 @@

srcpth = os.path.join(mfusgpth, prog_dict.srcdir)
epth = os.path.abspath(os.path.join(dstpth, target))
epth_gsi = os.path.abspath(os.path.join(dstpth, target_gsi))

name_files = [
"01A_nestedgrid_nognc/flow.nam",
Expand All @@ -43,6 +46,10 @@
pm.target = target
pm.appdir = dstpth

pm_gsi = pymake.Pymake(verbose=True)
pm_gsi.target = target_gsi
pm_gsi.appdir = dstpth


def edit_namefile(namefile):
# read existing namefile
Expand All @@ -64,13 +71,18 @@ def edit_namefile(namefile):
def clean_up():
print("Removing test files and directories")

# finalize pymake object
# finalize pymake objects
pm.finalize()
pm_gsi.finalize()

if os.path.isfile(epth):
print("Removing " + target)
os.remove(epth)

if os.path.isfile(epth_gsi):
print("Removing " + target_gsi)
os.remove(epth_gsi)

dirs_temp = [dstpth]
for d in dirs_temp:
if os.path.isdir(d):
Expand All @@ -79,15 +91,15 @@ def clean_up():
return


def run_mfusg(fn):
def run_mfusg(fn, exe):
# edit namefile
edit_namefile(fn)
# run test models
print(f"running model...{os.path.basename(fn)}")
success, buff = flopy.run_model(
epth, os.path.basename(fn), model_ws=os.path.dirname(fn), silent=False
exe, os.path.basename(fn), model_ws=os.path.dirname(fn), silent=False
)
errmsg = f"could not run {fn}"
errmsg = f"could not run {fn} with {exe}"
assert success, errmsg

return
Expand All @@ -103,17 +115,23 @@ def test_download():
pm.download_target(target, download_path=dstpth)
assert pm.download, f"could not download {target}"

# download the gsi version of modflow-usg
pm_gsi.download_target(target_gsi, download_path=dstpth)
assert pm_gsi.download, f"could not download {target_gsi}"


@pytest.mark.base
def test_compile():
assert pm.build() == 0, f"could not compile {target}"
assert pm_gsi.build() == 0, f"could not compile {target_gsi}"
return


@pytest.mark.regression
@pytest.mark.parametrize("fn", name_files)
def test_mfusg(fn):
run_mfusg(fn)
run_mfusg(fn, epth)
run_mfusg(fn, epth_gsi)


@pytest.mark.base
Expand Down
56 changes: 56 additions & 0 deletions pymake/utils/_usgs_src_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import shutil
import sys
import types
import pathlib as pl

from .usgsprograms import usgs_program_data

Expand Down Expand Up @@ -406,6 +407,61 @@ def _update_mf2005_files(srcdir, fc, cc, arch, double):
_update_pcg(srcdir)


def _update_mfusg_gsi_files(srcdir, fc, cc, arch, double):
"""Update GSI version of MODFLOW-USG source files
Parameters
----------
srcdir : str
path to directory with source files
fc : str
fortran compiler
cc : str
c/c++ compiler
arch : str
architecture
double : bool
boolean indicating if compiler switches are used to build a
double precision target
Returns
-------
"""
tags = {
"FMTARG = 'BINARY'": "FMTARG = 'UNFORMATTED'\n ACCARG = 'STREAM'",
",SHARED,ACCESS='SEQUENTIAL'": ",ACCESS='SEQUENTIAL'",
"FORM=FMTARG,SHARED,": "FORM=FMTARG,",
}

fpth = pl.Path(srcdir) / "glo2basu1.f"
if fpth.exists():
with open(fpth) as f:
lines = f.readlines()
f = open(fpth, "w")
for idx, line in enumerate(lines):
for key, value in tags.items():
if key in line:
line = line.replace(key, value)
f.write(line)
f.close()

tag = "DEALLOCATE(ITHFLG)"
tag2 = "DEALLOCATE(LAYTYP)"
fpth = pl.Path(srcdir) / "gwf2bcf-lpf-u1.f"
if fpth.exists():
with open(fpth) as f:
lines = f.readlines()
f = open(fpth, "w")
for idx, line in enumerate(lines):
if tag in line:
line = line.replace(tag, f"!{tag}")
if tag2 in line:
line = line.replace(tag2, f"{tag}\n {tag2}")
f.write(line)
f.close()


def _update_mfnwt_files(srcdir, fc, cc, arch, double):
"""Update MODFLOW-NWT source files
Expand Down
6 changes: 3 additions & 3 deletions pymake/utils/usgsprograms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ crt , 1.3.1 , True , https://water.usgs.gov/ogw/CRT/CRT_1.3.1.zip
sutra , 3.0 , True , https://water.usgs.gov/water-resources/software/sutra/SUTRA_3_0_0.zip , SutraSuite , SUTRA_3_0/source , True , False , False
mf2000 , 1.19.01, True , https://water.usgs.gov/nrp/gwsoftware/modflow2000/mf2k1_19_01.tar.gz , mf2k.1_19 , src , True , False , False
mf2005 , 1.12.00, True , https://github.com/MODFLOW-USGS/mf2005/releases/download/v.1.12.00/MF2005.1_12u.zip , MF2005.1_12u , src , True , True , False
mf2005.1.11, 1.11.00, False , https://water.usgs.gov/ogw/modflow/archive-mf2005/MODFLOW-2005_v1.11.00/mf2005v1_11_00_unix.zip, Unix , src , True , False , False
mfusg , 1.5 , True , https://water.usgs.gov/water-resources/software/MODFLOW-USG/mfusg1_5.zip , mfusg1_5 , src , True , True , False
zonbudusg , 1.5 , True , https://water.usgs.gov/water-resources/software/MODFLOW-USG/mfusg1_5.zip , mfusg1_5 , src/zonebudusg , True , False , False
swtv4 , 4.00.05, True , https://water.usgs.gov/water-resources/software/SEAWAT/swt_v4_00_05.zip , swt_v4_00_05 , source , False , True , False
mp6 , 6.0.1 , True , https://water.usgs.gov/water-resources/software/MODPATH/modpath.6_0_01.zip , modpath.6_0 , src , True , False , False
mflgr , 2.0.0 , True , https://water.usgs.gov/ogw/modflow-lgr/modflow-lgr-v2.0.0/mflgrv2_0_00.zip , mflgr.2_0 , src , True , True , False
zonbud3 , 3.01 , True , https://water.usgs.gov/water-resources/software/ZONEBUDGET/zonbud3_01.exe , Zonbud.3_01 , Src , True , False , False
mfnwt1.1.4 , 1.1.4 , False , https://water.usgs.gov/water-resources/software/MODFLOW-NWT/MODFLOW-NWT_1.1.4.zip , MODFLOW-NWT_1.1.4 , src , True , False , False
mfnwt , 1.3.0 , True , https://water.usgs.gov/water-resources/software/MODFLOW-NWT/MODFLOW-NWT_1.3.0.zip , MODFLOW-NWT , src , True , True , False
mfnwt1.1.4 , 1.1.4 , False , https://water.usgs.gov/water-resources/software/MODFLOW-NWT/MODFLOW-NWT_1.1.4.zip , MODFLOW-NWT_1.1.4 , src , True , False , False
mfnwt , 1.3.0 , True , https://water.usgs.gov/water-resources/software/MODFLOW-NWT/MODFLOW-NWT_1.3.0.zip , MODFLOW-NWT , src , True , True , False
mfusg_gsi , 2.01.0 , True , https://www.gsienv.com/wp-content/uploads/2023/01/USG-Transport-V_2.1.0-1.zip , . , Source , True , True , False

0 comments on commit 077adec

Please sign in to comment.