16#ifndef dealii_sundials_arkode_stepper_h
17#define dealii_sundials_arkode_stepper_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>
48# include <boost/signals2.hpp>
50# include <sundials/sundials_linearsolver.h>
51# include <sundials/sundials_math.h>
62#ifdef DEAL_II_WITH_SUNDIALS
69 template <
typename VectorType>
82 template <
typename VectorType>
90 friend class ARKode<VectorType>;
135 const VectorType &y0,
144 template <
typename Stepper>
400 template <
typename VectorType = Vector<
double>>
455 explicit AdditionalData(
456 const unsigned int order = 0,
571 void(
const double t,
const VectorType &y, VectorType &explicit_f)>
590 std::function<void(
const double t,
const VectorType &y, VectorType &res)>
611 std::function<void(
const double t,
const VectorType &v, VectorType &Mv)>
676 std::function<void(
const VectorType &v,
680 const VectorType &fy)>
719 void(
const double t,
const VectorType &y,
const VectorType &fy)>
805 std::function<void(
const double t,
807 const VectorType &fy,
857 std::function<void(
const double t,
859 const VectorType &fy,
892 std::function<void(
const double t,
970 const VectorType &y0,
1016 std::unique_ptr<internal::LinearSolverWrapper<VectorType>>
mass_solver;
1033 template <
typename VectorType>
1035 const unsigned int order,
1036 const unsigned int maximum_non_linear_iterations,
1037 const bool implicit_function_is_linear,
1038 const bool implicit_function_is_time_independent,
1039 const bool mass_is_time_independent,
1040 const int anderson_acceleration_subspace,
1041 const std::string &implicit_butcher_table,
1042 const std::string &explicit_butcher_table)
1044 , maximum_non_linear_iterations(maximum_non_linear_iterations)
1045 , implicit_function_is_linear(implicit_function_is_linear)
1046 , implicit_function_is_time_independent(
1047 implicit_function_is_time_independent)
1048 , mass_is_time_independent(mass_is_time_independent)
1049 , anderson_acceleration_subspace(anderson_acceleration_subspace)
1050 , implicit_butcher_table(implicit_butcher_table)
1051 , explicit_butcher_table(explicit_butcher_table)
1056 template <
typename VectorType>
1062 maximum_non_linear_iterations);
1064 implicit_function_is_linear);
1066 implicit_function_is_time_independent);
1067 prm.
add_parameter(
"Mass is time independent", mass_is_time_independent);
1069 anderson_acceleration_subspace);
1070 prm.
add_parameter(
"Implicit Butcher table", implicit_butcher_table);
1071 prm.
add_parameter(
"Explicit Butcher table", explicit_butcher_table);
1144 template <
typename VectorType = Vector<
double>>
1171 const std::string &explicit_butcher_table =
"");
1233 void(
const double t,
const VectorType &y, VectorType &explicit_f)>
1281 const VectorType &y0,
1301 template <
typename VectorType>
1303 const unsigned int order,
1304 const std::string &explicit_butcher_table)
1306 , explicit_butcher_table(explicit_butcher_table)
1311 template <
typename VectorType>
1316 prm.
add_parameter(
"Explicit Butcher table", explicit_butcher_table);
1320# if DEAL_II_SUNDIALS_VERSION_GTE(7, 2, 0)
1371 template <
typename VectorType = Vector<
double>>
1417 const std::string &method_name =
"",
1419 const unsigned int max_num_stages = 0,
1420 const unsigned int dom_eig_estimator_max_iters = 0,
1421 const double dom_eig_estimator_rel_tol = 0,
1422 const unsigned int dom_eig_estimator_num_warmups =
1424 : method_name(method_name)
1425 , dom_eig_frequency(dom_eig_frequency)
1426 , max_num_stages(max_num_stages)
1427 , dom_eig_estimator_max_iters(dom_eig_estimator_max_iters)
1428 , dom_eig_estimator_rel_tol(dom_eig_estimator_rel_tol)
1429 , dom_eig_estimator_num_warmups(dom_eig_estimator_num_warmups)
1513 void(
const double t,
const VectorType &y, VectorType &explicit_f)>
1543 std::function<std::complex<double>(
const double t,
1544 const VectorType &y,
1545 const VectorType &f)>
1582 const VectorType &y0,
1590# if DEAL_II_SUNDIALS_VERSION_GTE(7, 5, 0)
1599 std::unique_ptr<void, void (*)(
void *)> dom_eig_estimator;
1614 template <
typename VectorType>
1622 "STS method name passed to LSRKStepSetSTSMethodByName. "
1623 "If empty, SUNDIALS uses the default (ARKODE_LSRK_RKC_2).");
1625 "Dominant eigenvalue recomputation frequency",
1627 "Number of successful steps after which the dominant eigenvalue "
1628 "estimate is recomputed. 0 means constant dominant eigenvalue "
1629 "(no change throughout the simulation). Any negative value leaves "
1630 "this option at the SUNDIALS default of 25.");
1633 "Maximum number of polynomial stages per time step. "
1634 "0 means no limit.");
1636 "Dominant eigenvalue estimator maximum iterations",
1637 dom_eig_estimator_max_iters,
1638 "Maximum number of power iterations performed by the built-in "
1639 "dominant-eigenvalue estimator. Only used when no dominant eigenvalue "
1640 "function is provided.");
1642 "Dominant eigenvalue estimator relative tolerance",
1643 dom_eig_estimator_rel_tol,
1644 "Relative convergence tolerance of the power iteration used by the "
1645 "built-in dominant-eigenvalue estimator. Only used when no dominant "
1646 "eigenvalue function is provided.");
1648 "Dominant eigenvalue estimator warmup iterations",
1649 dom_eig_estimator_num_warmups,
1650 "Number of preprocessing warmup iterations performed once when the "
1651 "built-in dominant-eigenvalue estimator is first initialized. Only used "
1652 "when no dominant eigenvalue function is provided.");
1683 template <
typename VectorType = Vector<
double>>
1706 const unsigned int num_stages = 0)
1707 : method_name(method_name)
1708 , num_stages(num_stages)
1755 void(
const double t,
const VectorType &y, VectorType &explicit_f)>
1792 const VectorType &y0,
1812 template <
typename VectorType>
1820 "SSP method name passed to LSRKStepSetSSPMethodByName. "
1821 "If empty, SUNDIALS uses the default (ARKODE_LSRK_SSP_10_4).");
1824 "Number of stages for variable-stage SSP methods "
1825 "(ARKODE_LSRK_SSP_S_2, ARKODE_LSRK_SSP_S_3). "
1826 "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
void setup_mass_solver(const VectorType &solution, internal::InvocationContext inv_ctx)
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, internal::InvocationContext inv_ctx) override
std::function< void(const double t, const VectorType &y, VectorType &res)> implicit_function
std::function< void(const double t)> mass_times_vector_setup
ARKStepper(const AdditionalData &data=AdditionalData())
CallbackContext callback_ctx
typename ARKodeStepper< VectorType >::template CallbackContext< ARKStepper< VectorType > > CallbackContext
void setup_system_solver(const VectorType &solution, internal::InvocationContext inv_ctx)
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 ~ARKodeStepper()=default
virtual void reinit(double t0, const VectorType &y0, internal::InvocationContext inv_ctx)=0
std::unique_ptr< void, void(*)(void *)> ARKodeMemoryPtr
virtual void * get_arkode_memory() const =0
AdditionalData(const unsigned int order=0, const std::string &explicit_butcher_table="")
void add_parameters(ParameterHandler &prm)
std::string explicit_butcher_table
void reinit(double t0, const VectorType &y0, internal::InvocationContext inv_ctx) override
CallbackContext callback_ctx
ARKodeMemoryPtr arkode_mem
void * get_arkode_memory() const override
std::function< void(void *arkode_mem)> custom_setup
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
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
ARKodeMemoryPtr arkode_mem
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 reinit(double t0, const VectorType &y0, internal::InvocationContext inv_ctx) override
typename ARKodeStepper< VectorType >::template CallbackContext< LSRKStepperSTS< VectorType > > CallbackContext
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
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