From 8fb51073185ac05b35391ddb86853b4e8eb2025d Mon Sep 17 00:00:00 2001 From: fenclmar Date: Wed, 25 Oct 2017 13:12:05 +0200 Subject: [PATCH] fix missing last flow/substance record --- SPG/R/functions.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/SPG/R/functions.R b/SPG/R/functions.R index 1cf5698..dbc51bf 100644 --- a/SPG/R/functions.R +++ b/SPG/R/functions.R @@ -203,9 +203,10 @@ pump.trans <- function(flow, V.max, V.min=0, pump.rate) { temp.res.sim <- attr(flow, "temp.res.sim") ## V = Volume of water in 'tank' - V <- rep(0, nrow(flow)) + V <- rep(0, nrow(flow) + 1) + ## S = mass of substance in 'tank' - S <- rep(0, nrow(flow)) + S <- rep(0, nrow(flow) + 1) ## water flow out of pump Q.out <- rep(0, nrow(flow)) @@ -215,7 +216,7 @@ pump.trans <- function(flow, V.max, V.min=0, pump.rate) { ## state of pump state <- 'off' ## mass balances - for(t in 2:nrow(flow)) { + for(t in 2 : (nrow(flow) + 1)) { ## switch pump 'on' if volume is larger than V.max if(V[t-1] > V.max) { state <- 'on' @@ -251,7 +252,7 @@ pump.trans <- function(flow, V.max, V.min=0, pump.rate) { dimnames(flow.out) <- dimnames(flow) class(flow.out) <- "flow" attr(flow.out, "temp.res.sim") <- temp.res.sim # store resolution as attribute - + attr(flow.out, "V.sump.left") <- V[t] # store volume left in a pum sump as attribute return(flow.out) }