The PidControl node controls the level in a Basin by continuously controlling the flow rate of a connected Pump or Outlet. See also PID controller.
In the future controlling the flow on a particular link could be supported.
1 Tables
1.1 Static
Code
include("../../../utils/gen_docs_table.jl")table_from_schema( Ribasim.Schema.PidControl.Static; restrictions =Dict(:listen_node_id =>"must be a Basin"),)
column
type
unit
optional
restriction
node_id
Int32
-
x
-
listen_node_id
Int32
-
x
must be a Basin
target
Float64
m
x
-
proportional
Float64
s⁻¹
x
-
integral
Float64
s⁻²
x
-
derivative
Float64
-
x
-
control_state
String
-
✓
-
1.2 Time
This table is the transient form of the PidControl table. The difference is that a time column is added. With this the target level and PID coefficients can be updated over time. In between the given times the values are block interpolated (forward fill), and outside this range the values are kept constant at the value from the nearest time. Note that a node_id can be either in this table or in the static one, but not both.
Code
table_from_schema( Ribasim.Schema.PidControl.Time; restrictions =Dict(:listen_node_id =>"must be a Basin"),)
column
type
unit
optional
restriction
node_id
Int32
-
x
-
listen_node_id
Int32
-
x
must be a Basin
time
DateTime
-
x
-
target
Float64
m
x
-
proportional
Float64
s⁻¹
x
-
integral
Float64
s⁻²
x
-
derivative
Float64
-
x
-
2 Equations
The PID controller continuously sets the flow rate of a Pump or Outlet to bring the level of a certain Basin closer to its setpoint. If we denote the setpoint by \(\text{SP}(t)\) and the Basin level by \(y(t)\), then the error is given by
\[
e(t) = \text{SP}(t) - y(t).
\tag{1}\]
The output of the PID controller for the flow rate of the Pump or Outlet is then given by
The \(Q_\text{PID}(t)\) is not directly applied; it is passed through the Pump/Outlet equations, acting as \(Q_\text{set}\).
For the integral term we denote \[
I(t) = \int_{t_0}^t e(\tau)\text{d}\tau,
\]
where \(t_0\) is the simulation start time. \(I(t)\) is treated as a state of the system and thus it has its own equation in the system: \[
\frac{\text{d}I}{\text{d}t} = e(t).
\]
Note
In the case of the controlled Outlet, the upstream node can also be a level boundary. In this case we define \(\phi = 1\).
2.1 The derivative term
When \(K_d \ne 0\) this adds a level of complexity. We can see this by looking at the error derivative more closely: \[
\frac{\text{d}e}{\text{d}t} = \frac{\text{d}\text{SP}}{\text{d}t} - \frac{1}{A(u_\text{PID})}\frac{\text{d}u_\text{PID}}{\text{d}t},
\]
where \(A(u_\text{PID})\) is the area of the controlled basin as a function of the storage of the controlled basin \(u_\text{PID}\). The complexity arises from the fact that \(Q_\text{PID}\) is a contribution to \(\frac{\text{d}u_\text{PID}}{\text{d}t} = f_\text{PID}\), which makes Equation 2 an implicit equation for \(Q_\text{PID}\). We define
that is, \(\hat{f}_\text{PID}\) is the right hand side of the ODE for the controlled basin storage state without the contribution of the PID controlled pump. The plus sign holds for an outlet and the minus sign for a pump, dictated by the way the pump and outlet connectivity to the controlled basin is enforced.
Using this, solving Equation 2 for \(Q_\text{PID}\) yields \[
Q_\text{pump/outlet} = \text{clamp}\left(\phi(u_\text{us})\frac{K_pe + K_iI + K_d \left(\frac{\text{d}\text{SP}}{\text{d}t}-\frac{\hat{f}_\text{PID}}{A(u_\text{PID})}\right)}{1\pm\phi(u_\text{us})\frac{K_d}{A(u_\text{PID})}}, Q_{\min}, Q_{\max}\right),
\]
where the clamping is again done last. Note that to compute this, \(\hat{f}_\text{PID}\) has to be known first, meaning that the PID controlled Pump or Outlet flow rate has to be computed after all other contributions to the PID controlled Basin’s storage are known.
2.2 The sign of the parameters
Note by Equation 1 that the error is positive if the setpoint is larger than the Basin level and negative if the setpoint is smaller than the Basin level.
We enforce the convention that when a Pump is controlled, its link points away from the Basin, and when an Outlet is controlled, its link points towards the Basin, so that the main flow direction along these links is positive. Therefore, positive flows of the Pump and Outlet have opposite effects on the Basin, and thus the parameters \(K_p,K_i,K_d\) of the Pump and Outlet must have opposite signs to achieve the same goal.
3 Hydrological interpretation of the parameters
The PID controller mimics what a gate or pump operator does: compare the water level with the target level and adjust the discharge. Since \(Q\) is in \(\text{m}^3/\text{s}\) and the error \(e\) in \(\text{m}\), the parameters have the following units and meaning.
Parameter
Unit
Operator’s rule of thumb
\(K_p\)
\(\text{m}^2/\text{s}\)
“For every metre the level is off target, change the discharge by this much.”
\(K_i\)
\(\text{m}^2/\text{s}^2\)
“If the level stays off target, the discharge keeps increasing, the longer the more until the target is reached.”
\(K_d\)
\(\text{m}^2\)
“If the level is moving quickly towards or away from the target, react in advance.”
Remember that \(K_p,K_i,K_d\) of a Pump and an Outlet need opposite signs, see the sign of the parameters. The values below are therefore given as magnitudes.
3.1 Proportional term \(K_p\)
\(K_p\) is the discharge per metre of level error, which is like the slope of a weir or gate rating curve. A Basin with surface area \(A\) that is controlled by \(K_p\) alone behaves like a linear reservoir with time scale
\[
\tau = \frac{A}{K_p}.
\]
The level error decays exponentially with this time scale, so a large \(K_p\) gives a quick but possibly abrupt response, and a small \(K_p\) a slow one. Starting from a desired response time \(\tau\) (e.g. the Basin should recover within a day), a first estimate is \(K_p = A/\tau\). Another way to find \(K_p\) is the maximum discharge \(Q_\text{max}\) of the Pump or Outlet and the level deviation \(\Delta h\) at which the structure should be fully open: \(K_p = Q_\text{max}/\Delta h\).
A proportional controller on its own leaves a steady-state offset whenever there is a constant inflow or outflow that is not matched, since a nonzero error is needed to produce the required discharge. For example, with a constant net inflow \(Q_\text{in}\) that must be pumped out, the Basin level settles at \(Q_\text{in}/K_p\) above the target.
3.2 Integral term \(K_i\)
\(K_i\) removes this steady-state offset: as long as the level is off target, the integral keeps growing and so does the discharge, until the level is back at the target. Hydrologically, it learns the unknown inflow (e.g. seepage, precipitation surplus or upstream supply) that must be compensated. The cost is a slower response and a possible overshoot, where the level passes the target and the Basin oscillates around it. Therefore \(K_i\) is usually chosen small compared to \(K_p\). A common choice is to make the integral time \(T_i = K_p/K_i\) longer than the response time \(\tau\), for instance several times \(\tau\).
3.3 Derivative term \(K_d\)
\(K_d\) reacts to the rate of change of the error, and thereby damps overshoot and oscillations: when the level approaches the target quickly, the discharge is reduced already before the target is reached. In many water systems it is not needed, and often it can be left at \(0\). It can be useful for systems with a large delay or a fast-changing setpoint. Setting \(K_d \ne 0\) makes the equations implicit, see the derivative term. In addition, a large \(K_d\) makes the controller sensitive to fast fluctuations of the level, such as those caused by a sudden change of inflow.
3.4 Practical guidance
Start with \(K_i = K_d = 0\) and choose \(K_p\) from the Basin area and the desired response time, or from the capacity of the structure. Check that the resulting discharge stays within the \(Q_\text{min}\) and \(Q_\text{max}\) of the Pump or Outlet, otherwise the controller saturates and behaves like an on/off controller.
Add a small \(K_i\) if the level does not reach the target, but stays offset.
Only add \(K_d\) if the level oscillates or overshoots despite a smaller \(K_i\).
Values for real systems can often be derived from available information: the Basin area from the water level-area relation, and \(Q_\text{max}\) and the allowed level deviation from the structure’s specifications or operational rules (e.g. the target level band of a polder).
Allocation assumes that the flow rate that this node sets on a Pump or Outlet stays the same until the next intervention time, set by intervention_interval in the allocation settings. Since a PidControl node changes the flow rate continuously, the simulated flows can differ from what allocation planned.