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\}}\)
kinsol.h
Go to the documentation of this file.
1 //-----------------------------------------------------------
2 //
3 // Copyright (C) 2017 - 2021 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_kinsol_h
17 #define dealii_sundials_kinsol_h
18 
19 #include <deal.II/base/config.h>
20 
21 #ifdef DEAL_II_WITH_SUNDIALS
22 
23 
25 # include <deal.II/base/exceptions.h>
26 # include <deal.II/base/logstream.h>
27 # include <deal.II/base/mpi.h>
29 
30 # include <deal.II/lac/vector.h>
32 
33 # include <boost/signals2.hpp>
34 
35 # include <kinsol/kinsol.h>
36 # if DEAL_II_SUNDIALS_VERSION_LT(4, 1, 0)
37 # include <kinsol/kinsol_impl.h>
38 # endif
39 # include <nvector/nvector_serial.h>
40 # include <sundials/sundials_math.h>
41 # include <sundials/sundials_types.h>
42 
43 # include <memory>
44 
45 
47 
48 // Shorthand notation for KINSOL error codes.
49 # define AssertKINSOL(code) Assert(code >= 0, ExcKINSOLError(code))
50 
51 namespace SUNDIALS
52 {
182  template <typename VectorType = Vector<double>>
183  class KINSOL
184  {
185  public:
190  {
191  public:
197  {
201  newton = KIN_NONE,
205  linesearch = KIN_LINESEARCH,
209  fixed_point = KIN_FP,
213  picard = KIN_PICARD,
214  };
215 
245  const unsigned int maximum_non_linear_iterations = 200,
246  const double function_tolerance = 0.0,
247  const double step_tolerance = 0.0,
248  const bool no_init_setup = false,
249  const unsigned int maximum_setup_calls = 0,
250  const double maximum_newton_step = 0.0,
251  const double dq_relative_error = 0.0,
252  const unsigned int maximum_beta_failures = 0,
253  const unsigned int anderson_subspace_size = 0);
254 
293  void
295 
304 
309 
317 
325 
335 
344  unsigned int maximum_setup_calls;
345 
352 
361 
367  unsigned int maximum_beta_failures;
368 
376  };
377 
387  const MPI_Comm & mpi_comm = MPI_COMM_WORLD);
388 
392  ~KINSOL();
393 
399  unsigned int
400  solve(VectorType &initial_guess_and_solution);
401 
409  std::function<void(VectorType &)> reinit_vector;
410 
424  std::function<int(const VectorType &src, VectorType &dst)> residual;
425 
440  std::function<int(const VectorType &src, VectorType &dst)>
442 
488  std::function<int(const VectorType &current_u, const VectorType &current_f)>
490 
549  std::function<int(const VectorType &ycur,
550  const VectorType &fcur,
551  const VectorType &rhs,
552  VectorType & dst)>
554 
594  std::function<
595  int(const VectorType &rhs, VectorType &dst, const double tolerance)>
597 
636  std::function<VectorType &()> get_solution_scaling;
637 
652  std::function<VectorType &()> get_function_scaling;
653 
658  int,
659  << "One of the SUNDIALS KINSOL internal functions "
660  << "returned a negative error code: " << arg1
661  << ". Please consult SUNDIALS manual.");
662 
663 
664  private:
670  std::string,
671  << "Please provide an implementation for the function \""
672  << arg1 << "\"");
673 
679  void
681 
686 
690  void *kinsol_mem;
691 
696  };
697 
698 } // namespace SUNDIALS
699 
700 
702 
703 #endif
704 
705 #endif
unsigned int maximum_setup_calls
Definition: kinsol.h:344
SolutionStrategy strategy
Definition: kinsol.h:303
unsigned int maximum_beta_failures
Definition: kinsol.h:367
AdditionalData(const SolutionStrategy &strategy=linesearch, const unsigned int maximum_non_linear_iterations=200, const double function_tolerance=0.0, const double step_tolerance=0.0, const bool no_init_setup=false, const unsigned int maximum_setup_calls=0, const double maximum_newton_step=0.0, const double dq_relative_error=0.0, const unsigned int maximum_beta_failures=0, const unsigned int anderson_subspace_size=0)
Definition: kinsol.cc:57
void add_parameters(ParameterHandler &prm)
Definition: kinsol.cc:84
unsigned int maximum_non_linear_iterations
Definition: kinsol.h:308
unsigned int anderson_subspace_size
Definition: kinsol.h:375
std::function< VectorType &()> get_solution_scaling
Definition: kinsol.h:636
std::function< int(const VectorType &rhs, VectorType &dst, const double tolerance)> solve_with_jacobian
Definition: kinsol.h:596
std::function< int(const VectorType &current_u, const VectorType &current_f)> setup_jacobian
Definition: kinsol.h:489
void set_functions_to_trigger_an_assert()
Definition: kinsol.cc:535
KINSOL(const AdditionalData &data=AdditionalData(), const MPI_Comm &mpi_comm=MPI_COMM_WORLD)
Definition: kinsol.cc:309
std::function< int(const VectorType &ycur, const VectorType &fcur, const VectorType &rhs, VectorType &dst)> solve_jacobian_system
Definition: kinsol.h:553
unsigned int solve(VectorType &initial_guess_and_solution)
Definition: kinsol.cc:329
GrowingVectorMemory< VectorType > mem
Definition: kinsol.h:695
std::function< int(const VectorType &src, VectorType &dst)> residual
Definition: kinsol.h:424
std::function< VectorType &()> get_function_scaling
Definition: kinsol.h:652
std::function< void(VectorType &)> reinit_vector
Definition: kinsol.h:409
AdditionalData data
Definition: kinsol.h:685
std::function< int(const VectorType &src, VectorType &dst)> iteration_function
Definition: kinsol.h:441
void * kinsol_mem
Definition: kinsol.h:690
#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 & ExcFunctionNotProvided(std::string arg1)
static ::ExceptionBase & ExcKINSOLError(int arg1)
DeclException1(ExcARKodeError, int,<< "One of the SUNDIALS ARKode internal functions "<< " returned a negative error code: "<< arg1<< ". Please consult SUNDIALS manual.")