14#ifndef dealii_sundials_arkode_stepper_h
15#define dealii_sundials_arkode_stepper_h
20#ifdef DEAL_II_WITH_SUNDIALS
27# ifdef DEAL_II_WITH_PETSC
34# include <arkode/arkode.h>
35# include <nvector/nvector_serial.h>
36# ifdef DEAL_II_WITH_MPI
37# include <nvector/nvector_parallel.h>
47# include <boost/signals2.hpp>
49# include <sundials/sundials_linearsolver.h>
50# include <sundials/sundials_math.h>
51# include <sundials/sundials_nonlinearsolver.h>
63#ifdef DEAL_II_WITH_SUNDIALS
70 template <
typename VectorType>
83 template <
typename VectorType>
91 friend class ARKode<VectorType>;
128 attach(std::exception_ptr &pending_exception
136 ExcMessage(
"This stepper is already attached to an ARKode "
139# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
153 reinit(
double t0,
const VectorType &y0) = 0;
166 resize(
double t0,
const VectorType &y0,
double hscale) = 0;
174 template <
typename Stepper>
199 ExcMessage(
"This stepper is not attached to an ARKode object."));
203# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
216# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
465 template <
typename VectorType = Vector<
double>>
520 explicit AdditionalData(
521 const unsigned int order = 0,
636 void(
const double t,
const VectorType &y, VectorType &explicit_f)>
655 std::function<void(
const double t,
const VectorType &y, VectorType &res)>
676 std::function<void(
const double t,
const VectorType &v, VectorType &Mv)>
741 std::function<void(
const VectorType &v,
745 const VectorType &fy)>
784 void(
const double t,
const VectorType &y,
const VectorType &fy)>
870 std::function<void(
const double t,
872 const VectorType &fy,
922 std::function<void(
const double t,
924 const VectorType &fy,
957 std::function<void(
const double t,
1032 reinit(
double t0,
const VectorType &y0)
override;
1045 resize(
double t0,
const VectorType &y0,
double hscale)
override;
1119 template <
typename VectorType>
1121 const unsigned int order,
1122 const unsigned int maximum_non_linear_iterations,
1123 const bool implicit_function_is_linear,
1124 const bool implicit_function_is_time_independent,
1125 const bool mass_is_time_independent,
1126 const int anderson_acceleration_subspace,
1127 const std::string &implicit_butcher_table,
1128 const std::string &explicit_butcher_table)
1130 , maximum_non_linear_iterations(maximum_non_linear_iterations)
1131 , implicit_function_is_linear(implicit_function_is_linear)
1132 , implicit_function_is_time_independent(
1133 implicit_function_is_time_independent)
1134 , mass_is_time_independent(mass_is_time_independent)
1135 , anderson_acceleration_subspace(anderson_acceleration_subspace)
1136 , implicit_butcher_table(implicit_butcher_table)
1137 , explicit_butcher_table(explicit_butcher_table)
1142 template <
typename VectorType>
1148 maximum_non_linear_iterations);
1150 implicit_function_is_linear);
1152 implicit_function_is_time_independent);
1153 prm.
add_parameter(
"Mass is time independent", mass_is_time_independent);
1155 anderson_acceleration_subspace);
1156 prm.
add_parameter(
"Implicit Butcher table", implicit_butcher_table);
1157 prm.
add_parameter(
"Explicit Butcher table", explicit_butcher_table);
1230 template <
typename VectorType = Vector<
double>>
1257 const std::string &explicit_butcher_table =
"");
1319 void(
const double t,
const VectorType &y, VectorType &explicit_f)>
1364 reinit(
double t0,
const VectorType &y0)
override;
1375 resize(
double t0,
const VectorType &y0,
double hscale)
override;
1394 template <
typename VectorType>
1396 const unsigned int order,
1397 const std::string &explicit_butcher_table)
1399 , explicit_butcher_table(explicit_butcher_table)
1404 template <
typename VectorType>
1409 prm.
add_parameter(
"Explicit Butcher table", explicit_butcher_table);
1413# if DEAL_II_SUNDIALS_VERSION_GTE(7, 2, 0)
1464 template <
typename VectorType = Vector<
double>>
1510 const std::string &method_name =
"",
1512 const unsigned int max_num_stages = 0,
1513 const unsigned int dom_eig_estimator_max_iters = 0,
1514 const double dom_eig_estimator_rel_tol = 0,
1515 const unsigned int dom_eig_estimator_num_warmups =
1517 : method_name(method_name)
1518 , dom_eig_frequency(dom_eig_frequency)
1519 , max_num_stages(max_num_stages)
1520 , dom_eig_estimator_max_iters(dom_eig_estimator_max_iters)
1521 , dom_eig_estimator_rel_tol(dom_eig_estimator_rel_tol)
1522 , dom_eig_estimator_num_warmups(dom_eig_estimator_num_warmups)
1606 void(
const double t,
const VectorType &y, VectorType &explicit_f)>
1636 std::function<std::complex<double>(
const double t,
1637 const VectorType &y,
1638 const VectorType &f)>
1672 reinit(
double t0,
const VectorType &y0)
override;
1685 resize(
double t0,
const VectorType &y0,
double hscale)
override;
1687# if DEAL_II_SUNDIALS_VERSION_GTE(7, 5, 0)
1702# if DEAL_II_SUNDIALS_VERSION_GTE(7, 5, 0)
1711 std::unique_ptr<void, void (*)(
void *)> dom_eig_estimator;
1726 template <
typename VectorType>
1734 "STS method name passed to LSRKStepSetSTSMethodByName. "
1735 "If empty, SUNDIALS uses the default (ARKODE_LSRK_RKC_2).");
1737 "Dominant eigenvalue recomputation frequency",
1739 "Number of successful steps after which the dominant eigenvalue "
1740 "estimate is recomputed. 0 means constant dominant eigenvalue "
1741 "(no change throughout the simulation). Any negative value leaves "
1742 "this option at the SUNDIALS default of 25.");
1745 "Maximum number of polynomial stages per time step. "
1746 "0 means no limit.");
1748 "Dominant eigenvalue estimator maximum iterations",
1749 dom_eig_estimator_max_iters,
1750 "Maximum number of power iterations performed by the built-in "
1751 "dominant-eigenvalue estimator. Only used when no dominant eigenvalue "
1752 "function is provided.");
1754 "Dominant eigenvalue estimator relative tolerance",
1755 dom_eig_estimator_rel_tol,
1756 "Relative convergence tolerance of the power iteration used by the "
1757 "built-in dominant-eigenvalue estimator. Only used when no dominant "
1758 "eigenvalue function is provided.");
1760 "Dominant eigenvalue estimator warmup iterations",
1761 dom_eig_estimator_num_warmups,
1762 "Number of preprocessing warmup iterations performed once when the "
1763 "built-in dominant-eigenvalue estimator is first initialized. Only used "
1764 "when no dominant eigenvalue function is provided.");
1795 template <
typename VectorType = Vector<
double>>
1818 const unsigned int num_stages = 0)
1819 : method_name(method_name)
1820 , num_stages(num_stages)
1867 void(
const double t,
const VectorType &y, VectorType &explicit_f)>
1901 reinit(
double t0,
const VectorType &y0)
override;
1912 resize(
double t0,
const VectorType &y0,
double hscale)
override;
1931 template <
typename VectorType>
1939 "SSP method name passed to LSRKStepSetSSPMethodByName. "
1940 "If empty, SUNDIALS uses the default (ARKODE_LSRK_SSP_10_4).");
1943 "Number of stages for variable-stage SSP methods "
1944 "(ARKODE_LSRK_SSP_S_2, ARKODE_LSRK_SSP_S_3). "
1945 "0 means SUNDIALS default.");
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)
unsigned int maximum_non_linear_iterations
void add_parameters(ParameterHandler &prm)
std::string explicit_butcher_table
int anderson_acceleration_subspace
std::string implicit_butcher_table
bool implicit_function_is_time_independent
AdditionalData(const unsigned int order=0, 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 std::string &implicit_butcher_table="", const std::string &explicit_butcher_table="")
bool mass_is_time_independent
bool implicit_function_is_linear
std::optional< internal::SundialsNonlinearSolver > fixed_point_solver
std::function< void(void *arkode_mem)> custom_setup
void reinit(double t0, const VectorType &y0) override
std::optional< internal::SundialsLinearSolver > default_mass_solver
std::function< void(const double t, const VectorType &y, VectorType &res)> implicit_function
std::function< void(const double t)> mass_times_vector_setup
void setup_system_solver(const VectorType &solution)
ARKStepper(const AdditionalData &data=AdditionalData())
CallbackContext callback_ctx
void setup_mass_solver(const VectorType &solution)
typename ARKodeStepper< VectorType >::template CallbackContext< ARKStepper< VectorType > > CallbackContext
void resize(double t0, const VectorType &y0, double hscale) override
std::optional< internal::LinearSolverWrapper< VectorType > > linear_solver
std::function< void(const double t)> mass_preconditioner_setup
std::function< void(const double t, const VectorType &y, VectorType &explicit_f)> explicit_function
std::function< void(const double t, const VectorType &v, VectorType &Mv)> mass_times_vector
std::function< void(const double t, const VectorType &y, const VectorType &fy)> jacobian_times_vector_setup
std::optional< internal::LinearSolverWrapper< VectorType > > mass_solver
ARKodeMemoryPtr arkode_mem
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
std::function< void(const double t, const VectorType &r, VectorType &z, const double tol, const int lr)> mass_preconditioner_solve
typename ARKodeStepper< VectorType >::ARKodeMemoryPtr ARKodeMemoryPtr
LinearSolveFunction< VectorType > solve_linearized_system
std::optional< internal::SundialsLinearSolver > default_linear_solver
LinearSolveFunction< VectorType > solve_mass
std::function< void(const VectorType &v, VectorType &Jv, const double t, const VectorType &y, const VectorType &fy)> jacobian_times_vector
std::function< void(const double t, const VectorType &y, const VectorType &fy, const int jok, int &jcur, const double gamma)> jacobian_preconditioner_setup
void * get_arkode_memory() const override
virtual void reinit(double t0, const VectorType &y0)=0
internal::InvocationContext invocation_context() const
virtual ~ARKodeStepper()=default
std::exception_ptr * pending_exception_ptr
std::unique_ptr< void, void(*)(void *)> ARKodeMemoryPtr
internal::SharedSUNContext sundials_context
void attach(std::exception_ptr &pending_exception, const internal::SharedSUNContext &context)
virtual void * get_arkode_memory() const =0
virtual void resize(double t0, const VectorType &y0, double hscale)=0
AdditionalData(const unsigned int order=0, const std::string &explicit_butcher_table="")
void add_parameters(ParameterHandler &prm)
std::string explicit_butcher_table
CallbackContext callback_ctx
ARKodeMemoryPtr arkode_mem
void * get_arkode_memory() const override
std::function< void(void *arkode_mem)> custom_setup
void reinit(double t0, const VectorType &y0) override
ERKStepper(const AdditionalData &data=AdditionalData())
typename ARKodeStepper< VectorType >::ARKodeMemoryPtr ARKodeMemoryPtr
typename ARKodeStepper< VectorType >::template CallbackContext< ERKStepper< VectorType > > CallbackContext
std::function< void(const double t, const VectorType &y, VectorType &explicit_f)> explicit_function
void resize(double t0, const VectorType &y0, double hscale) override
unsigned int dom_eig_estimator_num_warmups
unsigned int dom_eig_frequency
double dom_eig_estimator_rel_tol
AdditionalData(const std::string &method_name="", const unsigned int dom_eig_frequency=numbers::invalid_unsigned_int, const unsigned int max_num_stages=0, const unsigned int dom_eig_estimator_max_iters=0, const double dom_eig_estimator_rel_tol=0, const unsigned int dom_eig_estimator_num_warmups=numbers::invalid_unsigned_int)
unsigned int dom_eig_estimator_max_iters
unsigned int max_num_stages
void add_parameters(ParameterHandler &prm)
std::function< void(const double t, const VectorType &y, VectorType &explicit_f)> explicit_function
typename ARKodeStepper< VectorType >::ARKodeMemoryPtr ARKodeMemoryPtr
void reinit(double t0, const VectorType &y0) override
ARKodeMemoryPtr arkode_mem
void resize(double t0, const VectorType &y0, double hscale) override
LSRKStepperSTS(const AdditionalData &data=AdditionalData())
std::function< std::complex< double >(const double t, const VectorType &y, const VectorType &f)> dominant_eigenvalue_function
CallbackContext callback_ctx
std::function< void(void *arkode_mem)> custom_setup
void * get_arkode_memory() const override
void attach_default_dom_eig_estimator(N_Vector y, SUNContext context)
typename ARKodeStepper< VectorType >::template CallbackContext< LSRKStepperSTS< VectorType > > CallbackContext
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_SUNDIALS_VERSION_GTE(major, minor, patch)
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)
std::vector< index_type > data
std::function< void(SundialsOperator< VectorType > &op, SundialsPreconditioner< VectorType > &prec, VectorType &x, const VectorType &b, double tol)> LinearSolveFunction
constexpr unsigned int invalid_unsigned_int
std::exception_ptr * pending_exception