Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/22/18 10:02:42 (6 years ago)
Author:
gkronber
Message:

#2925 extracted CVODES external methods into a separate class

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2925_AutoDiffForDynamicalModels/AutoDiffForDynamicalModelsTest/TestCvodes.cs

    r16246 r16248  
    1010      // test vectors
    1111      var arr = new double[] { 3.14, 2.71 };
    12       var vec = Problem.N_VMake_Serial(2, arr);
    13       Problem.N_VDestroy_Serial(vec);
    14 
    15       vec = Problem.N_VNew_Serial(10);
     12      var vec = CVODES.N_VMake_Serial(2, arr);
     13      CVODES.N_VDestroy_Serial(vec);
     14
     15      vec = CVODES.N_VNew_Serial(10);
    1616
    1717      unsafe {
     
    2424        double data0 = *data;
    2525      }
    26       Problem.N_VConst_Serial(2.0, vec);
    27       Problem.N_VPrint_Serial(vec);
    28       Assert.AreEqual(20, Problem.N_VL1Norm_Serial(vec));
    29       Problem.N_VDestroy_Serial(vec);
     26      CVODES.N_VConst_Serial(2.0, vec);
     27      CVODES.N_VPrint_Serial(vec);
     28      Assert.AreEqual(20, CVODES.N_VL1Norm_Serial(vec));
     29      CVODES.N_VDestroy_Serial(vec);
    3030
    3131
    3232      // linear oscillator
    3333      int numberOfEquations = 2;
    34       var y = Problem.N_VNew_Serial(numberOfEquations);
     34      var y = CVODES.N_VNew_Serial(numberOfEquations);
    3535      // y must be initialized before calling CVodeInit
    36       // Problem.N_VConst_Serial(100.0, y);
    37       Problem.NV_Set_Ith_S(y, 0, 0.5); // x
    38       Problem.NV_Set_Ith_S(y, 1, 1);  // v
    39 
    40       var cvode_mem = Problem.CVodeCreate(Problem.MultistepMethod.CV_ADAMS, Problem.NonlinearSolverIteration.CV_FUNCTIONAL);
    41 
    42       var flag = Problem.CVodeInit(cvode_mem, F, 0.0, y);
    43       Assert.AreEqual(Problem.CV_SUCCESS, flag);
    44 
    45       flag = Problem.CVodeSStolerances(cvode_mem, 1E-4, 1.0);
    46       Assert.AreEqual(Problem.CV_SUCCESS, flag);
    47 
    48       var A = Problem.SUNDenseMatrix(numberOfEquations, numberOfEquations);
     36      // CVODES.N_VConst_Serial(100.0, y);
     37      CVODES.NV_Set_Ith_S(y, 0, 0.5); // x
     38      CVODES.NV_Set_Ith_S(y, 1, 1);  // v
     39
     40      var cvode_mem = CVODES.CVodeCreate(CVODES.MultistepMethod.CV_ADAMS, CVODES.NonlinearSolverIteration.CV_FUNCTIONAL);
     41
     42      var flag = CVODES.CVodeInit(cvode_mem, F, 0.0, y);
     43      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
     44
     45      flag = CVODES.CVodeSStolerances(cvode_mem, 1E-4, 1.0);
     46      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
     47
     48      var A = CVODES.SUNDenseMatrix(numberOfEquations, numberOfEquations);
    4949      Assert.AreNotSame(A, IntPtr.Zero);
    5050
    5151
    52       var linearSolver = Problem.SUNDenseLinearSolver(y, A);
     52      var linearSolver = CVODES.SUNDenseLinearSolver(y, A);
    5353      Assert.AreNotSame(linearSolver, IntPtr.Zero);
    5454
    55       flag = Problem.CVDlsSetLinearSolver(cvode_mem, linearSolver, A);
    56       Assert.AreEqual(Problem.CV_SUCCESS, flag);
    57 
    58       // flag = Problem.CVDlsSetJacFn(cvode_mem, JacF);
    59       // Assert.AreEqual(Problem.CV_SUCCESS, flag);
     55      flag = CVODES.CVDlsSetLinearSolver(cvode_mem, linearSolver, A);
     56      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
     57
     58      // flag = CVODES.CVDlsSetJacFn(cvode_mem, JacF);
     59      // Assert.AreEqual(CVODES.CV_SUCCESS, flag);
    6060
    6161      // var ns = 1; // number of parameters
    6262      // var p = new double[1]; // set as user-data
    63       // var yS0 = Problem.N_VCloneVectorArray_Serial(ns, y); // clone the output vector for each parameter, TODO: free
     63      // var yS0 = CVODES.N_VCloneVectorArray_Serial(ns, y); // clone the output vector for each parameter, TODO: free
    6464      // for(int i=0;i<ns;i++) {
    6565      //
     
    6767
    6868
    69       var q = Problem.N_VNew_Serial(1);
    70       Problem.NV_Set_Ith_S(q, 0, 0.0);
    71       flag = Problem.CVodeQuadInit(cvode_mem, FQ, q);
    72       Assert.AreEqual(Problem.CV_SUCCESS, flag);
     69      var q = CVODES.N_VNew_Serial(1);
     70      CVODES.NV_Set_Ith_S(q, 0, 0.0);
     71      flag = CVODES.CVodeQuadInit(cvode_mem, FQ, q);
     72      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
    7373
    7474
    7575      int steps = 10;
    76       flag = Problem.CVodeAdjInit(cvode_mem, steps, Problem.CV_HERMITE);
    77       Assert.AreEqual(Problem.CV_SUCCESS, flag);
     76      flag = CVODES.CVodeAdjInit(cvode_mem, steps, CVODES.CV_HERMITE);
     77      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
    7878
    7979      /* step by step forward integration
     
    8282      int nout = 100; // number of output times
    8383      for (int iout = 0; iout < nout; iout++) {
    84         flag = Problem.CVode(cvode_mem, tout, y, ref t, Problem.CV_NORMAL);
    85         Assert.AreEqual(Problem.CV_SUCCESS, flag);
    86         Console.WriteLine("{0} {1} {2}", t, Problem.NV_Get_Ith_S(y, 0), Problem.NV_Get_Ith_S(y, 1));
    87         // Problem.N_VPrint_Serial(y);
     84        flag = CVODES.CVode(cvode_mem, tout, y, ref t, CVODES.CV_NORMAL);
     85        Assert.AreEqual(CVODES.CV_SUCCESS, flag);
     86        Console.WriteLine("{0} {1} {2}", t, CVODES.NV_Get_Ith_S(y, 0), CVODES.NV_Get_Ith_S(y, 1));
     87        // CVODES.N_VPrint_Serial(y);
    8888        tout += 0.1;
    8989      }
     
    9494      double time = 0.0;
    9595      int ncheck = 0; // number of checkpoints
    96       flag = Problem.CVodeF(cvode_mem, tout, y, ref time, Problem.CV_NORMAL, ref ncheck);
    97       Assert.AreEqual(Problem.CV_SUCCESS, flag);
     96      flag = CVODES.CVodeF(cvode_mem, tout, y, ref time, CVODES.CV_NORMAL, ref ncheck);
     97      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
    9898
    9999      long numSteps = 0;
    100       flag = Problem.CVodeGetNumSteps(cvode_mem, ref numSteps);
    101       Assert.AreEqual(Problem.CV_SUCCESS, flag);
    102 
    103       var yB = Problem.N_VNew_Serial(numberOfEquations);
    104       Problem.N_VConst_Serial(0.0, yB);
     100      flag = CVODES.CVodeGetNumSteps(cvode_mem, ref numSteps);
     101      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
     102
     103      var yB = CVODES.N_VNew_Serial(numberOfEquations);
     104      CVODES.N_VConst_Serial(0.0, yB);
    105105
    106106      int numberOfParameters = 2;
    107       var qB = Problem.N_VNew_Serial(numberOfParameters);
    108       Problem.N_VConst_Serial(0.0, qB);
     107      var qB = CVODES.N_VNew_Serial(numberOfParameters);
     108      CVODES.N_VConst_Serial(0.0, qB);
    109109
    110110      int indexB = 0;
    111       flag = Problem.CVodeCreateB(cvode_mem, Problem.MultistepMethod.CV_BDF, Problem.NonlinearSolverIteration.CV_NEWTON, ref indexB);
    112       Assert.AreEqual(Problem.CV_SUCCESS, flag);
     111      flag = CVODES.CVodeCreateB(cvode_mem, CVODES.MultistepMethod.CV_BDF, CVODES.NonlinearSolverIteration.CV_NEWTON, ref indexB);
     112      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
    113113
    114114      var TB1 = tout;
    115       flag = Problem.CVodeInitB(cvode_mem, indexB, FB, TB1, yB);
    116       Assert.AreEqual(Problem.CV_SUCCESS, flag);
     115      flag = CVODES.CVodeInitB(cvode_mem, indexB, FB, TB1, yB);
     116      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
    117117
    118118      var relTolB = 1E-6;
    119119      var absTolB = 1E-8;
    120       flag = Problem.CVodeSStolerancesB(cvode_mem, indexB, relTolB, absTolB);
    121       Assert.AreEqual(Problem.CV_SUCCESS, flag);
    122 
    123       var AB = Problem.SUNDenseMatrix(numberOfEquations, numberOfEquations);
     120      flag = CVODES.CVodeSStolerancesB(cvode_mem, indexB, relTolB, absTolB);
     121      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
     122
     123      var AB = CVODES.SUNDenseMatrix(numberOfEquations, numberOfEquations);
    124124      Assert.AreNotSame(linearSolver, IntPtr.Zero);
    125125
    126       var lsB = Problem.SUNDenseLinearSolver(yB, AB);
     126      var lsB = CVODES.SUNDenseLinearSolver(yB, AB);
    127127      Assert.AreNotSame(linearSolver, IntPtr.Zero);
    128128
    129       flag = Problem.CVDlsSetLinearSolverB(cvode_mem, indexB, lsB, AB);
    130       Assert.AreEqual(Problem.CV_SUCCESS, flag);
    131 
    132       flag = Problem.CVDlsSetJacFnB(cvode_mem, indexB, JacFB);
    133       Assert.AreEqual(Problem.CV_SUCCESS, flag);
    134 
    135       flag = Problem.CVodeQuadInitB(cvode_mem, indexB, FQB, qB);
    136       Assert.AreEqual(Problem.CV_SUCCESS, flag);
     129      flag = CVODES.CVDlsSetLinearSolverB(cvode_mem, indexB, lsB, AB);
     130      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
     131
     132      flag = CVODES.CVDlsSetJacFnB(cvode_mem, indexB, JacFB);
     133      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
     134
     135      flag = CVODES.CVodeQuadInitB(cvode_mem, indexB, FQB, qB);
     136      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
    137137
    138138      /* First get results at t = TBout1 */
    139139
    140       /* Call CVodeB to integrate the backward ODE problem. */
     140      /* Call CVodeB to integrate the backward ODE CVODES. */
    141141      var tBackOut = 50.0;
    142       flag = Problem.CVodeB(cvode_mem, tBackOut, Problem.CV_NORMAL);
    143       Assert.AreEqual(Problem.CV_SUCCESS, flag);
    144 
    145       /* Call CVodeGetB to get yB of the backward ODE problem. */
    146       flag = Problem.CVodeGetB(cvode_mem, indexB, ref time, yB);
    147       Assert.AreEqual(Problem.CV_SUCCESS, flag);
     142      flag = CVODES.CVodeB(cvode_mem, tBackOut, CVODES.CV_NORMAL);
     143      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
     144
     145      /* Call CVodeGetB to get yB of the backward ODE CVODES. */
     146      flag = CVODES.CVodeGetB(cvode_mem, indexB, ref time, yB);
     147      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
    148148
    149149      /* Call CVodeGetAdjY to get the interpolated value of the forward solution
    150150         y during a backward integration. */
    151       flag = Problem.CVodeGetAdjY(cvode_mem, tBackOut, y);
    152       Assert.AreEqual(Problem.CV_SUCCESS, flag);
     151      flag = CVODES.CVodeGetAdjY(cvode_mem, tBackOut, y);
     152      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
    153153
    154154      /* Then at t = T0 */
    155155
    156156      double t0 = 0.0;
    157       flag = Problem.CVodeB(cvode_mem, t0, Problem.CV_NORMAL);
    158       Assert.AreEqual(Problem.CV_SUCCESS, flag);
     157      flag = CVODES.CVodeB(cvode_mem, t0, CVODES.CV_NORMAL);
     158      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
    159159
    160160      long nstB = 0;
    161       Problem.CVodeGetNumSteps(Problem.CVodeGetAdjCVodeBmem(cvode_mem, indexB), ref nstB);
    162 
    163       flag = Problem.CVodeGetB(cvode_mem, indexB, ref time, yB);
    164       Assert.AreEqual(Problem.CV_SUCCESS, flag);
    165 
    166 
    167       flag = Problem.CVodeGetQuadB(cvode_mem, indexB, ref time, qB);
    168       Assert.AreEqual(Problem.CV_SUCCESS, flag);
    169 
    170       flag = Problem.CVodeGetAdjY(cvode_mem, t0, y);
    171       Assert.AreEqual(Problem.CV_SUCCESS, flag);
    172 
    173       Problem.N_VDestroy_Serial(y);
    174       Problem.CVodeFree(cvode_mem);
    175       Problem.SUNLinSolFree(linearSolver);
    176       Problem.SUNMatDestroy(A);
     161      CVODES.CVodeGetNumSteps(CVODES.CVodeGetAdjCVodeBmem(cvode_mem, indexB), ref nstB);
     162
     163      flag = CVODES.CVodeGetB(cvode_mem, indexB, ref time, yB);
     164      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
     165
     166
     167      flag = CVODES.CVodeGetQuadB(cvode_mem, indexB, ref time, qB);
     168      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
     169
     170      flag = CVODES.CVodeGetAdjY(cvode_mem, t0, y);
     171      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
     172
     173      CVODES.N_VDestroy_Serial(y);
     174      CVODES.CVodeFree(cvode_mem);
     175      CVODES.SUNLinSolFree(linearSolver);
     176      CVODES.SUNMatDestroy(A);
    177177    }
    178178
     
    182182      // linear oscillator
    183183      int numberOfEquations = 2;
    184       var y = Problem.N_VNew_Serial(numberOfEquations);
     184      var y = CVODES.N_VNew_Serial(numberOfEquations);
    185185      // y must be initialized before calling CVodeInit
    186       // Problem.N_VConst_Serial(100.0, y);
    187       Problem.NV_Set_Ith_S(y, 0, 0.5); // x
    188       Problem.NV_Set_Ith_S(y, 1, 1);  // v
    189 
    190       var cvode_mem = Problem.CVodeCreate(Problem.MultistepMethod.CV_ADAMS, Problem.NonlinearSolverIteration.CV_FUNCTIONAL);
    191 
    192       var flag = Problem.CVodeInit(cvode_mem, F, 0.0, y);
    193       Assert.AreEqual(Problem.CV_SUCCESS, flag);
    194 
    195       flag = Problem.CVodeSStolerances(cvode_mem, 1E-4, 1.0);
    196       Assert.AreEqual(Problem.CV_SUCCESS, flag);
    197 
    198       var A = Problem.SUNDenseMatrix(numberOfEquations, numberOfEquations);
     186      // CVODES.N_VConst_Serial(100.0, y);
     187      CVODES.NV_Set_Ith_S(y, 0, 0.5); // x
     188      CVODES.NV_Set_Ith_S(y, 1, 1);  // v
     189
     190      var cvode_mem = CVODES.CVodeCreate(CVODES.MultistepMethod.CV_ADAMS, CVODES.NonlinearSolverIteration.CV_FUNCTIONAL);
     191
     192      var flag = CVODES.CVodeInit(cvode_mem, F, 0.0, y);
     193      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
     194
     195      flag = CVODES.CVodeSStolerances(cvode_mem, 1E-4, 1.0);
     196      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
     197
     198      var A = CVODES.SUNDenseMatrix(numberOfEquations, numberOfEquations);
    199199      Assert.AreNotSame(A, IntPtr.Zero);
    200       Console.WriteLine(Problem.SUNDenseMatrix_Get(A, 0, 0));
    201 
    202 
    203       var linearSolver = Problem.SUNDenseLinearSolver(y, A);
     200      Console.WriteLine(CVODES.SUNDenseMatrix_Get(A, 0, 0));
     201
     202
     203      var linearSolver = CVODES.SUNDenseLinearSolver(y, A);
    204204      Assert.AreNotSame(linearSolver, IntPtr.Zero);
    205205
    206       flag = Problem.CVDlsSetLinearSolver(cvode_mem, linearSolver, A);
    207       Assert.AreEqual(Problem.CV_SUCCESS, flag);
    208 
    209       flag = Problem.CVDlsSetJacFn(cvode_mem, JacF);
    210       Assert.AreEqual(Problem.CV_SUCCESS, flag);
     206      flag = CVODES.CVDlsSetLinearSolver(cvode_mem, linearSolver, A);
     207      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
     208
     209      flag = CVODES.CVDlsSetJacFn(cvode_mem, JacF);
     210      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
    211211
    212212      var ns = 1; // number of parameters
    213213      var p = new double[1]; // set as user-data
    214       var yS0 = Problem.N_VCloneVectorArray_Serial(ns, y); // clone the output vector for each parameter, TODO: free
     214      var yS0 = CVODES.N_VCloneVectorArray_Serial(ns, y); // clone the output vector for each parameter, TODO: free
    215215      unsafe {
    216216        for (int i = 0; i < ns; i++) {
    217217          var yS0_i = *((IntPtr*)yS0.ToPointer() + i);
    218           Problem.N_VConst_Serial(0.0, yS0_i);
     218          CVODES.N_VConst_Serial(0.0, yS0_i);
    219219        }
    220220      }
    221221
    222222
    223       flag = Problem.CVodeSensInit(cvode_mem, ns, Problem.CV_SIMULTANEOUS, FS, yS0);
    224       Assert.AreEqual(Problem.CV_SUCCESS, flag);
     223      flag = CVODES.CVodeSensInit(cvode_mem, ns, CVODES.CV_SIMULTANEOUS, FS, yS0);
     224      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
    225225
    226226      double reltolS = 1E-5;
    227227      var abstolS = new double[] { 1E-6 };
    228       // flag = Problem.CVodeSensSStolerances(cvode_mem, reltolS, abstolS);
    229       // Assert.AreEqual(Problem.CV_SUCCESS, flag);
    230       flag = Problem.CVodeSensEEtolerances(cvode_mem);
    231       Assert.AreEqual(Problem.CV_SUCCESS, flag);
    232 
    233 
    234       // var q = Problem.N_VNew_Serial(1);
    235       // Problem.NV_Set_Ith_S(q, 0, 0.0);
    236       // flag = Problem.CVodeQuadInit(cvode_mem, FQ, q);
    237       // Assert.AreEqual(Problem.CV_SUCCESS, flag);
     228      // flag = CVODES.CVodeSensSStolerances(cvode_mem, reltolS, abstolS);
     229      // Assert.AreEqual(CVODES.CV_SUCCESS, flag);
     230      flag = CVODES.CVodeSensEEtolerances(cvode_mem);
     231      Assert.AreEqual(CVODES.CV_SUCCESS, flag);
     232
     233
     234      // var q = CVODES.N_VNew_Serial(1);
     235      // CVODES.NV_Set_Ith_S(q, 0, 0.0);
     236      // flag = CVODES.CVodeQuadInit(cvode_mem, FQ, q);
     237      // Assert.AreEqual(CVODES.CV_SUCCESS, flag);
    238238
    239239
    240240      // int steps = 10;
    241       // flag = Problem.CVodeAdjInit(cvode_mem, steps, Problem.CV_HERMITE);
    242       // Assert.AreEqual(Problem.CV_SUCCESS, flag);
     241      // flag = CVODES.CVodeAdjInit(cvode_mem, steps, CVODES.CV_HERMITE);
     242      // Assert.AreEqual(CVODES.CV_SUCCESS, flag);
    243243
    244244      // step by step forward integration
     
    247247      int nout = 1000; // number of output times
    248248      for (int iout = 0; iout < nout; iout++) {
    249         flag = Problem.CVode(cvode_mem, tout, y, ref t, Problem.CV_NORMAL);
    250         Assert.AreEqual(Problem.CV_SUCCESS, flag);
     249        flag = CVODES.CVode(cvode_mem, tout, y, ref t, CVODES.CV_NORMAL);
     250        Assert.AreEqual(CVODES.CV_SUCCESS, flag);
    251251
    252252        // get sensitivities
    253         flag = Problem.CVodeGetSens(cvode_mem, ref t, yS0);
    254         Assert.AreEqual(Problem.CV_SUCCESS, flag);
     253        flag = CVODES.CVodeGetSens(cvode_mem, ref t, yS0);
     254        Assert.AreEqual(CVODES.CV_SUCCESS, flag);
    255255        unsafe {
    256256          var ySP0 = *(IntPtr*)yS0.ToPointer(); // parameter of sensitivities for first component
    257           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));
     257          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));
    258258        }
    259259
     
    263263
    264264
    265       Problem.N_VDestroy_Serial(y);
    266       Problem.CVodeFree(cvode_mem);
    267       Problem.SUNLinSolFree(linearSolver);
    268       Problem.SUNMatDestroy(A);
     265      CVODES.N_VDestroy_Serial(y);
     266      CVODES.CVodeFree(cvode_mem);
     267      CVODES.SUNLinSolFree(linearSolver);
     268      CVODES.SUNMatDestroy(A);
    269269    }
    270270
     
    280280      // ∂y1/∂t = y2
    281281      // ∂y2/∂t = -0.3 y1
    282       Problem.NV_Set_Ith_S(ydot, 0, Problem.NV_Get_Ith_S(y, 1));
    283       Problem.NV_Set_Ith_S(ydot, 1, -0.3 * Problem.NV_Get_Ith_S(y, 0));
     282      CVODES.NV_Set_Ith_S(ydot, 0, CVODES.NV_Get_Ith_S(y, 1));
     283      CVODES.NV_Set_Ith_S(ydot, 1, -0.3 * CVODES.NV_Get_Ith_S(y, 0));
    284284      return 0;
    285285      ;
     
    297297      //  ∂f2/∂y1  ∂f2/∂y2
    298298
    299       Problem.SUNDenseMatrix_Set(Jac, 0, 0, 0.0);
    300       Problem.SUNDenseMatrix_Set(Jac, 0, 1, 1.0);
    301       Problem.SUNDenseMatrix_Set(Jac, 1, 0, -0.3);
    302       Problem.SUNDenseMatrix_Set(Jac, 1, 1, 0.0);
     299      CVODES.SUNDenseMatrix_Set(Jac, 0, 0, 0.0);
     300      CVODES.SUNDenseMatrix_Set(Jac, 0, 1, 1.0);
     301      CVODES.SUNDenseMatrix_Set(Jac, 1, 0, -0.3);
     302      CVODES.SUNDenseMatrix_Set(Jac, 1, 1, 0.0);
    303303      return 0;
    304304    }
     
    323323
    324324      // (∂f /∂y)s_i(t) + ∂f /∂p_i
    325       var y1 = Problem.NV_Get_Ith_S(y, 0); var y2 = Problem.NV_Get_Ith_S(y, 1);
     325      var y1 = CVODES.NV_Get_Ith_S(y, 0); var y2 = CVODES.NV_Get_Ith_S(y, 1);
    326326
    327327      unsafe {
    328328        var yS_p0 = *(IntPtr*)yS.ToPointer();
    329         var s1 = Problem.NV_Get_Ith_S(yS_p0, 0); var s2 = Problem.NV_Get_Ith_S(yS_p0, 1);
    330 
    331 
    332         // (∂f /∂y)s_i(t)  = Jac s_i(t)
     329        var s1 = CVODES.NV_Get_Ith_S(yS_p0, 0); var s2 = CVODES.NV_Get_Ith_S(yS_p0, 1);
     330
     331
     332        // (∂f /∂y)s_i(t)  == Jac s_i(t)
    333333        var sd1 = s2;
    334334        var sd2 = -0.3 * s1;
    335335
    336336        var s_p0 = *(IntPtr*)ySdot.ToPointer();
    337         Problem.NV_Set_Ith_S(s_p0, 0, sd1 + 0.0);
    338         Problem.NV_Set_Ith_S(s_p0, 1, sd2 - 0.3);
     337        CVODES.NV_Set_Ith_S(s_p0, 0, sd1 + 0.0);
     338        CVODES.NV_Set_Ith_S(s_p0, 1, sd2 - 0.3);
    339339      }
    340340
     
    365365      // λ2' = 1.0 λ1 - 0.0
    366366
    367       Problem.NV_Set_Ith_S(yBdot, 0, 0.3 * Problem.NV_Get_Ith_S(yB, 1));
    368       Problem.NV_Set_Ith_S(yBdot, 1, Problem.NV_Get_Ith_S(yB, 0));
     367      CVODES.NV_Set_Ith_S(yBdot, 0, 0.3 * CVODES.NV_Get_Ith_S(yB, 1));
     368      CVODES.NV_Set_Ith_S(yBdot, 1, CVODES.NV_Get_Ith_S(yB, 0));
    369369
    370370      return 0;
     
    374374    private int FQ(double t, IntPtr y, IntPtr yQdot, IntPtr user_data) {
    375375      // TODO: squared error
    376       Problem.NV_Set_Ith_S(yQdot, 0, Problem.NV_Get_Ith_S(y, 2));
     376      CVODES.NV_Set_Ith_S(yQdot, 0, CVODES.NV_Get_Ith_S(y, 2));
    377377      return 0;
    378378    }
Note: See TracChangeset for help on using the changeset viewer.