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;
132 output_step(0, solution, solution_dot, 0);
134 while (t <
data.final_time)
136 next_time +=
data.output_period;
138 auto yy = internal::make_nvector_view(solution
144 auto yp = internal::make_nvector_view(solution_dot
155 status = IDASolve(ida_mem, next_time, &t, yy, yp, IDA_NORMAL);
156 if (pending_exception)
160 std::rethrow_exception(pending_exception);
164 pending_exception =
nullptr;
172 pending_exception =
nullptr;
178 status = IDAGetLastStep(ida_mem, &h);
181 while (solver_should_restart(t, solution, solution_dot))
182 reset(t, h, solution, solution_dot);
186 output_step(t, solution, solution_dot, step_number);
189 status = IDAGetNumSteps(ida_mem, &
n_steps);
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);
214 SUNContext_Create(mpi_communicator == MPI_COMM_SELF ? SUN_COMM_NULL :
218# elif DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
219 status = SUNContext_Free(&ida_ctx);
224 SUNContext_Create(mpi_communicator == MPI_COMM_SELF ?
nullptr :
236# if DEAL_II_SUNDIALS_VERSION_LT(6, 0, 0)
237 ida_mem = IDACreate();
239 ida_mem = IDACreate(ida_ctx);
242 auto yy = internal::make_nvector_view(solution
248 auto yp = internal::make_nvector_view(solution_dot
261 void *user_data) ->
int {
264 auto *src_yy = internal::unwrap_nvector_const<VectorType>(yy);
265 auto *src_yp = internal::unwrap_nvector_const<VectorType>(yp);
266 auto *residual = internal::unwrap_nvector<VectorType>(rr);
280 if (get_local_tolerances)
282 const auto abs_tols = internal::make_nvector_view(get_local_tolerances()
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);
305 if (
data.ic_type == AdditionalData::use_y_diff ||
306 data.reset_type == AdditionalData::use_y_diff ||
307 data.ignore_algebraic_terms_for_errors)
309 VectorType diff_comp_vector(solution);
310 diff_comp_vector = 0.0;
311 for (
const auto &component : differential_components())
312 diff_comp_vector[component] = 1.0;
315 const auto diff_id = internal::make_nvector_view(diff_comp_vector
321 status = IDASetId(ida_mem, diff_id);
325 status = IDASetSuppressAlg(ida_mem,
data.ignore_algebraic_terms_for_errors);
329 status = IDASetStopTime(ida_mem,
data.final_time);
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;
379 auto *src_b = internal::unwrap_nvector_const<VectorType>(b);
380 auto *dst_x = internal::unwrap_nvector<VectorType>(x);
408# if DEAL_II_SUNDIALS_VERSION_LT(6, 0, 0)
409 J = SUNMatNewEmpty();
411 J = SUNMatNewEmpty(ida_ctx);
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(
457 auto *src_yy = internal::unwrap_nvector_const<VectorType>(yy);
458 auto *src_yp = internal::unwrap_nvector_const<VectorType>(yp);
469 status = IDASetMaxOrd(ida_mem,
data.maximum_order);
476 type =
data.reset_type;
479 IDASetMaxNumItersIC(ida_mem,
data.maximum_non_linear_iterations_ic);
482 if (type == AdditionalData::use_y_dot)
486 IDACalcIC(ida_mem, IDA_Y_INIT, current_time + current_time_step);
489 status = IDAGetConsistentIC(ida_mem, yy, yp);
492 else if (type == AdditionalData::use_y_diff)
495 IDACalcIC(ida_mem, IDA_YA_YDP_INIT, current_time + current_time_step);
498 status = IDAGetConsistentIC(ida_mem, yy, yp);