From 31a345f18a105e5d4432aeb01bbe6afa76caf8e0 Mon Sep 17 00:00:00 2001 From: Hua Zhang Date: Thu, 2 Sep 2021 13:49:38 -0400 Subject: [PATCH 1/3] ModflowHob performance --- flopy/modflow/mfhob.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/flopy/modflow/mfhob.py b/flopy/modflow/mfhob.py index 5d0a9a89a8..d13573b085 100755 --- a/flopy/modflow/mfhob.py +++ b/flopy/modflow/mfhob.py @@ -371,7 +371,8 @@ def load(cls, f, model, ext_unit_dict=None, check=True): nobs = 0 # set to False for 1st call to ensure that totim cache is updated - use_cached_totim = False + tmax = model.dis.get_final_totim() + use_cached_totim = True while True: # read dataset 3 @@ -431,7 +432,6 @@ def load(cls, f, model, ext_unit_dict=None, check=True): names = [obsnam] tsd = [totim, hob] nobs += 1 - use_cached_totim = True else: names = [] tsd = [] @@ -452,7 +452,6 @@ def load(cls, f, model, ext_unit_dict=None, check=True): hob = float(t[3]) tsd.append([totim, hob]) nobs += 1 - use_cached_totim = True obs_data.append( HeadObservation( @@ -466,6 +465,7 @@ def load(cls, f, model, ext_unit_dict=None, check=True): obsname=obsnam, mlay=mlay, itt=itt, + tmax=tmax, time_series_data=tsd, names=names, ) @@ -588,6 +588,7 @@ def __init__( roff=0.0, coff=0.0, itt=1, + tmax=None, mlay=None, time_series_data=None, names=None, @@ -645,7 +646,8 @@ def __init__( time_series_data = np.reshape(time_series_data, (1, 2)) # find indices of time series data that are valid - tmax = model.dis.get_final_totim() + if tmax is None: + tmax = model.dis.get_final_totim() keep_idx = time_series_data[:, 0] <= tmax time_series_data = time_series_data[keep_idx, :] @@ -677,22 +679,18 @@ def __init__( "{} names are required.".format(len(names), self.nobs) ) - # set use_cached_totim to False first to ensure totim is updated - use_cached_totim = False - # create time_series_data self.time_series_data = self._get_empty(ncells=shape[0]) for idx in range(self.nobs): t = time_series_data[idx, 0] kstp, kper, toffset = model.dis.get_kstp_kper_toffset( - t, use_cached_totim + t, use_cached_totim = True ) self.time_series_data[idx]["totim"] = t self.time_series_data[idx]["irefsp"] = kper self.time_series_data[idx]["toffset"] = toffset / tomulth self.time_series_data[idx]["hobs"] = time_series_data[idx, 1] self.time_series_data[idx]["obsname"] = names[idx] - use_cached_totim = True if self.nobs > 1: self.irefsp = -self.nobs From b2a4a1835ce457615bbb38585fd227309c4c78b9 Mon Sep 17 00:00:00 2001 From: swfwmd Date: Thu, 2 Sep 2021 15:15:50 -0400 Subject: [PATCH 2/3] ModflowHob Performance --- flopy/modflow/mfhob.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flopy/modflow/mfhob.py b/flopy/modflow/mfhob.py index d13573b085..ca60ad4e24 100755 --- a/flopy/modflow/mfhob.py +++ b/flopy/modflow/mfhob.py @@ -684,7 +684,7 @@ def __init__( for idx in range(self.nobs): t = time_series_data[idx, 0] kstp, kper, toffset = model.dis.get_kstp_kper_toffset( - t, use_cached_totim = True + t, use_cached_totim=True ) self.time_series_data[idx]["totim"] = t self.time_series_data[idx]["irefsp"] = kper From 1b6311e09c3d62745e703a897ea0c07776181eba Mon Sep 17 00:00:00 2001 From: swfwmd Date: Tue, 7 Sep 2021 09:17:02 -0400 Subject: [PATCH 3/3] [modflowpy/flopy] update(ModflowHob): Improve HOB file performance --- flopy/modflow/mfhob.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flopy/modflow/mfhob.py b/flopy/modflow/mfhob.py index ca60ad4e24..19f1cae593 100755 --- a/flopy/modflow/mfhob.py +++ b/flopy/modflow/mfhob.py @@ -543,6 +543,9 @@ class HeadObservation: observations. itt = 1 specified for heads and itt = 2 specified if initial value is head and subsequent changes in head. Only specified if irefsp is < 0. Default is 1. + tmax : float + Maximum simulation time calculated using get_final_totim function of + ModflowDis. Added to avoid repetitive calls. mlay : dictionary of length (abs(irefsp)) Key represents zero-based layer numbers for multilayer observations and value represents the fractional value for each layer of multilayer