run.streambugs: Run the streambugs ODE model

View source: R/streambugs.r

run.streambugsR Documentation

Run the streambugs ODE model

Description

Numerically solve streambugs ODE model (in either R or C version) for given parameters, inputs and time points, using the ode routine.

Usage

run.streambugs(
  y.names,
  times,
  par,
  inp = NA,
  C = FALSE,
  file.def = NA,
  file.res = NA,
  file.add = NA,
  return.res.add = FALSE,
  tout.add = NA,
  verbose = TRUE,
  method = "lsoda",
  rtol = 1e-04,
  atol = 1e-04,
  ...
)

Arguments

y.names

state variables names, either as a vector encoded in the form "Reach_Habitat_Taxon" or "Reach_Habitat_Taxon_Group", or a list as returned by decode.statevarnames function

times

vector with time points for which output is wanted; the first

par

vector with constant parameters and model inputs

inp

list with time-dependent parameters or model inputs with one list element for each parameter or input that includes a matrix where first column is the time and second the corresponding parameter or input value

C

identifier for C- or R-Version

file.def

file name for writing system definition

file.res

file name for results

file.add

file name for additional output (e.g. process rates)

return.res.add

returns res.add output additionally to res

tout.add

optional identifier for specific output times for the additional output, if NA all res.add is calculated for all times

verbose

prints some outputs to console

method

method used by ode

rtol

argument of ode function defining relative error tolerance, either a scalar or an array of the same size as y.names

atol

argument of ode function defining absolute error, either a scalar or an array of the same size as y.names

...

further arguments passed to ode

Value

A list with:

$res

matrix of class streambugs with up to as many rows aselements in times and as many columns as elements in y.names, plus an additional column for the time value. There will be a row for each element in times unless the FORTRAN routine "lsoda" returns with an unrecoverable error.

$res.add

optional additional output matrix with process rates and taxon specific factors, present only if return.res.add input parameter is set to TRUE.

Model syntax

See "docs/Streambugs_syntax.pdf" file in the package installation folder: system.file("docs", "Streambugs_syntax.pdf", package="streambugs").

Examples

m <- streambugs.example.model.toy()
# Display inputs: list of perturbed variables with time points and new values
m$inp
# Simluate
res.C.default <- run.streambugs(y.names = m$y.names, times = m$times,
   par = m$par, inp = m$inp, C = TRUE)
# Modify input (halve second perturbation size) and re-simulate
m$inp$Reach3_w[2,2] <- m$inp$Reach3_w[2,2] / 2
m$inp
res.C.modified <- run.streambugs(y.names = m$y.names, times = m$times,
   par = m$par, inp = m$inp, C = TRUE)
# Compare examplary trajectory of organic matter in one of the habitats
var.name <- "Reach3_Hab1_POM1_POM"
plot(m$times,res.C.default$res[, var.name], type="l", col="red")
lines(m$times, res.C.modified$res[, var.name], col="green")


streambugs documentation built on Feb. 16, 2023, 9:48 p.m.