landlab.core.model_runner¶
- class Clock[source]¶
Bases:
objectDefine the time domain and default time step for a model run.
- Parameters:
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)¶
- classmethod __new__(*args, **kwargs)¶
- class ModelRunner[source]¶
Bases:
objectAdvance a model through time and run scheduled events.
A model runner owns the current model time. It advances the model by calling its
updatemethod 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
- classmethod __new__(*args, **kwargs)¶