Reservoir release cannot be regulated by a Controller if there is a Diversion on the reservoir
This is a regression due to the implementation of #146 (closed) allowing Diversion in the reservoir.
Both Qrelease
and Qdiv
are variables provided by the user and can be controlled by the Supervisor. However, since the location of the command U
is only defined by the node ID and both diversion and reservoir have the same node ID, only one of them can be addressed. In the code, we see that only Diversion would be considered in case of the presence of a Diversion in a Reservoir:
if (sv$nodeProperties[locU, "DirectInjection"]) {
# Direct injection node => update Qusptream of downstream node
node <- sv$griwrm4U$down[sv$griwrm4U$id == locU]
# ! Qupstream contains warm up period and run period => the index is shifted
if (!is.null(sv$InputsModel[[node]])) {
sv$InputsModel[[node]]$Qupstream[sv$ts.index0 + sv$ts.index, locU] <- U
}
} else if (sv$nodeProperties[locU, "Diversion"]){
# Diversion node => update Qdiv with -U
sv$InputsModel[[locU]]$Qdiv[sv$ts.index0 + sv$ts.index] <- -U
} else if (sv$nodeProperties[locU, "Reservoir"]) {
sv$InputsModel[[locU]]$Qrelease[sv$ts.index0 + sv$ts.index] <- U
} else {
stop("Node ", locU, " must be a Direct Injection or a Diversion node")
}