Changeset 16256 for branches/2925_AutoDiffForDynamicalModels
- Timestamp:
- 10/24/18 19:58:44 (6 years ago)
- Location:
- branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/CVODES.cs
r16254 r16256 174 174 ); 175 175 176 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeCreate", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]177 176 // returns a void* to the cvodes memory block if successful otherwise NULL 178 public static extern IntPtr CVodeCreate(MultistepMethod lmm, NonlinearSolverIteration iter); 179 180 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 181 public static extern int CVodeInit( 177 public static IntPtr CVodeCreate(MultistepMethod lmm, NonlinearSolverIteration iter) { 178 if (Environment.Is64BitProcess) return CVodeCreate_x64(lmm, iter); 179 else return CVodeCreate_x86(lmm, iter); 180 } 181 182 public static int CVodeInit( 182 183 IntPtr cvode_mem, // pointer returned by CVodeCreate 183 184 CVRhsFunc f, 184 185 double t0, // realtype, the inital value of t 185 186 IntPtr y0 // N_Vector the initial value of y 186 ); 187 188 189 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeSStolerances", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 190 public static extern int CVodeSStolerances( 187 ) { 188 if (Environment.Is64BitProcess) return CVodeInit_x64(cvode_mem, f, t0, y0); 189 else return CVodeInit_x86(cvode_mem, f, t0, y0); 190 } 191 192 193 public static int CVodeSStolerances( 191 194 IntPtr cvode_mem, 192 195 double reltol, 193 196 double abstol 194 ); 195 196 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVDlsSetLinearSolver", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 197 public static extern int CVDlsSetLinearSolver( 197 ) { 198 if (Environment.Is64BitProcess) return CVodeSStolerances_x64(cvode_mem, reltol, abstol); 199 else return CVodeSStolerances_x86(cvode_mem, reltol, abstol); 200 } 201 202 public static int CVDlsSetLinearSolver( 198 203 IntPtr cvode_mem, 199 204 IntPtr linearSolver, // SUNLinearSolver 200 205 IntPtr j // SUNMatrix 201 ); 202 203 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVDlsSetJacFn", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 204 public static extern int CVDlsSetJacFn( 206 ) { 207 if (Environment.Is64BitProcess) return CVDlsSetLinearSolver_x64(cvode_mem, linearSolver, j); 208 else return CVDlsSetLinearSolver_x86(cvode_mem, linearSolver, j); 209 } 210 211 public static int CVDlsSetJacFn( 205 212 IntPtr cvode_mem, 206 213 CVDlsJacFunc jacFunc 207 ); 208 209 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeSensInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 210 public static extern int CVodeSensInit( 214 ) { 215 if (Environment.Is64BitProcess) return CVDlsSetJacFn_x64(cvode_mem, jacFunc); 216 else return CVDlsSetJacFn_x86(cvode_mem, jacFunc); 217 } 218 219 public static int CVodeSensInit( 211 220 IntPtr cvode_mem, 212 221 int Ns, // number of parameters … … 214 223 CVSensRhsFn fS, // right hand side function which computes all sensitivity RHS at the same time 215 224 IntPtr yS0 // N_Vector 216 ); 217 218 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeSensSStolerances", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 219 public static extern int CVodeSensSStolerances( 225 ) { 226 if (Environment.Is64BitProcess) return CVodeSensInit_x64(cvode_mem, Ns, ism, fS, yS0); 227 else return CVodeSensInit_x86(cvode_mem, Ns, ism, fS, yS0); 228 } 229 230 public static int CVodeSensSStolerances( 220 231 IntPtr cvode_mem, 221 232 double reltol, 222 233 double[] abstol 223 ); 234 ) { 235 if (Environment.Is64BitProcess) return CVodeSensSStolerances_x64(cvode_mem, reltol, abstol); 236 else return CVodeSensSStolerances_x86(cvode_mem, reltol, abstol); 237 } 224 238 225 239 /* Call CVodeSensEEtolerances to estimate tolerances for sensitivity 226 240 variables based on the rolerances supplied for states variables and 227 241 the scaling factor pbar */ 228 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeSensEEtolerances", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 229 public static extern int CVodeSensEEtolerances( 242 public static int CVodeSensEEtolerances( 230 243 IntPtr cvode_mem 231 ); 232 233 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeGetSens", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 234 public static extern int CVodeGetSens( 244 ) { 245 if (Environment.Is64BitProcess) return CVodeSensEEtolerances_x64(cvode_mem); 246 else return CVodeSensEEtolerances_x86(cvode_mem); 247 } 248 249 public static int CVodeGetSens( 235 250 IntPtr cvode_mem, 236 251 ref double tret, 237 252 IntPtr yS //N_Vector*, one vector for each parameter 238 ); 239 240 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeQuadInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 241 public static extern int CVodeQuadInit( 253 ) { 254 if (Environment.Is64BitProcess) return CVodeGetSens_x64(cvode_mem, ref tret, yS); 255 else return CVodeGetSens_x86(cvode_mem, ref tret, yS); 256 } 257 258 public static int CVodeQuadInit( 242 259 IntPtr cvode_mem, 243 260 CVQuadRhsFn qF, 244 261 IntPtr yQ0 // N_Vector, initial value of yQ 245 ); 246 247 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeQuadInitB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 248 public static extern int CVodeQuadInitB( 262 ) { 263 if (Environment.Is64BitProcess) return CVodeQuadInit_x64(cvode_mem, qF, yQ0); 264 else return CVodeQuadInit_x86(cvode_mem, qF, yQ0); 265 } 266 267 public static int CVodeQuadInitB( 249 268 IntPtr cvode_mem, 250 269 int indexB, 251 270 CVQuadRhsFnB rhsQB, 252 271 IntPtr yQB0 // N_Vector, initial value of yQB 253 ); 254 255 256 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeAdjInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 257 public static extern int CVodeAdjInit( 272 ) { 273 if (Environment.Is64BitProcess) return CVodeQuadInitB_x64(cvode_mem, indexB, rhsQB, yQB0); 274 else return CVodeQuadInitB_x86(cvode_mem, indexB, rhsQB, yQB0); 275 } 276 277 278 public static int CVodeAdjInit( 258 279 IntPtr cvode_mem, 259 280 int nd, // integration steps between checkpoints 260 281 int interpType // either CV_POLYNOMIAL or CV_HERMITE 261 ); 262 263 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeF", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 264 public static extern int CVodeF( 282 ) { 283 if (Environment.Is64BitProcess) return CVodeAdjInit_x64(cvode_mem, nd, interpType); 284 else return CVodeAdjInit_x86(cvode_mem, nd, interpType); 285 } 286 287 public static int CVodeF( 265 288 IntPtr cvode_mem, 266 289 double t_out, // the next time at which a computed solution is desired … … 269 292 int itask, // CV_NORMAL or CV_ONE_STEP 270 293 ref int ncheck // the number of internal checkpoints stored so far. 271 ); 272 273 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeGetNumSteps", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 274 public static extern int CVodeGetNumSteps( 294 ) { 295 if (Environment.Is64BitProcess) return CVodeF_x64(cvode_mem, t_out, y, ref t_ret, itask, ref ncheck); 296 else return CVodeF_x86(cvode_mem, t_out, y, ref t_ret, itask, ref ncheck); 297 } 298 299 public static int CVodeGetNumSteps( 275 300 IntPtr cvode_mem, 276 301 ref long ncheck // the number of steps taken 277 ); 278 279 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeCreateB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 280 public static extern int CVodeCreateB( 302 ) { 303 if (Environment.Is64BitProcess) return CVodeGetNumSteps_x64(cvode_mem, ref ncheck); 304 else return CVodeGetNumSteps_x86(cvode_mem, ref ncheck); 305 } 306 307 public static int CVodeCreateB( 281 308 IntPtr cvode_mem, 282 309 MultistepMethod lmmB, 283 310 NonlinearSolverIteration iterB, 284 311 ref int which 285 ); 286 287 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeInitB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 288 public static extern int CVodeInitB( 312 ) { 313 if (Environment.Is64BitProcess) return CVodeCreateB_x64(cvode_mem, lmmB, iterB, ref which); 314 else return CVodeCreateB_x86(cvode_mem, lmmB, iterB, ref which); 315 } 316 317 public static int CVodeInitB( 289 318 IntPtr cvode_mem, 290 319 int which, … … 292 321 double tB0, // endpoint T where final conditions are provided (equal to endpoint of forward integration) 293 322 IntPtr yB0 // N_Vector inital value at t=tb0 of backward solution 294 ); 295 296 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVode", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 297 public static extern int CVode( 323 ) { 324 if (Environment.Is64BitProcess) return CVodeInitB_x64(cvode_mem, which, rightHandSide, tB0, yB0); 325 else return CVodeInitB_x86(cvode_mem, which, rightHandSide, tB0, yB0); 326 } 327 328 public static int CVode( 298 329 IntPtr cvode_mem, 299 330 double tout, // next time at which a solution is desired … … 301 332 ref double tret, // the time reached by the solver (output) 302 333 int itask // flag indicating the job of the solver for the next step. 303 ); 304 305 306 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeSStolerancesB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 307 public static extern int CVodeSStolerancesB( 334 ) { 335 if (Environment.Is64BitProcess) return CVode_x64(cvode_mem, tout, yout, ref tret, itask); 336 else return CVode_x86(cvode_mem, tout, yout, ref tret, itask); 337 } 338 339 340 public static int CVodeSStolerancesB( 308 341 IntPtr cvode_mem, 309 342 int which, 310 343 double reltol, 311 344 double abstol 312 ); 313 314 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVDlsSetLinearSolverB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 315 public static extern int CVDlsSetLinearSolverB( 345 ) { 346 if (Environment.Is64BitProcess) return CVodeSStolerancesB_x64(cvode_mem, which, reltol, abstol); 347 else return CVodeSStolerancesB_x86(cvode_mem, which, reltol, abstol); 348 } 349 350 public static int CVDlsSetLinearSolverB( 316 351 IntPtr cvode_mem, 317 352 int which, 318 353 IntPtr linearSolver, // SUNLinearSolver 319 354 IntPtr j // SUNMatrix 320 ); 321 322 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVDlsSetJacFnB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 323 public static extern int CVDlsSetJacFnB( 355 ) { 356 if (Environment.Is64BitProcess) return CVDlsSetLinearSolverB_x64(cvode_mem, which, linearSolver, j); 357 else return CVDlsSetLinearSolverB_x86(cvode_mem, which, linearSolver, j); 358 } 359 360 public static int CVDlsSetJacFnB( 324 361 IntPtr cvode_mem, 325 362 int which, 326 363 CVDlsJacFuncB jacFunc 327 ); 328 329 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 330 public static extern int CVodeB( 364 ) { 365 if (Environment.Is64BitProcess) return CVDlsSetJacFnB_x64(cvode_mem, which, jacFunc); 366 else return CVDlsSetJacFnB_x86(cvode_mem, which, jacFunc); 367 } 368 369 public static int CVodeB( 331 370 IntPtr cvode_mem, 332 371 double tout, // next time at which a solution is desired 333 372 int itask // flag indicating the job of the solver for the next step. 373 ) { 374 if (Environment.Is64BitProcess) return CVodeB_x64(cvode_mem, tout, itask); 375 else return CVodeB_x86(cvode_mem, tout, itask); 376 } 377 378 public static int CVodeGetB( 379 IntPtr cvode_mem, 380 int which, 381 ref double tret, 382 IntPtr yB // the backward solution at time tret 383 ) { 384 if (Environment.Is64BitProcess) return CVodeGetB_x64(cvode_mem, which, ref tret, yB); 385 else return CVodeGetB_x86(cvode_mem, which, ref tret, yB); 386 } 387 public static int CVodeGetAdjY( 388 IntPtr cvode_mem, 389 double t, 390 IntPtr y // the forward solution y(t) 391 ) { 392 if (Environment.Is64BitProcess) return CVodeGetAdjY_x64(cvode_mem, t, y); 393 else return CVodeGetAdjY_x86(cvode_mem, t, y); 394 } 395 396 public static IntPtr CVodeGetAdjCVodeBmem( 397 IntPtr cvode_mem, 398 int which 399 ) { 400 if (Environment.Is64BitProcess) return CVodeGetAdjCVodeBmem_x64(cvode_mem, which); 401 else return CVodeGetAdjCVodeBmem_x86(cvode_mem, which); 402 } 403 404 public static int CVodeGetQuadB( 405 IntPtr cvode_mem, 406 int which, 407 ref double tret, 408 IntPtr yQB // N_Vector 409 ) { 410 if (Environment.Is64BitProcess) return CVodeGetQuadB_x64(cvode_mem, which, ref tret, yQB); 411 else return CVodeGetQuadB_x86(cvode_mem, which, ref tret, yQB); 412 } 413 414 public static int CVodeFree(ref IntPtr cvode_mem) { 415 if (Environment.Is64BitProcess) return CVodeFree_x64(ref cvode_mem); 416 else return CVodeFree_x86(ref cvode_mem); 417 } 418 419 #region matrix 420 public static IntPtr SUNDenseMatrix(long m, long n) { 421 if (Environment.Is64BitProcess) return SUNDenseMatrix_x64(m, n); 422 else return SUNDenseMatrix_x86(m, n); 423 } 424 425 public static void SUNMatDestroy(IntPtr A) { 426 if (Environment.Is64BitProcess) SUNMatDestroy_x64(A); 427 else SUNMatDestroy_x86(A); 428 } 429 430 public unsafe static double* SUNDenseMatrix_Data(IntPtr matrix) { 431 if (Environment.Is64BitProcess) return SUNDenseMatrix_Data_x64(matrix); 432 else return SUNDenseMatrix_Data_x86(matrix); 433 } 434 435 public static long SUNDenseMatrix_Cols(IntPtr matrix) { 436 if (Environment.Is64BitProcess) return SUNDenseMatrix_Cols_x64(matrix); 437 else return SUNDenseMatrix_Cols_x86(matrix); 438 } 439 440 public static long SUNDenseMatrix_Rows(IntPtr matrix) { 441 if (Environment.Is64BitProcess) return SUNDenseMatrix_Rows_x64(matrix); 442 else return SUNDenseMatrix_Rows_x86(matrix); 443 } 444 445 public unsafe static double SUNDenseMatrix_Get(IntPtr mat, long i, long j) { 446 if (Environment.Is64BitProcess) { 447 long M = SUNDenseMatrix_Rows_x64(mat); 448 // the(i, j)th element of A(with 0 <= i<M and 0 <= j<N) is given by(A->data)[j*M+i] 449 return SUNDenseMatrix_Data_x64(mat)[j * M + i]; 450 } else { 451 long M = SUNDenseMatrix_Rows_x86(mat); 452 return SUNDenseMatrix_Data_x86(mat)[j * M + i]; 453 } 454 } 455 456 public unsafe static void SUNDenseMatrix_Set(IntPtr mat, long i, long j, double val) { 457 if (Environment.Is64BitProcess) { 458 long M = SUNDenseMatrix_Rows_x64(mat); 459 // the(i, j)th element of A(with 0 <= i<M and 0 <= j<N) is given by(A->data)[j*M+i] 460 SUNDenseMatrix_Data_x64(mat)[j * M + i] = val; 461 } else { 462 long M = SUNDenseMatrix_Rows_x86(mat); 463 // the(i, j)th element of A(with 0 <= i<M and 0 <= j<N) is given by(A->data)[j*M+i] 464 SUNDenseMatrix_Data_x86(mat)[j * M + i] = val; 465 } 466 } 467 468 #endregion 469 470 #region linear solver 471 public static IntPtr SUNDenseLinearSolver( 472 IntPtr y, // N_Vector 473 IntPtr A // SUNMatrix 474 ) { 475 if (Environment.Is64BitProcess) return SUNDenseLinearSolver_x64(y, A); 476 else return SUNDenseLinearSolver_x86(y, A); 477 } 478 479 public static int SUNLinSolInitialize(IntPtr linearSolver) { 480 if (Environment.Is64BitProcess) return SUNLinSolInitialize_x64(linearSolver); 481 else return SUNLinSolInitialize_x86(linearSolver); 482 } 483 484 public static int SUNLinSolSetup( 485 IntPtr linearSolver, 486 IntPtr A // SUNMatrix 487 ) { 488 if (Environment.Is64BitProcess) return SUNLinSolSetup_x64(linearSolver, A); 489 else return SUNLinSolSetup_x86(linearSolver, A); 490 } 491 492 public static int SUNLinSolSolve( 493 IntPtr linearSolver, 494 IntPtr A, // SUNMatrix 495 IntPtr x, // N_Vector 496 IntPtr b, // N_Vector 497 double tol 498 ) { 499 if (Environment.Is64BitProcess) return SUNLinSolSolve_x64(linearSolver, A, x, b, tol); 500 else return SUNLinSolSolve_x86(linearSolver, A, x, b, tol); 501 } 502 503 public static int SUNLinSolFree(IntPtr linearSolver) { 504 if (Environment.Is64BitProcess) return SUNLinSolFree_x64(linearSolver); 505 else return SUNLinSolFree_x86(linearSolver); 506 } 507 508 #endregion 509 510 #region N_Vector 511 public static IntPtr N_VNew_Serial(long vec_length) { 512 if (Environment.Is64BitProcess) return N_VNew_Serial_x64(vec_length); 513 else return N_VNew_Serial_x86(vec_length); 514 } 515 516 public static void N_VDestroy_Serial(IntPtr vec) { 517 if (Environment.Is64BitProcess) N_VDestroy_Serial_x64(vec); 518 else N_VDestroy_Serial_x86(vec); 519 } 520 521 public static void N_VDestroyVectorArray_Serial(IntPtr vecArr, int count) { 522 if (Environment.Is64BitProcess) N_VDestroyVectorArray_Serial_x64(vecArr, count); 523 else N_VDestroyVectorArray_Serial_x86(vecArr, count); 524 } 525 526 public static void N_VPrint_Serial(IntPtr vec) { 527 if (Environment.Is64BitProcess) N_VPrint_Serial_x64(vec); 528 else N_VPrint_Serial_x86(vec); 529 } 530 531 public static void N_VConst_Serial(double c, IntPtr vec) { 532 if (Environment.Is64BitProcess) N_VConst_Serial_x64(c, vec); 533 else N_VConst_Serial_x86(c, vec); 534 } 535 536 537 public static double N_VL1Norm_Serial(IntPtr vec) { 538 if (Environment.Is64BitProcess) return N_VL1Norm_Serial_x64(vec); 539 else return N_VL1Norm_Serial_x86(vec); 540 } 541 542 public static IntPtr N_VMake_Serial(long vec_length, double[] v_data) { 543 if (Environment.Is64BitProcess) return N_VMake_Serial_x64(vec_length, v_data); 544 else return N_VMake_Serial_x86(vec_length, v_data); 545 } 546 547 /// Performs the operation z = c*x 548 public static void N_VScale(double s, 549 IntPtr x, // N_Vector 550 IntPtr z // N_Vector 551 ) { 552 if (Environment.Is64BitProcess) N_VScale_x64(s, x, z); 553 else N_VScale_x86(s, x, z); 554 } 555 556 public unsafe static double* N_VGetArrayPointer_Serial(IntPtr vec) { 557 if (Environment.Is64BitProcess) return N_VGetArrayPointer_Serial_x64(vec); 558 else return N_VGetArrayPointer_Serial_x86(vec); 559 } 560 561 public static IntPtr N_VCloneVectorArray_Serial(int count, IntPtr vec) { 562 if (Environment.Is64BitProcess) return N_VCloneVectorArray_Serial_x64(count, vec); 563 else return N_VCloneVectorArray_Serial_x86(count, vec); 564 } 565 566 567 /* 568 #define NV_CONTENT_S(v) ( (N_VectorContent_Serial)(v->content) ) 569 570 #define NV_LENGTH_S(v) ( NV_CONTENT_S(v)->length ) 571 572 #define NV_OWN_DATA_S(v) ( NV_CONTENT_S(v)->own_data ) 573 574 #define NV_DATA_S(v) ( NV_CONTENT_S(v)->data ) 575 576 #define NV_Ith_S(v,i) ( NV_DATA_S(v)[i] ) 577 */ 578 // methods for macros 579 // the vector is a pointer to a struct 580 // the struct has following layout 581 // { 582 // long length, 583 // int own_data, // flag to store whether the memory for the vector is managed internally 584 // double* data, // pointer to the actual elements 585 // } 586 587 private unsafe static IntPtr NV_CONTENT_S(IntPtr v) { 588 if (Environment.Is64BitProcess) { 589 return new IntPtr(*(Int64*)v.ToPointer()); 590 } else { 591 return new IntPtr(*(Int32*)v.ToPointer()); 592 } 593 } 594 595 public unsafe static long NV_LENGTH_S(IntPtr v) { 596 long length = *(long*)NV_CONTENT_S(v).ToPointer(); 597 return length; 598 } 599 public unsafe static bool NV_OWN_DATA_S(IntPtr v) { 600 var content = (int*)NV_CONTENT_S(v).ToPointer(); 601 int own_data = *(content + 2); 602 return own_data > 0; 603 } 604 public unsafe static double* NV_DATA_S(IntPtr v) { 605 if (Environment.Is64BitProcess) { 606 var content = (long*)NV_CONTENT_S(v).ToPointer(); 607 double* data = (double*)*(content + 2); // different alignment or sizeof(int)? 608 return data; 609 } else { 610 var content = (int*)NV_CONTENT_S(v).ToPointer(); 611 double* data = (double*)*(content + 3); 612 return data; 613 } 614 } 615 public unsafe static double NV_Get_Ith_S(IntPtr v, long i) { 616 return NV_DATA_S(v)[i]; 617 } 618 public unsafe static void NV_Set_Ith_S(IntPtr v, long i, double val) { 619 NV_DATA_S(v)[i] = val; 620 } 621 #endregion 622 623 624 #region x86 625 626 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeCreate", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 627 // returns a void* to the cvodes memory block if successful otherwise NULL 628 private static extern IntPtr CVodeCreate_x86(MultistepMethod lmm, NonlinearSolverIteration iter); 629 630 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 631 private static extern int CVodeInit_x86( 632 IntPtr cvode_mem, // pointer returned by CVodeCreate 633 CVRhsFunc f, 634 double t0, // realtype, the inital value of t 635 IntPtr y0 // N_Vector the initial value of y 636 ); 637 638 639 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeSStolerances", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 640 private static extern int CVodeSStolerances_x86( 641 IntPtr cvode_mem, 642 double reltol, 643 double abstol 644 ); 645 646 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVDlsSetLinearSolver", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 647 private static extern int CVDlsSetLinearSolver_x86( 648 IntPtr cvode_mem, 649 IntPtr linearSolver, // SUNLinearSolver 650 IntPtr j // SUNMatrix 651 ); 652 653 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVDlsSetJacFn", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 654 private static extern int CVDlsSetJacFn_x86( 655 IntPtr cvode_mem, 656 CVDlsJacFunc jacFunc 657 ); 658 659 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeSensInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 660 private static extern int CVodeSensInit_x86( 661 IntPtr cvode_mem, 662 int Ns, // number of parameters 663 int ism, // sensitivity solution method, CV_SIMULTANEOUS or CV_STAGGERED 664 CVSensRhsFn fS, // right hand side function which computes all sensitivity RHS at the same time 665 IntPtr yS0 // N_Vector 666 ); 667 668 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeSensSStolerances", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 669 private static extern int CVodeSensSStolerances_x86( 670 IntPtr cvode_mem, 671 double reltol, 672 double[] abstol 673 ); 674 675 /* Call CVodeSensEEtolerances to estimate tolerances for sensitivity 676 variables based on the rolerances supplied for states variables and 677 the scaling factor pbar */ 678 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeSensEEtolerances", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 679 private static extern int CVodeSensEEtolerances_x86( 680 IntPtr cvode_mem 681 ); 682 683 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeGetSens", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 684 private static extern int CVodeGetSens_x86( 685 IntPtr cvode_mem, 686 ref double tret, 687 IntPtr yS //N_Vector*, one vector for each parameter 688 ); 689 690 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeQuadInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 691 private static extern int CVodeQuadInit_x86( 692 IntPtr cvode_mem, 693 CVQuadRhsFn qF, 694 IntPtr yQ0 // N_Vector, initial value of yQ 695 ); 696 697 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeQuadInitB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 698 private static extern int CVodeQuadInitB_x86( 699 IntPtr cvode_mem, 700 int indexB, 701 CVQuadRhsFnB rhsQB, 702 IntPtr yQB0 // N_Vector, initial value of yQB 703 ); 704 705 706 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeAdjInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 707 private static extern int CVodeAdjInit_x86( 708 IntPtr cvode_mem, 709 int nd, // integration steps between checkpoints 710 int interpType // either CV_POLYNOMIAL or CV_HERMITE 711 ); 712 713 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeF", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 714 private static extern int CVodeF_x86( 715 IntPtr cvode_mem, 716 double t_out, // the next time at which a computed solution is desired 717 IntPtr y, // N_Vector, the solution vector y 718 ref double t_ret, // the time reached by the solver (output) 719 int itask, // CV_NORMAL or CV_ONE_STEP 720 ref int ncheck // the number of internal checkpoints stored so far. 721 ); 722 723 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeGetNumSteps", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 724 private static extern int CVodeGetNumSteps_x86( 725 IntPtr cvode_mem, 726 ref long ncheck // the number of steps taken 727 ); 728 729 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeCreateB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 730 private static extern int CVodeCreateB_x86( 731 IntPtr cvode_mem, 732 MultistepMethod lmmB, 733 NonlinearSolverIteration iterB, 734 ref int which 735 ); 736 737 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeInitB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 738 private static extern int CVodeInitB_x86( 739 IntPtr cvode_mem, 740 int which, 741 CVRhsFuncB rightHandSide, 742 double tB0, // endpoint T where final conditions are provided (equal to endpoint of forward integration) 743 IntPtr yB0 // N_Vector inital value at t=tb0 of backward solution 744 ); 745 746 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVode", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 747 private static extern int CVode_x86( 748 IntPtr cvode_mem, 749 double tout, // next time at which a solution is desired 750 IntPtr yout, // N_Vector 751 ref double tret, // the time reached by the solver (output) 752 int itask // flag indicating the job of the solver for the next step. 753 ); 754 755 756 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeSStolerancesB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 757 private static extern int CVodeSStolerancesB_x86( 758 IntPtr cvode_mem, 759 int which, 760 double reltol, 761 double abstol 762 ); 763 764 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVDlsSetLinearSolverB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 765 private static extern int CVDlsSetLinearSolverB_x86( 766 IntPtr cvode_mem, 767 int which, 768 IntPtr linearSolver, // SUNLinearSolver 769 IntPtr j // SUNMatrix 770 ); 771 772 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVDlsSetJacFnB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 773 private static extern int CVDlsSetJacFnB_x86( 774 IntPtr cvode_mem, 775 int which, 776 CVDlsJacFuncB jacFunc 777 ); 778 779 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 780 private static extern int CVodeB_x86( 781 IntPtr cvode_mem, 782 double tout, // next time at which a solution is desired 783 int itask // flag indicating the job of the solver for the next step. 334 784 ); 335 785 336 786 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeGetB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 337 p ublic static extern int CVodeGetB(787 private static extern int CVodeGetB_x86( 338 788 IntPtr cvode_mem, 339 789 int which, … … 342 792 ); 343 793 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeGetAdjY", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 344 p ublic static extern int CVodeGetAdjY(794 private static extern int CVodeGetAdjY_x86( 345 795 IntPtr cvode_mem, 346 796 double t, … … 349 799 350 800 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeGetAdjCVodeBmem", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 351 p ublic static extern IntPtr CVodeGetAdjCVodeBmem(801 private static extern IntPtr CVodeGetAdjCVodeBmem_x86( 352 802 IntPtr cvode_mem, 353 803 int which … … 355 805 356 806 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeGetQuadB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 357 p ublic static extern int CVodeGetQuadB(807 private static extern int CVodeGetQuadB_x86( 358 808 IntPtr cvode_mem, 359 809 int which, … … 364 814 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "CVodeFree", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 365 815 366 p ublic static extern int CVodeFree(ref IntPtr cvode_mem);816 private static extern int CVodeFree_x86(ref IntPtr cvode_mem); 367 817 368 818 #region matrix 369 819 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "SUNDenseMatrix", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 370 p ublic static extern IntPtr SUNDenseMatrix(long m, long n);820 private static extern IntPtr SUNDenseMatrix_x86(long m, long n); 371 821 372 822 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "SUNMatDestroy", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 373 p ublic static extern void SUNMatDestroy(IntPtr A);823 private static extern void SUNMatDestroy_x86(IntPtr A); 374 824 375 825 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "SUNDenseMatrix_Data", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 376 p ublic unsafe static extern double* SUNDenseMatrix_Data(IntPtr matrix);826 private unsafe static extern double* SUNDenseMatrix_Data_x86(IntPtr matrix); 377 827 378 828 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "SUNDenseMatrix_Cols", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 379 p ublic static extern long SUNDenseMatrix_Cols(IntPtr matrix);829 private static extern long SUNDenseMatrix_Cols_x86(IntPtr matrix); 380 830 381 831 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "SUNDenseMatrix_Rows", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 382 public static extern long SUNDenseMatrix_Rows(IntPtr matrix); 383 384 385 public unsafe static double SUNDenseMatrix_Get(IntPtr mat, long i, long j) { 386 long M = SUNDenseMatrix_Rows(mat); 387 // the(i, j)th element of A(with 0 <= i<M and 0 <= j<N) is given by(A->data)[j*M+i] 388 return SUNDenseMatrix_Data(mat)[j * M + i]; 389 } 390 391 public unsafe static void SUNDenseMatrix_Set(IntPtr mat, long i, long j, double val) { 392 long M = SUNDenseMatrix_Rows(mat); 393 // the(i, j)th element of A(with 0 <= i<M and 0 <= j<N) is given by(A->data)[j*M+i] 394 SUNDenseMatrix_Data(mat)[j * M + i] = val; 395 } 832 private static extern long SUNDenseMatrix_Rows_x86(IntPtr matrix); 833 396 834 397 835 #endregion … … 399 837 #region linear solver 400 838 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "SUNDenseLinearSolver", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 401 p ublic static extern IntPtr SUNDenseLinearSolver(839 private static extern IntPtr SUNDenseLinearSolver_x86( 402 840 IntPtr y, // N_Vector 403 841 IntPtr A // SUNMatrix … … 405 843 406 844 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "SUNLinSolInitialize", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 407 p ublic static extern int SUNLinSolInitialize(IntPtr linearSolver);845 private static extern int SUNLinSolInitialize_x86(IntPtr linearSolver); 408 846 409 847 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "SUNLinSolSetup", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 410 p ublic static extern int SUNLinSolSetup(848 private static extern int SUNLinSolSetup_x86( 411 849 IntPtr linearSolver, 412 850 IntPtr A // SUNMatrix … … 414 852 415 853 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "SUNLinSolSolve", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 416 p ublic static extern int SUNLinSolSolve(854 private static extern int SUNLinSolSolve_x86( 417 855 IntPtr linearSolver, 418 856 IntPtr A, // SUNMatrix … … 423 861 424 862 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "SUNLinSolFree", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 425 p ublic static extern int SUNLinSolFree(IntPtr linearSolver);863 private static extern int SUNLinSolFree_x86(IntPtr linearSolver); 426 864 427 865 #endregion … … 429 867 #region N_Vector 430 868 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "N_VNew_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 431 p ublic static extern IntPtr N_VNew_Serial(long vec_length);869 private static extern IntPtr N_VNew_Serial_x86(long vec_length); 432 870 433 871 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "N_VDestroy_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 434 p ublic static extern void N_VDestroy_Serial(IntPtr vec);872 private static extern void N_VDestroy_Serial_x86(IntPtr vec); 435 873 436 874 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "N_VDestroyVectorArray_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 437 p ublic static extern void N_VDestroyVectorArray_Serial(IntPtr vecArr, int count);875 private static extern void N_VDestroyVectorArray_Serial_x86(IntPtr vecArr, int count); 438 876 439 877 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "N_VPrint_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 440 p ublic static extern void N_VPrint_Serial(IntPtr vec);878 private static extern void N_VPrint_Serial_x86(IntPtr vec); 441 879 442 880 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "N_VConst_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 443 p ublic static extern void N_VConst_Serial(double c, IntPtr vec);881 private static extern void N_VConst_Serial_x86(double c, IntPtr vec); 444 882 445 883 446 884 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "N_VL1Norm_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 447 p ublic static extern double N_VL1Norm_Serial(IntPtr vec);885 private static extern double N_VL1Norm_Serial_x86(IntPtr vec); 448 886 449 887 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "N_VMake_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 450 p ublic static extern IntPtr N_VMake_Serial(long vec_length, double[] v_data);888 private static extern IntPtr N_VMake_Serial_x86(long vec_length, double[] v_data); 451 889 452 890 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "N_VScale", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 453 891 /// Performs the operation z = c*x 454 p ublic static extern void N_VScale(double s,892 private static extern void N_VScale_x86(double s, 455 893 IntPtr x, // N_Vector 456 894 IntPtr z // N_Vector … … 458 896 459 897 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "N_VMake_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 460 p ublic unsafe static extern double* N_VGetArrayPointer_Serial(IntPtr vec);898 private unsafe static extern double* N_VGetArrayPointer_Serial_x86(IntPtr vec); 461 899 462 900 [DllImport("sundials_cvodes-x86.dll", EntryPoint = "N_VCloneVectorArray_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 463 public static extern IntPtr N_VCloneVectorArray_Serial(int count, IntPtr vec); // returns N_Vector* ! 464 465 466 /* 467 #define NV_CONTENT_S(v) ( (N_VectorContent_Serial)(v->content) ) 468 469 #define NV_LENGTH_S(v) ( NV_CONTENT_S(v)->length ) 470 471 #define NV_OWN_DATA_S(v) ( NV_CONTENT_S(v)->own_data ) 472 473 #define NV_DATA_S(v) ( NV_CONTENT_S(v)->data ) 474 475 #define NV_Ith_S(v,i) ( NV_DATA_S(v)[i] ) 476 */ 477 // methods for macros 478 public unsafe static int* NV_CONTENT_S(IntPtr v) { 479 int* content = (int*)*(int*)v.ToPointer(); 480 return content; 481 } 482 483 public unsafe static long NV_LENGTH_S(IntPtr v) { 484 long length = *NV_CONTENT_S(v); 485 return length; 486 } 487 public unsafe static bool NV_OWN_DATA_S(IntPtr v) { 488 var content = NV_CONTENT_S(v); 489 int own_data = *(content + 2); 490 return own_data > 0; 491 } 492 public unsafe static double* NV_DATA_S(IntPtr v) { 493 var content = NV_CONTENT_S(v); 494 double* data = (double*)*(content + 3); 495 return data; 496 } 497 public unsafe static double NV_Get_Ith_S(IntPtr v, long i) { 498 return NV_DATA_S(v)[i]; 499 } 500 public unsafe static void NV_Set_Ith_S(IntPtr v, long i, double val) { 501 NV_DATA_S(v)[i] = val; 502 } 901 private static extern IntPtr N_VCloneVectorArray_Serial_x86(int count, IntPtr vec); // returns N_Vector* ! 902 503 903 #endregion 504 904 505 905 #endregion 906 907 #region x64 908 909 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeCreate", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 910 // returns a void* to the cvodes memory block if successful otherwise NULL 911 private static extern IntPtr CVodeCreate_x64(MultistepMethod lmm, NonlinearSolverIteration iter); 912 913 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 914 private static extern int CVodeInit_x64( 915 IntPtr cvode_mem, // pointer returned by CVodeCreate 916 CVRhsFunc f, 917 double t0, // realtype, the inital value of t 918 IntPtr y0 // N_Vector the initial value of y 919 ); 920 921 922 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeSStolerances", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 923 private static extern int CVodeSStolerances_x64( 924 IntPtr cvode_mem, 925 double reltol, 926 double abstol 927 ); 928 929 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVDlsSetLinearSolver", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 930 private static extern int CVDlsSetLinearSolver_x64( 931 IntPtr cvode_mem, 932 IntPtr linearSolver, // SUNLinearSolver 933 IntPtr j // SUNMatrix 934 ); 935 936 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVDlsSetJacFn", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 937 private static extern int CVDlsSetJacFn_x64( 938 IntPtr cvode_mem, 939 CVDlsJacFunc jacFunc 940 ); 941 942 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeSensInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 943 private static extern int CVodeSensInit_x64( 944 IntPtr cvode_mem, 945 int Ns, // number of parameters 946 int ism, // sensitivity solution method, CV_SIMULTANEOUS or CV_STAGGERED 947 CVSensRhsFn fS, // right hand side function which computes all sensitivity RHS at the same time 948 IntPtr yS0 // N_Vector 949 ); 950 951 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeSensSStolerances", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 952 private static extern int CVodeSensSStolerances_x64( 953 IntPtr cvode_mem, 954 double reltol, 955 double[] abstol 956 ); 957 958 /* Call CVodeSensEEtolerances to estimate tolerances for sensitivity 959 variables based on the rolerances supplied for states variables and 960 the scaling factor pbar */ 961 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeSensEEtolerances", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 962 private static extern int CVodeSensEEtolerances_x64( 963 IntPtr cvode_mem 964 ); 965 966 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeGetSens", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 967 private static extern int CVodeGetSens_x64( 968 IntPtr cvode_mem, 969 ref double tret, 970 IntPtr yS //N_Vector*, one vector for each parameter 971 ); 972 973 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeQuadInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 974 private static extern int CVodeQuadInit_x64( 975 IntPtr cvode_mem, 976 CVQuadRhsFn qF, 977 IntPtr yQ0 // N_Vector, initial value of yQ 978 ); 979 980 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeQuadInitB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 981 private static extern int CVodeQuadInitB_x64( 982 IntPtr cvode_mem, 983 int indexB, 984 CVQuadRhsFnB rhsQB, 985 IntPtr yQB0 // N_Vector, initial value of yQB 986 ); 987 988 989 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeAdjInit", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 990 private static extern int CVodeAdjInit_x64( 991 IntPtr cvode_mem, 992 int nd, // integration steps between checkpoints 993 int interpType // either CV_POLYNOMIAL or CV_HERMITE 994 ); 995 996 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeF", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 997 private static extern int CVodeF_x64( 998 IntPtr cvode_mem, 999 double t_out, // the next time at which a computed solution is desired 1000 IntPtr y, // N_Vector, the solution vector y 1001 ref double t_ret, // the time reached by the solver (output) 1002 int itask, // CV_NORMAL or CV_ONE_STEP 1003 ref int ncheck // the number of internal checkpoints stored so far. 1004 ); 1005 1006 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeGetNumSteps", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1007 private static extern int CVodeGetNumSteps_x64( 1008 IntPtr cvode_mem, 1009 ref long ncheck // the number of steps taken 1010 ); 1011 1012 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeCreateB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1013 private static extern int CVodeCreateB_x64( 1014 IntPtr cvode_mem, 1015 MultistepMethod lmmB, 1016 NonlinearSolverIteration iterB, 1017 ref int which 1018 ); 1019 1020 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeInitB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1021 private static extern int CVodeInitB_x64( 1022 IntPtr cvode_mem, 1023 int which, 1024 CVRhsFuncB rightHandSide, 1025 double tB0, // endpoint T where final conditions are provided (equal to endpoint of forward integration) 1026 IntPtr yB0 // N_Vector inital value at t=tb0 of backward solution 1027 ); 1028 1029 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVode", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1030 private static extern int CVode_x64( 1031 IntPtr cvode_mem, 1032 double tout, // next time at which a solution is desired 1033 IntPtr yout, // N_Vector 1034 ref double tret, // the time reached by the solver (output) 1035 int itask // flag indicating the job of the solver for the next step. 1036 ); 1037 1038 1039 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeSStolerancesB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1040 private static extern int CVodeSStolerancesB_x64( 1041 IntPtr cvode_mem, 1042 int which, 1043 double reltol, 1044 double abstol 1045 ); 1046 1047 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVDlsSetLinearSolverB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1048 private static extern int CVDlsSetLinearSolverB_x64( 1049 IntPtr cvode_mem, 1050 int which, 1051 IntPtr linearSolver, // SUNLinearSolver 1052 IntPtr j // SUNMatrix 1053 ); 1054 1055 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVDlsSetJacFnB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1056 private static extern int CVDlsSetJacFnB_x64( 1057 IntPtr cvode_mem, 1058 int which, 1059 CVDlsJacFuncB jacFunc 1060 ); 1061 1062 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1063 private static extern int CVodeB_x64( 1064 IntPtr cvode_mem, 1065 double tout, // next time at which a solution is desired 1066 int itask // flag indicating the job of the solver for the next step. 1067 ); 1068 1069 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeGetB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1070 private static extern int CVodeGetB_x64( 1071 IntPtr cvode_mem, 1072 int which, 1073 ref double tret, 1074 IntPtr yB // the backward solution at time tret 1075 ); 1076 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeGetAdjY", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1077 private static extern int CVodeGetAdjY_x64( 1078 IntPtr cvode_mem, 1079 double t, 1080 IntPtr y // the forward solution y(t) 1081 ); 1082 1083 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeGetAdjCVodeBmem", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1084 private static extern IntPtr CVodeGetAdjCVodeBmem_x64( 1085 IntPtr cvode_mem, 1086 int which 1087 ); 1088 1089 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeGetQuadB", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1090 private static extern int CVodeGetQuadB_x64( 1091 IntPtr cvode_mem, 1092 int which, 1093 ref double tret, 1094 IntPtr yQB // N_Vector 1095 ); 1096 1097 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "CVodeFree", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1098 1099 private static extern int CVodeFree_x64(ref IntPtr cvode_mem); 1100 1101 #region matrix 1102 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "SUNDenseMatrix", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1103 private static extern IntPtr SUNDenseMatrix_x64(long m, long n); 1104 1105 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "SUNMatDestroy", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1106 private static extern void SUNMatDestroy_x64(IntPtr A); 1107 1108 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "SUNDenseMatrix_Data", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1109 private unsafe static extern double* SUNDenseMatrix_Data_x64(IntPtr matrix); 1110 1111 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "SUNDenseMatrix_Cols", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1112 private static extern long SUNDenseMatrix_Cols_x64(IntPtr matrix); 1113 1114 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "SUNDenseMatrix_Rows", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1115 private static extern long SUNDenseMatrix_Rows_x64(IntPtr matrix); 1116 1117 #endregion 1118 1119 #region linear solver 1120 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "SUNDenseLinearSolver", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1121 private static extern IntPtr SUNDenseLinearSolver_x64( 1122 IntPtr y, // N_Vector 1123 IntPtr A // SUNMatrix 1124 ); 1125 1126 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "SUNLinSolInitialize", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1127 private static extern int SUNLinSolInitialize_x64(IntPtr linearSolver); 1128 1129 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "SUNLinSolSetup", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1130 private static extern int SUNLinSolSetup_x64( 1131 IntPtr linearSolver, 1132 IntPtr A // SUNMatrix 1133 ); 1134 1135 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "SUNLinSolSolve", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1136 private static extern int SUNLinSolSolve_x64( 1137 IntPtr linearSolver, 1138 IntPtr A, // SUNMatrix 1139 IntPtr x, // N_Vector 1140 IntPtr b, // N_Vector 1141 double tol 1142 ); 1143 1144 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "SUNLinSolFree", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1145 private static extern int SUNLinSolFree_x64(IntPtr linearSolver); 1146 1147 #endregion 1148 1149 #region N_Vector 1150 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "N_VNew_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1151 private static extern IntPtr N_VNew_Serial_x64(long vec_length); 1152 1153 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "N_VDestroy_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1154 private static extern void N_VDestroy_Serial_x64(IntPtr vec); 1155 1156 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "N_VDestroyVectorArray_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1157 private static extern void N_VDestroyVectorArray_Serial_x64(IntPtr vecArr, int count); 1158 1159 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "N_VPrint_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1160 private static extern void N_VPrint_Serial_x64(IntPtr vec); 1161 1162 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "N_VConst_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1163 private static extern void N_VConst_Serial_x64(double c, IntPtr vec); 1164 1165 1166 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "N_VL1Norm_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1167 private static extern double N_VL1Norm_Serial_x64(IntPtr vec); 1168 1169 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "N_VMake_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1170 private static extern IntPtr N_VMake_Serial_x64(long vec_length, double[] v_data); 1171 1172 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "N_VScale", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1173 /// Performs the operation z = c*x 1174 private static extern void N_VScale_x64(double s, 1175 IntPtr x, // N_Vector 1176 IntPtr z // N_Vector 1177 ); 1178 1179 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "N_VMake_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1180 private unsafe static extern double* N_VGetArrayPointer_Serial_x64(IntPtr vec); 1181 1182 [DllImport("sundials_cvodes-x64.dll", EntryPoint = "N_VCloneVectorArray_Serial", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] 1183 private static extern IntPtr N_VCloneVectorArray_Serial_x64(int count, IntPtr vec); // returns N_Vector* ! 1184 #endregion 1185 1186 #endregion 506 1187 } 507 1188 } -
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/HeuristicLab.Problems.DynamicalSystemsModelling-3.3.csproj
r16254 r16256 221 221 </ItemGroup> 222 222 <ItemGroup> 223 <Content Include="sundials_cvodes-x64.dll"> 224 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 225 </Content> 223 226 <Content Include="sundials_cvodes-x86.dll"> 224 227 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Note: See TracChangeset
for help on using the changeset viewer.