Skip to content

Commit

Permalink
fix(float32, empty stress period): #1779 and #1793 (#1806)
Browse files Browse the repository at this point in the history
* fix(float32, empty stress period): #1779 and #1793

* fix(float32, empty stress period): #1779 and #1793

---------

Co-authored-by: scottrp <45947939+scottrp@users.noreply.github.com>
  • Loading branch information
spaulins-usgs and scottrp authored Jun 2, 2023
1 parent de16784 commit 6ad17ac
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
1 change: 1 addition & 0 deletions flopy/mf6/data/mfdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class MFTransient:
def __init__(self, *args, **kwargs):
self._current_key = None
self._data_storage = None
self.empty_keys = {}

def add_transient_key(self, transient_key):
if isinstance(transient_key, int):
Expand Down
4 changes: 3 additions & 1 deletion flopy/mf6/data/mfdataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,9 @@ def __init__(
dimensions=None,
block=None,
):
super().__init__(
MFTransient.__init__(self)
MFArray.__init__(
self,
sim_data=sim_data,
model_or_sim=model_or_sim,
structure=structure,
Expand Down
5 changes: 3 additions & 2 deletions flopy/mf6/data/mfdatalist.py
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,9 @@ def __init__(
package=None,
block=None,
):
super().__init__(
mfdata.MFTransient.__init__(self)
MFList.__init__(
self,
sim_data=sim_data,
model_or_sim=model_or_sim,
structure=structure,
Expand All @@ -1488,7 +1490,6 @@ def __init__(
)
self._transient_setup(self._data_storage)
self.repeating = True
self.empty_keys = {}

@property
def data_type(self):
Expand Down
4 changes: 3 additions & 1 deletion flopy/mf6/data/mfdatascalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,9 @@ def __init__(
path=None,
dimensions=None,
):
super().__init__(
mfdata.MFTransient.__init__(self)
MFScalar.__init__(
self,
sim_data=sim_data,
model_or_sim=model_or_sim,
structure=structure,
Expand Down
4 changes: 4 additions & 0 deletions flopy/mf6/data/mfdatastorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,10 @@ def _resolve_multitype_fields(self, data):
not isinstance(data_val, int)
or self._recarray_type_list[index][1] != float
)
and (
self._recarray_type_list[index][1] != float
or not isinstance(data_val, np.floating)
)
):
# for inconsistent types use generic object type
self._recarray_type_list[index] = (
Expand Down
30 changes: 25 additions & 5 deletions flopy/mf6/mfpackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,10 +1246,22 @@ def write(self, fd, ext_file_action=ExtFileAction.copy_relative_paths):
self._write_block(fd, self.block_headers[0], ext_file_action)

def _add_missing_block_headers(self, repeating_dataset):
for key in repeating_dataset.get_active_key_list():
key_data_list = repeating_dataset.get_active_key_list()
# assemble a dictionary of data keys and empty keys
key_dict = {}
for key in key_data_list:
key_dict[key[0]] = True
for key, value in repeating_dataset.empty_keys.items():
if value:
key_dict[key] = True
for key in key_dict.keys():
has_data = repeating_dataset.has_data(key)
if not self.header_exists(key[0]) and has_data:
self._build_repeating_header([key[0]])
empty_key = (
key in repeating_dataset.empty_keys
and repeating_dataset.empty_keys[key]
)
if not self.header_exists(key) and (has_data or empty_key):
self._build_repeating_header([key])

def header_exists(self, key, data_path=None):
if not isinstance(key, list):
Expand Down Expand Up @@ -1877,15 +1889,23 @@ def _add_package(self, package, path):
def _get_aux_data(self, aux_names):
if hasattr(self, "stress_period_data"):
spd = self.stress_period_data.get_data()
if 0 in spd and aux_names[0][1] in spd[0].dtype.names:
if (
0 in spd
and spd[0] is not None
and aux_names[0][1] in spd[0].dtype.names
):
return spd
if hasattr(self, "packagedata"):
pd = self.packagedata.get_data()
if aux_names[0][1] in pd.dtype.names:
return pd
if hasattr(self, "perioddata"):
spd = self.perioddata.get_data()
if 0 in spd and aux_names[0][1] in spd[0].dtype.names:
if (
0 in spd
and spd[0] is not None
and aux_names[0][1] in spd[0].dtype.names
):
return spd
if hasattr(self, "aux"):
return self.aux.get_data()
Expand Down

0 comments on commit 6ad17ac

Please sign in to comment.