diff --git a/R/RunModel_Lag.R b/R/RunModel_Lag.R index 4bfaaadc93496f04b962e033e957d06eb8854920..9344a78bee11963b6da67520e7186e97ef94ce03 100644 --- a/R/RunModel_Lag.R +++ b/R/RunModel_Lag.R @@ -39,7 +39,7 @@ RunModel_Lag <- function(InputsModel, RunOptions, Param) { } # propagation time from upstream meshes to outlet - PT <- InputsModel$LengthHydro / Param[1L] / TimeStep + PT <- InputsModel$LengthHydro * 1e3 / Param[1L] / TimeStep HUTRANS <- rbind(1 - (PT - floor(PT)), PT - floor(PT)) NbUpBasins <- length(InputsModel$LengthHydro) diff --git a/man/CreateInputsModel.Rd b/man/CreateInputsModel.Rd index 958f9e7eec4e2216912acb52c567a6636c443232..365955eb5d5af4700695578bcaae7e61ebfba4ae 100644 --- a/man/CreateInputsModel.Rd +++ b/man/CreateInputsModel.Rd @@ -52,7 +52,7 @@ CreateInputsModel(FUN_MOD, DatesR, Precip, PrecipScale = TRUE, PotEvap = NULL, \item{Qupstream}{(optional) [numerical matrix] time series of upstream flows (catchment average) [mm/time step or m3/time step, see details], required to create the SD model inputs . See details} -\item{LengthHydro}{(optional) [numeric] real giving the distance between the downstream outlet and each upstream inlet of the sub-catchment [m], required to create the SD model inputs . See details} +\item{LengthHydro}{(optional) [numeric] real giving the distance between the downstream outlet and each upstream inlet of the sub-catchment [km], required to create the SD model inputs . See details} \item{BasinAreas}{(optional) [numeric] real giving the area of each upstream sub-catchment [km2] and the area of the downstream sub-catchment in the last item, required to create the SD model inputs . See details} @@ -83,7 +83,6 @@ Please note that if CemaNeige is used, and \code{ZInputs} is different than \cod Users wanting to use a semi-distributed (SD) lag model should provide valid \code{Qupstream}, \code{LengthHydro}, and \code{BasinAreas} parameters. Each upstream sub-catchment is described by an upstream flow time series (one column in \code{Qupstream} matrix), a distance between the downstream outlet and the upstream inlet (one item in \code{LengthHydro}) and an area (one item in \code{BasinAreas}). The order of the columns or of the items should be consistent for all these parameters. \code{BasinAreas} should contain one extra information (stored in the last item) which is the area of the downstream sub-catchment. Upstream flows that are not related to a sub-catchment such as a release or withdraw spot are identified by an area equal to \code{NA} and an upstream flow expressed in m3/time step instead of mm/time step. -Please note that the use of SD lag model require to use the \code{\link{RunModel}} function instead of \code{\link{RunModel_GR4J}} or the other \code{RunModel_*} functions. } \examples{ diff --git a/man/RunModel_Lag.Rd b/man/RunModel_Lag.Rd index c8bb7ea4bca6bdacc8439a6f05c50b5a90212670..b37487679c2734efdddda7f066a4ad9133e07cff 100644 --- a/man/RunModel_Lag.Rd +++ b/man/RunModel_Lag.Rd @@ -62,7 +62,7 @@ Qupstream <- Qupstream * 86400 ## Conversion in m3/day BasinAreas <- c(NA, BasinInfo$BasinArea) ## delay time between the reservoir and the catchment outlet is 2 days and the distance is 150 km -LengthHydro <- 150000 +LengthHydro <- 150 InputsModel <- CreateInputsModel(FUN_MOD = RunModel_GR4J, DatesR = BasinObs$DatesR, Precip = BasinObs$P, PotEvap = BasinObs$E, @@ -86,7 +86,7 @@ OutputsModelDown <- RunModel_GR4J(InputsModel = InputsModel, RunOptions = RunOptions, Param = Param) ## with a delay of 2 days for 150 km, the flow velocity is 75 km per day -Velocity <- (LengthHydro / 2) / 86400 ## Conversion m/day -> m/s +Velocity <- (LengthHydro * 1e3 / 2) / (24 * 60 * 60) ## Conversion km/day -> m/s ## add the output of the precipitation-runoff model in the InputsModel object InputsModel$OutputsModel <- OutputsModelDown diff --git a/tests/testthat/test-RunModel_Lag.R b/tests/testthat/test-RunModel_Lag.R index bfef15d2833076d4dc30005615c46d9ed00eb2fe..179bd87e7f45cd93705ef4a2f6902c4195bfeca7 100644 --- a/tests/testthat/test-RunModel_Lag.R +++ b/tests/testthat/test-RunModel_Lag.R @@ -43,7 +43,7 @@ InputsModel <- CreateInputsModel( Precip = BasinObs$P, PotEvap = BasinObs$E, Qupstream = matrix(Qupstream, ncol = 1), - LengthHydro = 1000, + LengthHydro = 1, BasinAreas = BasinAreas ) @@ -114,7 +114,7 @@ test_that("Downstream basin with nil area and nul upstream length should return expect_equal(OutputsSD$Qsim, Qupstream[Ind_Run]) }) -ParamSD <- c(InputsModel$LengthHydro / (24 * 60 * 60), Param) # Speed corresponding to one time step delay +ParamSD <- c(InputsModel$LengthHydro * 1e3 / (24 * 60 * 60), Param) # Speed corresponding to one time step delay QlsGR4Only <- OutputsGR4JOnly$Qsim * InputsModel$BasinAreas[2L] * 1e6 / 86400 @@ -127,7 +127,7 @@ test_that("1 input with lag of 1 time step delay out gives an output delayed of test_that("1 input with lag of 0.5 time step delay out gives an output delayed of 0.5 time step", { OutputsSD <- RunModel(InputsModel, RunOptions, - Param = c(InputsModel$LengthHydro / (12 * 3600), Param), + Param = c(InputsModel$LengthHydro * 1e3 / (12 * 3600), Param), FUN_MOD = RunModel_GR4J) QlsSdSim <- OutputsSD$Qsim * sum(InputsModel$BasinAreas) * 1e6 / 86400 QlsUpstLagObs <- (Qupstream[Ind_Run] + c(0, Qupstream[Ind_Run[1:(length(Ind_Run) - 1)]]))/2 * InputsModel$BasinAreas[1L] * 1e6 / 86400 @@ -180,7 +180,7 @@ test_that("1 no area input with lag of 1 time step delay out gives an output del IM <- InputsModel IM$BasinAreas <- rep(BasinInfo$BasinArea, 3) IM$Qupstream <- cbind(IM$Qupstream, IM$Qupstream) -IM$LengthHydro <- c(1000, 1500) +IM$LengthHydro <- c(1, 1.5) PSDini <- ParamSD PSDini[1] <- PSDini[1] / 2 # 2 time step delay diff --git a/vignettes/V05_sd_model.Rmd b/vignettes/V05_sd_model.Rmd index e0cb7c64b514ecb11167ec325bf01f6018cc7747..430c8e3b62eeb619533a1e1c8480a4318946618e 100644 --- a/vignettes/V05_sd_model.Rmd +++ b/vignettes/V05_sd_model.Rmd @@ -104,7 +104,7 @@ InputsModelDown1 <- CreateInputsModel( FUN_MOD = RunModel_GR4J, DatesR = BasinObs$DatesR, Precip = BasinObs$P, PotEvap = BasinObs$E, Qupstream = matrix(QObsUp, ncol = 1), # upstream observed flow - LengthHydro = 1e2 * 1e3, # distance between upstream catchment outlet & the downstream one [m] + LengthHydro = 100, # distance between upstream catchment outlet & the downstream one [km] BasinAreas = c(180, 180) # upstream and downstream areas [km²] ) ``` @@ -173,7 +173,7 @@ ParamDown2 <- OutputsCalibDown2$ParamFinalR The theoretical Velocity parameter should be equal to: ```{r} -Velocity <- InputsModelDown1$LengthHydro / (2 * 86400) +Velocity <- InputsModelDown1$LengthHydro * 1e3 / (2 * 86400) paste(format(Velocity), "m/s") ```