Skip to content

Commit

Permalink
Add get_time_step_length
Browse files Browse the repository at this point in the history
  • Loading branch information
rubencalje committed Mar 15, 2024
1 parent 97182fa commit 75632b2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions nlmod/dims/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,31 @@ def estimate_nstp(
return nstp_ceiled


def get_time_step_length(perlen, nstp, tsmult):
"""
Get the length of the timesteps within a singe stress-period.
Parameters
----------
perlen : float
The length of the stress period, in the time unit of the model (generally days).
nstp : int
The numer of timesteps within the stress period.
tsmult : float
THe time step multiplier, generally equal or lager than 1.
Returns
-------
t : np.ndarray
An array with the length of each of the timesteps within the stress period, in
the same unit as perlen.
"""
t = np.array([tsmult**x for x in range(nstp)])
t = t * perlen / t.sum()
return t


def ds_time_from_model(gwf):
warnings.warn(
"this function was renamed to `ds_time_idx_from_model`. "
Expand Down
4 changes: 4 additions & 0 deletions tests/test_016_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ def test_ds_time_from_tdis_settings():

elapsed = (tidx.to_numpy() - np.datetime64("2000")) / np.timedelta64(1, "D")
assert np.allclose(elapsed, [100, 150, 200, 233.33333333, 300.0])


def test_get_time_step_length():
assert (nlmod.time.get_time_step_length(100, 2, 1.5) == np.array([40, 60])).all()

0 comments on commit 75632b2

Please sign in to comment.