Commit 96b3ec9e authored by Delaigue Olivier's avatar Delaigue Olivier
Browse files

v1.2.0.4 NEW, add an IsHyst argument in RunModel_CemaNeige to use hysteresis #5252

Showing with 26 additions and 12 deletions
+26 -12
Package: airGR Package: airGR
Type: Package Type: Package
Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling
Version: 1.2.0.3 Version: 1.2.0.4
Date: 2019-01-29 Date: 2019-01-30
Authors@R: c( Authors@R: c(
person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")), person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")),
person("Charles", "Perrin", role = c("aut", "ths"), comment = c(ORCID = "0000-0001-8552-1881")), person("Charles", "Perrin", role = c("aut", "ths"), comment = c(ORCID = "0000-0001-8552-1881")),
......
...@@ -13,7 +13,7 @@ output: ...@@ -13,7 +13,7 @@ output:
### 1.2.0.3 Release Notes (2019-01-29) ### 1.2.0.4 Release Notes (2019-01-30)
......
RunModel_CemaNeige <- function(InputsModel, RunOptions, Param) { RunModel_CemaNeige <- function(InputsModel, RunOptions, Param, IsHyst) {
## Arguments_check
if (!is.logical(IsHyst) | length(IsHyst) != 1L) {
stop("'IsHyst' must be a 'logical' of length 1")
return(NULL)
}
NParam <- 2L
## Initialization of variables
NParam <- ifelse(IsHyst, 4L, 2L)
NStates <- 4L
FortranOutputsCemaNeige <- c("Pliq", "Psol", FortranOutputsCemaNeige <- c("Pliq", "Psol",
"SnowPack", "ThermalState", "Gratio", "SnowPack", "ThermalState", "Gratio",
"PotMelt", "Melt", "PliqAndMelt", "Temp") "PotMelt", "Melt", "PliqAndMelt", "Temp",
"Gthreshold", "Glocalmax")
...@@ -47,7 +57,7 @@ RunModel_CemaNeige <- function(InputsModel, RunOptions, Param) { ...@@ -47,7 +57,7 @@ RunModel_CemaNeige <- function(InputsModel, RunOptions, Param) {
ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim
ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim
...@@ -81,17 +91,18 @@ RunModel_CemaNeige <- function(InputsModel, RunOptions, Param) { ...@@ -81,17 +91,18 @@ RunModel_CemaNeige <- function(InputsModel, RunOptions, Param) {
InputsFracSolidPrecip = InputsModel$LayerFracSolidPrecip[[iLayer]][IndPeriod1], ### input series of fraction of solid precipitation [0-1] InputsFracSolidPrecip = InputsModel$LayerFracSolidPrecip[[iLayer]][IndPeriod1], ### input series of fraction of solid precipitation [0-1]
InputsTemp = InputsModel$LayerTemp[[iLayer]][IndPeriod1], ### input series of air mean temperature [degC] InputsTemp = InputsModel$LayerTemp[[iLayer]][IndPeriod1], ### input series of air mean temperature [degC]
MeanAnSolidPrecip = RunOptions$MeanAnSolidPrecip[iLayer], ### value of annual mean solid precip [mm/y] MeanAnSolidPrecip = RunOptions$MeanAnSolidPrecip[iLayer], ### value of annual mean solid precip [mm/y]
NParam = as.integer(2), ### number of model parameter = 2 NParam = as.integer(NParam), ### number of model parameter
Param = as.double(ParamCemaNeige), ### parameter set Param = as.double(ParamCemaNeige), ### parameter set
NStates = as.integer(2), ### number of state variables used for model initialising = 2 NStates = as.integer(NStates), ### number of state variables used for model initialising
StateStart = StateStartCemaNeige, ### state variables used when the model run starts StateStart = StateStartCemaNeige, ### state variables used when the model run starts
IsHyst = as.integer(IsHyst), ### use of hysteresis
NOutputs = as.integer(length(IndOutputsCemaNeige)), ### number of output series NOutputs = as.integer(length(IndOutputsCemaNeige)), ### number of output series
IndOutputs = IndOutputsCemaNeige, ### indices of output series IndOutputs = IndOutputsCemaNeige, ### indices of output series
## outputs ## outputs
Outputs = matrix(-999.999, ### output series [mm] Outputs = matrix(-999.999, ### output series [mm]
nrow = length(IndPeriod1), nrow = length(IndPeriod1),
ncol = length(IndOutputsCemaNeige)), ncol = length(IndOutputsCemaNeige)),
StateEnd = rep(-999.999, 2) ### state variables at the end of the model run (reservoir levels [mm] and HU) StateEnd = rep(-999.999, NStates) ### state variables at the end of the model run (reservoir levels [mm] and HU)
) )
RESULTS$Outputs[round(RESULTS$Outputs , 3) == -999.999] <- NA RESULTS$Outputs[round(RESULTS$Outputs , 3) == -999.999] <- NA
RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA RESULTS$StateEnd[round(RESULTS$StateEnd, 3) == -999.999] <- NA
...@@ -112,11 +123,14 @@ RunModel_CemaNeige <- function(InputsModel, RunOptions, Param) { ...@@ -112,11 +123,14 @@ RunModel_CemaNeige <- function(InputsModel, RunOptions, Param) {
names(CemaNeigeLayers) <- sprintf("Layer%02i", seq_len(NLayers)) names(CemaNeigeLayers) <- sprintf("Layer%02i", seq_len(NLayers))
if (ExportStateEnd) { if (ExportStateEnd) {
idNStates <- seq_len(NStates*NLayers) %% NStates
CemaNeigeStateEnd <- CreateIniStates(FUN_MOD = RunModel_CemaNeige, InputsModel = InputsModel, CemaNeigeStateEnd <- CreateIniStates(FUN_MOD = RunModel_CemaNeige, InputsModel = InputsModel,
ProdStore = NULL, RoutStore = NULL, ExpStore = NULL, ProdStore = NULL, RoutStore = NULL, ExpStore = NULL,
UH1 = NULL, UH2 = NULL, UH1 = NULL, UH2 = NULL,
GCemaNeigeLayers = CemaNeigeStateEnd[seq_len(2*NLayers)[seq_len(2*NLayers) %% 2 == 1]], GCemaNeigeLayers = CemaNeigeStateEnd[seq_len(NStates*NLayers)[idNStates == 3]],
eTGCemaNeigeLayers = CemaNeigeStateEnd[seq_len(2*NLayers)[seq_len(2*NLayers) %% 2 == 0]], eTGCemaNeigeLayers = CemaNeigeStateEnd[seq_len(NStates*NLayers)[idNStates == 2]],
GthrCemaNeigeLayers = CemaNeigeStateEnd[seq_len(NStates*NLayers)[idNStates == 1]],
GlocmaxCemaNeigeLayers = CemaNeigeStateEnd[seq_len(NStates*NLayers)[idNStates == 0]],
verbose = FALSE) verbose = FALSE)
} }
......
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