16 #ifndef dealii_sundials_ida_h 17 #define dealii_sundials_ida_h 19 #include <deal.II/base/config.h> 20 #include <deal.II/base/mpi.h> 21 #ifdef DEAL_II_WITH_SUNDIALS 23 #include <deal.II/base/logstream.h> 24 #include <deal.II/base/exceptions.h> 25 #include <deal.II/base/parameter_handler.h> 26 #include <deal.II/base/conditional_ostream.h> 27 #include <deal.II/base/mpi.h> 28 #ifdef DEAL_II_WITH_PETSC 29 # include <deal.II/lac/petsc_parallel_block_vector.h> 30 # include <deal.II/lac/petsc_parallel_vector.h> 32 #include <deal.II/lac/vector.h> 33 #include <deal.II/lac/vector_memory.h> 35 #ifdef DEAL_II_SUNDIALS_WITH_IDAS 36 #include <idas/idas.h> 41 #include <sundials/sundials_config.h> 42 #if DEAL_II_SUNDIALS_VERSION_LT(3,0,0) 43 # include <ida/ida_spgmr.h> 44 # include <ida/ida_spbcgs.h> 45 # include <ida/ida_sptfqmr.h> 47 #include <nvector/nvector_serial.h> 48 #include <sundials/sundials_math.h> 49 #include <sundials/sundials_types.h> 51 #include <boost/signals2.hpp> 55 DEAL_II_NAMESPACE_OPEN
58 #define AssertIDA(code) Assert(code >= 0, ExcIDAError(code)) 235 template<
typename VectorType=Vector<
double> >
394 "Indicate whether or not to suppress algebraic variables " 395 "in the local error test.");
399 static std::string ic_type_str=
"use_y_diff";
400 prm.
add_parameter(
"Correction type at initial time", ic_type_str,
401 "This is one of the following three options for the " 402 "initial condition calculation. \n" 403 " none: do not try to make initial conditions consistent. \n" 404 " use_y_diff: compute the algebraic components of y and differential\n" 405 " components of y_dot, given the differential components of y. \n" 406 " This option requires that the user specifies differential and \n" 407 " algebraic components in the function get_differential_components.\n" 408 " use_y_dot: compute all components of y, given y_dot.",
410 prm.
add_action(
"Correction type at initial time",[&](
const std::string &value)
412 if (value ==
"use_y_diff")
414 else if (value ==
"use_y_dot")
416 else if (value ==
"none")
422 static std::string reset_type_str=
"use_y_diff";
423 prm.
add_parameter(
"Correction type after restart", reset_type_str,
424 "This is one of the following three options for the " 425 "initial condition calculation. \n" 426 " none: do not try to make initial conditions consistent. \n" 427 " use_y_diff: compute the algebraic components of y and differential\n" 428 " components of y_dot, given the differential components of y. \n" 429 " This option requires that the user specifies differential and \n" 430 " algebraic components in the function get_differential_components.\n" 431 " use_y_dot: compute all components of y, given y_dot.",
433 prm.
add_action(
"Correction type after restart",[&](
const std::string &value)
435 if (value ==
"use_y_diff")
437 else if (value ==
"use_y_dot")
439 else if (value ==
"none")
568 const MPI_Comm mpi_comm = MPI_COMM_WORLD);
579 unsigned int solve_dae(VectorType &solution,
580 VectorType &solution_dot);
603 void reset(
const double &t,
623 std::function<int(
const double t,
625 const VectorType &y_dot,
658 std::function<int(
const double t,
660 const VectorType &y_dot,
707 std::function<void (
const double t,
708 const VectorType &sol,
709 const VectorType &sol_dot,
728 std::function<bool (
const double t,
753 DeclException1(ExcIDAError,
int, <<
"One of the SUNDIALS IDA internal functions " 754 <<
" returned a negative error code: " 755 << arg1 <<
". Please consult SUNDIALS manual.");
764 <<
"Please provide an implementation for the function \"" << arg1 <<
"\"");
815 #ifdef DEAL_II_WITH_PETSC 816 #ifdef PETSC_USE_COMPLEX 817 static_assert(!std::is_same<VectorType, PETScWrappers::MPI::Vector>::value,
818 "Sundials does not support complex scalar types, " 819 "but PETSc is configured to use a complex scalar type!");
821 static_assert(!std::is_same<VectorType, PETScWrappers::MPI::BlockVector>::value,
822 "Sundials does not support complex scalar types, " 823 "but PETSc is configured to use a complex scalar type!");
824 #endif // PETSC_USE_COMPLEX 825 #endif // DEAL_II_WITH_PETSC 830 DEAL_II_NAMESPACE_CLOSE
832 #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
void reset(const double &t, const double &h, VectorType &y, VectorType &yp)
std::function< int(const double t, const VectorType &y, const VectorType &y_dot, VectorType &res)> residual
InitialConditionCorrection reset_type
#define AssertThrow(cond, exc)
IDA(const AdditionalData &data=AdditionalData(), const MPI_Comm mpi_comm=MPI_COMM_WORLD)
void enter_subsection(const std::string &subsection)
std::function< void(const double t, const VectorType &sol, const VectorType &sol_dot, const unsigned int step_number)> output_step
bool ignore_algebraic_terms_for_errors
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)
std::function< int(const VectorType &rhs, VectorType &dst)> solve_jacobian_system
void add_parameter(const std::string &entry, ParameterType ¶meter, const std::string &documentation=std::string(), const Patterns::PatternBase &pattern= *Patterns::Tools::Convert< ParameterType >::to_pattern())
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)
std::function< bool(const double t, VectorType &sol, VectorType &sol_dot)> solver_should_restart
double relative_tolerance
double absolute_tolerance
std::function< VectorType &()> get_local_tolerances
InitialConditionCorrection ic_type
static ::ExceptionBase & ExcInternalError()
std::function< int(const double t, const VectorType &y, const VectorType &y_dot, const double alpha)> setup_jacobian