sdStaticModel: Creates Static Model Object

Description Usage Arguments Details Value Examples

Description

A factory function that creates a sdStaticModelClass object from a list of algebraic equations that calculates the system in equilibrium and a default scenario describing the system environment (variables and default values).

Usage

1
2
3
sdStaticModel(staticModelId = NULL, staticModelDescription = NULL,
  defaultScenario = NULL, equations = NULL, InitVars = NULL,
  globalFunctions = NULL)

Arguments

staticModelId

A character string with the model ID. Any non-word character will be removed and the result will be converted to a valid name (see make.names).

staticModelDescription

A string with the model description.

defaultScenario

The model default scenario, a sdScenarioClass object without state variables. It should contain all the model variables initialized with default values that ensures the model simulation.

equations

(Optional) A list with the model algebraic equations in strings or R-expressions written in R-format.

They have access to the following variables: (t, ct, par, inp, sw, eq). Where t is the current time point in the integration, st is a list with the current estimate of the state variables in the ODE system, ct is a list with the model constant variables, par is a list with the model parameter variables, inp is a list with the model input variables with the time series variables evaluated for the current time step, sw is list with the model switch variables and eq is a list with the predecessors algebraic equations, following the sorted list, evaluated for the current time step.

The algebraic equation are evaluated at each time step during simulations.

See the function sdInitEquations to learn how this list is generated.

InitVars

(Optional) An R-function that initialize or change the initial values of the model variables before the solver call when running a simulation. It can be used, for example, to compute some dependent parameter variables or the initial value of variables, using the arguments.

It must be defined as: function(ct, par, inp, sw, eq). Where ct is a list with the model constant variables, par is a list with the model parameter variables, inp is a list with the model input variables, sw is a list with the model switch variables and eq is a list with the model algebraic equations in R-expression format, as defined by the user.

The return value of the InitVars function should be a list containing all the function arguments, except the algebraic equations, named in the same way, e.g. return(list(ct = ct, inp = inp, par = par, sw = sw)).

globalFunctions

A named list of extra functions that can be executed in the scope of any other function or algebraic equation defined in the model. They can be called by their names in the list.

Details

To load a model from a XML file use the sdLoadModel function.

To simulate a model in different scenarios use the sdSimulate function.

Value

A sdStaticModelClass object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## Let's create a simplified model to represent an environment capacity
# regulated by a population size

# define the parameter: the environment carrying capacity
parEnv <- data.frame(Variable = c("K"),
                        Value = c(10),
                        Description =c("carrying capacity"))

# define the input: the population size
inpEnv <- data.frame(Variable = c("P"),
                     Value = c(1),
                     Description = c("Population size"))

# define the algebraic equation that regulate the capacity
algEqEnvironment <- list(regulatingCapacity = "1 - inp$P/par$K")

# create the environment capacity scenario
envScen <- sdScenario(scenarioId = "EnvironmentCapacityScen", 
                      parameter = parEnv,
                      input = inpEnv,
                      times = list(from = 0, to = 200, by = 1))

# create the static model of an environment capacity
envCapacity <- sdStaticModel(staticModelId = "EnvironmentCapacity",
                             defaultScenario = envScen,
                             equations = algEqEnvironment)
# validate the equations and simulate the model
envCapacity$verifyModel()
outEnvCapacity <- sdSimulate(envCapacity)
print(outEnvCapacity)

# note that static models without time series variables have constant result
# and therefore will only be simulated for the first time step if not coupled

EmbrapaInformaticaAgropecuaria/sdsim documentation built on May 10, 2019, 9:58 a.m.