odeModel
),gridModel
), andrwalkModel
),simObj
.simObj
)
with the following slots:
main = function(time, init, parms, ...)
: a function holding the
main equations of the model,equations
: an optional non-nested list holding arbitrary
sub-equations (sub-models) of the
model. Sub-equations can be interdependent and can be called
directly from withinmain
orinitialize
.parms
: a list (or vector for some classes) with
constant model parameters,times
: vector of time steps or vector with three
named valuesfrom
,to
,by
specifying the
simulation time steps. The from-to-by form can be edited withfixParms
.init
: initial state (start values) of the
simulation. This is typically a named vector (state variables inodeModel
s) or matrix (e.g. initial grid ofgridModel
s).inputs
: time dependend or spatially resolved external
inputs can be specified as data frame or matrix (more efficient). It
is up to the user to evaluate the corresponding values within themain
function. Performance optimized version ofapprox
(seeapproxTime
) are available.solver
: character string specifying the numerical algorithm
used. Currently"lsoda"
and"rk4"
are directly imported from packageodesolve
). In addition to this solvers from packages"deSolve"
and"ddesolve"
can also be used.
Simecol introduces two additional solvers,"euler"
and"iterator"
(for models with discrete time steps) and it is
also possible to provide own algorithms (solvers).out
: this slot holds the simulation results after a
simulation run as data frame or list (of matrices).initfunc
: this slot can hold an optional function which is called
automatically when a new object is created bynew
or when it
is re-initialized byinitialize
. simObj
model objects should be defined and created using the
common S4 mechanisms (new
).
In this way, a simObj
object may contain all data, which are
needed to run simulations simply by entering the model object
via source()
or data()
and then to run and plot the
model for example via plot(sim(obj))
.
Accessor functions (with names identical to the slot names) are
provided to get or set model parameters,
time steps, initial values, inputs, the solver, the main and
sub-equations or initfunc or to extract the model outputs.
It is also possible to modify the components of the simecol objects
directly, e.g. the model equations of a model lv
with
lv@main
, but there is no guarantee that this will work in a compatible
way in future versions.
Models of different type are provided as data and some more in source code (see directory examples).
The examples are intended as a starting point to
write your own simObj
objects and to distribute them to whomever you wish.
The package is supplemented with several utility functions
(e.g. seedfill
or neighbours
), which can
be used independently from simObj
objects.
The following are sources of information on simecol
:
## -- binary examples -------------------------------
data(lv) # load basic Lotka-Volterra model
fixParms(lv)
parms(lv)
main(lv)
lv <- sim(lv)
plot(lv)
results <- out(lv)
data(conway) # Conway's game of life
init(conway) <- matrix(0, 10, 10)
fixInit(conway) # enter some "1"
sim(conway, animate=TRUE, delay=10)
## -- sourcecode examples ----------------------------
## open the directory with all sourcecode examples
browseURL(paste(system.file(package="simecol"), "/examples", sep=""))
Run the code above in your browser using DataLab