Reference documentation for deal.II version 9.3.0
\(\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\}}\)
ida.h
Go to the documentation of this file.
1 //-----------------------------------------------------------
2 //
3 // Copyright (C) 2017 - 2020 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 //---------------------------------------------------------------
15 
16 #ifndef dealii_sundials_ida_h
17 #define dealii_sundials_ida_h
18 
19 #include <deal.II/base/config.h>
20 
21 #include <deal.II/base/mpi.h>
22 #ifdef DEAL_II_WITH_SUNDIALS
24 # include <deal.II/base/exceptions.h>
25 # include <deal.II/base/logstream.h>
27 # ifdef DEAL_II_WITH_PETSC
30 # endif
31 # include <deal.II/lac/vector.h>
33 
34 # ifdef DEAL_II_SUNDIALS_WITH_IDAS
35 # include <idas/idas.h>
36 # else
37 # include <ida/ida.h>
38 # endif
39 
40 # include <sundials/sundials_config.h>
41 # if DEAL_II_SUNDIALS_VERSION_LT(3, 0, 0)
42 # include <ida/ida_spbcgs.h>
43 # include <ida/ida_spgmr.h>
44 # include <ida/ida_sptfqmr.h>
45 # endif
47 
48 # include <boost/signals2.hpp>
49 
50 # include <nvector/nvector_serial.h>
51 # include <sundials/sundials_math.h>
52 # include <sundials/sundials_types.h>
53 
54 # include <memory>
55 
56 
58 
59 // Shorthand notation for IDA error codes.
60 # define AssertIDA(code) Assert(code >= 0, ExcIDAError(code))
61 
62 namespace SUNDIALS
63 {
238  template <typename VectorType = Vector<double>>
239  class IDA
240  {
241  public:
246  {
247  public:
258  {
262  none = 0,
263 
271 
275  use_y_dot = 2
276  };
277 
312  AdditionalData( // Initial parameters
313  const double initial_time = 0.0,
314  const double final_time = 1.0,
315  const double initial_step_size = 1e-2,
316  const double output_period = 1e-1,
317  // Running parameters
318  const double minimum_step_size = 1e-6,
319  const unsigned int maximum_order = 5,
320  const unsigned int maximum_non_linear_iterations = 10,
321  const double ls_norm_factor = 0,
322  // Error parameters
323  const double absolute_tolerance = 1e-6,
324  const double relative_tolerance = 1e-5,
325  const bool ignore_algebraic_terms_for_errors = true,
326  // Initial conditions parameters
329  const unsigned int maximum_non_linear_iterations_ic = 5)
339  , ic_type(ic_type)
344  {}
345 
388  void
390  {
391  prm.add_parameter("Initial time", initial_time);
392  prm.add_parameter("Final time", final_time);
393  prm.add_parameter("Time interval between each output", output_period);
394 
395  prm.enter_subsection("Running parameters");
396  prm.add_parameter("Initial step size", initial_step_size);
397  prm.add_parameter("Minimum step size", minimum_step_size);
398  prm.add_parameter("Maximum order of BDF", maximum_order);
399  prm.add_parameter("Maximum number of nonlinear iterations",
401  prm.leave_subsection();
402 
403  prm.enter_subsection("Error control");
404  prm.add_parameter("Absolute error tolerance", absolute_tolerance);
405  prm.add_parameter("Relative error tolerance", relative_tolerance);
406  prm.add_parameter(
407  "Ignore algebraic terms for error computations",
409  "Indicate whether or not to suppress algebraic variables "
410  "in the local error test.");
411  prm.leave_subsection();
412 
413  prm.enter_subsection("Initial condition correction parameters");
414  static std::string ic_type_str = "use_y_diff";
415  prm.add_parameter(
416  "Correction type at initial time",
417  ic_type_str,
418  "This is one of the following three options for the "
419  "initial condition calculation. \n"
420  " none: do not try to make initial conditions consistent. \n"
421  " use_y_diff: compute the algebraic components of y and differential\n"
422  " components of y_dot, given the differential components of y. \n"
423  " This option requires that the user specifies differential and \n"
424  " algebraic components in the function get_differential_components.\n"
425  " use_y_dot: compute all components of y, given y_dot.",
426  Patterns::Selection("none|use_y_diff|use_y_dot"));
427  prm.add_action("Correction type at initial time",
428  [&](const std::string &value) {
429  if (value == "use_y_diff")
431  else if (value == "use_y_dot")
432  ic_type = use_y_dot;
433  else if (value == "none")
434  ic_type = none;
435  else
436  AssertThrow(false, ExcInternalError());
437  });
438 
439  static std::string reset_type_str = "use_y_diff";
440  prm.add_parameter(
441  "Correction type after restart",
442  reset_type_str,
443  "This is one of the following three options for the "
444  "initial condition calculation. \n"
445  " none: do not try to make initial conditions consistent. \n"
446  " use_y_diff: compute the algebraic components of y and differential\n"
447  " components of y_dot, given the differential components of y. \n"
448  " This option requires that the user specifies differential and \n"
449  " algebraic components in the function get_differential_components.\n"
450  " use_y_dot: compute all components of y, given y_dot.",
451  Patterns::Selection("none|use_y_diff|use_y_dot"));
452  prm.add_action("Correction type after restart",
453  [&](const std::string &value) {
454  if (value == "use_y_diff")
456  else if (value == "use_y_dot")
458  else if (value == "none")
459  reset_type = none;
460  else
461  AssertThrow(false, ExcInternalError());
462  });
463  prm.add_parameter("Maximum number of nonlinear iterations",
465  prm.add_parameter(
466  "Factor to use when converting from the integrator tolerance to the linear solver tolerance",
468  prm.leave_subsection();
469  }
470 
474  double initial_time;
475 
479  double final_time;
480 
485 
490 
495 
500 
504  unsigned int maximum_order;
505 
510 
515 
531 
543 
548 
553 
559  };
560 
603  const MPI_Comm & mpi_comm = MPI_COMM_WORLD);
604 
608  ~IDA();
609 
614  unsigned int
615  solve_dae(VectorType &solution, VectorType &solution_dot);
616 
638  void
639  reset(const double t, const double h, VectorType &y, VectorType &yp);
640 
644  std::function<void(VectorType &)> reinit_vector;
645 
656  std::function<int(const double t,
657  const VectorType &y,
658  const VectorType &y_dot,
659  VectorType & res)>
661 
696  std::function<int(const double t,
697  const VectorType &y,
698  const VectorType &y_dot,
699  const double alpha)>
701 
735  std::function<int(const VectorType &rhs, VectorType &dst)>
737 
779  std::function<
780  int(const VectorType &rhs, VectorType &dst, const double tolerance)>
782 
797  std::function<void(const double t,
798  const VectorType & sol,
799  const VectorType & sol_dot,
800  const unsigned int step_number)>
802 
819  std::function<bool(const double t, VectorType &sol, VectorType &sol_dot)>
821 
837 
844  std::function<VectorType &()> get_local_tolerances;
845 
849  DeclException1(ExcIDAError,
850  int,
851  << "One of the SUNDIALS IDA internal functions "
852  << " returned a negative error code: " << arg1
853  << ". Please consult SUNDIALS manual.");
854 
855 
856  private:
861  DeclException1(ExcFunctionNotProvided,
862  std::string,
863  << "Please provide an implementation for the function \""
864  << arg1 << "\"");
865 
871  void
873 
878 
882  void *ida_mem;
883 
889  MPI_Comm communicator;
890 
895 
896 # ifdef DEAL_II_WITH_PETSC
897 # ifdef PETSC_USE_COMPLEX
898  static_assert(!std::is_same<VectorType, PETScWrappers::MPI::Vector>::value,
899  "Sundials does not support complex scalar types, "
900  "but PETSc is configured to use a complex scalar type!");
901 
902  static_assert(
903  !std::is_same<VectorType, PETScWrappers::MPI::BlockVector>::value,
904  "Sundials does not support complex scalar types, "
905  "but PETSc is configured to use a complex scalar type!");
906 # endif // PETSC_USE_COMPLEX
907 # endif // DEAL_II_WITH_PETSC
908  };
909 } // namespace SUNDIALS
910 
912 
913 #endif // DEAL_II_WITH_SUNDIALS
914 
915 #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 add_action(const std::string &entry, const std::function< void(const std::string &value)> &action)
void enter_subsection(const std::string &subsection)
InitialConditionCorrection ic_type
Definition: ida.h:530
bool ignore_algebraic_terms_for_errors
Definition: ida.h:514
void add_parameters(ParameterHandler &prm)
Definition: ida.h:389
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:312
unsigned maximum_non_linear_iterations_ic
Definition: ida.h:547
InitialConditionCorrection reset_type
Definition: ida.h:542
unsigned int maximum_order
Definition: ida.h:504
unsigned int maximum_non_linear_iterations
Definition: ida.h:552
unsigned int solve_dae(VectorType &solution, VectorType &solution_dot)
Definition: ida.cc:228
void set_functions_to_trigger_an_assert()
Definition: ida.cc:478
const AdditionalData data
Definition: ida.h:877
void reset(const double t, const double h, VectorType &y, VectorType &yp)
Definition: ida.cc:275
std::function< IndexSet()> differential_components
Definition: ida.h:836
DeclException1(ExcIDAError, int,<< "One of the SUNDIALS IDA internal functions "<< " returned a negative error code: "<< arg1<< ". Please consult SUNDIALS manual.")
IDA(const AdditionalData &data=AdditionalData(), const MPI_Comm &mpi_comm=MPI_COMM_WORLD)
Definition: ida.cc:199
std::function< int(const double t, const VectorType &y, const VectorType &y_dot, VectorType &res)> residual
Definition: ida.h:660
std::function< VectorType &()> get_local_tolerances
Definition: ida.h:844
void * ida_mem
Definition: ida.h:882
std::function< void(const double t, const VectorType &sol, const VectorType &sol_dot, const unsigned int step_number)> output_step
Definition: ida.h:801
std::function< bool(const double t, VectorType &sol, VectorType &sol_dot)> solver_should_restart
Definition: ida.h:820
std::function< int(const double t, const VectorType &y, const VectorType &y_dot, const double alpha)> setup_jacobian
Definition: ida.h:700
DeclException1(ExcFunctionNotProvided, std::string,<< "Please provide an implementation for the function \""<< arg1<< "\"")
GrowingVectorMemory< VectorType > mem
Definition: ida.h:894
std::function< void(VectorType &)> reinit_vector
Definition: ida.h:644
std::function< int(const VectorType &rhs, VectorType &dst, const double tolerance)> solve_with_jacobian
Definition: ida.h:781
MPI_Comm communicator
Definition: ida.h:889
DEAL_II_DEPRECATED_EARLY std::function< int(const VectorType &rhs, VectorType &dst)> solve_jacobian_system
Definition: ida.h:736
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:394
#define DEAL_II_DEPRECATED_EARLY
Definition: config.h:165
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:395
static ::ExceptionBase & ExcInternalError()
#define AssertThrow(cond, exc)
Definition: exceptions.h:1575
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)