\section{/home/peifer/diffit/modules/integrate\-CVODES.cc File Reference}
\label{integrateCVODES_8cc}\index{/home/peifer/diffit/modules/integrateCVODES.cc@{/home/peifer/diffit/modules/integrateCVODES.cc}}
{\tt \#include $<$math.h$>$}\par
{\tt \#include $<$iostream$>$}\par
{\tt \#include \char`\"{}../nr.h\char`\"{}}\par
{\tt \#include \char`\"{}../def.h\char`\"{}}\par
{\tt \#include \char`\"{}../model.h\char`\"{}}\par
{\tt \#include $<$string.h$>$}\par
{\tt \#include \char`\"{}../lib\-CVODES/sundialstypes.h\char`\"{}}\par
{\tt \#include \char`\"{}../lib\-CVODES/cvodes.h\char`\"{}}\par
{\tt \#include \char`\"{}../lib\-CVODES/cvdense.h\char`\"{}}\par
{\tt \#include \char`\"{}../lib\-CVODES/nvector\_\-serial.h\char`\"{}}\par
{\tt \#include \char`\"{}../lib\-CVODES/dense.h\char`\"{}}\par
{\tt \#include \char`\"{}../lib\-CVODES/sundialsmath.h\char`\"{}}\par
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define {\bf Ith}(v, i)~NV\_\-Ith\_\-S(v,i-1)
\item 
\#define {\bf IJth}(A, i, j)~DENSE\_\-ELEM(A,i-1,j-1)
\item 
\#define {\bf RTOL}~RCONST(1e-8)
\item 
\#define {\bf ATOL}~RCONST(1e-8)
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
void {\bf f} (realtype t, N\_\-Vector y, N\_\-Vector ydot, void $\ast$f\_\-data)
\item 
void {\bf sens\-Derivs} (double t, double $\ast$Yt, double $\ast$Ft, double $\ast$p)
\item 
void {\bf integrate\-CVODES} ({\bf Glob} $\ast$globs, double ystart[$\,$], double p[$\,$], long nvar, double x1, double x2, double eps, int sensi)
\end{CompactItemize}


\subsection{Define Documentation}
\index{integrateCVODES.cc@{integrate\-CVODES.cc}!ATOL@{ATOL}}
\index{ATOL@{ATOL}!integrateCVODES.cc@{integrate\-CVODES.cc}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define ATOL~RCONST(1e-8)}\label{integrateCVODES_8cc_29a15cd00b37b1f4a5b4ec9f07c742f4}




Definition at line 22 of file integrate\-CVODES.cc.

Referenced by integrate\-CVODES().\index{integrateCVODES.cc@{integrate\-CVODES.cc}!IJth@{IJth}}
\index{IJth@{IJth}!integrateCVODES.cc@{integrate\-CVODES.cc}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define IJth(A, i, j)~DENSE\_\-ELEM(A,i-1,j-1)}\label{integrateCVODES_8cc_8411c7c4b6e3b6c2848d50803031205e}




Definition at line 19 of file integrate\-CVODES.cc.\index{integrateCVODES.cc@{integrate\-CVODES.cc}!Ith@{Ith}}
\index{Ith@{Ith}!integrateCVODES.cc@{integrate\-CVODES.cc}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define Ith(v, i)~NV\_\-Ith\_\-S(v,i-1)}\label{integrateCVODES_8cc_07521380e95cb0bd9c30b37bf54089eb}




Definition at line 18 of file integrate\-CVODES.cc.

Referenced by f(), and integrate\-CVODES().\index{integrateCVODES.cc@{integrate\-CVODES.cc}!RTOL@{RTOL}}
\index{RTOL@{RTOL}!integrateCVODES.cc@{integrate\-CVODES.cc}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}\#define RTOL~RCONST(1e-8)}\label{integrateCVODES_8cc_f50ac611d9fae906f9419504fd2caa5d}




Definition at line 21 of file integrate\-CVODES.cc.

Referenced by integrate\-CVODES().

\subsection{Function Documentation}
\index{integrateCVODES.cc@{integrate\-CVODES.cc}!f@{f}}
\index{f@{f}!integrateCVODES.cc@{integrate\-CVODES.cc}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void f (realtype {\em t}, N\_\-Vector {\em y}, N\_\-Vector {\em ydot}, void $\ast$ {\em f\_\-data})}\label{integrateCVODES_8cc_d518e16ca83db4f1ab85234900402660}




Definition at line 98 of file integrate\-CVODES.cc.

References Ith, sens\-Derivs(), and TRUE.

Referenced by integrate\-CVODES(), and objective\-F().

\footnotesize\begin{verbatim}99 {
100   UserData data;
101   data = (UserData) f_data;
102   long i,nvar=data->nvar;
103   double *ydot_nr=(double*)malloc((nvar+1)*sizeof(double));
104   double *y_nr=(double*)malloc((nvar+1)*sizeof(double));
105 
106   for(i=1;i<=nvar;i++)
107     y_nr[i]=Ith(y,i);
108   
109   if(data->sensi==TRUE)
110     sensDerivs((double)t,y_nr,ydot_nr,data->p);
111   else
112     ode((double)t,y_nr,ydot_nr,data->p);
113   
114   for(i=1;i<=nvar;i++)
115       Ith(ydot,i)=ydot_nr[i];
116 
117   free(y_nr);
118   free(ydot_nr);
119 
120 }
\end{verbatim}\normalsize 


\index{integrateCVODES.cc@{integrate\-CVODES.cc}!integrateCVODES@{integrateCVODES}}
\index{integrateCVODES@{integrateCVODES}!integrateCVODES.cc@{integrate\-CVODES.cc}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void integrate\-CVODES ({\bf Glob} $\ast$ {\em globs}, double {\em ystart}[$\,$], double {\em p}[$\,$], long {\em nvar}, double {\em x1}, double {\em x2}, double {\em eps}, int {\em sensi})}\label{integrateCVODES_8cc_9bfb9898c2fb997e79d258462eca03af}




Definition at line 40 of file integrate\-CVODES.cc.

References ATOL, f(), Ith, and RTOL.

\footnotesize\begin{verbatim}42 {
43   
44   void *cvode_mem;
45   UserData data;
46   realtype t,t0,t1;
47   N_Vector y;
48   long i;
49 
50   cvode_mem = NULL;
51   data      = NULL;
52   y         = NULL;
53 
54  
55   data = (UserData) malloc(sizeof *data);
56   
57   //user data
58   data->p=p;
59   data->nvar=nvar;
60   data->sensi=sensi;
61   
62   //  Initial conditions 
63   y = N_VNew_Serial(nvar);
64   for(i=1;i<=nvar;i++)
65     Ith(y,i)=ystart[i];
66 
67   t0= RCONST(x1);
68   t1= RCONST(x2);
69   t = RCONST(t1);
70 
71   /* Create CVODES object */
72   cvode_mem = CVodeCreate(CV_BDF, CV_NEWTON);
73   /* Allocate space for CVODES */
74   realtype atol=ATOL;
75   CVodeMalloc(cvode_mem, f, t0, y, CV_SS, RTOL, &atol);
76   /* Attach user data */
77   CVodeSetFdata(cvode_mem, data);
78   /* Attach linear solver */
79   CVDense(cvode_mem, nvar);
80   
81   //integrate
82   CVode(cvode_mem, t1, y, &t, CV_NORMAL);
83 
84   //copy output back
85   for(i=1;i<=nvar;i++)
86     ystart[i]=Ith(y,i);
87 
88   //free memory
89   N_VDestroy_Serial(y);
90   free(data);
91   CVodeFree(cvode_mem);
92 }
\end{verbatim}\normalsize 


\index{integrateCVODES.cc@{integrate\-CVODES.cc}!sensDerivs@{sensDerivs}}
\index{sensDerivs@{sensDerivs}!integrateCVODES.cc@{integrate\-CVODES.cc}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void sens\-Derivs (double {\em t}, double $\ast$ {\em Yt}, double $\ast$ {\em Ft}, double $\ast$ {\em p})}\label{integrateCVODES_8cc_04f1a9061c83a6e0996603630ded0547}




Definition at line 72 of file int\-ODE.cc.

References dfill0(), and dmatrix().

Referenced by f(), and tabulate\-Values().

\footnotesize\begin{verbatim}73 {
74   //  sensitivity equations
75   // P=(p,y0)
76   // S=dy/dP
77   // Y=(y,S)
78   // F=dY/dt=(f,df/dy*S+df/dP)
79   // Y and F are stored in column major format and rolled out as Yt and Ft
80 
81   long i, j, k;
82   dfill0 (Ft, (1 + NPARAMS + NEQNS) * NEQNS);       // initialize to zero
83   // ode, inhomo and jacobi set only non-zero elements
84   // inhome expects a dmatrix; we create one who's data lies in Ft
85   double **dfdpt = new double *[NPARAMS] - 1;
86   for (i = 1; i <= NPARAMS; i++)
87     dfdpt[i] = Ft + i * NEQNS;
88   ode (t, Yt, Ft, p);           // first part of Y,F are y,f
89   inhomo (t, Yt, dfdpt, p);     // fill df/dp into F
90   delete[]++ dfdpt;
91 
92   // now F=df/dP
93   // add M*S, M=df/dy
94   double **M = dmatrix (1, NEQNS, 1, NEQNS);
95   dfill0 (M[1], NEQNS * NEQNS);
96   jacobi (t, Yt, M, p);         // get M
97   for (i = 1; i <= NEQNS; i++)
98     for (j = 1; j <= NPARAMS + NEQNS; j++)
99       {
100         double &sum = Ft[j * NEQNS + i];
101         for (k = 1; k <= NEQNS; k++)
102           sum += M[k][i] * Yt[j * NEQNS + k];
103       }                         // for i,j
104   free_dmatrix (M, 1, NEQNS, 1, NEQNS);
105  }                               // sensDerivs
\end{verbatim}\normalsize 


