16#ifndef dealii_sundials_arkode_h
17#define dealii_sundials_arkode_h
22#ifdef DEAL_II_WITH_SUNDIALS
29# ifdef DEAL_II_WITH_PETSC
36# include <arkode/arkode.h>
37# include <nvector/nvector_serial.h>
38# ifdef DEAL_II_WITH_MPI
39# include <nvector/nvector_parallel.h>
47# include <boost/signals2.hpp>
49# include <sundials/sundials_linearsolver.h>
50# include <sundials/sundials_math.h>
60# define AssertARKode(code) Assert(code >= 0, ExcARKodeError(code))
327 template <
typename VectorType = Vector<
double>>
536 const double intermediate_time,
537 const bool reset_solver =
false);
554 reset(
const double t,
const double h,
const VectorType &y);
592 void(
const double t,
const VectorType &y, VectorType &explicit_f)>
611 std::function<void(
const double t,
const VectorType &y, VectorType &res)>
631 std::function<void(
const double t,
const VectorType &v, VectorType &Mv)>
696 std::function<void(
const VectorType &v,
700 const VectorType &fy)>
738 void(
const double t,
const VectorType &y,
const VectorType &fy)>
824 std::function<void(
const double t,
826 const VectorType &fy,
876 std::function<void(
const double t,
878 const VectorType &fy,
911 std::function<void(
const double t,
958 std::function<void(
const double t,
959 const VectorType &sol,
960 const unsigned int step_number)>
1023 <<
"Please provide an implementation for the function \""
1032 const bool do_reset);
1070# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
1089 std::unique_ptr<internal::LinearSolverWrapper<VectorType>>
mass_solver;
1098# ifdef DEAL_II_WITH_PETSC
1099# ifdef PETSC_USE_COMPLEX
1100 static_assert(!std::is_same_v<VectorType, PETScWrappers::MPI::Vector>,
1101 "Sundials does not support complex scalar types, "
1102 "but PETSc is configured to use a complex scalar type!");
1104 static_assert(!std::is_same_v<VectorType, PETScWrappers::MPI::BlockVector>,
1105 "Sundials does not support complex scalar types, "
1106 "but PETSc is configured to use a complex scalar type!");
1117 <<
"One of the SUNDIALS ARKode internal functions "
1118 <<
" returned a negative error code: " << arg1
1119 <<
". Please consult SUNDIALS manual.");
1122 template <
typename VectorType>
1125 const double initial_time,
1126 const double final_time,
1127 const double initial_step_size,
1128 const double output_period,
1130 const double minimum_step_size,
1131 const unsigned int maximum_order,
1132 const unsigned int maximum_non_linear_iterations,
1133 const bool implicit_function_is_linear,
1134 const bool implicit_function_is_time_independent,
1135 const bool mass_is_time_independent,
1136 const int anderson_acceleration_subspace,
1138 const double absolute_tolerance,
1139 const double relative_tolerance)
1140 : initial_time(initial_time)
1141 , final_time(final_time)
1142 , initial_step_size(initial_step_size)
1143 , minimum_step_size(minimum_step_size)
1144 , absolute_tolerance(absolute_tolerance)
1145 , relative_tolerance(relative_tolerance)
1146 , maximum_order(maximum_order)
1147 , output_period(output_period)
1148 , maximum_non_linear_iterations(maximum_non_linear_iterations)
1149 , implicit_function_is_linear(implicit_function_is_linear)
1150 , implicit_function_is_time_independent(
1151 implicit_function_is_time_independent)
1152 , mass_is_time_independent(mass_is_time_independent)
1153 , anderson_acceleration_subspace(anderson_acceleration_subspace)
1158 template <
typename VectorType>
1164 prm.
add_parameter(
"Time interval between each output", output_period);
1170 maximum_non_linear_iterations);
1172 implicit_function_is_linear);
1174 implicit_function_is_time_independent);
1175 prm.
add_parameter(
"Mass is time independent", mass_is_time_independent);
1177 anderson_acceleration_subspace);
1180 prm.
add_parameter(
"Absolute error tolerance", absolute_tolerance);
1181 prm.
add_parameter(
"Relative error tolerance", relative_tolerance);
void add_parameter(const std::string &entry, ParameterType ¶meter, const std::string &documentation="", const Patterns::PatternBase &pattern= *Patterns::Tools::Convert< ParameterType >::to_pattern(), const bool has_to_be_set=false)
void enter_subsection(const std::string &subsection, const bool create_path_if_needed=true)
double absolute_tolerance
unsigned int maximum_order
bool implicit_function_is_linear
bool mass_is_time_independent
bool implicit_function_is_time_independent
double relative_tolerance
void add_parameters(ParameterHandler &prm)
int anderson_acceleration_subspace
AdditionalData(const double initial_time=0.0, const double final_time=1.0, const double initial_step_size=1e-2, const double output_period=1e-1, const double minimum_step_size=1e-6, const unsigned int maximum_order=5, const unsigned int maximum_non_linear_iterations=10, const bool implicit_function_is_linear=false, const bool implicit_function_is_time_independent=false, const bool mass_is_time_independent=false, const int anderson_acceleration_subspace=3, const double absolute_tolerance=1e-6, const double relative_tolerance=1e-5)
unsigned int maximum_non_linear_iterations
void setup_mass_solver(const VectorType &solution)
std::function< void(const double t)> mass_preconditioner_setup
std::function< void(const double t, const VectorType &y, VectorType &explicit_f)> explicit_function
std::exception_ptr pending_exception
std::function< void(const double t, const VectorType &y, const VectorType &fy, const VectorType &r, VectorType &z, const double gamma, const double tol, const int lr)> jacobian_preconditioner_solve
ARKode(const AdditionalData &data=AdditionalData())
void * get_arkode_memory() const
std::function< void(const double t, const VectorType &sol, const unsigned int step_number)> output_step
std::function< VectorType &()> get_local_tolerances
LinearSolveFunction< VectorType > solve_linearized_system
std::function< void(const double t, const VectorType &y, VectorType &res)> implicit_function
std::function< void(const double t, const VectorType &r, VectorType &z, const double tol, const int lr)> mass_preconditioner_solve
MPI_Comm mpi_communicator
void reset(const double t, const double h, const VectorType &y)
std::unique_ptr< internal::LinearSolverWrapper< VectorType > > mass_solver
std::function< void(const double t, const VectorType &y, const VectorType &fy, const int jok, int &jcur, const double gamma)> jacobian_preconditioner_setup
std::function< bool(const double t, VectorType &sol)> solver_should_restart
unsigned int do_evolve_time(VectorType &solution, ::DiscreteTime &time, const bool do_reset)
std::function< void(const double t)> mass_times_setup
void set_functions_to_trigger_an_assert()
std::unique_ptr< internal::LinearSolverWrapper< VectorType > > linear_solver
std::function< void(const double t, const VectorType &v, VectorType &Mv)> mass_times_vector
LinearSolveFunction< VectorType > solve_mass
std::function< void(const double t, const VectorType &y, const VectorType &fy)> jacobian_times_setup
unsigned int solve_ode(VectorType &solution)
void setup_system_solver(const VectorType &solution)
unsigned int solve_ode_incrementally(VectorType &solution, const double intermediate_time, const bool reset_solver=false)
std::function< void(void *arkode_mem)> custom_setup
std::function< void(const VectorType &v, VectorType &Jv, const double t, const VectorType &y, const VectorType &fy)> jacobian_times_vector
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcARKodeError(int arg1)
static ::ExceptionBase & ExcFunctionNotProvided(std::string arg1)
#define DeclException1(Exception1, type1, outsequence)
std::function< void(SundialsOperator< VectorType > &op, SundialsPreconditioner< VectorType > &prec, VectorType &x, const VectorType &b, double tol)> LinearSolveFunction