deal.II version GIT relicensing-6842-g793a97d2aa 2026-10-02 14:00:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
ida.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2017 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13
14#ifndef dealii_sundials_ida_h
15#define dealii_sundials_ida_h
16
17#include <deal.II/base/config.h>
18
19#ifdef DEAL_II_WITH_SUNDIALS
24
25# ifdef DEAL_II_WITH_PETSC
28# endif
29# include <deal.II/lac/vector.h>
31
32# ifdef DEAL_II_SUNDIALS_WITH_IDAS
33# include <idas/idas.h>
34# else
35# include <ida/ida.h>
36# endif
37
40
41# include <boost/signals2.hpp>
42
43# include <nvector/nvector_serial.h>
44# include <sundials/sundials_config.h>
45# include <sundials/sundials_math.h>
46
47# include <memory>
48
49#endif // DEAL_II_WITH_SUNDIALS
50
52
53#ifdef DEAL_II_WITH_SUNDIALS
54namespace SUNDIALS
55{
479 template <typename VectorType = Vector<double>>
480 class IDA
481 {
482 public:
487 {
488 public:
499 {
503 none = 0,
504
513
517 use_y_dot = 2
518 };
519
554 AdditionalData( // Initial parameters
555 const double initial_time = 0.0,
556 const double final_time = 1.0,
557 const double initial_step_size = 1e-2,
558 const double output_period = 1e-1,
559 // Running parameters
560 const double minimum_step_size = 1e-6,
561 const unsigned int maximum_order = 5,
562 const unsigned int maximum_non_linear_iterations = 10,
563 const double ls_norm_factor = 0,
564 // Error parameters
565 const double absolute_tolerance = 1e-6,
566 const double relative_tolerance = 1e-5,
567 const bool ignore_algebraic_terms_for_errors = true,
568 // Initial conditions parameters
571 const unsigned int maximum_non_linear_iterations_ic = 5)
586 {}
587
630 void
632 {
633 prm.add_parameter("Initial time", initial_time);
634 prm.add_parameter("Final time", final_time);
635 prm.add_parameter("Time interval between each output", output_period);
636
637 prm.enter_subsection("Running parameters");
638 prm.add_parameter("Initial step size", initial_step_size);
639 prm.add_parameter("Minimum step size", minimum_step_size);
640 prm.add_parameter("Maximum order of BDF", maximum_order);
641 prm.add_parameter("Maximum number of nonlinear iterations",
643 prm.leave_subsection();
644
645 prm.enter_subsection("Error control");
646 prm.add_parameter("Absolute error tolerance", absolute_tolerance);
647 prm.add_parameter("Relative error tolerance", relative_tolerance);
648 prm.add_parameter(
649 "Ignore algebraic terms for error computations",
651 "Indicate whether or not to suppress algebraic variables "
652 "in the local error test.");
653 prm.leave_subsection();
654
655 prm.enter_subsection("Initial condition correction parameters");
656 static std::string ic_type_str = "use_y_diff";
657 prm.add_parameter(
658 "Correction type at initial time",
659 ic_type_str,
660 "This is one of the following three options for the "
661 "initial condition calculation. \n"
662 " none: do not try to make initial conditions consistent. \n"
663 " use_y_diff: compute the algebraic components of y and differential\n"
664 " components of y_dot, given the differential components of y. \n"
665 " This option requires that the user specifies differential and \n"
666 " algebraic components in the function differential_components().\n"
667 " use_y_dot: compute all components of y, given y_dot.",
668 Patterns::Selection("none|use_y_diff|use_y_dot"));
669 prm.add_action("Correction type at initial time",
670 [&](const std::string &value) {
671 if (value == "use_y_diff")
673 else if (value == "use_y_dot")
675 else if (value == "none")
676 ic_type = none;
677 else
679 });
680
681 static std::string reset_type_str = "use_y_diff";
682 prm.add_parameter(
683 "Correction type after restart",
684 reset_type_str,
685 "This is one of the following three options for the "
686 "initial condition calculation. \n"
687 " none: do not try to make initial conditions consistent. \n"
688 " use_y_diff: compute the algebraic components of y and differential\n"
689 " components of y_dot, given the differential components of y. \n"
690 " This option requires that the user specifies differential and \n"
691 " algebraic components in the function differential_components().\n"
692 " use_y_dot: compute all components of y, given y_dot.",
693 Patterns::Selection("none|use_y_diff|use_y_dot"));
694 prm.add_action("Correction type after restart",
695 [&](const std::string &value) {
696 if (value == "use_y_diff")
698 else if (value == "use_y_dot")
700 else if (value == "none")
702 else
704 });
705 prm.add_parameter("Maximum number of nonlinear iterations",
707 prm.add_parameter(
708 "Factor to use when converting from the integrator tolerance to the linear solver tolerance",
710 prm.leave_subsection();
711 }
712
717
722
727
732
737
742
746 unsigned int maximum_order;
747
752
757
773
785
790
795
801 };
802
846
854 IDA(const AdditionalData &data, const MPI_Comm mpi_comm);
855
859 ~IDA();
860
865 unsigned int
866 solve_dae(VectorType &solution, VectorType &solution_dot);
867
889 void
890 reset(const double t, const double h, VectorType &y, VectorType &yp);
891
895 std::function<void(VectorType &)> reinit_vector;
896
907 std::function<void(const double t,
908 const VectorType &y,
909 const VectorType &y_dot,
910 VectorType &res)>
912
943 std::function<void(const double t,
944 const VectorType &y,
945 const VectorType &y_dot,
946 const double alpha)>
948
990 std::function<
991 void(const VectorType &rhs, VectorType &dst, const double tolerance)>
993
1008 std::function<void(const double t,
1009 const VectorType &sol,
1010 const VectorType &sol_dot,
1011 const unsigned int step_number)>
1013
1037 std::function<bool(const double t, VectorType &sol, VectorType &sol_dot)>
1039
1055
1062 std::function<VectorType &()> get_local_tolerances;
1063
1064 private:
1070 std::string,
1071 << "Please provide an implementation for the function \""
1072 << arg1 << "\"");
1073
1079 void
1081
1086
1090 void *ida_mem;
1091
1092# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
1097# endif
1098
1104
1109
1115 mutable std::exception_ptr pending_exception;
1116
1117# ifdef DEAL_II_WITH_PETSC
1118# ifdef PETSC_USE_COMPLEX
1119 static_assert(!std::is_same_v<VectorType, PETScWrappers::MPI::Vector>,
1120 "Sundials does not support complex scalar types, "
1121 "but PETSc is configured to use a complex scalar type!");
1122
1123 static_assert(!std::is_same_v<VectorType, PETScWrappers::MPI::BlockVector>,
1124 "Sundials does not support complex scalar types, "
1125 "but PETSc is configured to use a complex scalar type!");
1126# endif // PETSC_USE_COMPLEX
1127# endif // DEAL_II_WITH_PETSC
1128 };
1129
1134 int,
1135 << "One of SUNDIALS IDA's internal functions "
1136 << "returned an error code: " << arg1
1137 << ". Please consult SUNDIALS manual.");
1138
1139} // namespace SUNDIALS
1140
1141#endif // DEAL_II_WITH_SUNDIALS
1142
1144
1145#endif
void add_parameter(const std::string &entry, ParameterType &parameter, 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)
InitialConditionCorrection ic_type
Definition ida.h:772
bool ignore_algebraic_terms_for_errors
Definition ida.h:756
void add_parameters(ParameterHandler &prm)
Definition ida.h:631
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 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)
Definition ida.h:554
unsigned maximum_non_linear_iterations_ic
Definition ida.h:789
InitialConditionCorrection reset_type
Definition ida.h:784
unsigned int maximum_order
Definition ida.h:746
unsigned int maximum_non_linear_iterations
Definition ida.h:794
std::function< void(const VectorType &rhs, VectorType &dst, const double tolerance)> solve_with_jacobian
Definition ida.h:992
unsigned int solve_dae(VectorType &solution, VectorType &solution_dot)
Definition ida.cc:115
MPI_Comm mpi_communicator
Definition ida.h:1103
std::function< void(const double t, const VectorType &y, const VectorType &y_dot, const double alpha)> setup_jacobian
Definition ida.h:947
void set_functions_to_trigger_an_assert()
Definition ida.cc:505
const AdditionalData data
Definition ida.h:1085
void reset(const double t, const double h, VectorType &y, VectorType &yp)
Definition ida.cc:198
std::function< void(const double t, const VectorType &y, const VectorType &y_dot, VectorType &res)> residual
Definition ida.h:911
std::function< void(const double t, const VectorType &sol, const VectorType &sol_dot, const unsigned int step_number)> output_step
Definition ida.h:1012
std::function< IndexSet()> differential_components
Definition ida.h:1054
std::function< VectorType &()> get_local_tolerances
Definition ida.h:1062
void * ida_mem
Definition ida.h:1090
std::function< bool(const double t, VectorType &sol, VectorType &sol_dot)> solver_should_restart
Definition ida.h:1038
GrowingVectorMemory< VectorType > mem
Definition ida.h:1108
std::function< void(VectorType &)> reinit_vector
Definition ida.h:895
SUNContext ida_ctx
Definition ida.h:1096
std::exception_ptr pending_exception
Definition ida.h:1115
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
static ::ExceptionBase & ExcFunctionNotProvided(std::string arg1)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcIDAError(int arg1)
#define DeclException1(Exception1, type1, outsequence)
#define AssertThrow(cond, exc)