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

[modflowpy/flopy] update(ModflowHob): Improve HOB file performance #1158 (#1224) #1225

Merged
merged 4 commits into from
Sep 7, 2021
Merged
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
19 changes: 10 additions & 9 deletions flopy/modflow/mfhob.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand All @@ -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(
Expand All @@ -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,
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -588,6 +591,7 @@ def __init__(
roff=0.0,
coff=0.0,
itt=1,
tmax=None,
mlay=None,
time_series_data=None,
names=None,
Expand Down Expand Up @@ -645,7 +649,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, :]

Expand Down Expand Up @@ -677,22 +682,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
Expand Down