Commit 3a126703 authored by Dorchies David's avatar Dorchies David
Browse files

fix: injected flow in mm per time step

- Add UpstreamIsRunoff property to GRInputsModel
- Use to detect if simulated upstream flows should be imported from simulated upstream runoff models

Fix #23
Showing with 10 additions and 7 deletions
+10 -7
......@@ -27,7 +27,7 @@ Calibration.GRiwrmInputsModel <- function(InputsModel,
for(IM in InputsModel) {
if(verbose) cat("Calibration.GRiwrmInputsModel: Treating sub-basin", IM$id, "...\n")
if(useUpstreamQsim) {
if(useUpstreamQsim && any(IM$UpstreamIsRunoff)) {
# Update InputsModel$Qupstream with simulated upstream flows
IM <- UpdateQsimUpstream(IM, RunOptions[[IM$id]]$IndPeriod_Run, OutputsModel)
}
......
......@@ -82,6 +82,7 @@ CreateOneGRiwrmInputsModel <- function(id, griwrm, DatesR, Precip, PotEvap, Qobs
InputsModel$id <- id
if(length(UpstreamNodes) > 0) {
InputsModel$UpstreamNodes <- UpstreamNodes
InputsModel$UpstreamIsRunoff <- !is.na(griwrm$model[match(UpstreamNodes, griwrm$id)])
}
# Add the model function
InputsModel$FUN_MOD <- FUN_MOD
......
......@@ -17,7 +17,9 @@ RunModel.GRiwrmInputsModel <- function(InputsModel, RunOptions, Param, verbose =
if(verbose) cat("RunModel.GRiwrmInputsModel: Treating sub-basin", IM$id, "...\n")
# Update InputsModel$Qupstream with simulated upstream flows
IM <- UpdateQsimUpstream(IM, RunOptions[[IM$id]]$IndPeriod_Run, OutputsModel)
if(any(IM$UpstreamIsRunoff)) {
IM <- UpdateQsimUpstream(IM, RunOptions[[IM$id]]$IndPeriod_Run, OutputsModel)
}
# Run the model for the sub-basin
OutputsModel[[IM$id]] <- RunModel(
......
#' Update InputsModel$Qupstream with simulated upstream flows provided by GRiwrmOutputsModels object.
#'
#' @param InputsModel \emph{GRiwrmInputsModel} object. See \code{[CreateInputsModel.GRiwrm]}.
#' @param InputsModel \emph{InputsModel} object. See \code{\link[airGR]{CreateInputsModel}}
#' @param IndPeriod_Run numeric index of period to be used for the model run (-)
#' @param OutputsModel \emph{GRiwrmOutputsModel} object provided by \code{[RunModel.GRiwrmInputsModel]}.
#' @param OutputsModel \emph{GRiwrmOutputsModel} object provided by [RunModel.GRiwrmInputsModel].
#'
#' @description This function is used by \code{\link{RunModel.GRiwrmInputsModel}} and \code{\link{Calibration.GRiwrmInputsModel}} in order to provide upstream simulated flows to a node.
#' @description This function is used by [RunModel.GRiwrmInputsModel] and [Calibration.GRiwrmInputsModel] in order to provide upstream simulated flows to a node.
#'
#' @return InputsModel object with updated QobsUpsr
#' @return `InputsModel` object with updated `Qupstream`
#'
UpdateQsimUpstream <- function(InputsModel, IndPeriod_Run, OutputsModel) {
iQ <- which(!is.na(InputsModel$BasinAreas[-length(InputsModel$BasinAreas)]))
iQ <- which(InputsModel$UpstreamIsRunoff)
for(i in iQ) {
InputsModel$Qupstream[IndPeriod_Run, i] <- OutputsModel[[InputsModel$UpstreamNodes[i]]]$Qsim
}
......
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