21#ifdef DEAL_II_WITH_SUNDIALS
28# ifdef DEAL_II_WITH_TRILINOS
32# ifdef DEAL_II_WITH_PETSC
40# include <idas/idas.h>
41# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
42# include <sundials/sundials_context.h>
52 template <
typename VectorType>
59 template <
typename VectorType>
76# if DEAL_II_SUNDIALS_VERSION_GTE(7, 0, 0)
83# elif DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
95 template <
typename VectorType>
99# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
100 const int status = SUNContext_Free(&
ida_ctx);
110 template <
typename VectorType>
114 double t =
data.initial_time;
115 double h =
data.initial_step_size;
116 unsigned int step_number = 0;
121 reset(
data.initial_time,
data.initial_step_size, solution, solution_dot);
127 double next_time =
data.initial_time;
131 while (t <
data.final_time)
133 next_time +=
data.output_period;
152 status = IDASolve(
ida_mem, next_time, &t, yy, yp, IDA_NORMAL);
175 status = IDAGetLastStep(
ida_mem, &h);
179 reset(t, h, solution, solution_dot);
183 output_step(t, solution, solution_dot, step_number);
186 status = IDAGetNumSteps(
ida_mem, &n_steps);
193 template <
typename VectorType>
196 const double current_time_step,
197 VectorType &solution,
198 VectorType &solution_dot)
200 bool first_step = (current_time ==
data.initial_time);
205# if DEAL_II_SUNDIALS_VERSION_GTE(7, 0, 0)
206 status = SUNContext_Free(&
ida_ctx);
215# elif DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
216 status = SUNContext_Free(&
ida_ctx);
233# if DEAL_II_SUNDIALS_VERSION_LT(6, 0, 0)
258 void *user_data) ->
int {
285 status = IDASVtolerances(
ida_mem,
data.relative_tolerance, abs_tols);
290 status = IDASStolerances(
ida_mem,
291 data.relative_tolerance,
292 data.absolute_tolerance);
296 status = IDASetInitStep(
ida_mem, current_time_step);
299 status = IDASetUserData(
ida_mem,
this);
304 data.ignore_algebraic_terms_for_errors)
306 VectorType diff_comp_vector(solution);
307 diff_comp_vector = 0.0;
309 diff_comp_vector[component] = 1.0;
318 status = IDASetId(
ida_mem, diff_id);
322 status = IDASetSuppressAlg(
ida_mem,
data.ignore_algebraic_terms_for_errors);
329 status = IDASetMaxNonlinIters(
ida_mem,
data.maximum_non_linear_iterations);
333 SUNMatrix J =
nullptr;
340# if DEAL_II_SUNDIALS_VERSION_LT(6, 0, 0)
341 LS = SUNLinSolNewEmpty();
343 LS = SUNLinSolNewEmpty(
ida_ctx);
349 return SUNLINEARSOLVER_MATRIX_ITERATIVE;
355 LS->content =
nullptr;
405# if DEAL_II_SUNDIALS_VERSION_LT(6, 0, 0)
406 J = SUNMatNewEmpty();
412 J->ops->getid = [](SUNMatrix ) -> SUNMatrix_ID {
413 return SUNMATRIX_CUSTOM;
416 J->ops->destroy = [](SUNMatrix A) {
419 A->content =
nullptr;
431 status = IDASetLinearSolver(
ida_mem, LS, J);
434 status = IDASetLSNormFactor(
ida_mem,
data.ls_norm_factor);
439 status = IDASetJacFn(
466 status = IDASetMaxOrd(
ida_mem,
data.maximum_order);
473 type =
data.reset_type;
476 IDASetMaxNumItersIC(
ida_mem,
data.maximum_non_linear_iterations_ic);
483 IDACalcIC(
ida_mem, IDA_Y_INIT, current_time + current_time_step);
486 status = IDAGetConsistentIC(
ida_mem, yy, yp);
492 IDACalcIC(
ida_mem, IDA_YA_YDP_INIT, current_time + current_time_step);
495 status = IDAGetConsistentIC(
ida_mem, yy, yp);
500 template <
typename VectorType>
511 VectorType &) ->
int {
521 const unsigned int) {
return; };
524 [](
const double, VectorType &, VectorType &) ->
bool {
return false; };
530 return v->locally_owned_elements();
537# ifdef DEAL_II_WITH_MPI
539# ifdef DEAL_II_WITH_TRILINOS
544# ifdef DEAL_II_WITH_PETSC
545# ifndef PETSC_USE_COMPLEX
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)