- Timestamp:
- 10/22/18 10:02:42 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2925_AutoDiffForDynamicalModels/AutoDiffForDynamicalModelsTest/TestCvodes.cs
r16246 r16248 10 10 // test vectors 11 11 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); 16 16 17 17 unsafe { … … 24 24 double data0 = *data; 25 25 } 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); 30 30 31 31 32 32 // linear oscillator 33 33 int numberOfEquations = 2; 34 var y = Problem.N_VNew_Serial(numberOfEquations);34 var y = CVODES.N_VNew_Serial(numberOfEquations); 35 35 // 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); // x38 Problem.NV_Set_Ith_S(y, 1, 1); // v39 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); 49 49 Assert.AreNotSame(A, IntPtr.Zero); 50 50 51 51 52 var linearSolver = Problem.SUNDenseLinearSolver(y, A);52 var linearSolver = CVODES.SUNDenseLinearSolver(y, A); 53 53 Assert.AreNotSame(linearSolver, IntPtr.Zero); 54 54 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); 60 60 61 61 // var ns = 1; // number of parameters 62 62 // 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: free63 // var yS0 = CVODES.N_VCloneVectorArray_Serial(ns, y); // clone the output vector for each parameter, TODO: free 64 64 // for(int i=0;i<ns;i++) { 65 65 // … … 67 67 68 68 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); 73 73 74 74 75 75 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); 78 78 79 79 /* step by step forward integration … … 82 82 int nout = 100; // number of output times 83 83 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); 88 88 tout += 0.1; 89 89 } … … 94 94 double time = 0.0; 95 95 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); 98 98 99 99 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); 105 105 106 106 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); 109 109 110 110 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); 113 113 114 114 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); 117 117 118 118 var relTolB = 1E-6; 119 119 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); 124 124 Assert.AreNotSame(linearSolver, IntPtr.Zero); 125 125 126 var lsB = Problem.SUNDenseLinearSolver(yB, AB);126 var lsB = CVODES.SUNDenseLinearSolver(yB, AB); 127 127 Assert.AreNotSame(linearSolver, IntPtr.Zero); 128 128 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); 137 137 138 138 /* First get results at t = TBout1 */ 139 139 140 /* Call CVodeB to integrate the backward ODE problem. */140 /* Call CVodeB to integrate the backward ODE CVODES. */ 141 141 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); 148 148 149 149 /* Call CVodeGetAdjY to get the interpolated value of the forward solution 150 150 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); 153 153 154 154 /* Then at t = T0 */ 155 155 156 156 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); 159 159 160 160 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); 177 177 } 178 178 … … 182 182 // linear oscillator 183 183 int numberOfEquations = 2; 184 var y = Problem.N_VNew_Serial(numberOfEquations);184 var y = CVODES.N_VNew_Serial(numberOfEquations); 185 185 // 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); // x188 Problem.NV_Set_Ith_S(y, 1, 1); // v189 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); 199 199 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); 204 204 Assert.AreNotSame(linearSolver, IntPtr.Zero); 205 205 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); 211 211 212 212 var ns = 1; // number of parameters 213 213 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: free214 var yS0 = CVODES.N_VCloneVectorArray_Serial(ns, y); // clone the output vector for each parameter, TODO: free 215 215 unsafe { 216 216 for (int i = 0; i < ns; i++) { 217 217 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); 219 219 } 220 220 } 221 221 222 222 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); 225 225 226 226 double reltolS = 1E-5; 227 227 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); 238 238 239 239 240 240 // 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); 243 243 244 244 // step by step forward integration … … 247 247 int nout = 1000; // number of output times 248 248 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); 251 251 252 252 // 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); 255 255 unsafe { 256 256 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)); 258 258 } 259 259 … … 263 263 264 264 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); 269 269 } 270 270 … … 280 280 // ∂y1/∂t = y2 281 281 // ∂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)); 284 284 return 0; 285 285 ; … … 297 297 // ∂f2/∂y1 ∂f2/∂y2 298 298 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); 303 303 return 0; 304 304 } … … 323 323 324 324 // (∂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); 326 326 327 327 unsafe { 328 328 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) 333 333 var sd1 = s2; 334 334 var sd2 = -0.3 * s1; 335 335 336 336 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); 339 339 } 340 340 … … 365 365 // λ2' = 1.0 λ1 - 0.0 366 366 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)); 369 369 370 370 return 0; … … 374 374 private int FQ(double t, IntPtr y, IntPtr yQdot, IntPtr user_data) { 375 375 // 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)); 377 377 return 0; 378 378 }
Note: See TracChangeset
for help on using the changeset viewer.