192 std::vector<double>& rInitialY,
197 assert(maxStep > 0.0);
200#if CHASTE_SUNDIALS_VERSION >= 60000
201 N_Vector initial_values = N_VMake_Serial(rInitialY.size(), &(rInitialY[0]), CvodeContextManager::Instance()->GetSundialsContext());
203 N_Vector initial_values = N_VMake_Serial(rInitialY.size(), &(rInitialY[0]));
205 assert(NV_DATA_S(initial_values) == &(rInitialY[0]));
206 assert(!NV_OWN_DATA_S(initial_values));
216 for (
unsigned i = 0; i < size; i++)
229#if CHASTE_SUNDIALS_VERSION >= 60000
230 mpCvodeMem = CVodeCreate(CV_BDF, CvodeContextManager::Instance()->GetSundialsContext());
231#elif CHASTE_SUNDIALS_VERSION >= 40000
242 CVodeSetErrHandlerFn(
mpCvodeMem, CvodeErrorHandler,
nullptr);
246#if CHASTE_SUNDIALS_VERSION >= 20400
253#if CHASTE_SUNDIALS_VERSION >= 20400
254 CVodeInit(
mpCvodeMem, CvodeRhsAdaptor, startTime, initial_values);
257 CVodeMalloc(
mpCvodeMem, CvodeRhsAdaptor, startTime, initial_values,
264#if CHASTE_SUNDIALS_VERSION >= 20400
265 CVodeRootInit(
mpCvodeMem, 1, CvodeRootAdaptor);
272#if CHASTE_SUNDIALS_VERSION >= 60000
273 mpSundialsDenseMatrix = SUNDenseMatrix(rInitialY.size(), rInitialY.size(), CvodeContextManager::Instance()->GetSundialsContext());
274#elif CHASTE_SUNDIALS_VERSION >= 30000
275 mpSundialsDenseMatrix = SUNDenseMatrix(rInitialY.size(), rInitialY.size());
278#if CHASTE_SUNDIALS_VERSION >= 60000
280 mpSundialsLinearSolver = SUNLinSol_Dense(initial_values, mpSundialsDenseMatrix, CvodeContextManager::Instance()->GetSundialsContext());
283 CVodeSetLinearSolver(
mpCvodeMem, mpSundialsLinearSolver, mpSundialsDenseMatrix);
284#elif CHASTE_SUNDIALS_VERSION >= 40000
286 mpSundialsLinearSolver = SUNLinSol_Dense(initial_values, mpSundialsDenseMatrix);
289 CVodeSetLinearSolver(
mpCvodeMem, mpSundialsLinearSolver, mpSundialsDenseMatrix);
290#elif CHASTE_SUNDIALS_VERSION >= 30000
292 mpSundialsLinearSolver = SUNDenseLinearSolver(initial_values, mpSundialsDenseMatrix);
295 CVDlsSetLinearSolver(
mpCvodeMem, mpSundialsLinearSolver, mpSundialsDenseMatrix);
307#if CHASTE_SUNDIALS_VERSION >= 20400
313#if CHASTE_SUNDIALS_VERSION >= 20400
314 CVodeReInit(
mpCvodeMem, startTime, initial_values);
317 CVodeReInit(
mpCvodeMem, CvodeRhsAdaptor, startTime, initial_values,
321#if CHASTE_SUNDIALS_VERSION >= 30000
322 if (mpSundialsLinearSolver)
325 SUNLinSolFree(mpSundialsLinearSolver);
327 if (mpSundialsDenseMatrix)
330 SUNMatDestroy(mpSundialsDenseMatrix);
334#if CHASTE_SUNDIALS_VERSION >= 60000
335 mpSundialsDenseMatrix = SUNDenseMatrix(rInitialY.size(), rInitialY.size(), CvodeContextManager::Instance()->GetSundialsContext());
337 mpSundialsDenseMatrix = SUNDenseMatrix(rInitialY.size(), rInitialY.size());
340#if CHASTE_SUNDIALS_VERSION >= 60000
342 mpSundialsLinearSolver = SUNLinSol_Dense(initial_values, mpSundialsDenseMatrix, CvodeContextManager::Instance()->GetSundialsContext());
345 CVodeSetLinearSolver(
mpCvodeMem, mpSundialsLinearSolver, mpSundialsDenseMatrix);
346#elif CHASTE_SUNDIALS_VERSION >= 40000
348 mpSundialsLinearSolver = SUNLinSol_Dense(initial_values, mpSundialsDenseMatrix);
351 CVodeSetLinearSolver(
mpCvodeMem, mpSundialsLinearSolver, mpSundialsDenseMatrix);
354 mpSundialsLinearSolver = SUNDenseLinearSolver(initial_values, mpSundialsDenseMatrix);
357 CVDlsSetLinearSolver(
mpCvodeMem, mpSundialsLinearSolver, mpSundialsDenseMatrix);
437 std::vector<double>& rYValues,
443 assert(endTime > startTime);
444 assert(timeSampling > 0.0);
449 EXCEPTION(
"(Solve with sampling) Stopping event is true for initial condition");
452 SetupCvode(pOdeSystem, rYValues, startTime, maxStep);
454 TimeStepper stepper(startTime, endTime, timeSampling);
455#if CHASTE_SUNDIALS_VERSION >= 60000
456 N_Vector yout = N_VMake_Serial(rYValues.size(), &(rYValues[0]), CvodeContextManager::Instance()->GetSundialsContext());
458 N_Vector yout = N_VMake_Serial(rYValues.size(), &(rYValues[0]));
465 solutions.
rGetTimes().push_back(startTime);
473 assert(ierr == CV_SUCCESS);
482 CvodeError(ierr,
"CVODE failed to solve system");
487 if (ierr == CV_ROOT_RETURN)
501 assert(ierr == CV_SUCCESS);
510 std::vector<double>& rYValues,
515 assert(endTime > startTime);
520 EXCEPTION(
"(Solve) Stopping event is true for initial condition");
523 SetupCvode(pOdeSystem, rYValues, startTime, maxStep);
525#if CHASTE_SUNDIALS_VERSION >= 60000
526 N_Vector yout = N_VMake_Serial(rYValues.size(), &(rYValues[0]), CvodeContextManager::Instance()->GetSundialsContext());
528 N_Vector yout = N_VMake_Serial(rYValues.size(), &(rYValues[0]));
532 int ierr = CVodeSetStopTime(
mpCvodeMem, endTime);
533 assert(ierr == CV_SUCCESS);
537 ierr = CVode(
mpCvodeMem, endTime, yout, &tend, CV_NORMAL);
542 CvodeError(ierr,
"CVODE failed to solve system");
544 if (ierr == CV_ROOT_RETURN)
550 assert(NV_DATA_S(yout) == &(rYValues[0]));
551 assert(!NV_OWN_DATA_S(yout));
558 assert(ierr == CV_SUCCESS);
569 mLastInternalStepSize(-0.0),
571 mCheckForRoots(false),
572 mLastSolutionState(nullptr),
573 mLastSolutionTime(0.0),
574#if CHASTE_SUNDIALS_VERSION >= 20400
579 mForceMinimalReset(false)
580#if CHASTE_SUNDIALS_VERSION >= 30000
582 mpSundialsDenseMatrix(nullptr),
583 mpSundialsLinearSolver(nullptr)