Index: branches/2925_AutoDiffForDynamicalModels/AutoDiffForDynamicalModelsTest/TestCvodes.cs
===================================================================
--- branches/2925_AutoDiffForDynamicalModels/AutoDiffForDynamicalModelsTest/TestCvodes.cs	(revision 16246)
+++ branches/2925_AutoDiffForDynamicalModels/AutoDiffForDynamicalModelsTest/TestCvodes.cs	(revision 16248)
@@ -10,8 +10,8 @@
       // test vectors
       var arr = new double[] { 3.14, 2.71 };
-      var vec = Problem.N_VMake_Serial(2, arr);
-      Problem.N_VDestroy_Serial(vec);
-
-      vec = Problem.N_VNew_Serial(10);
+      var vec = CVODES.N_VMake_Serial(2, arr);
+      CVODES.N_VDestroy_Serial(vec);
+
+      vec = CVODES.N_VNew_Serial(10);
 
       unsafe {
@@ -24,42 +24,42 @@
         double data0 = *data;
       }
-      Problem.N_VConst_Serial(2.0, vec);
-      Problem.N_VPrint_Serial(vec);
-      Assert.AreEqual(20, Problem.N_VL1Norm_Serial(vec));
-      Problem.N_VDestroy_Serial(vec);
+      CVODES.N_VConst_Serial(2.0, vec);
+      CVODES.N_VPrint_Serial(vec);
+      Assert.AreEqual(20, CVODES.N_VL1Norm_Serial(vec));
+      CVODES.N_VDestroy_Serial(vec);
 
 
       // linear oscillator
       int numberOfEquations = 2;
-      var y = Problem.N_VNew_Serial(numberOfEquations);
+      var y = CVODES.N_VNew_Serial(numberOfEquations);
       // y must be initialized before calling CVodeInit
-      // Problem.N_VConst_Serial(100.0, y);
-      Problem.NV_Set_Ith_S(y, 0, 0.5); // x
-      Problem.NV_Set_Ith_S(y, 1, 1);  // v
-
-      var cvode_mem = Problem.CVodeCreate(Problem.MultistepMethod.CV_ADAMS, Problem.NonlinearSolverIteration.CV_FUNCTIONAL);
-
-      var flag = Problem.CVodeInit(cvode_mem, F, 0.0, y);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
-
-      flag = Problem.CVodeSStolerances(cvode_mem, 1E-4, 1.0);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
-
-      var A = Problem.SUNDenseMatrix(numberOfEquations, numberOfEquations);
+      // CVODES.N_VConst_Serial(100.0, y);
+      CVODES.NV_Set_Ith_S(y, 0, 0.5); // x
+      CVODES.NV_Set_Ith_S(y, 1, 1);  // v
+
+      var cvode_mem = CVODES.CVodeCreate(CVODES.MultistepMethod.CV_ADAMS, CVODES.NonlinearSolverIteration.CV_FUNCTIONAL);
+
+      var flag = CVODES.CVodeInit(cvode_mem, F, 0.0, y);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
+
+      flag = CVODES.CVodeSStolerances(cvode_mem, 1E-4, 1.0);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
+
+      var A = CVODES.SUNDenseMatrix(numberOfEquations, numberOfEquations);
       Assert.AreNotSame(A, IntPtr.Zero);
 
 
-      var linearSolver = Problem.SUNDenseLinearSolver(y, A);
+      var linearSolver = CVODES.SUNDenseLinearSolver(y, A);
       Assert.AreNotSame(linearSolver, IntPtr.Zero);
 
-      flag = Problem.CVDlsSetLinearSolver(cvode_mem, linearSolver, A);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
-
-      // flag = Problem.CVDlsSetJacFn(cvode_mem, JacF);
-      // Assert.AreEqual(Problem.CV_SUCCESS, flag);
+      flag = CVODES.CVDlsSetLinearSolver(cvode_mem, linearSolver, A);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
+
+      // flag = CVODES.CVDlsSetJacFn(cvode_mem, JacF);
+      // Assert.AreEqual(CVODES.CV_SUCCESS, flag);
 
       // var ns = 1; // number of parameters
       // var p = new double[1]; // set as user-data
-      // var yS0 = Problem.N_VCloneVectorArray_Serial(ns, y); // clone the output vector for each parameter, TODO: free
+      // var yS0 = CVODES.N_VCloneVectorArray_Serial(ns, y); // clone the output vector for each parameter, TODO: free
       // for(int i=0;i<ns;i++) {
       // 
@@ -67,13 +67,13 @@
 
 
-      var q = Problem.N_VNew_Serial(1);
-      Problem.NV_Set_Ith_S(q, 0, 0.0);
-      flag = Problem.CVodeQuadInit(cvode_mem, FQ, q);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
+      var q = CVODES.N_VNew_Serial(1);
+      CVODES.NV_Set_Ith_S(q, 0, 0.0);
+      flag = CVODES.CVodeQuadInit(cvode_mem, FQ, q);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
 
 
       int steps = 10;
-      flag = Problem.CVodeAdjInit(cvode_mem, steps, Problem.CV_HERMITE);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
+      flag = CVODES.CVodeAdjInit(cvode_mem, steps, CVODES.CV_HERMITE);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
 
       /* step by step forward integration 
@@ -82,8 +82,8 @@
       int nout = 100; // number of output times
       for (int iout = 0; iout < nout; iout++) {
-        flag = Problem.CVode(cvode_mem, tout, y, ref t, Problem.CV_NORMAL);
-        Assert.AreEqual(Problem.CV_SUCCESS, flag);
-        Console.WriteLine("{0} {1} {2}", t, Problem.NV_Get_Ith_S(y, 0), Problem.NV_Get_Ith_S(y, 1));
-        // Problem.N_VPrint_Serial(y);
+        flag = CVODES.CVode(cvode_mem, tout, y, ref t, CVODES.CV_NORMAL);
+        Assert.AreEqual(CVODES.CV_SUCCESS, flag);
+        Console.WriteLine("{0} {1} {2}", t, CVODES.NV_Get_Ith_S(y, 0), CVODES.NV_Get_Ith_S(y, 1));
+        // CVODES.N_VPrint_Serial(y);
         tout += 0.1; 
       }
@@ -94,85 +94,85 @@
       double time = 0.0;
       int ncheck = 0; // number of checkpoints
-      flag = Problem.CVodeF(cvode_mem, tout, y, ref time, Problem.CV_NORMAL, ref ncheck);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
+      flag = CVODES.CVodeF(cvode_mem, tout, y, ref time, CVODES.CV_NORMAL, ref ncheck);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
 
       long numSteps = 0;
-      flag = Problem.CVodeGetNumSteps(cvode_mem, ref numSteps);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
-
-      var yB = Problem.N_VNew_Serial(numberOfEquations);
-      Problem.N_VConst_Serial(0.0, yB);
+      flag = CVODES.CVodeGetNumSteps(cvode_mem, ref numSteps);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
+
+      var yB = CVODES.N_VNew_Serial(numberOfEquations);
+      CVODES.N_VConst_Serial(0.0, yB);
 
       int numberOfParameters = 2;
-      var qB = Problem.N_VNew_Serial(numberOfParameters);
-      Problem.N_VConst_Serial(0.0, qB);
+      var qB = CVODES.N_VNew_Serial(numberOfParameters);
+      CVODES.N_VConst_Serial(0.0, qB);
 
       int indexB = 0;
-      flag = Problem.CVodeCreateB(cvode_mem, Problem.MultistepMethod.CV_BDF, Problem.NonlinearSolverIteration.CV_NEWTON, ref indexB);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
+      flag = CVODES.CVodeCreateB(cvode_mem, CVODES.MultistepMethod.CV_BDF, CVODES.NonlinearSolverIteration.CV_NEWTON, ref indexB);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
 
       var TB1 = tout;
-      flag = Problem.CVodeInitB(cvode_mem, indexB, FB, TB1, yB);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
+      flag = CVODES.CVodeInitB(cvode_mem, indexB, FB, TB1, yB);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
 
       var relTolB = 1E-6;
       var absTolB = 1E-8;
-      flag = Problem.CVodeSStolerancesB(cvode_mem, indexB, relTolB, absTolB);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
-
-      var AB = Problem.SUNDenseMatrix(numberOfEquations, numberOfEquations);
+      flag = CVODES.CVodeSStolerancesB(cvode_mem, indexB, relTolB, absTolB);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
+
+      var AB = CVODES.SUNDenseMatrix(numberOfEquations, numberOfEquations);
       Assert.AreNotSame(linearSolver, IntPtr.Zero);
 
-      var lsB = Problem.SUNDenseLinearSolver(yB, AB);
+      var lsB = CVODES.SUNDenseLinearSolver(yB, AB);
       Assert.AreNotSame(linearSolver, IntPtr.Zero);
 
-      flag = Problem.CVDlsSetLinearSolverB(cvode_mem, indexB, lsB, AB);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
-
-      flag = Problem.CVDlsSetJacFnB(cvode_mem, indexB, JacFB);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
-
-      flag = Problem.CVodeQuadInitB(cvode_mem, indexB, FQB, qB);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
+      flag = CVODES.CVDlsSetLinearSolverB(cvode_mem, indexB, lsB, AB);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
+
+      flag = CVODES.CVDlsSetJacFnB(cvode_mem, indexB, JacFB);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
+
+      flag = CVODES.CVodeQuadInitB(cvode_mem, indexB, FQB, qB);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
 
       /* First get results at t = TBout1 */
 
-      /* Call CVodeB to integrate the backward ODE problem. */
+      /* Call CVodeB to integrate the backward ODE CVODES. */
       var tBackOut = 50.0;
-      flag = Problem.CVodeB(cvode_mem, tBackOut, Problem.CV_NORMAL);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
-
-      /* Call CVodeGetB to get yB of the backward ODE problem. */
-      flag = Problem.CVodeGetB(cvode_mem, indexB, ref time, yB);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
+      flag = CVODES.CVodeB(cvode_mem, tBackOut, CVODES.CV_NORMAL);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
+
+      /* Call CVodeGetB to get yB of the backward ODE CVODES. */
+      flag = CVODES.CVodeGetB(cvode_mem, indexB, ref time, yB);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
 
       /* Call CVodeGetAdjY to get the interpolated value of the forward solution
          y during a backward integration. */
-      flag = Problem.CVodeGetAdjY(cvode_mem, tBackOut, y);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
+      flag = CVODES.CVodeGetAdjY(cvode_mem, tBackOut, y);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
 
       /* Then at t = T0 */
 
       double t0 = 0.0;
-      flag = Problem.CVodeB(cvode_mem, t0, Problem.CV_NORMAL);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
+      flag = CVODES.CVodeB(cvode_mem, t0, CVODES.CV_NORMAL);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
 
       long nstB = 0;
-      Problem.CVodeGetNumSteps(Problem.CVodeGetAdjCVodeBmem(cvode_mem, indexB), ref nstB);
-
-      flag = Problem.CVodeGetB(cvode_mem, indexB, ref time, yB);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
-
-
-      flag = Problem.CVodeGetQuadB(cvode_mem, indexB, ref time, qB);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
-
-      flag = Problem.CVodeGetAdjY(cvode_mem, t0, y);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
-
-      Problem.N_VDestroy_Serial(y);
-      Problem.CVodeFree(cvode_mem);
-      Problem.SUNLinSolFree(linearSolver);
-      Problem.SUNMatDestroy(A);
+      CVODES.CVodeGetNumSteps(CVODES.CVodeGetAdjCVodeBmem(cvode_mem, indexB), ref nstB);
+
+      flag = CVODES.CVodeGetB(cvode_mem, indexB, ref time, yB);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
+
+
+      flag = CVODES.CVodeGetQuadB(cvode_mem, indexB, ref time, qB);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
+
+      flag = CVODES.CVodeGetAdjY(cvode_mem, t0, y);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
+
+      CVODES.N_VDestroy_Serial(y);
+      CVODES.CVodeFree(cvode_mem);
+      CVODES.SUNLinSolFree(linearSolver);
+      CVODES.SUNMatDestroy(A);
     }
 
@@ -182,63 +182,63 @@
       // linear oscillator
       int numberOfEquations = 2;
-      var y = Problem.N_VNew_Serial(numberOfEquations);
+      var y = CVODES.N_VNew_Serial(numberOfEquations);
       // y must be initialized before calling CVodeInit
-      // Problem.N_VConst_Serial(100.0, y);
-      Problem.NV_Set_Ith_S(y, 0, 0.5); // x
-      Problem.NV_Set_Ith_S(y, 1, 1);  // v
-
-      var cvode_mem = Problem.CVodeCreate(Problem.MultistepMethod.CV_ADAMS, Problem.NonlinearSolverIteration.CV_FUNCTIONAL);
-
-      var flag = Problem.CVodeInit(cvode_mem, F, 0.0, y);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
-
-      flag = Problem.CVodeSStolerances(cvode_mem, 1E-4, 1.0);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
-
-      var A = Problem.SUNDenseMatrix(numberOfEquations, numberOfEquations);
+      // CVODES.N_VConst_Serial(100.0, y);
+      CVODES.NV_Set_Ith_S(y, 0, 0.5); // x
+      CVODES.NV_Set_Ith_S(y, 1, 1);  // v
+
+      var cvode_mem = CVODES.CVodeCreate(CVODES.MultistepMethod.CV_ADAMS, CVODES.NonlinearSolverIteration.CV_FUNCTIONAL);
+
+      var flag = CVODES.CVodeInit(cvode_mem, F, 0.0, y);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
+
+      flag = CVODES.CVodeSStolerances(cvode_mem, 1E-4, 1.0);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
+
+      var A = CVODES.SUNDenseMatrix(numberOfEquations, numberOfEquations);
       Assert.AreNotSame(A, IntPtr.Zero);
-      Console.WriteLine(Problem.SUNDenseMatrix_Get(A, 0, 0));
-
-
-      var linearSolver = Problem.SUNDenseLinearSolver(y, A);
+      Console.WriteLine(CVODES.SUNDenseMatrix_Get(A, 0, 0));
+
+
+      var linearSolver = CVODES.SUNDenseLinearSolver(y, A);
       Assert.AreNotSame(linearSolver, IntPtr.Zero);
 
-      flag = Problem.CVDlsSetLinearSolver(cvode_mem, linearSolver, A);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
-
-      flag = Problem.CVDlsSetJacFn(cvode_mem, JacF);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
+      flag = CVODES.CVDlsSetLinearSolver(cvode_mem, linearSolver, A);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
+
+      flag = CVODES.CVDlsSetJacFn(cvode_mem, JacF);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
 
       var ns = 1; // number of parameters
       var p = new double[1]; // set as user-data
-      var yS0 = Problem.N_VCloneVectorArray_Serial(ns, y); // clone the output vector for each parameter, TODO: free
+      var yS0 = CVODES.N_VCloneVectorArray_Serial(ns, y); // clone the output vector for each parameter, TODO: free
       unsafe {
         for (int i = 0; i < ns; i++) {
           var yS0_i = *((IntPtr*)yS0.ToPointer() + i);
-          Problem.N_VConst_Serial(0.0, yS0_i);
+          CVODES.N_VConst_Serial(0.0, yS0_i);
         }
       }
 
 
-      flag = Problem.CVodeSensInit(cvode_mem, ns, Problem.CV_SIMULTANEOUS, FS, yS0);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
+      flag = CVODES.CVodeSensInit(cvode_mem, ns, CVODES.CV_SIMULTANEOUS, FS, yS0);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
 
       double reltolS = 1E-5;
       var abstolS = new double[] { 1E-6 };
-      // flag = Problem.CVodeSensSStolerances(cvode_mem, reltolS, abstolS);
-      // Assert.AreEqual(Problem.CV_SUCCESS, flag);
-      flag = Problem.CVodeSensEEtolerances(cvode_mem);
-      Assert.AreEqual(Problem.CV_SUCCESS, flag);
-
-
-      // var q = Problem.N_VNew_Serial(1);
-      // Problem.NV_Set_Ith_S(q, 0, 0.0);
-      // flag = Problem.CVodeQuadInit(cvode_mem, FQ, q);
-      // Assert.AreEqual(Problem.CV_SUCCESS, flag);
+      // flag = CVODES.CVodeSensSStolerances(cvode_mem, reltolS, abstolS);
+      // Assert.AreEqual(CVODES.CV_SUCCESS, flag);
+      flag = CVODES.CVodeSensEEtolerances(cvode_mem);
+      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
+
+
+      // var q = CVODES.N_VNew_Serial(1);
+      // CVODES.NV_Set_Ith_S(q, 0, 0.0);
+      // flag = CVODES.CVodeQuadInit(cvode_mem, FQ, q);
+      // Assert.AreEqual(CVODES.CV_SUCCESS, flag);
 
 
       // int steps = 10;
-      // flag = Problem.CVodeAdjInit(cvode_mem, steps, Problem.CV_HERMITE);
-      // Assert.AreEqual(Problem.CV_SUCCESS, flag);
+      // flag = CVODES.CVodeAdjInit(cvode_mem, steps, CVODES.CV_HERMITE);
+      // Assert.AreEqual(CVODES.CV_SUCCESS, flag);
 
       // step by step forward integration 
@@ -247,13 +247,13 @@
       int nout = 1000; // number of output times
       for (int iout = 0; iout < nout; iout++) {
-        flag = Problem.CVode(cvode_mem, tout, y, ref t, Problem.CV_NORMAL);
-        Assert.AreEqual(Problem.CV_SUCCESS, flag);
+        flag = CVODES.CVode(cvode_mem, tout, y, ref t, CVODES.CV_NORMAL);
+        Assert.AreEqual(CVODES.CV_SUCCESS, flag);
 
         // get sensitivities
-        flag = Problem.CVodeGetSens(cvode_mem, ref t, yS0);
-        Assert.AreEqual(Problem.CV_SUCCESS, flag);
+        flag = CVODES.CVodeGetSens(cvode_mem, ref t, yS0);
+        Assert.AreEqual(CVODES.CV_SUCCESS, flag);
         unsafe {
           var ySP0 = *(IntPtr*)yS0.ToPointer(); // parameter of sensitivities for first component
-          Console.WriteLine("{0} {1} {2} {3} {4}", t, Problem.NV_Get_Ith_S(y, 0), Problem.NV_Get_Ith_S(y, 1), Problem.NV_Get_Ith_S(ySP0, 0), Problem.NV_Get_Ith_S(ySP0, 1));
+          Console.WriteLine("{0} {1} {2} {3} {4}", t, CVODES.NV_Get_Ith_S(y, 0), CVODES.NV_Get_Ith_S(y, 1), CVODES.NV_Get_Ith_S(ySP0, 0), CVODES.NV_Get_Ith_S(ySP0, 1));
         }
 
@@ -263,8 +263,8 @@
 
 
-      Problem.N_VDestroy_Serial(y);
-      Problem.CVodeFree(cvode_mem);
-      Problem.SUNLinSolFree(linearSolver);
-      Problem.SUNMatDestroy(A);
+      CVODES.N_VDestroy_Serial(y);
+      CVODES.CVodeFree(cvode_mem);
+      CVODES.SUNLinSolFree(linearSolver);
+      CVODES.SUNMatDestroy(A);
     }
 
@@ -280,6 +280,6 @@
       // ∂y1/∂t = y2
       // ∂y2/∂t = -0.3 y1
-      Problem.NV_Set_Ith_S(ydot, 0, Problem.NV_Get_Ith_S(y, 1));
-      Problem.NV_Set_Ith_S(ydot, 1, -0.3 * Problem.NV_Get_Ith_S(y, 0));
+      CVODES.NV_Set_Ith_S(ydot, 0, CVODES.NV_Get_Ith_S(y, 1));
+      CVODES.NV_Set_Ith_S(ydot, 1, -0.3 * CVODES.NV_Get_Ith_S(y, 0));
       return 0;
       ;
@@ -297,8 +297,8 @@
       //  ∂f2/∂y1  ∂f2/∂y2
 
-      Problem.SUNDenseMatrix_Set(Jac, 0, 0, 0.0);
-      Problem.SUNDenseMatrix_Set(Jac, 0, 1, 1.0);
-      Problem.SUNDenseMatrix_Set(Jac, 1, 0, -0.3);
-      Problem.SUNDenseMatrix_Set(Jac, 1, 1, 0.0);
+      CVODES.SUNDenseMatrix_Set(Jac, 0, 0, 0.0);
+      CVODES.SUNDenseMatrix_Set(Jac, 0, 1, 1.0);
+      CVODES.SUNDenseMatrix_Set(Jac, 1, 0, -0.3);
+      CVODES.SUNDenseMatrix_Set(Jac, 1, 1, 0.0);
       return 0;
     }
@@ -323,18 +323,18 @@
 
       // (∂f /∂y)s_i(t) + ∂f /∂p_i
-      var y1 = Problem.NV_Get_Ith_S(y, 0); var y2 = Problem.NV_Get_Ith_S(y, 1);
+      var y1 = CVODES.NV_Get_Ith_S(y, 0); var y2 = CVODES.NV_Get_Ith_S(y, 1);
 
       unsafe {
         var yS_p0 = *(IntPtr*)yS.ToPointer();
-        var s1 = Problem.NV_Get_Ith_S(yS_p0, 0); var s2 = Problem.NV_Get_Ith_S(yS_p0, 1);
-
-
-        // (∂f /∂y)s_i(t)  = Jac s_i(t)
+        var s1 = CVODES.NV_Get_Ith_S(yS_p0, 0); var s2 = CVODES.NV_Get_Ith_S(yS_p0, 1);
+
+
+        // (∂f /∂y)s_i(t)  == Jac s_i(t)
         var sd1 = s2;
         var sd2 = -0.3 * s1;
 
         var s_p0 = *(IntPtr*)ySdot.ToPointer();
-        Problem.NV_Set_Ith_S(s_p0, 0, sd1 + 0.0);
-        Problem.NV_Set_Ith_S(s_p0, 1, sd2 - 0.3);
+        CVODES.NV_Set_Ith_S(s_p0, 0, sd1 + 0.0);
+        CVODES.NV_Set_Ith_S(s_p0, 1, sd2 - 0.3);
       }
 
@@ -365,6 +365,6 @@
       // λ2' = 1.0 λ1 - 0.0
 
-      Problem.NV_Set_Ith_S(yBdot, 0, 0.3 * Problem.NV_Get_Ith_S(yB, 1));
-      Problem.NV_Set_Ith_S(yBdot, 1, Problem.NV_Get_Ith_S(yB, 0));
+      CVODES.NV_Set_Ith_S(yBdot, 0, 0.3 * CVODES.NV_Get_Ith_S(yB, 1));
+      CVODES.NV_Set_Ith_S(yBdot, 1, CVODES.NV_Get_Ith_S(yB, 0));
 
       return 0;
@@ -374,5 +374,5 @@
     private int FQ(double t, IntPtr y, IntPtr yQdot, IntPtr user_data) {
       // TODO: squared error
-      Problem.NV_Set_Ith_S(yQdot, 0, Problem.NV_Get_Ith_S(y, 2));
+      CVODES.NV_Set_Ith_S(yQdot, 0, CVODES.NV_Get_Ith_S(y, 2));
       return 0;
     }
Index: branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/CVODES.cs
===================================================================
--- branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/CVODES.cs	(revision 16248)
+++ branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/CVODES.cs	(revision 16248)
@@ -0,0 +1,504 @@
+﻿using System;
+using System.Runtime.InteropServices;
+
+namespace HeuristicLab.Problems.DynamicalSystemsModelling {
+  public static class CVODES {
+
+    // CVODES types
+    public enum MultistepMethod : int { CV_ADAMS = 1, CV_BDF = 2 };
+    public enum NonlinearSolverIteration : int { CV_NEWTON = 1, CV_FUNCTIONAL = 2 };
+
+
+    /* itask */
+    public const int CV_NORMAL = 1;
+    public const int CV_ONE_STEP = 2;
+
+    /* ism */
+    public const int CV_SIMULTANEOUS = 1;
+    public const int CV_STAGGERED = 2;
+    public const int CV_STAGGERED1 = 3;
+
+    /* DQtype */
+    public const int CV_CENTERED = 1;
+    public const int CV_FORWARD = 2;
+
+    /* interp */
+    public const int CV_HERMITE = 1;
+    public const int CV_POLYNOMIAL = 2;
+
+    /* 
+     * ----------------------------------------
+     * CVODES return flags
+     * ----------------------------------------
+     */
+
+    public const int CV_SUCCESS = 0;
+    public const int CV_TSTOP_RETURN = 1;
+    public const int CV_ROOT_RETURN = 2;
+
+    public const int CV_WARNING = 99;
+
+    public const int CV_TOO_MUCH_WORK = -1;
+    public const int CV_TOO_MUCH_ACC = -2;
+    public const int CV_ERR_FAILURE = -3;
+    public const int CV_CONV_FAILURE = -4;
+
+    public const int CV_LINIT_FAIL = -5;
+    public const int CV_LSETUP_FAIL = -6;
+    public const int CV_LSOLVE_FAIL = -7;
+    public const int CV_RHSFUNC_FAIL = -8;
+    public const int CV_FIRST_RHSFUNC_ERR = -9;
+    public const int CV_REPTD_RHSFUNC_ERR = -10;
+    public const int CV_UNREC_RHSFUNC_ERR = -11;
+    public const int CV_RTFUNC_FAIL = -12;
+    public const int CV_CONSTR_FAIL = -13;
+
+    public const int CV_MEM_FAIL = -20;
+    public const int CV_MEM_NULL = -21;
+    public const int CV_ILL_INPUT = -22;
+    public const int CV_NO_MALLOC = -23;
+    public const int CV_BAD_K = -24;
+    public const int CV_BAD_T = -25;
+    public const int CV_BAD_DKY = -26;
+    public const int CV_TOO_CLOSE = -27;
+
+    public const int CV_NO_QUAD = -30;
+    public const int CV_QRHSFUNC_FAIL = -31;
+    public const int CV_FIRST_QRHSFUNC_ERR = -32;
+    public const int CV_REPTD_QRHSFUNC_ERR = -33;
+    public const int CV_UNREC_QRHSFUNC_ERR = -34;
+
+    public const int CV_NO_SENS = -40;
+    public const int CV_SRHSFUNC_FAIL = -41;
+    public const int CV_FIRST_SRHSFUNC_ERR = -42;
+    public const int CV_REPTD_SRHSFUNC_ERR = -43;
+    public const int CV_UNREC_SRHSFUNC_ERR = -44;
+
+    public const int CV_BAD_IS = -45;
+
+    public const int CV_NO_QUADSENS = -50;
+    public const int CV_QSRHSFUNC_FAIL = -51;
+    public const int CV_FIRST_QSRHSFUNC_ERR = -52;
+    public const int CV_REPTD_QSRHSFUNC_ERR = -53;
+    public const int CV_UNREC_QSRHSFUNC_ERR = -54;
+
+    /* 
+     * ----------------------------------------
+     * CVODEA return flags
+     * ----------------------------------------
+     */
+
+    public const int CV_NO_ADJ = -101;
+    public const int CV_NO_FWD = -102;
+    public const int CV_NO_BCK = -103;
+    public const int CV_BAD_TB0 = -104;
+    public const int CV_REIFWD_FAIL = -105;
+    public const int CV_FWD_FAIL = -106;
+
+
+    public const int CV_GETY_BADT = -107;
+
+    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+    public delegate int CVRhsFunc(
+        double t, // realtype
+        IntPtr y, // N_Vector
+        IntPtr ydot, // N_Vector
+        IntPtr user_data
+      );
+
+    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+    public delegate int CVRhsFuncB(
+        double t, // realtype
+        IntPtr y, // N_Vector
+        IntPtr yB, // N_Vector
+        IntPtr yBdot, // N_Vector
+        IntPtr user_data
+      );
+
+    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+    public delegate int CVDlsJacFunc(
+      double t,
+      IntPtr y, // N_Vector
+      IntPtr fy, // N_Vector
+      IntPtr Jac, // SUNMatrix
+      IntPtr user_data,
+      IntPtr tmp1, // N_Vector
+      IntPtr tmp2, // N_Vector
+      IntPtr tmp3 // N_Vector
+      );
+
+    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+    public delegate int CVDlsJacFuncB(
+      double t,
+      IntPtr y, // N_Vector
+      IntPtr yB, // N_Vector
+      IntPtr fyB, // N_Vector
+      IntPtr Jac, // SUNMatrix
+      IntPtr user_data,
+      IntPtr tmp1, // N_Vector
+      IntPtr tmp2, // N_Vector
+      IntPtr tmp3 // N_Vector
+    );
+
+    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+    public delegate int CVQuadRhsFn(
+      double t,
+      IntPtr y, // N_Vector
+      IntPtr yQdot, // N_Vector
+      IntPtr user_data
+      );
+
+    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+    public delegate int CVQuadRhsFnB(
+      double t,
+      IntPtr y, // N_Vector
+      IntPtr yB, // N_Vector
+      IntPtr qBdot, // N_Vector
+      IntPtr user_data
+      );
+
+
+    // to calculate sensitivities RHS for all equations at once
+    // must compute (∂f/∂y)s_i(t) + ∂f/∂p_i
+    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+    public delegate int CVSensRhsFn(
+      int Ns,
+      double t,
+      IntPtr y, // N_Vector
+      IntPtr ydot, // N_Vector
+      IntPtr yS, // N_Vector* one vector for each parameter
+      IntPtr ySdot, // N_Vector* one vector for each parameter
+      IntPtr user_data,
+      IntPtr tmp1, // N_Vector
+      IntPtr tmp2 // N_Vector
+    );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeCreate", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    // returns a void* to the cvodes memory block if successful otherwise NULL
+    public static extern IntPtr CVodeCreate(MultistepMethod lmm, NonlinearSolverIteration iter);
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVodeInit(
+      IntPtr cvode_mem, // pointer returned by CVodeCreate
+      CVRhsFunc f,
+      double t0, // realtype, the inital value of t
+      IntPtr y0 // N_Vector the initial value of y
+    );
+
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeSStolerances", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVodeSStolerances(
+      IntPtr cvode_mem,
+      double reltol,
+      double abstol
+      );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVDlsSetLinearSolver", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVDlsSetLinearSolver(
+      IntPtr cvode_mem,
+      IntPtr linearSolver, // SUNLinearSolver
+      IntPtr j // SUNMatrix
+      );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVDlsSetJacFn", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVDlsSetJacFn(
+      IntPtr cvode_mem,
+      CVDlsJacFunc jacFunc
+      );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeSensInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVodeSensInit(
+      IntPtr cvode_mem,
+      int Ns, // number of parameters
+      int ism, // sensitivity solution method, CV_SIMULTANEOUS or CV_STAGGERED
+      CVSensRhsFn fS, // right hand side function which computes all sensitivity RHS at the same time
+      IntPtr yS0 // N_Vector
+      );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeSensSStolerances", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVodeSensSStolerances(
+      IntPtr cvode_mem,
+      double reltol,
+      double[] abstol
+    );
+
+    /* Call CVodeSensEEtolerances to estimate tolerances for sensitivity 
+   variables based on the rolerances supplied for states variables and 
+   the scaling factor pbar */
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeSensEEtolerances", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVodeSensEEtolerances(
+      IntPtr cvode_mem
+      );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeGetSens", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVodeGetSens(
+      IntPtr cvode_mem,
+      ref double tret,
+      IntPtr yS //N_Vector*, one vector for each parameter
+      );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeQuadInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVodeQuadInit(
+      IntPtr cvode_mem,
+      CVQuadRhsFn qF,
+      IntPtr yQ0 // N_Vector, initial value of yQ
+      );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeQuadInitB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVodeQuadInitB(
+      IntPtr cvode_mem,
+      int indexB,
+      CVQuadRhsFnB rhsQB,
+      IntPtr yQB0 // N_Vector, initial value of yQB
+    );
+
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeAdjInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVodeAdjInit(
+      IntPtr cvode_mem,
+      int nd,  // integration steps between checkpoints
+      int interpType // either CV_POLYNOMIAL or CV_HERMITE
+      );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeF", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVodeF(
+        IntPtr cvode_mem,
+        double t_out, // the next time at which a computed solution is desired
+        IntPtr y, // N_Vector, the solution vector y
+        ref double t_ret, // the time reached by the solver (output)
+        int itask, // CV_NORMAL or CV_ONE_STEP
+        ref int ncheck  // the number of internal checkpoints stored so far.
+      );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeGetNumSteps", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVodeGetNumSteps(
+      IntPtr cvode_mem,
+      ref long ncheck  // the number of steps taken
+    );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeCreateB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVodeCreateB(
+        IntPtr cvode_mem,
+        MultistepMethod lmmB,
+        NonlinearSolverIteration iterB,
+        ref int which
+      );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeInitB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVodeInitB(
+        IntPtr cvode_mem,
+        int which,
+        CVRhsFuncB rightHandSide,
+        double tB0, // endpoint T where final conditions are provided (equal to endpoint of forward integration)
+        IntPtr yB0 // N_Vector inital value at t=tb0 of backward solution
+      );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVode", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVode(
+      IntPtr cvode_mem,
+      double tout, // next time at which a solution is desired
+      IntPtr yout, // N_Vector
+      ref double tret, // the time reached by the solver (output)
+      int itask // flag indicating the job of the solver for the next step. 
+      );
+
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeSStolerancesB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVodeSStolerancesB(
+      IntPtr cvode_mem,
+      int which,
+      double reltol,
+      double abstol
+    );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVDlsSetLinearSolverB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVDlsSetLinearSolverB(
+      IntPtr cvode_mem,
+      int which,
+      IntPtr linearSolver, // SUNLinearSolver
+      IntPtr j // SUNMatrix
+    );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVDlsSetJacFnB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVDlsSetJacFnB(
+      IntPtr cvode_mem,
+      int which,
+      CVDlsJacFuncB jacFunc
+    );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVodeB(
+      IntPtr cvode_mem,
+      double tout, // next time at which a solution is desired
+      int itask // flag indicating the job of the solver for the next step. 
+    );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeGetB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVodeGetB(
+          IntPtr cvode_mem,
+          int which,
+          ref double tret,
+          IntPtr yB // the backward solution at time tret
+        );
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeGetAdjY", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVodeGetAdjY(
+          IntPtr cvode_mem,
+          double t,
+          IntPtr y // the forward solution y(t)
+        );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeGetAdjCVodeBmem", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern IntPtr CVodeGetAdjCVodeBmem(
+              IntPtr cvode_mem,
+              int which
+            );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeGetQuadB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int CVodeGetQuadB(
+        IntPtr cvode_mem,
+        int which,
+        ref double tret,
+        IntPtr yQB // N_Vector
+      );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeFree", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+
+    public static extern int CVodeFree(IntPtr cvode_mem);
+
+    #region matrix
+    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNDenseMatrix", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern IntPtr SUNDenseMatrix(long m, long n);
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNMatDestroy", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern void SUNMatDestroy(IntPtr A);
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNDenseMatrix_Data", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public unsafe static extern double* SUNDenseMatrix_Data(IntPtr matrix);
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNDenseMatrix_Cols", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern long SUNDenseMatrix_Cols(IntPtr matrix);
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNDenseMatrix_Rows", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern long SUNDenseMatrix_Rows(IntPtr matrix);
+
+
+    public unsafe static double SUNDenseMatrix_Get(IntPtr mat, long i, long j) {
+      long M = SUNDenseMatrix_Rows(mat);
+      // the(i, j)th element of A(with 0 <= i<M and 0 <= j<N) is given by(A->data)[j*M+i]
+      return SUNDenseMatrix_Data(mat)[j * M + i];
+    }
+
+    public unsafe static void SUNDenseMatrix_Set(IntPtr mat, long i, long j, double val) {
+      long M = SUNDenseMatrix_Rows(mat);
+      // the(i, j)th element of A(with 0 <= i<M and 0 <= j<N) is given by(A->data)[j*M+i]
+      SUNDenseMatrix_Data(mat)[j * M + i] = val;
+    }
+
+    #endregion
+
+    #region linear solver
+    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNDenseLinearSolver", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern IntPtr SUNDenseLinearSolver(
+      IntPtr y, // N_Vector
+      IntPtr A // SUNMatrix
+      );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNLinSolInitialize", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int SUNLinSolInitialize(IntPtr linearSolver);
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNLinSolSetup", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int SUNLinSolSetup(
+      IntPtr linearSolver,
+      IntPtr A // SUNMatrix
+      );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNLinSolSolve", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int SUNLinSolSolve(
+      IntPtr linearSolver,
+      IntPtr A, // SUNMatrix
+      IntPtr x, // N_Vector
+      IntPtr b, // N_Vector
+      double tol
+      );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNLinSolFree", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern int SUNLinSolFree(IntPtr linearSolver);
+
+    #endregion
+
+    #region N_Vector
+    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VNew_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern IntPtr N_VNew_Serial(long vec_length);
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VDestroy_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern void N_VDestroy_Serial(IntPtr vec);
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VPrint_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern void N_VPrint_Serial(IntPtr vec);
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VConst_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern void N_VConst_Serial(double c, IntPtr vec);
+
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VL1Norm_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern double N_VL1Norm_Serial(IntPtr vec);
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VMake_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern IntPtr N_VMake_Serial(long vec_length, double[] v_data);
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VScale", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    ///  Performs the operation z = c*x
+    public static extern void N_VScale(double s,
+      IntPtr x, // N_Vector
+      IntPtr z // N_Vector
+      );
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VMake_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public unsafe static extern double* N_VGetArrayPointer_Serial(IntPtr vec);
+
+    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VCloneVectorArray_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+    public static extern IntPtr N_VCloneVectorArray_Serial(int count, IntPtr vec); // returns N_Vector* !
+
+
+    /*
+#define NV_CONTENT_S(v)  ( (N_VectorContent_Serial)(v->content) )
+
+#define NV_LENGTH_S(v)   ( NV_CONTENT_S(v)->length )
+
+#define NV_OWN_DATA_S(v) ( NV_CONTENT_S(v)->own_data )
+
+#define NV_DATA_S(v)     ( NV_CONTENT_S(v)->data )
+
+#define NV_Ith_S(v,i)    ( NV_DATA_S(v)[i] )
+*/
+    // methods for macros
+    public unsafe static int* NV_CONTENT_S(IntPtr v) {
+      int* content = (int*)*(int*)v.ToPointer();
+      return content;
+    }
+
+    public unsafe static long NV_LENGTH_S(IntPtr v) {
+      long length = *NV_CONTENT_S(v);
+      return length;
+    }
+    public unsafe static bool NV_OWN_DATA_S(IntPtr v) {
+      var content = NV_CONTENT_S(v);
+      int own_data = *(content + 2);
+      return own_data > 0;
+    }
+    public unsafe static double* NV_DATA_S(IntPtr v) {
+      var content = NV_CONTENT_S(v);
+      double* data = (double*)*(content + 3);
+      return data;
+    }
+    public unsafe static double NV_Get_Ith_S(IntPtr v, long i) {
+      return NV_DATA_S(v)[i];
+    }
+    public unsafe static void NV_Set_Ith_S(IntPtr v, long i, double val) {
+      NV_DATA_S(v)[i] = val;
+    }
+    #endregion
+
+
+  }
+}
Index: branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/HeuristicLab.Problems.DynamicalSystemsModelling-3.3.csproj
===================================================================
--- branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/HeuristicLab.Problems.DynamicalSystemsModelling-3.3.csproj	(revision 16246)
+++ branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/HeuristicLab.Problems.DynamicalSystemsModelling-3.3.csproj	(revision 16248)
@@ -111,4 +111,5 @@
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="CVODES.cs" />
     <Compile Include="Plugin.cs" />
     <Compile Include="Problem.cs" />
Index: branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/Problem.cs
===================================================================
--- branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/Problem.cs	(revision 16246)
+++ branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/Problem.cs	(revision 16248)
@@ -24,5 +24,4 @@
 using System.Diagnostics;
 using System.Linq;
-using System.Runtime.InteropServices;
 using HeuristicLab.Analysis;
 using HeuristicLab.Collections;
@@ -132,500 +131,4 @@
   [StorableClass]
   public sealed class Problem : SingleObjectiveBasicProblem<MultiEncoding>, IRegressionProblem, IProblemInstanceConsumer<IRegressionProblemData>, IProblemInstanceExporter<IRegressionProblemData> {
-
-    // CVODES types
-    public enum MultistepMethod : int { CV_ADAMS = 1, CV_BDF = 2 };
-    public enum NonlinearSolverIteration : int { CV_NEWTON = 1, CV_FUNCTIONAL = 2 };
-
-
-    /* itask */
-    public const int CV_NORMAL = 1;
-    public const int CV_ONE_STEP = 2;
-
-    /* ism */
-    public const int CV_SIMULTANEOUS = 1;
-    public const int CV_STAGGERED = 2;
-    public const int CV_STAGGERED1 = 3;
-
-    /* DQtype */
-    public const int CV_CENTERED = 1;
-    public const int CV_FORWARD = 2;
-
-    /* interp */
-    public const int CV_HERMITE = 1;
-    public const int CV_POLYNOMIAL = 2;
-
-    /* 
-     * ----------------------------------------
-     * CVODES return flags
-     * ----------------------------------------
-     */
-
-    public const int CV_SUCCESS = 0;
-    public const int CV_TSTOP_RETURN = 1;
-    public const int CV_ROOT_RETURN = 2;
-
-    public const int CV_WARNING = 99;
-
-    public const int CV_TOO_MUCH_WORK = -1;
-    public const int CV_TOO_MUCH_ACC = -2;
-    public const int CV_ERR_FAILURE = -3;
-    public const int CV_CONV_FAILURE = -4;
-
-    public const int CV_LINIT_FAIL = -5;
-    public const int CV_LSETUP_FAIL = -6;
-    public const int CV_LSOLVE_FAIL = -7;
-    public const int CV_RHSFUNC_FAIL = -8;
-    public const int CV_FIRST_RHSFUNC_ERR = -9;
-    public const int CV_REPTD_RHSFUNC_ERR = -10;
-    public const int CV_UNREC_RHSFUNC_ERR = -11;
-    public const int CV_RTFUNC_FAIL = -12;
-    public const int CV_CONSTR_FAIL = -13;
-
-    public const int CV_MEM_FAIL = -20;
-    public const int CV_MEM_NULL = -21;
-    public const int CV_ILL_INPUT = -22;
-    public const int CV_NO_MALLOC = -23;
-    public const int CV_BAD_K = -24;
-    public const int CV_BAD_T = -25;
-    public const int CV_BAD_DKY = -26;
-    public const int CV_TOO_CLOSE = -27;
-
-    public const int CV_NO_QUAD = -30;
-    public const int CV_QRHSFUNC_FAIL = -31;
-    public const int CV_FIRST_QRHSFUNC_ERR = -32;
-    public const int CV_REPTD_QRHSFUNC_ERR = -33;
-    public const int CV_UNREC_QRHSFUNC_ERR = -34;
-
-    public const int CV_NO_SENS = -40;
-    public const int CV_SRHSFUNC_FAIL = -41;
-    public const int CV_FIRST_SRHSFUNC_ERR = -42;
-    public const int CV_REPTD_SRHSFUNC_ERR = -43;
-    public const int CV_UNREC_SRHSFUNC_ERR = -44;
-
-    public const int CV_BAD_IS = -45;
-
-    public const int CV_NO_QUADSENS = -50;
-    public const int CV_QSRHSFUNC_FAIL = -51;
-    public const int CV_FIRST_QSRHSFUNC_ERR = -52;
-    public const int CV_REPTD_QSRHSFUNC_ERR = -53;
-    public const int CV_UNREC_QSRHSFUNC_ERR = -54;
-
-    /* 
-     * ----------------------------------------
-     * CVODEA return flags
-     * ----------------------------------------
-     */
-
-    public const int CV_NO_ADJ = -101;
-    public const int CV_NO_FWD = -102;
-    public const int CV_NO_BCK = -103;
-    public const int CV_BAD_TB0 = -104;
-    public const int CV_REIFWD_FAIL = -105;
-    public const int CV_FWD_FAIL = -106;
-
-
-    public const int CV_GETY_BADT = -107;
-
-    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-    public delegate int CVRhsFunc(
-        double t, // realtype
-        IntPtr y, // N_Vector
-        IntPtr ydot, // N_Vector
-        IntPtr user_data
-      );
-
-    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-    public delegate int CVRhsFuncB(
-        double t, // realtype
-        IntPtr y, // N_Vector
-        IntPtr yB, // N_Vector
-        IntPtr yBdot, // N_Vector
-        IntPtr user_data
-      );
-
-    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-    public delegate int CVDlsJacFunc(
-      double t,
-      IntPtr y, // N_Vector
-      IntPtr fy, // N_Vector
-      IntPtr Jac, // SUNMatrix
-      IntPtr user_data,
-      IntPtr tmp1, // N_Vector
-      IntPtr tmp2, // N_Vector
-      IntPtr tmp3 // N_Vector
-      );
-
-    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-    public delegate int CVDlsJacFuncB(
-      double t,
-      IntPtr y, // N_Vector
-      IntPtr yB, // N_Vector
-      IntPtr fyB, // N_Vector
-      IntPtr Jac, // SUNMatrix
-      IntPtr user_data,
-      IntPtr tmp1, // N_Vector
-      IntPtr tmp2, // N_Vector
-      IntPtr tmp3 // N_Vector
-    );
-
-    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-    public delegate int CVQuadRhsFn(
-      double t,
-      IntPtr y, // N_Vector
-      IntPtr yQdot, // N_Vector
-      IntPtr user_data
-      );
-
-    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-    public delegate int CVQuadRhsFnB(
-      double t,
-      IntPtr y, // N_Vector
-      IntPtr yB, // N_Vector
-      IntPtr qBdot, // N_Vector
-      IntPtr user_data
-      );
-
-
-    // to calculate sensitivities RHS for all equations at once
-    // must compute (∂f/∂y)s_i(t) + ∂f/∂p_i
-    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-    public delegate int CVSensRhsFn(
-      int Ns,
-      double t,
-      IntPtr y, // N_Vector
-      IntPtr ydot, // N_Vector
-      IntPtr yS, // N_Vector* one vector for each parameter
-      IntPtr ySdot, // N_Vector* one vector for each parameter
-      IntPtr user_data,
-      IntPtr tmp1, // N_Vector
-      IntPtr tmp2 // N_Vector
-    );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeCreate", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    // returns a void* to the cvodes memory block if successful otherwise NULL
-    public static extern IntPtr CVodeCreate(MultistepMethod lmm, NonlinearSolverIteration iter);
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVodeInit(
-      IntPtr cvode_mem, // pointer returned by CVodeCreate
-      CVRhsFunc f,
-      double t0, // realtype, the inital value of t
-      IntPtr y0 // N_Vector the initial value of y
-    );
-
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeSStolerances", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVodeSStolerances(
-      IntPtr cvode_mem,
-      double reltol,
-      double abstol
-      );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVDlsSetLinearSolver", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVDlsSetLinearSolver(
-      IntPtr cvode_mem,
-      IntPtr linearSolver, // SUNLinearSolver
-      IntPtr j // SUNMatrix
-      );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVDlsSetJacFn", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVDlsSetJacFn(
-      IntPtr cvode_mem,
-      CVDlsJacFunc jacFunc
-      );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeSensInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVodeSensInit(
-      IntPtr cvode_mem,
-      int Ns, // number of parameters
-      int ism, // sensitivity solution method, CV_SIMULTANEOUS or CV_STAGGERED
-      CVSensRhsFn fS, // right hand side function which computes all sensitivity RHS at the same time
-      IntPtr yS0 // N_Vector
-      );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeSensSStolerances", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVodeSensSStolerances(
-      IntPtr cvode_mem,
-      double reltol,
-      double[] abstol
-    );
-
-    /* Call CVodeSensEEtolerances to estimate tolerances for sensitivity 
-   variables based on the rolerances supplied for states variables and 
-   the scaling factor pbar */
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeSensEEtolerances", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVodeSensEEtolerances(
-      IntPtr cvode_mem
-      );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeGetSens", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVodeGetSens(
-      IntPtr cvode_mem,
-      ref double tret,
-      IntPtr yS //N_Vector*, one vector for each parameter
-      );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeQuadInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVodeQuadInit(
-      IntPtr cvode_mem,
-      CVQuadRhsFn qF,
-      IntPtr yQ0 // N_Vector, initial value of yQ
-      );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeQuadInitB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVodeQuadInitB(
-      IntPtr cvode_mem,
-      int indexB,
-      CVQuadRhsFnB rhsQB,
-      IntPtr yQB0 // N_Vector, initial value of yQB
-    );
-
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeAdjInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVodeAdjInit(
-      IntPtr cvode_mem,
-      int nd,  // integration steps between checkpoints
-      int interpType // either CV_POLYNOMIAL or CV_HERMITE
-      );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeF", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVodeF(
-        IntPtr cvode_mem,
-        double t_out, // the next time at which a computed solution is desired
-        IntPtr y, // N_Vector, the solution vector y
-        ref double t_ret, // the time reached by the solver (output)
-        int itask, // CV_NORMAL or CV_ONE_STEP
-        ref int ncheck  // the number of internal checkpoints stored so far.
-      );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeGetNumSteps", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVodeGetNumSteps(
-      IntPtr cvode_mem,
-      ref long ncheck  // the number of steps taken
-    );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeCreateB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVodeCreateB(
-        IntPtr cvode_mem,
-        MultistepMethod lmmB,
-        NonlinearSolverIteration iterB,
-        ref int which
-      );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeInitB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVodeInitB(
-        IntPtr cvode_mem,
-        int which,
-        CVRhsFuncB rightHandSide,
-        double tB0, // endpoint T where final conditions are provided (equal to endpoint of forward integration)
-        IntPtr yB0 // N_Vector inital value at t=tb0 of backward solution
-      );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVode", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVode(
-      IntPtr cvode_mem,
-      double tout, // next time at which a solution is desired
-      IntPtr yout, // N_Vector
-      ref double tret, // the time reached by the solver (output)
-      int itask // flag indicating the job of the solver for the next step. 
-      );
-
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeSStolerancesB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVodeSStolerancesB(
-      IntPtr cvode_mem,
-      int which,
-      double reltol,
-      double abstol
-    );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVDlsSetLinearSolverB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVDlsSetLinearSolverB(
-      IntPtr cvode_mem,
-      int which,
-      IntPtr linearSolver, // SUNLinearSolver
-      IntPtr j // SUNMatrix
-    );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVDlsSetJacFnB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVDlsSetJacFnB(
-      IntPtr cvode_mem,
-      int which,
-      CVDlsJacFuncB jacFunc
-    );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVodeB(
-      IntPtr cvode_mem,
-      double tout, // next time at which a solution is desired
-      int itask // flag indicating the job of the solver for the next step. 
-    );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeGetB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVodeGetB(
-          IntPtr cvode_mem,
-          int which,
-          ref double tret,
-          IntPtr yB // the backward solution at time tret
-        );
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeGetAdjY", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVodeGetAdjY(
-          IntPtr cvode_mem,
-          double t,
-          IntPtr y // the forward solution y(t)
-        );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeGetAdjCVodeBmem", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern IntPtr CVodeGetAdjCVodeBmem(
-              IntPtr cvode_mem,
-              int which
-            );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeGetQuadB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int CVodeGetQuadB(
-        IntPtr cvode_mem,
-        int which,
-        ref double tret,
-        IntPtr yQB // N_Vector
-      );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "CVodeFree", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-
-    public static extern int CVodeFree(IntPtr cvode_mem);
-
-    #region matrix
-    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNDenseMatrix", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern IntPtr SUNDenseMatrix(long m, long n);
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNMatDestroy", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern void SUNMatDestroy(IntPtr A);
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNDenseMatrix_Data", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public unsafe static extern double* SUNDenseMatrix_Data(IntPtr matrix);
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNDenseMatrix_Cols", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern long SUNDenseMatrix_Cols(IntPtr matrix);
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNDenseMatrix_Rows", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern long SUNDenseMatrix_Rows(IntPtr matrix);
-
-
-    public unsafe static double SUNDenseMatrix_Get(IntPtr mat, long i, long j) {
-      long M = SUNDenseMatrix_Rows(mat);
-      // the(i, j)th element of A(with 0 <= i<M and 0 <= j<N) is given by(A->data)[j*M+i]
-      return SUNDenseMatrix_Data(mat)[j*M+i];
-    }
-
-    public unsafe static void SUNDenseMatrix_Set(IntPtr mat, long i, long j, double val) {
-      long M = SUNDenseMatrix_Rows(mat);
-      // the(i, j)th element of A(with 0 <= i<M and 0 <= j<N) is given by(A->data)[j*M+i]
-      SUNDenseMatrix_Data(mat)[j * M + i] = val;
-    }
-
-    #endregion
-
-    #region linear solver
-    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNDenseLinearSolver", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern IntPtr SUNDenseLinearSolver(
-      IntPtr y, // N_Vector
-      IntPtr A // SUNMatrix
-      );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNLinSolInitialize", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int SUNLinSolInitialize(IntPtr linearSolver);
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNLinSolSetup", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int SUNLinSolSetup(
-      IntPtr linearSolver,
-      IntPtr A // SUNMatrix
-      );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNLinSolSolve", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int SUNLinSolSolve(
-      IntPtr linearSolver,
-      IntPtr A, // SUNMatrix
-      IntPtr x, // N_Vector
-      IntPtr b, // N_Vector
-      double tol
-      );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "SUNLinSolFree", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern int SUNLinSolFree(IntPtr linearSolver);
-
-    #endregion
-
-    #region N_Vector
-    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VNew_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern IntPtr N_VNew_Serial(long vec_length);
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VDestroy_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern void N_VDestroy_Serial(IntPtr vec);
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VPrint_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern void N_VPrint_Serial(IntPtr vec);
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VConst_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern void N_VConst_Serial(double c, IntPtr vec);
-
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VL1Norm_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern double N_VL1Norm_Serial(IntPtr vec);
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VMake_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern IntPtr N_VMake_Serial(long vec_length, double[] v_data);
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VScale", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    ///  Performs the operation z = c*x
-    public static extern void N_VScale(double s,
-      IntPtr x, // N_Vector
-      IntPtr z // N_Vector
-      );
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VMake_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public unsafe static extern double* N_VGetArrayPointer_Serial(IntPtr vec);
-
-    [DllImport("sundials_cvodes.dll", EntryPoint = "N_VCloneVectorArray_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
-    public static extern IntPtr N_VCloneVectorArray_Serial(int count, IntPtr vec); // returns N_Vector* !
-
-
-    /*
-#define NV_CONTENT_S(v)  ( (N_VectorContent_Serial)(v->content) )
-
-#define NV_LENGTH_S(v)   ( NV_CONTENT_S(v)->length )
-
-#define NV_OWN_DATA_S(v) ( NV_CONTENT_S(v)->own_data )
-
-#define NV_DATA_S(v)     ( NV_CONTENT_S(v)->data )
-
-#define NV_Ith_S(v,i)    ( NV_DATA_S(v)[i] )
-*/
-    // methods for macros
-    public unsafe static int* NV_CONTENT_S(IntPtr v) {
-      int* content = (int*)*(int*)v.ToPointer();
-      return content;
-    }
-
-    public unsafe static long NV_LENGTH_S(IntPtr v) {
-      long length = *NV_CONTENT_S(v);
-      return length;
-    }
-    public unsafe static bool NV_OWN_DATA_S(IntPtr v) {
-      var content = NV_CONTENT_S(v);
-      int own_data = *(content + 2);
-      return own_data > 0;
-    }
-    public unsafe static double* NV_DATA_S(IntPtr v) {
-      var content = NV_CONTENT_S(v);
-      double* data = (double*)*(content + 3);
-      return data;
-    }
-    public unsafe static double NV_Get_Ith_S(IntPtr v, long i) {
-      return NV_DATA_S(v)[i];
-    }
-    public unsafe static void NV_Set_Ith_S(IntPtr v, long i, double val) {
-      NV_DATA_S(v)[i] = val;
-    }
-    #endregion
-
 
 
