I am using package deSolve to run some models that include an external forcing. To gain speed, I produced compiled code following the vignette of the package (see 6.2 in https://cran.r-project.org/web/packages/deSolve/vignettes/compiledCode.pdf). My problem is that now I want to introduce two external forcings in the compiled code. Does anyone have a working example/knows how to do it?
#include <R.h>
static double parms[6];
static double forc[1];
/* A trick to keep up with the parameters and forcings */
#define b parms[0]
#define c parms[1]
#define d parms[2]
#define e parms[3]
#define f parms[4]
#define g parms[5]
#define import forc[0]
/* initializers: */
void odec(void (* odeparms)(int *, double *))
{
int N=6;
odeparms(&N, parms);
}
void forcc(void (* odeforcs)(int *, double *))
{
int N=1;
odeforcs(&N, forc);
}
/* derivative function */
void derivsc(int *neq, double *t, double *y, double *ydot,double *yout, int*ip)
{
if (ip[0] <2) error("nout should be at least 2");
ydot[0] = import - b*y[0]*y[1] + g*y[2];
ydot[1] = c*y[0]*y[1] - d*y[2]*y[1];
ydot[2] = e*y[1]*y[2] - f*y[2];
yout[0] = y[0] + y[1] + y[2];
yout[1] = import;
}
Thanks