Reference documentation for deal.II version 9.6.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\}}\)
Loading...
Searching...
No Matches
kinsol.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2017 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
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
28
29# include <deal.II/lac/vector.h>
31
33
34# include <boost/signals2.hpp>
35
36# include <kinsol/kinsol.h>
37# include <nvector/nvector_serial.h>
38# include <sundials/sundials_math.h>
39
40# include <exception>
41# include <memory>
42
43
45
46// Shorthand notation for KINSOL error codes.
47# define AssertKINSOL(code) Assert(code >= 0, ExcKINSOLError(code))
48
49namespace SUNDIALS
50{
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
216
261
292 AdditionalData(const SolutionStrategy &strategy = linesearch,
293 const unsigned int maximum_non_linear_iterations = 200,
294 const double function_tolerance = 0.0,
295 const double step_tolerance = 0.0,
296 const bool no_init_setup = false,
297 const unsigned int maximum_setup_calls = 0,
298 const double maximum_newton_step = 0.0,
299 const double dq_relative_error = 0.0,
300 const unsigned int maximum_beta_failures = 0,
301 const unsigned int anderson_subspace_size = 0,
302 const OrthogonalizationStrategy
304
343 void
345
354
359
367
375
385
395
402
411
418
426
432 };
433
444
452 KINSOL(const AdditionalData &data, const MPI_Comm mpi_comm);
453
457 ~KINSOL();
458
464 unsigned int
465 solve(VectorType &initial_guess_and_solution);
466
481 std::function<void(VectorType &)> reinit_vector;
482
496 std::function<void(const VectorType &src, VectorType &dst)> residual;
497
511 std::function<void(const VectorType &src, VectorType &dst)>
513
559 std::function<void(const VectorType &current_u,
560 const VectorType &current_f)>
562
602 std::function<
603 void(const VectorType &rhs, VectorType &dst, const double tolerance)>
605
651 std::function<VectorType &()> get_solution_scaling;
652
674 std::function<VectorType &()> get_function_scaling;
675
676
705 std::function<void(void *kinsol_mem)> custom_setup;
706
711 int,
712 << "One of the SUNDIALS KINSOL internal functions "
713 << "returned a negative error code: " << arg1
714 << ". Please consult SUNDIALS manual.");
715
716 private:
722 std::string,
723 << "Please provide an implementation for the function \""
724 << arg1 << "\"");
725
731 void
733
738
743
748
749# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
754# endif
755
756
761
767 mutable std::exception_ptr pending_exception;
768 };
769
770} // namespace SUNDIALS
771
772
774
775#endif
776
777#endif
SolutionStrategy strategy
Definition kinsol.h:353
unsigned int maximum_beta_failures
Definition kinsol.h:417
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, const OrthogonalizationStrategy anderson_qr_orthogonalization=modified_gram_schmidt)
Definition kinsol.cc:60
OrthogonalizationStrategy anderson_qr_orthogonalization
Definition kinsol.h:431
void add_parameters(ParameterHandler &prm)
Definition kinsol.cc:89
unsigned int maximum_non_linear_iterations
Definition kinsol.h:358
unsigned int anderson_subspace_size
Definition kinsol.h:425
std::function< VectorType &()> get_solution_scaling
Definition kinsol.h:651
std::function< void(const VectorType &current_u, const VectorType &current_f)> setup_jacobian
Definition kinsol.h:561
void set_functions_to_trigger_an_assert()
Definition kinsol.cc:579
MPI_Comm mpi_communicator
Definition kinsol.h:742
unsigned int solve(VectorType &initial_guess_and_solution)
Definition kinsol.cc:223
SUNContext kinsol_ctx
Definition kinsol.h:753
std::function< void(const VectorType &src, VectorType &dst)> residual
Definition kinsol.h:496
std::function< void(const VectorType &src, VectorType &dst)> iteration_function
Definition kinsol.h:512
GrowingVectorMemory< VectorType > mem
Definition kinsol.h:760
std::exception_ptr pending_exception
Definition kinsol.h:767
std::function< void(const VectorType &rhs, VectorType &dst, const double tolerance)> solve_with_jacobian
Definition kinsol.h:604
std::function< VectorType &()> get_function_scaling
Definition kinsol.h:674
std::function< void(VectorType &)> reinit_vector
Definition kinsol.h:481
std::function< void(void *kinsol_mem)> custom_setup
Definition kinsol.h:705
AdditionalData data
Definition kinsol.h:737
KINSOL(const AdditionalData &data=AdditionalData())
Definition kinsol.cc:163
void * kinsol_mem
Definition kinsol.h:747
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:503
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504
static ::ExceptionBase & ExcKINSOLError(int arg1)
static ::ExceptionBase & ExcFunctionNotProvided(std::string arg1)
#define DeclException1(Exception1, type1, outsequence)
Definition exceptions.h:516