16 #ifndef dealii_sundials_ida_h 17 #define dealii_sundials_ida_h 19 #include <deal.II/base/config.h> 21 #include <deal.II/base/mpi.h> 22 #ifdef DEAL_II_WITH_SUNDIALS 24 # include <deal.II/base/conditional_ostream.h> 25 # include <deal.II/base/exceptions.h> 26 # include <deal.II/base/logstream.h> 27 # include <deal.II/base/mpi.h> 28 # include <deal.II/base/parameter_handler.h> 29 # ifdef DEAL_II_WITH_PETSC 30 # include <deal.II/lac/petsc_block_vector.h> 31 # include <deal.II/lac/petsc_vector.h> 33 # include <deal.II/lac/vector.h> 34 # include <deal.II/lac/vector_memory.h> 36 # ifdef DEAL_II_SUNDIALS_WITH_IDAS 37 # include <idas/idas.h> 42 # include <sundials/sundials_config.h> 43 # if DEAL_II_SUNDIALS_VERSION_LT(3, 0, 0) 44 # include <ida/ida_spbcgs.h> 45 # include <ida/ida_spgmr.h> 46 # include <ida/ida_sptfqmr.h> 48 # include <boost/signals2.hpp> 50 # include <nvector/nvector_serial.h> 51 # include <sundials/sundials_math.h> 52 # include <sundials/sundials_types.h> 57 DEAL_II_NAMESPACE_OPEN
60 # define AssertIDA(code) Assert(code >= 0, ExcIDAError(code)) 235 template <
typename VectorType = Vector<
double>>
399 "Ignore algebraic terms for error computations",
401 "Indicate whether or not to suppress algebraic variables " 402 "in the local error test.");
406 static std::string ic_type_str =
"use_y_diff";
408 "Correction type at initial time",
410 "This is one of the following three options for the " 411 "initial condition calculation. \n" 412 " none: do not try to make initial conditions consistent. \n" 413 " use_y_diff: compute the algebraic components of y and differential\n" 414 " components of y_dot, given the differential components of y. \n" 415 " This option requires that the user specifies differential and \n" 416 " algebraic components in the function get_differential_components.\n" 417 " use_y_dot: compute all components of y, given y_dot.",
419 prm.
add_action(
"Correction type at initial time",
420 [&](
const std::string &value) {
421 if (value ==
"use_y_diff")
423 else if (value ==
"use_y_dot")
425 else if (value ==
"none")
431 static std::string reset_type_str =
"use_y_diff";
433 "Correction type after restart",
435 "This is one of the following three options for the " 436 "initial condition calculation. \n" 437 " none: do not try to make initial conditions consistent. \n" 438 " use_y_diff: compute the algebraic components of y and differential\n" 439 " components of y_dot, given the differential components of y. \n" 440 " This option requires that the user specifies differential and \n" 441 " algebraic components in the function get_differential_components.\n" 442 " use_y_dot: compute all components of y, given y_dot.",
444 prm.
add_action(
"Correction type after restart",
445 [&](
const std::string &value) {
446 if (value ==
"use_y_diff")
448 else if (value ==
"use_y_dot")
450 else if (value ==
"none")
586 const MPI_Comm mpi_comm = MPI_COMM_WORLD);
598 solve_dae(VectorType &solution, VectorType &solution_dot);
622 reset(
const double t,
const double h, VectorType &y, VectorType &
yp);
639 std::function<int(
const double t,
641 const VectorType &y_dot,
675 std::function<int(
const double t,
677 const VectorType &y_dot,
709 std::function<int(const VectorType &rhs, VectorType &dst)>
726 std::function<void(
const double t,
727 const VectorType & sol,
728 const VectorType & sol_dot,
729 const unsigned int step_number)>
748 std::function<bool(const double t, VectorType &sol, VectorType &sol_dot)>
774 <<
"One of the SUNDIALS IDA internal functions " 775 <<
" returned a negative error code: " << arg1
776 <<
". Please consult SUNDIALS manual.");
786 <<
"Please provide an implementation for the function \"" 839 # ifdef DEAL_II_WITH_PETSC 840 # ifdef PETSC_USE_COMPLEX 841 static_assert(!std::is_same<VectorType, PETScWrappers::MPI::Vector>::value,
842 "Sundials does not support complex scalar types, " 843 "but PETSc is configured to use a complex scalar type!");
846 !std::is_same<VectorType, PETScWrappers::MPI::BlockVector>::value,
847 "Sundials does not support complex scalar types, " 848 "but PETSc is configured to use a complex scalar type!");
849 # endif // PETSC_USE_COMPLEX 850 # endif // DEAL_II_WITH_PETSC 855 DEAL_II_NAMESPACE_CLOSE
857 #endif // DEAL_II_WITH_SUNDIALS
void set_functions_to_trigger_an_assert()
GrowingVectorMemory< VectorType > mem
std::function< void(VectorType &)> reinit_vector
std::function< IndexSet()> differential_components
unsigned int maximum_order
DeclException1(ExcIDAError, int,<< "One of the SUNDIALS IDA internal functions "<< " returned a negative error code: "<< arg1<< ". Please consult SUNDIALS manual.")
InitialConditionCorrection
void add_parameters(ParameterHandler &prm)
unsigned maximum_non_linear_iterations_ic
InitialConditionCorrection reset_type
void reset(const double t, const double h, VectorType &y, VectorType &yp)
#define AssertThrow(cond, exc)
IDA(const AdditionalData &data=AdditionalData(), const MPI_Comm mpi_comm=MPI_COMM_WORLD)
void add_parameter(const std::string &entry, ParameterType ¶meter, const std::string &documentation="", const Patterns::PatternBase &pattern= *Patterns::Tools::Convert< ParameterType >::to_pattern())
std::function< VectorType &()> get_local_tolerances
void enter_subsection(const std::string &subsection)
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 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)
bool ignore_algebraic_terms_for_errors
std::function< int(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< int(const VectorType &rhs, VectorType &dst)> solve_jacobian_system
std::function< bool(const double t, VectorType &sol, VectorType &sol_dot)> solver_should_restart
unsigned int maximum_non_linear_iterations
void add_action(const std::string &entry, const std::function< void(const std::string &value)> &action)
unsigned int solve_dae(VectorType &solution, VectorType &solution_dot)
double relative_tolerance
double absolute_tolerance
InitialConditionCorrection ic_type
static ::ExceptionBase & ExcInternalError()
std::function< int(const double t, const VectorType &y, const VectorType &y_dot, const double alpha)> setup_jacobian