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

Fix(#870): Update ims name file record after removing ims package #880

Merged
merged 5 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions autotest/t504_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,14 +916,32 @@ def test027_timeseriestest():
assert pymake.compare_heads(None, None, files1=head_file, files2=head_new)


def test_replace_ims_package():
pth = os.path.join(cpth, "test001e_UZF_3lay")
sim = flopy.mf6.MFSimulation.load("mfsim", sim_ws=pth, exe_name=exe_name)

ims = sim.ims
sim.remove_package(ims)

ims = flopy.mf6.ModflowIms(sim, print_option='SUMMARY',
complexity="COMPLEX")
sim.register_ims_package(ims, ["gwf_1", ])
sim.write_simulation()
success, buff = sim.run_simulation()

if not success:
raise AssertionError()


if __name__ == '__main__':
test001a_tharmonic()
# test001a_tharmonic()
test001e_uzf_3lay()
test003_gwfs_disv()
test005_advgw_tidal()
test006_2models_mvr()
test006_gwf3()
test027_timeseriestest()
test036_twrihfb()
test045_lake1ss_table()
test045_lake2tr()
# test003_gwfs_disv()
# test005_advgw_tidal()
# test006_2models_mvr()
# test006_gwf3()
# test027_timeseriestest()
# test036_twrihfb()
# test045_lake1ss_table()
# test045_lake2tr()
test_replace_ims_package()
26 changes: 26 additions & 0 deletions flopy/mf6/modflow/mfsimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,7 @@ def remove_package(self, package_name):
del self._exchange_files[package.filename]
if package.filename in self._ims_files:
del self._ims_files[package.filename]
self._remove_ims_soultion_group(package.filename)
if package.filename in self._ghost_node_files:
del self._ghost_node_files[package.filename]
if package.filename in self._mover_files:
Expand Down Expand Up @@ -1748,6 +1749,31 @@ def _get_package_path(package):
else:
return (package.package_type,)

def _remove_ims_soultion_group(self, ims_file):
solution_recarray = self.name_file.solutiongroup
for solution_group_num in solution_recarray.get_active_key_list():
try:
rec_array = solution_recarray.get_data(solution_group_num[0])
except MFDataException as mfde:
message = 'An error occurred while getting solution group' \
'"{}" from the simulation name file' \
'.'.format(solution_group_num[0])
raise MFDataException(mfdata_except=mfde,
package='nam',
message=message)

new_array = []
for record in rec_array:
if record.slnfname == ims_file:
continue
else:
new_array.append(record)

if not new_array:
new_array = None

solution_recarray.set_data(new_array, solution_group_num[0])

def _append_to_ims_solution_group(self, ims_file, new_models):
solution_recarray = self.name_file.solutiongroup
for solution_group_num in solution_recarray.get_active_key_list():
Expand Down