14#ifndef dealii_sundials_ida_h
15#define dealii_sundials_ida_h
19#ifdef DEAL_II_WITH_SUNDIALS
25# ifdef DEAL_II_WITH_PETSC
32# ifdef DEAL_II_SUNDIALS_WITH_IDAS
33# include <idas/idas.h>
41# include <boost/signals2.hpp>
43# include <nvector/nvector_serial.h>
44# include <sundials/sundials_config.h>
45# include <sundials/sundials_math.h>
55#ifdef DEAL_II_WITH_SUNDIALS
490 template <
typename VectorType = Vector<
double>>
621 std::pow(std::numeric_limits<double>::epsilon(), 2.0 / 3.0),
730 "Smallest allowed integration step.");
734 "Largest allowed integration step; zero is unlimited.");
737 "Maximum internal steps between output times.");
739 "Maximum error test failures",
741 "Stops a solve after repeated local error test rejections.");
743 "Maximum nonlinear convergence failures",
745 "Stops a solve after repeated nonlinear solver failures.");
753 "Convergence coefficient",
755 "Controls when Newton corrections count as converged.");
762 "Ignore algebraic terms for error computations",
764 "Indicate whether or not to suppress algebraic variables "
765 "in the local error test.");
769 const auto correction_type_to_string =
774 return std::string(
"none");
776 return std::string(
"use_y_diff");
778 return std::string(
"use_y_dot");
782 return std::string();
784 const auto set_correction_type = [](
const std::string &value,
788 else if (value ==
"use_y_diff")
790 else if (value ==
"use_y_dot")
797 "Correction type at initial time",
798 correction_type_to_string(
ic_type),
800 "This is one of the following three options for the "
801 "initial condition calculation. \n"
802 " none: do not try to make initial conditions consistent. \n"
803 " use_y_diff: compute the algebraic components of y and differential\n"
804 " components of y_dot, given the differential components of y. \n"
805 " This option requires that the user specifies differential and \n"
806 " algebraic components in the function differential_components().\n"
807 " use_y_dot: compute all components of y, given y_dot.");
808 prm.
add_action(
"Correction type at initial time",
809 [
this, set_correction_type](
const std::string &value) {
810 set_correction_type(value,
ic_type);
813 "Correction type after restart",
816 "This is one of the following three options for the "
817 "initial condition calculation. \n"
818 " none: do not try to make initial conditions consistent. \n"
819 " use_y_diff: compute the algebraic components of y and differential\n"
820 " components of y_dot, given the differential components of y. \n"
821 " This option requires that the user specifies differential and \n"
822 " algebraic components in the function differential_components().\n"
823 " use_y_dot: compute all components of y, given y_dot.");
824 prm.
add_action(
"Correction type after restart",
825 [
this, set_correction_type](
const std::string &value) {
831 "Factor to use when converting from the integrator tolerance to the linear solver tolerance",
834 "Maximum number of steps",
836 "Bounds work while making the initial values consistent.");
838 "Maximum number of Jacobians",
840 "Bounds Jacobian refresh attempts during IC correction.");
843 "Limits trial reductions in the IC line search.");
846 "Enable backtracking when adjusting initial values.");
850 "Treats a sufficiently small Newton correction as convergence.");
852 "Nonlinear convergence coefficient",
854 "Sets the Newton convergence test used by IDACalcIC.");
859 "Linear tolerance factor",
861 "Relates linear solve accuracy to the nonlinear tolerance.");
863 "Difference quotient increment factor",
865 "Scales finite-difference perturbations in Jacobian products.");
867 "Linear solution scaling",
869 "Compensates for changes in Cj between linear solves.");
871 "Cj setup difference factor",
873 "Rebuilds linear setup when Cj changes by this fraction.");
878 "Minimum step growth factor",
880 "Prevents overly aggressive reductions in step size.");
883 "Caps step growth after a successful step.");
886 "Applies when IDA takes a lower-order step.");
887 prm.
add_parameter(
"Minimum growth factor after error failure",
889 "Limits step reduction after a failed error test.");
891 "Growth factor after convergence failure",
893 "Sets the next-step reduction after nonlinear failure.");
895 "Minimum fixed step growth factor",
897 "Lower step-size ratio bound for retaining the current step size.");
899 "Maximum fixed step growth factor",
901 "Upper step-size ratio bound for retaining the current step size.");
905 "Maximum constraint failures",
907 "Rejects a step after this many constraint violations.");
983 std::pow(std::numeric_limits<double>::epsilon(), 2.0 / 3.0);
1198 solve_dae(VectorType &solution, VectorType &solution_dot);
1222 reset(
const double t,
const double h, VectorType &y, VectorType &yp);
1241 std::function<void(
const double t,
1242 const VectorType &y,
1243 const VectorType &y_dot,
1277 std::function<void(
const double t,
1278 const VectorType &y,
1279 const VectorType &y_dot,
1280 const double alpha)>
1325 void(
const VectorType &rhs, VectorType &dst,
const double tolerance)>
1342 std::function<void(
const double t,
1343 const VectorType &sol,
1344 const VectorType &sol_dot,
1345 const unsigned int step_number)>
1371 std::function<
bool(
const double t, VectorType &sol, VectorType &sol_dot)>
1440 <<
"Please provide an implementation for the function \""
1461# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
1486# ifdef DEAL_II_WITH_PETSC
1487# ifdef PETSC_USE_COMPLEX
1488 static_assert(!std::is_same_v<VectorType, PETScWrappers::MPI::Vector>,
1489 "Sundials does not support complex scalar types, "
1490 "but PETSc is configured to use a complex scalar type!");
1492 static_assert(!std::is_same_v<VectorType, PETScWrappers::MPI::BlockVector>,
1493 "Sundials does not support complex scalar types, "
1494 "but PETSc is configured to use a complex scalar type!");
1504 <<
"One of SUNDIALS IDA's internal functions "
1505 <<
"returned an error code: " << arg1
1506 <<
". Please consult SUNDIALS manual.");
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)
void add_action(const std::string &entry, const std::function< void(const std::string &value)> &action, const bool execute_action=true)
void declare_entry(const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation="", const bool has_to_be_set=false)
double relative_tolerance
double nonlinear_convergence_coefficient_ic
unsigned int maximum_number_of_steps_ic
unsigned int maximum_number_of_backtracks_ic
InitialConditionCorrection ic_type
bool ignore_algebraic_terms_for_errors
void add_parameters(ParameterHandler &prm)
unsigned int maximum_convergence_failures
double nonlinear_convergence_coefficient
double linear_tolerance_factor
unsigned int maximum_error_test_failures
unsigned int maximum_constraint_failures
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-15, const unsigned int maximum_order=5, const unsigned int maximum_non_linear_iterations=10, const double ls_norm_factor=0, const double absolute_tolerance=1e-6, const double relative_tolerance=1e-5, const bool ignore_algebraic_terms_for_errors=true, const InitialConditionCorrection &ic_type=use_y_diff, const InitialConditionCorrection &reset_type=use_y_diff, const unsigned int maximum_non_linear_iterations_ic=5, const double maximum_step_size=0.0, const long int maximum_number_of_steps=500, const unsigned int maximum_error_test_failures=10, const unsigned int maximum_convergence_failures=10, const double nonlinear_convergence_coefficient=0.33, const unsigned int maximum_number_of_steps_ic=5, const unsigned int maximum_number_of_jacobians_ic=4, const unsigned int maximum_number_of_backtracks_ic=100, const bool line_search_enabled_ic=true, const double step_tolerance_ic=std::pow(std::numeric_limits< double >::epsilon(), 2.0/3.0), const double nonlinear_convergence_coefficient_ic=0.0033, const double linear_tolerance_factor=0.05, const double increment_factor=1.0, const bool linear_solution_scaling=true, const double delta_cj_lsetup=0.25, const double eta_min=0.5, const double eta_max=2.0, const double eta_low=0.9, const double eta_min_err_fail=0.25, const double eta_conv_fail=0.25, const double eta_min_fixed=1.0, const double eta_max_fixed=2.0, const unsigned int maximum_constraint_failures=10)
long int maximum_number_of_steps
unsigned maximum_non_linear_iterations_ic
InitialConditionCorrection reset_type
bool linear_solution_scaling
bool line_search_enabled_ic
unsigned int maximum_order
unsigned int maximum_number_of_jacobians_ic
InitialConditionCorrection
unsigned int maximum_non_linear_iterations
double absolute_tolerance
std::function< void(const VectorType &rhs, VectorType &dst, const double tolerance)> solve_with_jacobian
unsigned int solve_dae(VectorType &solution, VectorType &solution_dot)
MPI_Comm mpi_communicator
std::function< void(const double t, const VectorType &y, const VectorType &y_dot, const double alpha)> setup_jacobian
void set_functions_to_trigger_an_assert()
const AdditionalData data
void reset(const double t, const double h, VectorType &y, VectorType &yp)
std::function< void(const double t, const VectorType &y, const VectorType &y_dot, VectorType &res)> residual
std::function< void(const double t, const VectorType &sol, const VectorType &sol_dot, const unsigned int step_number)> output_step
std::function< IndexSet()> differential_components
std::function< void(void *ida_mem)> custom_setup
void * get_ida_memory() const
std::function< VectorType &()> get_local_tolerances
std::function< bool(const double t, VectorType &sol, VectorType &sol_dot)> solver_should_restart
GrowingVectorMemory< VectorType > mem
std::function< void(VectorType &)> reinit_vector
std::function< VectorType &()> get_constraint_vector
std::exception_ptr pending_exception
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_ASSERT_UNREACHABLE()
static ::ExceptionBase & ExcFunctionNotProvided(std::string arg1)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcIDAError(int arg1)
#define DeclException1(Exception1, type1, outsequence)
#define AssertThrow(cond, exc)
::VectorizedArray< Number, width > pow(const ::VectorizedArray< Number, width > &, const Number p)