Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions SPG/R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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'
Expand Down Expand Up @@ -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)

}
Expand Down