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>
46# include <boost/signals2.hpp>
48# include <sundials/sundials_linearsolver.h>
49# include <sundials/sundials_math.h>
60#ifdef DEAL_II_WITH_SUNDIALS
67 template <
typename VectorType>
80 template <
typename VectorType>
88 friend class ARKode<VectorType>;
125 attach(std::exception_ptr &pending_exception
133 ExcMessage(
"This stepper is already attached to an ARKode "
136# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
150 reinit(
double t0,
const VectorType &y0) = 0;
163 resize(
double t0,
const VectorType &y0,
double hscale) = 0;
171 template <
typename Stepper>
196 ExcMessage(
"This stepper is not attached to an ARKode object."));
200# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
213# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
462 template <
typename VectorType = Vector<
double>>
517 explicit AdditionalData(
518 const unsigned int order = 0,
633 void(
const double t,
const VectorType &y, VectorType &explicit_f)>
652 std::function<void(
const double t,
const VectorType &y, VectorType &res)>
673 std::function<void(
const double t,
const VectorType &v, VectorType &Mv)>
738 std::function<void(
const VectorType &v,
742 const VectorType &fy)>
781 void(
const double t,
const VectorType &y,
const VectorType &fy)>
867 std::function<void(
const double t,
869 const VectorType &fy,
919 std::function<void(
const double t,
921 const VectorType &fy,
954 std::function<void(
const double t,
1029 reinit(
double t0,
const VectorType &y0)
override;
1042 resize(
double t0,
const VectorType &y0,
double hscale)
override;
1081 std::unique_ptr<internal::LinearSolverWrapper<VectorType>>
mass_solver;
1098 template <
typename VectorType>
1100 const unsigned int order,
1101 const unsigned int maximum_non_linear_iterations,
1102 const bool implicit_function_is_linear,
1103 const bool implicit_function_is_time_independent,
1104 const bool mass_is_time_independent,
1105 const int anderson_acceleration_subspace,
1106 const std::string &implicit_butcher_table,
1107 const std::string &explicit_butcher_table)
1109 , maximum_non_linear_iterations(maximum_non_linear_iterations)
1110 , implicit_function_is_linear(implicit_function_is_linear)
1111 , implicit_function_is_time_independent(
1112 implicit_function_is_time_independent)
1113 , mass_is_time_independent(mass_is_time_independent)
1114 , anderson_acceleration_subspace(anderson_acceleration_subspace)
1115 , implicit_butcher_table(implicit_butcher_table)
1116 , explicit_butcher_table(explicit_butcher_table)
1121 template <
typename VectorType>
1127 maximum_non_linear_iterations);
1129 implicit_function_is_linear);
1131 implicit_function_is_time_independent);
1132 prm.
add_parameter(
"Mass is time independent", mass_is_time_independent);
1134 anderson_acceleration_subspace);
1135 prm.
add_parameter(
"Implicit Butcher table", implicit_butcher_table);
1136 prm.
add_parameter(
"Explicit Butcher table", explicit_butcher_table);
1209 template <
typename VectorType = Vector<
double>>
1236 const std::string &explicit_butcher_table =
"");
1298 void(
const double t,
const VectorType &y, VectorType &explicit_f)>
1343 reinit(
double t0,
const VectorType &y0)
override;
1354 resize(
double t0,
const VectorType &y0,
double hscale)
override;
1373 template <
typename VectorType>
1375 const unsigned int order,
1376 const std::string &explicit_butcher_table)
1378 , explicit_butcher_table(explicit_butcher_table)
1383 template <
typename VectorType>
1388 prm.
add_parameter(
"Explicit Butcher table", explicit_butcher_table);
1392# if DEAL_II_SUNDIALS_VERSION_GTE(7, 2, 0)
1443 template <
typename VectorType = Vector<
double>>
1489 const std::string &method_name =
"",
1491 const unsigned int max_num_stages = 0,
1492 const unsigned int dom_eig_estimator_max_iters = 0,
1493 const double dom_eig_estimator_rel_tol = 0,
1494 const unsigned int dom_eig_estimator_num_warmups =
1496 : method_name(method_name)
1497 , dom_eig_frequency(dom_eig_frequency)
1498 , max_num_stages(max_num_stages)
1499 , dom_eig_estimator_max_iters(dom_eig_estimator_max_iters)
1500 , dom_eig_estimator_rel_tol(dom_eig_estimator_rel_tol)
1501 , dom_eig_estimator_num_warmups(dom_eig_estimator_num_warmups)
1585 void(
const double t,
const VectorType &y, VectorType &explicit_f)>
1615 std::function<std::complex<double>(
const double t,
1616 const VectorType &y,
1617 const VectorType &f)>
1651 reinit(
double t0,
const VectorType &y0)
override;
1664 resize(
double t0,
const VectorType &y0,
double hscale)
override;
1666# if DEAL_II_SUNDIALS_VERSION_GTE(7, 5, 0)
1681# if DEAL_II_SUNDIALS_VERSION_GTE(7, 5, 0)
1690 std::unique_ptr<void, void (*)(
void *)> dom_eig_estimator;
1705 template <
typename VectorType>
1713 "STS method name passed to LSRKStepSetSTSMethodByName. "
1714 "If empty, SUNDIALS uses the default (ARKODE_LSRK_RKC_2).");
1716 "Dominant eigenvalue recomputation frequency",
1718 "Number of successful steps after which the dominant eigenvalue "
1719 "estimate is recomputed. 0 means constant dominant eigenvalue "
1720 "(no change throughout the simulation). Any negative value leaves "
1721 "this option at the SUNDIALS default of 25.");
1724 "Maximum number of polynomial stages per time step. "
1725 "0 means no limit.");
1727 "Dominant eigenvalue estimator maximum iterations",
1728 dom_eig_estimator_max_iters,
1729 "Maximum number of power iterations performed by the built-in "
1730 "dominant-eigenvalue estimator. Only used when no dominant eigenvalue "
1731 "function is provided.");
1733 "Dominant eigenvalue estimator relative tolerance",
1734 dom_eig_estimator_rel_tol,
1735 "Relative convergence tolerance of the power iteration used by the "
1736 "built-in dominant-eigenvalue estimator. Only used when no dominant "
1737 "eigenvalue function is provided.");
1739 "Dominant eigenvalue estimator warmup iterations",
1740 dom_eig_estimator_num_warmups,
1741 "Number of preprocessing warmup iterations performed once when the "
1742 "built-in dominant-eigenvalue estimator is first initialized. Only used "
1743 "when no dominant eigenvalue function is provided.");
1774 template <
typename VectorType = Vector<
double>>
1797 const unsigned int num_stages = 0)
1798 : method_name(method_name)
1799 , num_stages(num_stages)
1846 void(
const double t,
const VectorType &y, VectorType &explicit_f)>
1880 reinit(
double t0,
const VectorType &y0)
override;
1891 resize(
double t0,
const VectorType &y0,
double hscale)
override;
1910 template <
typename VectorType>
1918 "SSP method name passed to LSRKStepSetSSPMethodByName. "
1919 "If empty, SUNDIALS uses the default (ARKODE_LSRK_SSP_10_4).");
1922 "Number of stages for variable-stage SSP methods "
1923 "(ARKODE_LSRK_SSP_S_2, ARKODE_LSRK_SSP_S_3). "
1924 "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::unique_ptr< internal::LinearSolverWrapper< VectorType > > mass_solver
std::function< void(void *arkode_mem)> custom_setup
std::unique_ptr< internal::LinearSolverWrapper< VectorType > > linear_solver
void reinit(double t0, const VectorType &y0) override
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::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
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
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