RunModel_Lag: negative Qsim during Calibration produces NaNs
In case of a simulation with Direct Injection abstracting to much water, the downstream flow simulated by RunModel_Lag
can be negative. But there is a piece of code to cap it to zero:
if (length(RunOptions$Outputs_Sim) > 2) {
if (any(OutputsModel$Qsim[!is.na(OutputsModel$Qsim)] < 0)) {
warning(length(which(OutputsModel$Qsim < 0)), " time steps with negative flow, set to zero.")
OutputsModel$Qsim[OutputsModel$Qsim < 0] <- 0
}
# Warning for NAs
if (any(is.na(OutputsModel$Qsim))) {
warning(length(which(is.na(OutputsModel$Qsim))), " time steps with NA values")
}
}
Unfortunately the assignation to zero is in a condition that is not met during calibration. In case of using a square root transformation for the error criterion, the criterion produces NaNs with a lot of warnings.
Planned solution: move the cap to zero outside the condition linked to the warning (see code above) in order to make it systematic.