CreateController {airGRiwrm}R Documentation

Creation and adding of a controller in a supervisor


Creation and adding of a controller in a supervisor


CreateController(supervisor,, Y, U, FUN)



Supervisor object, see CreateSupervisor

character id of the controller (see Details)


character location of the controlled and/or measured variables in the model.


character location of the command variables in the model.


function controller logic which calculates U from Y (see Details)


The is a unique id for finding the controller in the supervisor. If a controller with the same id already exists, it is overwritten by this new one.

FUN should be a function with one numeric parameter. This parameter will receive the measured values of at Y locations as input for the previous time step and returns calculated U. These U will then be applied at their location for the current time step of calculation of the model.


a Controller object which is a list with the following items:


# First create a Supervisor from a model
nodes <- Severn$BasinsInfo[, c("gauge_id", "downstream_id", "distance_downstream", "area")]
nodes$model <- "RunModel_GR4J"
griwrm <- CreateGRiwrm(nodes,
                 list(id = "gauge_id",
                      down = "downstream_id",
                      length = "distance_downstream"))
BasinsObs <- Severn$BasinsObs
DatesR <- BasinsObs[[1]]$DatesR
PrecipTot <- cbind(sapply(BasinsObs, function(x) {x$precipitation}))
PotEvapTot <- cbind(sapply(BasinsObs, function(x) {x$peti}))
Qobs <- cbind(sapply(BasinsObs, function(x) {x$discharge_spec}))
Precip <- ConvertMeteoSD(griwrm, PrecipTot)
PotEvap <- ConvertMeteoSD(griwrm, PotEvapTot)
InputsModel <- CreateInputsModel(griwrm, DatesR, Precip, PotEvap, Qobs)
sv <- CreateSupervisor(InputsModel)

# A controller which usually releases 0.1 m3/s and provides
# extra release if the downstream flow is below 0.5 m3/s
logicDamRelease <- function(Y) max(0.5 - Y[1], 0.1)
CreateController(sv, "DamRelease", Y = c("54001"), U = c("54095"), FUN = logicDamRelease)

[Package airGRiwrm version 0.6.2 Index]