deal.II version GIT relicensing-7058-gb35ee29762 2026-11-11 09:30: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 <cmath>
48# include <limits>
49# include <memory>
50
51#endif // DEAL_II_WITH_SUNDIALS
52
54
55#ifdef DEAL_II_WITH_SUNDIALS
56namespace SUNDIALS
57{
490 template <typename VectorType = Vector<double>>
491 class IDA
492 {
493 public:
500 {
501 public:
512 {
516 none = 0,
517
526
530 use_y_dot = 2
531 };
532
591 AdditionalData( // Initial parameters
592 const double initial_time = 0.0,
593 const double final_time = 1.0,
594 const double initial_step_size = 1e-2,
595 const double output_period = 1e-1,
596 // Running parameters
597 const double minimum_step_size = 1e-15,
598 const unsigned int maximum_order = 5,
599 const unsigned int maximum_non_linear_iterations = 10,
600 const double ls_norm_factor = 0,
601 // Error parameters
602 const double absolute_tolerance = 1e-6,
603 const double relative_tolerance = 1e-5,
604 const bool ignore_algebraic_terms_for_errors = true,
605 // Initial conditions parameters
608 const unsigned int maximum_non_linear_iterations_ic = 5,
609 // Additional running and nonlinear solver parameters
610 const double maximum_step_size = 0.0,
611 const long int maximum_number_of_steps = 500,
612 const unsigned int maximum_error_test_failures = 10,
613 const unsigned int maximum_convergence_failures = 10,
614 const double nonlinear_convergence_coefficient = 0.33,
615 // Additional initial-condition correction parameters
616 const unsigned int maximum_number_of_steps_ic = 5,
617 const unsigned int maximum_number_of_jacobians_ic = 4,
618 const unsigned int maximum_number_of_backtracks_ic = 100,
619 const bool line_search_enabled_ic = true,
620 const double step_tolerance_ic =
621 std::pow(std::numeric_limits<double>::epsilon(), 2.0 / 3.0),
622 const double nonlinear_convergence_coefficient_ic = 0.0033,
623 // Additional linear solver parameters
624 const double linear_tolerance_factor = 0.05,
625 const double increment_factor = 1.0,
626 const bool linear_solution_scaling = true,
627 const double delta_cj_lsetup = 0.25,
628 // Step adaptivity parameters
629 const double eta_min = 0.5,
630 const double eta_max = 2.0,
631 const double eta_low = 0.9,
632 const double eta_min_err_fail = 0.25,
633 const double eta_conv_fail = 0.25,
634 const double eta_min_fixed = 1.0,
635 const double eta_max_fixed = 2.0,
636 const unsigned int maximum_constraint_failures = 10)
675 {}
676
719 void
721 {
722 prm.add_parameter("Initial time", initial_time);
723 prm.add_parameter("Final time", final_time);
724 prm.add_parameter("Time interval between each output", output_period);
725
726 prm.enter_subsection("Running parameters");
727 prm.add_parameter("Initial step size", initial_step_size);
728 prm.add_parameter("Minimum step size",
730 "Smallest allowed integration step.");
731 prm.add_parameter(
732 "Maximum step size",
734 "Largest allowed integration step; zero is unlimited.");
735 prm.add_parameter("Maximum number of steps",
737 "Maximum internal steps between output times.");
738 prm.add_parameter(
739 "Maximum error test failures",
741 "Stops a solve after repeated local error test rejections.");
742 prm.add_parameter(
743 "Maximum nonlinear convergence failures",
745 "Stops a solve after repeated nonlinear solver failures.");
746 prm.add_parameter("Maximum order of BDF", maximum_order);
747 prm.add_parameter("Maximum number of nonlinear iterations",
749 prm.leave_subsection();
750
751 prm.enter_subsection("Nonlinear solver");
752 prm.add_parameter(
753 "Convergence coefficient",
755 "Controls when Newton corrections count as converged.");
756 prm.leave_subsection();
757
758 prm.enter_subsection("Error control");
759 prm.add_parameter("Absolute error tolerance", absolute_tolerance);
760 prm.add_parameter("Relative error tolerance", relative_tolerance);
761 prm.add_parameter(
762 "Ignore algebraic terms for error computations",
764 "Indicate whether or not to suppress algebraic variables "
765 "in the local error test.");
766 prm.leave_subsection();
767
768 prm.enter_subsection("Initial condition correction parameters");
769 prm.add_parameter(
770 "Correction type at initial time",
771 ic_type,
772 "This is one of the following three options for the "
773 "initial condition calculation. \n"
774 " none: do not try to make initial conditions consistent. \n"
775 " use_y_diff: compute the algebraic components of y and differential\n"
776 " components of y_dot, given the differential components of y. \n"
777 " This option requires that the user specifies differential and \n"
778 " algebraic components in the function differential_components().\n"
779 " use_y_dot: compute all components of y, given y_dot.");
780 prm.add_parameter(
781 "Correction type after restart",
783 "This is one of the following three options for the "
784 "initial condition calculation. \n"
785 " none: do not try to make initial conditions consistent. \n"
786 " use_y_diff: compute the algebraic components of y and differential\n"
787 " components of y_dot, given the differential components of y. \n"
788 " This option requires that the user specifies differential and \n"
789 " algebraic components in the function differential_components().\n"
790 " use_y_dot: compute all components of y, given y_dot.");
791 prm.add_parameter("Maximum number of nonlinear iterations",
793 prm.add_parameter(
794 "Factor to use when converting from the integrator tolerance to the linear solver tolerance",
796 prm.add_parameter(
797 "Maximum number of steps",
799 "Bounds work while making the initial values consistent.");
800 prm.add_parameter(
801 "Maximum number of Jacobians",
803 "Bounds Jacobian refresh attempts during IC correction.");
804 prm.add_parameter("Maximum number of backtracks",
806 "Limits trial reductions in the IC line search.");
807 prm.add_parameter("Line search enabled",
809 "Enable backtracking when adjusting initial values.");
810 prm.add_parameter(
811 "Step tolerance",
813 "Treats a sufficiently small Newton correction as convergence.");
814 prm.add_parameter(
815 "Nonlinear convergence coefficient",
817 "Sets the Newton convergence test used by IDACalcIC.");
818 prm.leave_subsection();
819
820 prm.enter_subsection("Linear solver");
821 prm.add_parameter(
822 "Linear tolerance factor",
824 "Relates linear solve accuracy to the nonlinear tolerance.");
825 prm.add_parameter(
826 "Difference quotient increment factor",
828 "Scales finite-difference perturbations in Jacobian products.");
829 prm.add_parameter(
830 "Linear solution scaling",
832 "Compensates for changes in Cj between linear solves.");
833 prm.add_parameter(
834 "Cj setup difference factor",
836 "Rebuilds linear setup when Cj changes by this fraction.");
837 prm.leave_subsection();
838
839 prm.enter_subsection("Step adaptivity");
840 prm.add_parameter(
841 "Minimum step growth factor",
842 eta_min,
843 "Prevents overly aggressive reductions in step size.");
844 prm.add_parameter("Maximum step growth factor",
845 eta_max,
846 "Caps step growth after a successful step.");
847 prm.add_parameter("Low step growth factor",
848 eta_low,
849 "Applies when IDA takes a lower-order step.");
850 prm.add_parameter("Minimum growth factor after error failure",
852 "Limits step reduction after a failed error test.");
853 prm.add_parameter(
854 "Growth factor after convergence failure",
856 "Sets the next-step reduction after nonlinear failure.");
857 prm.add_parameter(
858 "Minimum fixed step growth factor",
860 "Lower step-size ratio bound for retaining the current step size.");
861 prm.add_parameter(
862 "Maximum fixed step growth factor",
864 "Upper step-size ratio bound for retaining the current step size.");
865 prm.leave_subsection();
866 prm.enter_subsection("Constraints");
867 prm.add_parameter(
868 "Maximum constraint failures",
870 "Rejects a step after this many constraint violations.");
871 prm.leave_subsection();
872 }
873
878
883
888
893
897 double maximum_step_size = 0.0;
898
906
911
916
921
926
931
936
941
946 std::pow(std::numeric_limits<double>::epsilon(), 2.0 / 3.0);
947
952
958
962 double increment_factor = 1.0;
963
969
974 double delta_cj_lsetup = 0.25;
975
980 double eta_min = 0.5;
981
986 double eta_max = 2.0;
987
992 double eta_low = 0.9;
993
998 double eta_min_err_fail = 0.25;
999
1004 double eta_conv_fail = 0.25;
1005
1012 double eta_min_fixed = 1.0;
1013
1020 double eta_max_fixed = 2.0;
1021
1027
1032
1037
1041 unsigned int maximum_order;
1042
1047
1052
1068
1080
1085
1090
1096 };
1097
1141
1149 IDA(const AdditionalData &data, const MPI_Comm mpi_comm);
1150
1154 ~IDA();
1155
1160 unsigned int
1161 solve_dae(VectorType &solution, VectorType &solution_dot);
1162
1184 void
1185 reset(const double t, const double h, VectorType &y, VectorType &yp);
1186
1192 std::function<void(VectorType &)> reinit_vector;
1193
1204 std::function<void(const double t,
1205 const VectorType &y,
1206 const VectorType &y_dot,
1207 VectorType &res)>
1209
1240 std::function<void(const double t,
1241 const VectorType &y,
1242 const VectorType &y_dot,
1243 const double alpha)>
1245
1287 std::function<
1288 void(const VectorType &rhs, VectorType &dst, const double tolerance)>
1290
1305 std::function<void(const double t,
1306 const VectorType &sol,
1307 const VectorType &sol_dot,
1308 const unsigned int step_number)>
1310
1334 std::function<bool(const double t, VectorType &sol, VectorType &sol_dot)>
1336
1354
1363 std::function<VectorType &()> get_local_tolerances;
1364
1375 std::function<VectorType &()> get_constraint_vector;
1376
1382 void *
1383 get_ida_memory() const;
1384
1394 std::function<void(void *ida_mem)> custom_setup;
1395
1396 private:
1402 std::string,
1403 << "Please provide an implementation for the function \""
1404 << arg1 << "\"");
1405
1411 void
1413
1418
1422 void *ida_mem;
1423
1424# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
1429# endif
1430
1436
1441
1447 mutable std::exception_ptr pending_exception;
1448
1449# ifdef DEAL_II_WITH_PETSC
1450# ifdef PETSC_USE_COMPLEX
1451 static_assert(!std::is_same_v<VectorType, PETScWrappers::MPI::Vector>,
1452 "Sundials does not support complex scalar types, "
1453 "but PETSc is configured to use a complex scalar type!");
1454
1455 static_assert(!std::is_same_v<VectorType, PETScWrappers::MPI::BlockVector>,
1456 "Sundials does not support complex scalar types, "
1457 "but PETSc is configured to use a complex scalar type!");
1458# endif // PETSC_USE_COMPLEX
1459# endif // DEAL_II_WITH_PETSC
1460 };
1461
1466 int,
1467 << "One of SUNDIALS IDA's internal functions "
1468 << "returned an error code: " << arg1
1469 << ". Please consult SUNDIALS manual.");
1470
1471} // namespace SUNDIALS
1472
1473#endif // DEAL_II_WITH_SUNDIALS
1474
1476
1477#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)
double nonlinear_convergence_coefficient_ic
Definition ida.h:951
unsigned int maximum_number_of_steps_ic
Definition ida.h:925
unsigned int maximum_number_of_backtracks_ic
Definition ida.h:935
InitialConditionCorrection ic_type
Definition ida.h:1067
void add_parameters(ParameterHandler &prm)
Definition ida.h:720
unsigned int maximum_convergence_failures
Definition ida.h:915
double nonlinear_convergence_coefficient
Definition ida.h:920
unsigned int maximum_error_test_failures
Definition ida.h:910
unsigned int maximum_constraint_failures
Definition ida.h:1026
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)
Definition ida.h:591
long int maximum_number_of_steps
Definition ida.h:905
unsigned maximum_non_linear_iterations_ic
Definition ida.h:1084
InitialConditionCorrection reset_type
Definition ida.h:1079
unsigned int maximum_order
Definition ida.h:1041
unsigned int maximum_number_of_jacobians_ic
Definition ida.h:930
unsigned int maximum_non_linear_iterations
Definition ida.h:1089
std::function< void(const VectorType &rhs, VectorType &dst, const double tolerance)> solve_with_jacobian
Definition ida.h:1289
unsigned int solve_dae(VectorType &solution, VectorType &solution_dot)
Definition ida.cc:115
MPI_Comm mpi_communicator
Definition ida.h:1435
std::function< void(const double t, const VectorType &y, const VectorType &y_dot, const double alpha)> setup_jacobian
Definition ida.h:1244
void set_functions_to_trigger_an_assert()
Definition ida.cc:587
const AdditionalData data
Definition ida.h:1417
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:1208
std::function< void(const double t, const VectorType &sol, const VectorType &sol_dot, const unsigned int step_number)> output_step
Definition ida.h:1309
std::function< IndexSet()> differential_components
Definition ida.h:1353
std::function< void(void *ida_mem)> custom_setup
Definition ida.h:1394
void * get_ida_memory() const
Definition ida.cc:622
std::function< VectorType &()> get_local_tolerances
Definition ida.h:1363
void * ida_mem
Definition ida.h:1422
std::function< bool(const double t, VectorType &sol, VectorType &sol_dot)> solver_should_restart
Definition ida.h:1335
GrowingVectorMemory< VectorType > mem
Definition ida.h:1440
std::function< void(VectorType &)> reinit_vector
Definition ida.h:1192
std::function< VectorType &()> get_constraint_vector
Definition ida.h:1375
SUNContext ida_ctx
Definition ida.h:1428
std::exception_ptr pending_exception
Definition ida.h:1447
#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 & ExcIDAError(int arg1)
#define DeclException1(Exception1, type1, outsequence)
::VectorizedArray< Number, width > pow(const ::VectorizedArray< Number, width > &, const Number p)