Julia structures
Model
Below the composite type that represents all different aspects of a Wflow.Model
, such as the network, parameters, clock, model type, configuration and input and output.
struct Model{N,L,V,R,W,T}
::Config # all configuration options
config::N # connectivity information, directed graph
network::L # lateral model that holds lateral state, moves along network
lateral::V # vertical model that holds vertical state, independent of each other
vertical::Clock # to keep track of simulation time
clock::R # provides the model with dynamic input
reader::W # writes model output
writertype::T # model type
end
The lateral
field of the struct Model
can contain different lateral concepts. For each wflow model these different lateral concepts are mapped through the use of a NamedTuple
. The vertical
field of the struct Model
always contains one vertical concept, for example the SBM vertical concept.
Below an example how lateral concepts are mapped for the SBM model through a NamedTuple
:
= ssf, land = olf, river = rf) (subsurface
The subsurface
part is mapped to the lateral subsurface flow kinematic wave concept, the land
part is mapped the overland flow kinematic wave concept and the river
part is mapped to the river flow kinematic wave concept. Knowledge of this specific mapping is required to understand and correctly set input, output and state variables in the TOML configuration file, see also Config and TOML. This mapping is described in more detail for each model in the section Models. Also the struct
of each mapped concept is provided, so one can check the internal variables in the code. These structs are defined as a parametric composite type, with type parameters between curly braces after the struct
name. See also the next paragraph Vertical and lateral models for a more detailed description.
Vertical and lateral models
The different model concepts used in wflow are defined as parametric composite types. For example the vertical SBM
concept is defined as follows: struct SBM{T,N,M}
. T
, N
and M
between curly braces after the struct
name refer to type parameters, for more information about type parameters you can check out Type parameters. Since these parameters can be of any type, it is possible to declare an unlimited number of composite types. The type parameters are used to set the type of struct
fields, below an example with a part of the SBM
struct:
@get_units @with_kw struct SBM{T,N,M}
# Model time step [s]
::T | "s"
dt# Maximum number of soil layers
::Int | "-"
maxlayers# number of cells
::Int | "-"
n# Number of soil layers
::Vector{Int} | "-"
nlayers# Number of unsaturated soil layers
::Vector{Int} | "-"
n_unsatlayers# Fraction of river [-]
::Vector{T} | "-"
riverfrac# Saturated water content (porosity) [mm mm⁻¹]
::Vector{T} | "mm mm-1"
theta_s# Residual water content [mm mm⁻¹]
::Vector{T} | "mm mm-1"
theta_r# Vertical hydraulic conductivity [mm Δt⁻¹] at soil surface
::Vector{T} | "mm dt-1"
kv_0# Muliplication factor [-] applied to kv_z (vertical flow)
::Vector{SVector{N,T}} | "-" kvfrac
The type parameter T
is used in wflow as a subtype of AbstractFloat
, allowing to store fields with a certain floating point precision (e.g. Float64
or Float32
) in a flexible way. N
refers to the maximum number of soil layers of the SBM
soil column, and M
refers to the maximum number of soil layers + 1. See also part of the following instance of SBM
:
= SBM{Float,maxlayers,maxlayers + 1}(
sbm = tosecond(dt),
dt = maxlayers,
maxlayers = n, n
For the other model concepts, we refer to the code to check these type parameters.