funC: Generate C code for a function and compile it

Description Usage Arguments Details Value Examples

Description

Generate C code for a function and compile it

Usage

1
2
3
4
5
funC(f, forcings = NULL, outputs = NULL, jacobian = c("none", "full",
  "inz.lsodes", "jacvec.lsodes"), rootfunc = NULL, boundary = NULL,
  compile = TRUE, fcontrol = c("nospline", "einspline"),
  nGridpoints = 500, precision = 1e-05, modelname = NULL,
  verbose = FALSE)

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

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 the number of grid points between tmin and tmax where the ODE is computed in any case. Indicates also the number of spline nodes if fcontrol = "einspline".

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.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## 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)

dlill/cOde2ndsens documentation built on May 30, 2019, 1:37 p.m.