Commit ec18eb2e authored by David's avatar David
Browse files

fix(RunModel.Supervisor): offset in node properties

In case of a network with disordered Diversions

Fix #126
Showing with 6 additions and 10 deletions
+6 -10
......@@ -34,11 +34,7 @@ CreateSupervisor <- function(InputsModel, TimeStep = 1L) {
e$InputsModel <- InputsModel
e$griwrm <- attr(InputsModel, "GRiwrm")
# Commands U are only applied on DirectInjection and Diversion
e$nodeProperties <- lapply(e$griwrm$id[getDiversionRows(e$griwrm, TRUE)],
getNodeProperties,
griwrm = e$griwrm)
names(e$nodeProperties) <- unique(e$griwrm$id)
dfNP <- do.call(rbind, lapply(e$nodeProperties, dplyr::bind_cols))
e$nodeProperties <- getAllNodesProperties(e$griwrm)
models4U <- c("Diversion", "RunModel_Reservoir")
e$griwrm4U <-
e$griwrm[is.na(e$griwrm$model) |
......
......@@ -11,8 +11,8 @@ getDataFromLocation <- function(loc, sv) {
if (length(grep("\\[[0-9]+\\]$", loc)) > 0) {
stop("Reaching output of other controller is not implemented yet")
} else {
if (!sv$nodeProperties[[loc]]$DirectInjection) {
if (sv$nodeProperties[[loc]]$Upstream) {
if (!sv$nodeProperties[loc, "DirectInjection"]) {
if (sv$nodeProperties[loc, "Upstream"]) {
sv$OutputsModel[[loc]]$Qsim_m3[sv$ts.previous]
} else {
sv$OutputsModel[[loc]]$Qsim_m3
......@@ -39,17 +39,17 @@ setDataToLocation <- function(ctrlr, sv) {
locU <- ctrlr$Unames[i]
if (sv$nodeProperties[[locU]]$DirectInjection) {
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){
} 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) {
} 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")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment