Skip to contents

Simulate a stock-and-flow model with simulation specifications defined by sim_specs(). If not already run, the Julia environment will first be set up with use_julia(). If any problems are detected by debugger(), the model cannot be simulated.

Usage

simulate(
  sfm,
  keep_nonnegative_flow = TRUE,
  keep_nonnegative_stock = FALSE,
  keep_unit = TRUE,
  only_stocks = TRUE,
  verbose = FALSE,
  ...
)

Arguments

sfm

Stock-and-flow model, object of class sdbuildR_xmile.

keep_nonnegative_flow

If TRUE, keeps original non-negativity setting of flows. Defaults to TRUE.

keep_nonnegative_stock

If TRUE, keeps original non-negativity setting of stocks Defaults to TRUE.

keep_unit

If TRUE, keeps units of variables. Defaults to TRUE.

only_stocks

If TRUE, only save stocks. If FALSE, auxiliaries and flows are saved using a callback function. Only applies if language is set to "Julia" in sim_specs() and no delay functions are used. Defaults to FALSE.

verbose

If TRUE, update on progress. Defaults to FALSE.

...

Optional arguments

Value

Object of class sdbuildR_sim, which is a list containing:

df

Dataframe, timeseries of computed variables in the ODE

init

Initial value of stocks

constants

Constant parameters

script

Simulation script

duration

Duration of simulation

success

If TRUE, simulation was successful. If FALSE, simulation failed.

...

Other parameters passed to simulate

Examples

sfm <- xmile("SIR")
sim <- simulate(sfm)
plot(sim)
# Obtain all model variables sim <- simulate(sfm, only_stocks = FALSE) plot(sim, add_constants = TRUE)
# Use Julia for models with units or delay functions sfm <- sim_specs(xmile("coffee_cup"), language = "Julia") sim <- simulate(sfm) #> Starting Julia ... #> Connecting to Julia TCP server at localhost:11980 ... #> Setting up Julia environment for sdbuildR... plot(sim)
# Close Julia session use_julia(stop = TRUE)