funC {cOde} | R Documentation |
Generate C code for a function and compile it
Description
Generate C code for a function and compile it
Usage
funC(
f,
forcings = NULL,
events = NULL,
fixed = NULL,
outputs = NULL,
jacobian = c("none", "full", "inz.lsodes", "jacvec.lsodes"),
rootfunc = NULL,
boundary = NULL,
compile = TRUE,
fcontrol = c("nospline", "einspline"),
nGridpoints = -1,
includeTimeZero = TRUE,
precision = 1e-05,
modelname = NULL,
verbose = FALSE,
solver = c("deSolve", "Sundials")
)
Arguments
f |
Named character vector containing the right-hand sides of the ODE.
You may use the key word |
forcings |
Character vector with the names of the forcings |
events |
data.frame of events with columns "var" (character, the name of the state to be
affected), "time" (numeric or character, time point),
"value" (numeric or character, value), "method" (character, either
"replace" or "add"). See events. If "var" and "time" are
characters, their values need to be speciefied in the parameter vector
when calling |
fixed |
character vector with the names of parameters (initial values and dynamic) for which no sensitivities are required (will speed up the integration). |
outputs |
Named character vector for additional output variables, see
arguments |
jacobian |
Character, either "none" (no jacobian is computed), "full" (full jacobian is computed and written as a function into the C file) or "inz.lsodes" (only the non-zero elements of the jacobian are determined, see lsodes) |
rootfunc |
Named character vector. The root function (see
lsoda). Besides the variable names ( |
boundary |
data.frame with columns name, yini, yend specifying the boundary condition set-up. NULL if not a boundary value problem |
compile |
Logical. If FALSE, only the C file is written |
fcontrol |
Character, either |
nGridpoints |
Integer, defining for which time points the ODE is evaluated
or the solution is returned: Set |
includeTimeZero |
Logical. Include t = 0 in the integration time points if |
precision |
Numeric. Only used when |
modelname |
Character. The C file is generated in the working directory
and is named <modelname>.c. If |
verbose |
Print compiler output to R command line. |
solver |
Select the solver suite as either |
Details
The function replaces variables by arrays y[i]
, etc. and
replaces "^" by pow() in order to have the correct C syntax. The file name
of the C-File is derived from f
. I.e. funC(abc, ...
will
generate a file abc.c in the current directory. Currently, only explicit
ODE specification is supported, i.e. you need to have the right-hand sides
of the ODE.
Value
the name of the generated shared object file together with a number of attributes
Examples
## Not run:
# Exponential decay plus constant supply
f <- c(x = "-k*x + supply")
func <- funC(f, forcings = "supply")
# Example 2: root function
f <- c(A = "-k1*A + k2*B", B = "k1*A - k2*B")
rootfunc <- c(steadyState = "-k1*A + k2*B - tol")
func <- funC(f, rootfunc = rootfunc, modelname = "test")
yini <- c(A = 1, B = 2)
parms <- c(k1 = 1, k2 = 5, tol = 0.1)
times <- seq(0, 10, len = 100)
odeC(yini, times, func, parms)
## End(Not run)