https://github.com/cran/simecol
Tip revision: a184a5e60f35697c7bfe3dc3d076e08939c26ee4 authored by Thomas Petzoldt on 01 December 2010, 00:00:00 UTC
version 0.7
version 0.7
Tip revision: a184a5e
sim.R
setGeneric("sim", function(obj, initialize = TRUE, ...) standardGeneric("sim"))
setMethod("sim", "simObj",
function(obj, initialize = TRUE, ...) {
if (initialize & !is.null(obj@initfunc)) obj <- initialize(obj)
out <- do.call(obj@solver, list(obj, ...))
obj@out <- out
invisible(obj)
}
)
setMethod("sim", "odeModel",
function(obj, initialize = TRUE, ...) {
if (initialize & !is.null(obj@initfunc)) obj <- initialize(obj)
times <- fromtoby(obj@times)
func <- obj@main
inputs <- obj@inputs
equations <- obj@equations
environment(func) <- environment()
equations <- addtoenv(equations)
if (is.null(inputs)) {
out <- do.call(obj@solver, list(obj@init, times, func, obj@parms, ...))
} else {
out <- do.call(obj@solver, list(obj@init, times, func, obj@parms, inputs=obj@inputs, ...))
}
obj@out <- out
invisible(obj)
}
)
setMethod("sim", "gridModel",
function(obj, initialize = TRUE, ...) {
if (initialize & !is.null(obj@initfunc)) obj <- initialize(obj)
times <- fromtoby(obj@times)
out <- do.call(obj@solver, list(obj, ...))
obj@out <- out
invisible(obj)
}
)