diff --git a/R/RunModel.GRiwrmOutputsModel.R b/R/RunModel.GRiwrmOutputsModel.R index c24a5c4002c6781fc0969b628cabe2d3893f4fc1..d314ebb09363873a2fa8195226f2106d8a7ec59e 100644 --- a/R/RunModel.GRiwrmOutputsModel.R +++ b/R/RunModel.GRiwrmOutputsModel.R @@ -6,7 +6,8 @@ #' #' @details #' `IndPeriod_Run` or `DatesR` must must be continuous periods starting the -#' time step after the last simulation time step of `OutputsModel`. +#' time step after the last simulation time step of the `GRiwrmOutputsModel` +#' object provided through the argument `x`. #' #' `Qinf`, `Qmin`, and `Qrelease` are used for overwriting the corresponding #' arguments provided to [CreateInputsModel.GRiwrm] for the period to be simulated. @@ -14,7 +15,7 @@ #' `IndPeriod_Run` or `DatesR` lengths. #' #' @inheritParams getNextTimeSteps -#' @inheritParams Calibration +#' @inheritParams RunModel.GRiwrmInputsModel #' @inheritParams airGR::CreateRunOptions #' @param DatesR (optional) [POSIXt] vector of dates of period to be used for #' the model run. See details @@ -30,24 +31,25 @@ #' @param Qrelease (optional) [matrix] or [data.frame] of [numeric] containing #' release flows by nodes using the model `RunModel_Reservoir` \[m3 per #' time step\]. See details +#' @param ... Further arguments for compatibility with S3 methods #' #' @inherit RunModel.GRiwrmInputsModel return #' @export #' -RunModel.GRiwrmOutputsModel <- function(OutputsModel, +RunModel.GRiwrmOutputsModel <- function(x, InputsModel, RunOptions, IndPeriod_Run = which(InputsModel[[1]]$DatesR %in% DatesR), - DatesR = getNextTimeSteps(OutputsModel), + DatesR = getNextTimeSteps(x), Qinf = NULL, Qrelease = NULL, Qmin = NULL, ...) { - stopifnot(inherits(OutputsModel, "GRiwrmOutputsModel"), + stopifnot(inherits(x, "GRiwrmOutputsModel"), inherits(InputsModel, "GRiwrmInputsModel"), inherits(RunOptions, "GRiwrmRunOptions")) # Check Run Period - next_time_step <- getNextTimeSteps(OutputsModel) + next_time_step <- getNextTimeSteps(x) next_index <- which(InputsModel[[1]]$DatesR == next_time_step) if (IndPeriod_Run[1] != next_index) { stop("`IndPeriod_Run` should have its first element equal to ", next_index) @@ -57,7 +59,7 @@ RunModel.GRiwrmOutputsModel <- function(OutputsModel, for (id in names(RunOptions)) { # Run model for the sub-basin and one time step RunOptions[[id]]$IniResLevels <- NULL - RunOptions[[id]]$IniStates <- serializeIniStates(OutputsModel[[id]]$StateEnd) + RunOptions[[id]]$IniStates <- serializeIniStates(x[[id]]$StateEnd) RunOptions[[id]]$IndPeriod_WarmUp <- 0L RunOptions[[id]]$IndPeriod_Run <- IndPeriod_Run } @@ -84,7 +86,7 @@ RunModel.GRiwrmOutputsModel <- function(OutputsModel, if (inputArg == "Qrelease" && !InputsModel[[id]]$isReservoir) { stop("The column ", id, " of the argument `Qrelease` does not refer to a Reservoir node") } - if (inputArg == "Qmin" && !InputsModel[[id]]$isDiversion) { + if (inputArg == "Qmin" && !InputsModel[[id]]$hasDiversion) { stop("The column ", id, " of the argument `Qmin` does not refer to a Diversion node") } if (is.null(InputsModel[[id]][[inputArg]])) { @@ -93,13 +95,13 @@ RunModel.GRiwrmOutputsModel <- function(OutputsModel, InputsModel[[id]][[inputArg]][IndPeriod_Run] <- v } if (inputArg == "Qinf") { + g <- attr(InputsModel, "GRiwrm") if (is.null(InputsModel[[id]])) { # Direct Injection - g <- attr(InputsModel, "GRiwrm") id_down <- g$down[g$id == id] InputsModel[[id_down]]$Qupstream[IndPeriod_Run, id] <- v } else { - if (!InputsModel[[id]]$isDiversion) { + if (!InputsModel[[id]]$hasDiversion) { stop("The column ", id, " of the argument `Qinf` does not refer to a DirectInjection or a Diversion node") } InputsModel[[id]]$Qdiv[IndPeriod_Run] <- v diff --git a/R/utils.RunModel.R b/R/utils.RunModel.R index e5aefacecfc73a658ed6fefd65d3f65749226c0d..a86b7126a033dce312058af1aee38a72268ee61b 100644 --- a/R/utils.RunModel.R +++ b/R/utils.RunModel.R @@ -93,7 +93,7 @@ calcOverAbstraction <- function(O, WarmUp) { #' Get the next time steps date/time of a simulation #' -#' @param OutputsModel Object returned by [RunModel.GRiwrmInputsModel], +#' @param x Object returned by [RunModel.GRiwrmInputsModel], #' [RunModel.Supervisor], or [RunModel.GRiwrmOutputsModel] #' @param TimeStep [integer] number of time steps to get after the end of the #' simulation @@ -102,10 +102,10 @@ calcOverAbstraction <- function(O, WarmUp) { #' the end of the simulation. #' @export #' -getNextTimeSteps <- function(OutputsModel, TimeStep = 1L) { - stopifnot(inherits(OutputsModel, "GRiwrmOutputsModel"), +getNextTimeSteps <- function(x, TimeStep = 1L) { + stopifnot(inherits(x, "GRiwrmOutputsModel"), is.integer(TimeStep)) - last_date <- dplyr::last(OutputsModel[[1]]$DatesR) - first_date <- last_date + attr(OutputsModel, "TimeStep") - return(seq(first_date, length.out = TimeStep, by = attr(OutputsModel, "TimeStep"))) + last_date <- dplyr::last(x[[1]]$DatesR) + first_date <- last_date + attr(x, "TimeStep") + return(seq(first_date, length.out = TimeStep, by = attr(x, "TimeStep"))) } diff --git a/man/RunModel.GRiwrmOutputsModel.Rd b/man/RunModel.GRiwrmOutputsModel.Rd index cbd837efe7fd831d78501b308127f0fc9c20cb75..66eb328ab8671730563a7d360187298600b9763d 100644 --- a/man/RunModel.GRiwrmOutputsModel.Rd +++ b/man/RunModel.GRiwrmOutputsModel.Rd @@ -5,24 +5,25 @@ \title{RunModel for hot restart after a previous simulation period} \usage{ \method{RunModel}{GRiwrmOutputsModel}( - OutputsModel, + x, InputsModel, RunOptions, IndPeriod_Run = which(InputsModel[[1]]$DatesR \%in\% DatesR), - DatesR = getNextTimeSteps(OutputsModel), + DatesR = getNextTimeSteps(x), Qinf = NULL, Qrelease = NULL, Qmin = NULL, + merge_outputs = TRUE, ... ) } \arguments{ -\item{OutputsModel}{Object returned by \link{RunModel.GRiwrmInputsModel}, +\item{x}{Object returned by \link{RunModel.GRiwrmInputsModel}, \link{RunModel.Supervisor}, or \link{RunModel.GRiwrmOutputsModel}} -\item{InputsModel}{[object of class \emph{InputsModel} or \emph{GRiwrmInputsModel}] see \link{CreateInputsModel}} +\item{InputsModel}{[object of class \emph{InputsModel}] see \code{\link[airGR]{CreateInputsModel}} for details} -\item{RunOptions}{[object of class \emph{RunOptions} or \emph{GRiwrmRunOptions}] see \link{CreateRunOptions}} +\item{RunOptions}{[object of class \emph{GRiwrmRunOptions}] see \link{CreateRunOptions.GRiwrmInputsModel} for details} \item{IndPeriod_Run}{[numeric] index of period to be used for the model run [-]. See details} @@ -44,7 +45,7 @@ minimum flows to let downstream of a node with a Diversion [m3 per time step]. Default is zero. Column names correspond to node IDs. See details} -\item{...}{further arguments passed to \link[airGR:Calibration]{airGR::Calibration}, see details} +\item{...}{Further arguments for compatibility with S3 methods} } \value{ An object of class \emph{GRiwrmOutputsModel}. @@ -66,7 +67,8 @@ redefined for this new simulation period. } \details{ \code{IndPeriod_Run} or \code{DatesR} must must be continuous periods starting the -time step after the last simulation time step of \code{OutputsModel}. +time step after the last simulation time step of the \code{GRiwrmOutputsModel} +object provided through the argument \code{x}. \code{Qinf}, \code{Qmin}, and \code{Qrelease} are used for overwriting the corresponding arguments provided to \link{CreateInputsModel.GRiwrm} for the period to be simulated. diff --git a/man/getNextTimeSteps.Rd b/man/getNextTimeSteps.Rd index 41ddb9dd224ea60726cf70fd78ef35c14309eacf..d3984e0822b2f990d14566a6a30921b992a6d982 100644 --- a/man/getNextTimeSteps.Rd +++ b/man/getNextTimeSteps.Rd @@ -4,10 +4,10 @@ \alias{getNextTimeSteps} \title{Get the next time steps date/time of a simulation} \usage{ -getNextTimeSteps(OutputsModel, TimeStep = 1L) +getNextTimeSteps(x, TimeStep = 1L) } \arguments{ -\item{OutputsModel}{Object returned by \link{RunModel.GRiwrmInputsModel}, +\item{x}{Object returned by \link{RunModel.GRiwrmInputsModel}, \link{RunModel.Supervisor}, or \link{RunModel.GRiwrmOutputsModel}} \item{TimeStep}{\link{integer} number of time steps to get after the end of the