19#ifdef DEAL_II_WITH_SUNDIALS
26# ifdef DEAL_II_WITH_TRILINOS
30# ifdef DEAL_II_WITH_PETSC
38# include <idas/idas.h>
39# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
40# include <sundials/sundials_context.h>
51#ifdef DEAL_II_WITH_SUNDIALS
55 template <
typename VectorType>
62 template <
typename VectorType>
79# if DEAL_II_SUNDIALS_VERSION_GTE(7, 0, 0)
86# elif DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
98 template <
typename VectorType>
102# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
103 const int status = SUNContext_Free(&
ida_ctx);
113 template <
typename VectorType>
117 double t =
data.initial_time;
118 double h =
data.initial_step_size;
119 unsigned int step_number = 0;
124 reset(
data.initial_time,
data.initial_step_size, solution, solution_dot);
130 double next_time =
data.initial_time;
134 while (t <
data.final_time)
136 next_time +=
data.output_period;
155 status = IDASolve(
ida_mem, next_time, &t, yy, yp, IDA_NORMAL);
178 status = IDAGetLastStep(
ida_mem, &h);
182 reset(t, h, solution, solution_dot);
186 output_step(t, solution, solution_dot, step_number);
196 template <
typename VectorType>
199 const double current_time_step,
200 VectorType &solution,
201 VectorType &solution_dot)
203 bool first_step = (current_time ==
data.initial_time);
208# if DEAL_II_SUNDIALS_VERSION_GTE(7, 0, 0)
209 status = SUNContext_Free(&
ida_ctx);
218# elif DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
219 status = SUNContext_Free(&
ida_ctx);
236# if DEAL_II_SUNDIALS_VERSION_LT(6, 0, 0)
261 void *user_data) ->
int {
288 status = IDASVtolerances(
ida_mem,
data.relative_tolerance, abs_tols);
293 status = IDASStolerances(
ida_mem,
294 data.relative_tolerance,
295 data.absolute_tolerance);
299 status = IDASetInitStep(
ida_mem, current_time_step);
302 status = IDASetUserData(
ida_mem,
this);
307 data.ignore_algebraic_terms_for_errors)
309 VectorType diff_comp_vector(solution);
310 diff_comp_vector = 0.0;
312 diff_comp_vector[component] = 1.0;
321 status = IDASetId(
ida_mem, diff_id);
325 status = IDASetSuppressAlg(
ida_mem,
data.ignore_algebraic_terms_for_errors);
332 status = IDASetMaxNonlinIters(
ida_mem,
data.maximum_non_linear_iterations);
336 SUNMatrix J =
nullptr;
343# if DEAL_II_SUNDIALS_VERSION_LT(6, 0, 0)
344 LS = SUNLinSolNewEmpty();
346 LS = SUNLinSolNewEmpty(
ida_ctx);
352 return SUNLINEARSOLVER_MATRIX_ITERATIVE;
358 LS->content =
nullptr;
408# if DEAL_II_SUNDIALS_VERSION_LT(6, 0, 0)
409 J = SUNMatNewEmpty();
415 J->ops->getid = [](SUNMatrix ) -> SUNMatrix_ID {
416 return SUNMATRIX_CUSTOM;
419 J->ops->destroy = [](SUNMatrix A) {
422 A->content =
nullptr;
434 status = IDASetLinearSolver(
ida_mem, LS, J);
437 status = IDASetLSNormFactor(
ida_mem,
data.ls_norm_factor);
442 status = IDASetJacFn(
469 status = IDASetMaxOrd(
ida_mem,
data.maximum_order);
476 type =
data.reset_type;
479 IDASetMaxNumItersIC(
ida_mem,
data.maximum_non_linear_iterations_ic);
486 IDACalcIC(
ida_mem, IDA_Y_INIT, current_time + current_time_step);
489 status = IDAGetConsistentIC(
ida_mem, yy, yp);
495 IDACalcIC(
ida_mem, IDA_YA_YDP_INIT, current_time + current_time_step);
498 status = IDAGetConsistentIC(
ida_mem, yy, yp);
503 template <
typename VectorType>
514 VectorType &) ->
int {
524 const unsigned int) {
return; };
527 [](
const double, VectorType &, VectorType &) ->
bool {
return false; };
533 return v->locally_owned_elements();
540# ifdef DEAL_II_WITH_MPI
542# ifdef DEAL_II_WITH_TRILINOS
547# ifdef DEAL_II_WITH_PETSC
548# ifndef PETSC_USE_COMPLEX
*const unsigned int n_steps
InitialConditionCorrection
std::function< void(const VectorType &rhs, VectorType &dst, const double tolerance)> solve_with_jacobian
unsigned int solve_dae(VectorType &solution, VectorType &solution_dot)
MPI_Comm mpi_communicator
std::function< void(const double t, const VectorType &y, const VectorType &y_dot, const double alpha)> setup_jacobian
void set_functions_to_trigger_an_assert()
const AdditionalData data
void reset(const double t, const double h, VectorType &y, VectorType &yp)
std::function< void(const double t, const VectorType &y, const VectorType &y_dot, VectorType &res)> residual
std::function< void(const double t, const VectorType &sol, const VectorType &sol_dot, const unsigned int step_number)> output_step
std::function< IndexSet()> differential_components
std::function< VectorType &()> get_local_tolerances
std::function< bool(const double t, VectorType &sol, VectorType &sol_dot)> solver_should_restart
GrowingVectorMemory< VectorType > mem
std::function< void(VectorType &)> reinit_vector
IDA(const AdditionalData &data=AdditionalData())
std::exception_ptr pending_exception
NVectorView< VectorType > make_nvector_view(VectorType &vector, SUNContext nvector_context)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_SUNDIALS_VERSION_GTE(major, minor, patch)
#define DEAL_II_SUNDIALS_VERSION_LT(major, minor, patch)
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcFunctionNotProvided(std::string arg1)
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & RecoverableUserCallbackError()
#define AssertThrow(cond, exc)
int call_and_possibly_capture_exception(const F &f, std::exception_ptr &eptr, Args &&...args)
VectorType * unwrap_nvector(N_Vector v)
const VectorType * unwrap_nvector_const(N_Vector v)