landlab.core.model_runner

class Clock[source]

Bases: object

Define the time domain and default time step for a model run.

Parameters:
  • start (float, optional) – Initial model time.

  • stop (float, optional) – Final model time. It must be greater than start.

  • step (float, optional) – Positive, finite default time-step duration.

Examples

>>> clock = Clock(start=2.0, stop=8.0, step=0.5)
>>> clock.duration
6.0
__init__(start=0.0, stop=inf, step=1.0)
Parameters:
Return type:

None

classmethod __new__(*args, **kwargs)
property duration: float
start: float
step: float
stop: float
class ModelRunner[source]

Bases: object

Advance a model through time and run scheduled events.

A model runner owns the current model time. It advances the model by calling its update method with time-step durations no greater than the requested step. Scheduled events are run at their specified absolute model times.

Parameters:
  • model (_TimeSteppable) – Object with an update(dt) method that advances its state.

  • clock (Clock) – Time domain and default time step for the run.

  • events (mapping of str to _Event, optional) – Named events to run according to their schedules.

Examples

>>> from landlab.core.model_runner import ModelRunner
>>> class MyModel:
...     def __init__(self):
...         self.elapsed = 0.0
...
...     def update(self, dt):
...         self.elapsed += dt
...
>>> model = MyModel()
>>> runner = ModelRunner(model, clock=Clock(start=1.0, stop=3.5, step=1.0))
>>> runner.run()
>>> runner.current_time
3.5
>>> model.elapsed
2.5
__init__(model, *, clock, events=None)[source]
Parameters:
  • model (_TimeSteppable)

  • clock (Clock)

  • events (Mapping[str, _Event] | None)

Return type:

None

classmethod __new__(*args, **kwargs)
property current_time: float
property dt: float
run(duration=None, dt=None)[source]
Parameters:
Return type:

None

update_until(update_to_time, dt)[source]
Parameters:
Return type:

None