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(empty transient arrays): #2145 #2146

Merged
merged 1 commit into from
Apr 12, 2024
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
7 changes: 6 additions & 1 deletion autotest/regression/test_mf6.py
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,7 @@ def test004_create_tests_bcfss(function_tmpdir, example_data_path):
readasarrays=True,
save_flows=True,
auxiliary=[("var1", "var2")],
recharge={0: 0.004},
recharge={0: 0.004, 1: []},
aux=aux,
) # *** test if aux works ***
chk = rch_package.check()
Expand All @@ -2078,6 +2078,11 @@ def test004_create_tests_bcfss(function_tmpdir, example_data_path):
assert aux_out[0][1][0, 0] == 1.3
assert aux_out[1][0][0, 0] == 200.0
assert aux_out[1][1][0, 0] == 1.5
# write test
sim.set_sim_path(function_tmpdir)
sim.write_simulation()
# update recharge
recharge = {0: 0.004, 1: 0.004}

riv_period = {}
riv_period_array = []
Expand Down
13 changes: 13 additions & 0 deletions flopy/mf6/data/mfdataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,9 @@ def has_data(self, layer=None):
self.get_data_prep(sto_key)
if super().has_data():
return True
for val in self.empty_keys.values():
if val:
return True
return False
else:
self.get_data_prep(layer)
Expand Down Expand Up @@ -1918,7 +1921,11 @@ def _set_data_record(
if list_item is None:
self.remove_transient_key(key)
del_keys.append(key)
self.empty_keys[key] = False
elif isinstance(list_item, list) and len(list_item) == 0:
self.empty_keys[key] = True
else:
self.empty_keys[key] = False
self._set_data_prep(list_item, key)
if is_record:
super().set_record(list_item)
Expand All @@ -1940,7 +1947,11 @@ def _set_data_record(
key = 0
if data is None:
self.remove_transient_key(key)
elif isinstance(data, list) and len(data) == 0:
# add empty record
self.empty_keys[key] = True
else:
self.empty_keys[key] = False
self._set_data_prep(data, key)
super().set_data(data, multiplier, layer)

Expand All @@ -1962,6 +1973,8 @@ def get_file_entry(

"""

if key in self.empty_keys and self.empty_keys[key]:
return ""
self._get_file_entry_prep(key)
return super().get_file_entry(ext_file_action=ext_file_action)

Expand Down
2 changes: 1 addition & 1 deletion flopy/mf6/mfpackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ def load(self, block_header, fd, strict=True):
for ds in self.datasets.values():
if isinstance(ds, mfdata.MFTransient):
transient_key = block_header.get_transient_key()
ds.set_data(empty_arr, transient_key)
ds.set_data(empty_arr, key=transient_key)
self.loaded = True
self.is_valid()

Expand Down
Loading