| 1 |
\name{DLLres} |
| 2 |
\alias{DLLres} |
| 3 |
\title{Evaluates a Residual Derivative Function Represented in a DLL |
| 4 |
} |
| 5 |
\description{ |
| 6 |
Calls a residual function, \eqn{F(t,y,y')} of a DAE system |
| 7 |
(differential algebraic equations) defined in a compiled language as a |
| 8 |
DLL. |
| 9 |
|
| 10 |
To be used for testing the implementation of DAE problems in compiled code |
| 11 |
} |
| 12 |
\usage{DLLres(res, times, y, dy, parms, dllname, |
| 13 |
initfunc = dllname, rpar = NULL, ipar = NULL, nout = 0, |
| 14 |
outnames = NULL, forcings = NULL, initforc = NULL, |
| 15 |
fcontrol = NULL) |
| 16 |
} |
| 17 |
\arguments{ |
| 18 |
\item{res }{the name of the function in the dynamically loaded |
| 19 |
shared library, |
| 20 |
} |
| 21 |
\item{times }{first value = the time at which the function needs to be |
| 22 |
evaluated, |
| 23 |
} |
| 24 |
\item{y }{the values of the dependent variables for which the function needs |
| 25 |
to be evaluated, |
| 26 |
} |
| 27 |
\item{dy }{the derivative of the values of the dependent variables for |
| 28 |
which the function needs to be evaluated, |
| 29 |
} |
| 30 |
\item{parms }{the parameters that are passed to the initialiser function, |
| 31 |
} |
| 32 |
\item{dllname }{a string giving the name of the shared library (without |
| 33 |
extension) that contains the compiled function or subroutine definitions |
| 34 |
referred to in \code{func}, |
| 35 |
} |
| 36 |
\item{initfunc }{if not NULL, the name of the initialisation function |
| 37 |
(which initialises values of parameters), as provided in \file{dllname}. |
| 38 |
See details, |
| 39 |
} |
| 40 |
\item{rpar }{a vector with double precision values passed to the |
| 41 |
DLL-function \code{func} and \code{jacfunc} present in the DLL, via |
| 42 |
argument \code{rpar}, |
| 43 |
} |
| 44 |
\item{ipar }{a vector with integer values passed to the DLL-function |
| 45 |
\code{func} and \code{jacfunc} present in the DLL, via function argument |
| 46 |
\code{ipar}, |
| 47 |
} |
| 48 |
\item{nout }{the number of output variables. |
| 49 |
} |
| 50 |
\item{outnames }{only used if \file{dllname} is specified and |
| 51 |
\code{nout} > 0: the names of output variables calculated in the |
| 52 |
compiled function \code{func}, present in the shared library. |
| 53 |
} |
| 54 |
\item{forcings }{only used if \file{dllname} is specified: a list with |
| 55 |
the forcing function data sets, each present as a two-columned matrix, |
| 56 |
with (time,value); interpolation outside the interval |
| 57 |
[min(\code{times}), max(\code{times})] is done by taking the value at |
| 58 |
the closest data extreme. |
| 59 |
|
| 60 |
See package vignette \code{"compiledCode"}. |
| 61 |
} |
| 62 |
\item{initforc }{if not \code{NULL}, the name of the forcing function |
| 63 |
initialisation function, as provided in |
| 64 |
\file{dllname}. It MUST be present if \code{forcings} has been given a |
| 65 |
value. |
| 66 |
See package vignette \code{"compiledCode"}. |
| 67 |
} |
| 68 |
\item{fcontrol }{A list of control parameters for the forcing functions. |
| 69 |
See package vignette \code{"compiledCode"}. |
| 70 |
} |
| 71 |
} |
| 72 |
\value{ |
| 73 |
a list containing: |
| 74 |
\item{res }{the residual of derivative estimated by the function} |
| 75 |
\item{var }{the ordinary output variables of the function} |
| 76 |
} |
| 77 |
\details{ |
| 78 |
This function is meant to help developing FORTRAN or C models that are to be |
| 79 |
used to solve differential algebraic equations (DAE) in |
| 80 |
package \code{deSolve}. |
| 81 |
} |
| 82 |
\author{Karline Soetaert <[email protected]>} |
| 83 |
\keyword{utilities} |
| 84 |
|
| 85 |
\examples{ |
| 86 |
## ========================================================================= |
| 87 |
## Residuals from the daspk chemical model, production a forcing function |
| 88 |
## ========================================================================= |
| 89 |
## Parameter values and initial conditions |
| 90 |
## see example(daspk) for a more comprehensive implementation |
| 91 |
|
| 92 |
pars <- c(K = 1, ka = 1e6, r = 1) |
| 93 |
|
| 94 |
## Initial conc; D is in equilibrium with A,B |
| 95 |
y <- c(A = 2, B = 3, D = 2 * 3/pars["K"]) |
| 96 |
|
| 97 |
## Initial rate of change |
| 98 |
dy <- c(dA = 0, dB = 0, dD = 0) |
| 99 |
|
| 100 |
## production increases with time |
| 101 |
prod <- matrix(ncol = 2, |
| 102 |
data = c(seq(0, 100, by = 10), seq(0.1, 0.5, len = 11))) |
| 103 |
|
| 104 |
DLLres(y = y, dy = dy, times = 5, res = "chemres", |
| 105 |
dllname = "deSolve", initfunc = "initparms", |
| 106 |
initforc = "initforcs", parms = pars, forcings = prod, |
| 107 |
nout = 2, outnames = c("CONC", "Prod")) |
| 108 |
|
| 109 |
} |
| 110 |
\seealso{ |
| 111 |
\link{daspk} to solve DAE problems |
| 112 |
} |