Skip to content

Router

All routing is performed by the Router class, Muskingum with static coefficients. What it routes is described by the forcing configuration key, and how each river computes by the compute options dt_routing, use_subreaches, and use_subcycles.

A Router takes a Configs and nothing else: Router(configs). It owns one simulation: the coefficients, the time options, the channel state, and the routing loop. The network it routes over belongs to Network and the weight table gridded runoff is aggregated with belongs to a RunoffForcing class chosen by forcing, and the Router builds both from its Configs. The RunoffForcing is only built when runoff is routed, so channel routing never reads a weight table.

Router

Muskingum river routing with static coefficients, each river's k and x fixed for the whole run - forcing: the channel alone, or runoff on grids or meshes or already aggregated to catchments, read from the forcing files - validity: dt_routing auto gives each river its own valid step, use_subreaches splits rivers too long for their step into sub-reaches, and use_subcycles routes rivers too short for it in subcycles, so that every coefficient is non-negative

__init__(configs)

Parameters:

Name Type Description Default
configs Configs

options describing the simulation, from Configs(...) or Configs.from_json(path). They are validated for routing when route is called. A Router takes its options only from this object, and builds its network from the network file here and its runoff reader the first time runoff is routed, so build a new Configs and a Router from it to change them.

required

route(thread_pool=None, threads=1, kernel='auto')

Executes the routing calculations. This is the primary method of the Router class.

You need to provide both the thread pool and the thread count. This method neither creates nor closes a thread pool so you can recycle properly configured pools without additional overhead. The thread count int statically determines how rivers are partitioned into groups that, as near as possible, give equal work to each thread.

Parameters:

Name Type Description Default
thread_pool ThreadPoolExecutor | None

optional, the pool to assign parallelizable work to. Not created or closed by this method

None
threads int

The number of discrete work pieces which work should be balanced across.

1
kernel str

'auto' (default) prefers a compiled c kernel, else 'c' or 'numba'

'auto'

Returns:

Name Type Description
Self Self

the class instance with updated channel_state and output files written to disk

set_discharge_writer(func)

Set how discharge results are saved to disk, with the function signature types.WriteDischargesFn