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 time in your equations for non-autonomous ODEs.

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 odeC. An event function is generated and compiled with the ODE.

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 nout and outnames of lsode

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 (names(f)) also other symbols are allowed that are treated like new parameters.

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 "nospline" (default, forcings are handled by deSolve) or "einspline" (forcings are handled as splines within the C code based on the einspline library).

nGridpoints

Integer, defining for which time points the ODE is evaluated or the solution is returned: Set -1 to return only the explicitly requested time points (default). If additional time points are introduced through events, they will not be returned. Set >= 0 to introduce additional time points between tmin and tmax where the ODE is evaluated in any case. Additional time points that might be introduced by events will be returned. If splines are used with fcontrol = "einspline", nGridpoinnts also indicates the number of spline nodes.

includeTimeZero

Logical. Include t = 0 in the integration time points if TRUE (default). Consequently, integration starts at t = 0 if only positive time points are provided by the user and at tmin, if also negtive time points are provided.

precision

Numeric. Only used when fcontrol = "einspline".

modelname

Character. The C file is generated in the working directory and is named <modelname>.c. If NULL, a random name starting with ".f" is chosen, i.e. the file is hidden on a UNIX system.

verbose

Print compiler output to R command line.

solver

Select the solver suite as either deSolve or Sundials (not available any more). Defaults to deSolve.

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)

[Package cOde version 1.1.1 Index]