Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: MAW package: SHUT_OFF keword not recognised #1616

Closed
giovannifi opened this issue Nov 3, 2022 · 1 comment
Closed

bug: MAW package: SHUT_OFF keword not recognised #1616

giovannifi opened this issue Nov 3, 2022 · 1 comment
Assignees
Labels

Comments

@giovannifi
Copy link

giovannifi commented Nov 3, 2022

Describe the bug
I am playing with the options of the MAW package and I was trying to set the SHUT_OFF option. Every time I run my script with this option I get the error message below. I I run the script using the keyword SHUTOFF the script for creating the packages works fine, but I get an error if I try to run the model. To make the model run I have to manually open the MAW package and replace SHUTOFF with SHUT_OFF. I think there is a bug with the keys of some dictionaries in the flopy modules.

Traceback (most recent call last):
  File "H:\scripts\XXXX\test_injection_dummy_model.py", line 130, in <module>
    sim.write_simulation()
  File "C:\Program Files\Python39\lib\site-packages\flopy\mf6\modflow\mfsimulation.py", line 1589, in write_simulation
    model.write(ext_file_action=ext_file_action)
  File "C:\Program Files\Python39\lib\site-packages\flopy\mf6\mfmodel.py", line 1143, in write
    pp.write(ext_file_action=ext_file_action)
  File "C:\Program Files\Python39\lib\site-packages\flopy\mf6\mfpackage.py", line 2690, in write
    self._write_blocks(fd, ext_file_action)
  File "C:\Program Files\Python39\lib\site-packages\flopy\mf6\mfpackage.py", line 2853, in _write_blocks
    block.write(fd, ext_file_action=ext_file_action)
  File "C:\Program Files\Python39\lib\site-packages\flopy\mf6\mfpackage.py", line 1236, in write
    self._write_block(fd, block_header, ext_file_action)
  File "C:\Program Files\Python39\lib\site-packages\flopy\mf6\mfpackage.py", line 1374, in _write_block
    output = dataset.get_file_entry(
  File "C:\Program Files\Python39\lib\site-packages\flopy\mf6\data\mfdatalist.py", line 1788, in get_file_entry
    return super().get_file_entry(ext_file_action=ext_file_action)
  File "C:\Program Files\Python39\lib\site-packages\flopy\mf6\data\mfdatalist.py", line 712, in get_file_entry
    return self._get_file_entry(ext_file_action)
  File "C:\Program Files\Python39\lib\site-packages\flopy\mf6\data\mfdatalist.py", line 810, in _get_file_entry
    self._get_file_entry_record(
  File "C:\Program Files\Python39\lib\site-packages\flopy\mf6\data\mfdatalist.py", line 1036, in _get_file_entry_record
    keystr_struct = data_item.keystring_dict[
KeyError: 'shut_offrecord'

you can try this script to reproduce the problem:

import numpy as np
import flopy
import flopy.utils.binaryfile as bf
import matplotlib.pyplot as plt

path_exe = r'F:\Working_Folder\testing\injection_opt\mf6.exe'
path_model = r'F:\Working_Folder\testing\injection_opt'

modelname = 'inj_opt'
run_mf = True

# Model domain and grid definition
Lx = 10000.
Ly = 10000.
ztop = 0.
zbot = -20.
nlay = 1
nrow = 100
ncol = 100
delr = Lx / ncol
delc = Ly / nrow
delv = (ztop - zbot) / nlay

# drain location and zonebuget zones
drn_r = 49
drn_c = 49
stage = -5.0
cond_drn = 100.0
idx_drn = (0, drn_r, drn_c)
idx_drn2 = (0, drn_r + 5, drn_c + 5)

# Injection well location
wrow = 9
wcol = 19
idx_wel = (0, wrow, wcol)

# Create the Flopy simulation object
sim = flopy.mf6.MFSimulation(sim_name=modelname, exe_name=path_exe, sim_ws=path_model)

# Create the Flopy temporal discretization object
nper = 31
n_days = 10
n_ts = 100
tdis_perioddata = [(1.0, 1, 1.0)]
for sp in range(nper-1):
    tdis_perioddata.append((n_days, n_ts, 1.0))
tdis = flopy.mf6.ModflowTdis(sim, pname='tdis', time_units='DAYS', nper=nper, perioddata=tdis_perioddata)

# Create the Flopy groundwater flow (gwf) model object
model_nam_file = '{}.nam'.format(modelname)
gwf = flopy.mf6.ModflowGwf(sim, modelname=modelname, model_nam_file=model_nam_file, save_flows=True)
gwf.name_file.save_flows = True

# Create the Flopy iterative model solver (ims) Package object
ims = flopy.mf6.ModflowIms(sim, pname='ims', complexity='SIMPLE')

# discretization package
dis = flopy.mf6.ModflowGwfdis(gwf, pname='dis', nlay=nlay, nrow=nrow, ncol=ncol,delr=delr, delc=delc, top=ztop, botm=zbot, filename='{}.dis'.format(modelname))

# Create the initial conditions package
h0 = 30.0
start = h0 * np.ones((nlay, nrow, ncol))
ic = flopy.mf6.ModflowGwfic(gwf, pname='ic', strt=start)

# Create the node property flow package
kh = 10.0  # m/d
ss_value = 1.e-4
npf = flopy.mf6.ModflowGwfnpf(gwf, pname='npf', icelltype=0, k=kh, k33=kh, save_flows=True)
ss = flopy.mf6.ModflowGwfsto.ss.empty(gwf, layered=True, default_value=ss_value)
sto = flopy.mf6.ModflowGwfsto(gwf, pname='sto', save_flows=True, iconvert=1, ss=ss, steady_state={0:True}, transient={1:True})

# Create the constant head package.
chd_rec = []
ch_east = 5.0
ch_west = 30.0
for r in range(nrow):
    chd_rec.append(((0, r, 0), ch_west))
    chd_rec.append(((0, r, ncol - 1), ch_east))
chd = flopy.mf6.modflow.mfgwfchd.ModflowGwfchd(gwf, pname='chd', maxbound=len(chd_rec), stress_period_data=chd_rec, save_flows=True)

drn_data = {}
# drain package
drn_data[0] = [(idx_drn, 0.0, 0.0), (idx_drn2, 0.0, 0.0)]
n_drn = len(drn_data[0])
for sp in range(nper - 1):
    drn_data[sp + 1] = [(idx_drn, stage, cond_drn), (idx_drn2, stage - 1.0, cond_drn)]

drn = flopy.mf6.ModflowGwfdrn(gwf, pname='drn-1', mover=True, save_flows=True, stress_period_data=drn_data, maxbound=n_drn)

# water mover package
excess_rate = 0.0
water_demand = [0.0] + [excess_rate for i in range(1, nper)]
mvr_perioddata = {}
for sp in range(nper):
    mvr_perioddata[sp] = []
    for d in range(n_drn):
        mvr_perioddata[sp].append(('drn-1', d, 'maw-1', 0, 'EXCESS', water_demand[sp]))

mvr = flopy.mf6.ModflowGwfmvr(gwf, pname='mvr', print_flows=True, maxmvr=2, maxpackages=2,
                                               packages=[('drn-1',), ('maw-1',)], perioddata=mvr_perioddata)


# well package
well_packagedata = [(0, 0.01, zbot, h0, 'THIEM', 1)]
well_condata = [(0, 0, idx_wel, ztop, zbot, 0, 0)]
# well_rates = [0.0] + [5000. for i in range(nper - 1)]
well_perioddata = {0: [(0, 'STATUS', 'INACTIVE')]}
head_limit = 34.
scaling_length = 0.01
for sp in range(1, nper):
    # well_perioddata[sp] = [(0, 'RATE', well_rates[sp]), (0, 'HEAD_LIMIT', head_limit)]
    # well_perioddata[sp] = [(0, 'STATUS', 'ACTIVE'), (0, 'HEAD_LIMIT', head_limit)]
    # well_perioddata[sp] = [(0, 'STATUS', 'ACTIVE'), (0, 'RATE_SCALING', head_limit, scaling_length)]
    well_perioddata[sp] = [(0, 'STATUS', 'ACTIVE'),  (0, 'HEAD_LIMIT', head_limit), (0, 'SHUT_OFF', 1000., 5000.)]
   # well_perioddata[sp] = [(0, 'STATUS', 'ACTIVE'),  (0, 'HEAD_LIMIT', head_limit), (0, 'SHUTOFF', 1000., 5000.)]

maw = flopy.mf6.ModflowGwfmaw(gwf, pname='maw-1', mover=True, save_flows=True, nmawwells=1,
                                               no_well_storage=True, packagedata=well_packagedata,
                                               connectiondata=well_condata, perioddata=well_perioddata)


# output control
oc = flopy.mf6.ModflowGwfoc(gwf, pname='oc', budget_filerecord='{}.cbb'.format(modelname),
                            head_filerecord='{}.hds'.format(modelname),
                            headprintrecord=[('COLUMNS', 10, 'WIDTH', 15,'DIGITS', 6, 'GENERAL')],
                            saverecord=[('HEAD', 'ALL'), ('BUDGET', 'ALL')],
                            printrecord=[('HEAD', 'FIRST'), ('HEAD', 'LAST'), ('BUDGET', 'LAST')])


# write simulation to new location
sim.write_simulation()

# Run the simulation
if run_mf:
    success, buff = sim.run_simulation(silent=True)
    print('Success is: ' + str(success))
else:
    success = True

To Reproduce
Steps to reproduce the behavior:

  1. run the script provided above

Expected behavior
I would expect the script to create the MAW package including the keword SHUT_OFF

Desktop (please complete the following information):

  • OS: Windows 10
  • PyCharm 2021.1.1
  • Flopy version 3.3.5
  • python version 3.9
@giovannifi giovannifi added the bug label Nov 3, 2022
spaulins-usgs added a commit that referenced this issue Jun 15, 2023
…string of the keystring record name (#1616) (#1830)

Co-authored-by: scottrp <45947939+scottrp@users.noreply.github.com>
@spaulins-usgs
Copy link
Contributor

@giovannifi, I just committed a fix to develop. Please use the latest flopy code from the develop branch and confirm that it fixes this problem for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants