22#ifdef DEAL_II_WITH_SUNDIALS
30# ifdef DEAL_II_WITH_TRILINOS
34# ifdef DEAL_II_WITH_PETSC
43# include <sundials/sundials_config.h>
45# include <kinsol/kinsol_direct.h>
46# include <sunlinsol/sunlinsol_dense.h>
47# include <sunmatrix/sunmatrix_dense.h>
56 template <
typename VectorType>
59 const unsigned int maximum_non_linear_iterations,
60 const double function_tolerance,
61 const double step_tolerance,
62 const bool no_init_setup,
63 const unsigned int maximum_setup_calls,
64 const double maximum_newton_step,
65 const double dq_relative_error,
66 const unsigned int maximum_beta_failures,
67 const unsigned int anderson_subspace_size)
69 , maximum_non_linear_iterations(maximum_non_linear_iterations)
70 , function_tolerance(function_tolerance)
71 , step_tolerance(step_tolerance)
72 , no_init_setup(no_init_setup)
73 , maximum_setup_calls(maximum_setup_calls)
74 , maximum_newton_step(maximum_newton_step)
75 , dq_relative_error(dq_relative_error)
76 , maximum_beta_failures(maximum_beta_failures)
77 , anderson_subspace_size(anderson_subspace_size)
82 template <
typename VectorType>
89 "Choose among newton|linesearch|fixed_point|picard",
91 "newton|linesearch|fixed_point|picard"));
92 prm.
add_action(
"Solution strategy", [&](
const std::string &value) {
93 if (value ==
"newton")
95 else if (value ==
"linesearch")
96 strategy = linesearch;
97 else if (value ==
"fixed_point")
98 strategy = fixed_point;
99 else if (value ==
"picard")
105 maximum_non_linear_iterations);
106 prm.
add_parameter(
"Function norm stopping tolerance", function_tolerance);
107 prm.
add_parameter(
"Scaled step stopping tolerance", step_tolerance);
112 maximum_setup_calls);
113 prm.
add_parameter(
"Maximum allowable scaled length of the Newton step",
114 maximum_newton_step);
115 prm.
add_parameter(
"Relative error for different quotient computation",
120 prm.
add_parameter(
"Maximum number of beta-condition failures",
121 maximum_beta_failures);
127 anderson_subspace_size);
133 template <
typename VectorType>
140 template <
typename VectorType>
153# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
170 template <
typename VectorType>
174# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
185 template <
typename VectorType>
190 if (data.strategy == AdditionalData::fixed_point)
192 Assert(iteration_function,
198 Assert(solve_jacobian_system || solve_with_jacobian,
200 "solve_jacobian_system || solve_with_jacobian"));
208# if DEAL_II_SUNDIALS_VERSION_GTE(6, 0, 0)
213# if DEAL_II_SUNDIALS_VERSION_LT(6, 0, 0)
232# if DEAL_II_SUNDIALS_VERSION_LT(6, 0, 0)
233 [](
auto &v) {
return internal::make_nvector_view(v); };
235 [
this](
auto &v) {
return internal::make_nvector_view(v, kinsol_ctx); };
241 if (!get_function_scaling || !get_solution_scaling)
248 get_solution_scaling ? get_solution_scaling() :
ones);
250 get_function_scaling ? get_function_scaling() :
ones);
259 status =
KINSetMAA(kinsol_mem, data.anderson_subspace_size);
262 if (data.strategy == AdditionalData::fixed_point)
270 auto src_yy = internal::unwrap_nvector_const<VectorType>(
yy);
271 auto dst_FF = internal::unwrap_nvector<VectorType>(
FF);
276 solver.iteration_function,
277 solver.pending_exception,
292 auto src_yy = internal::unwrap_nvector_const<VectorType>(
yy);
293 auto dst_FF = internal::unwrap_nvector<VectorType>(
FF);
298 solver.residual, solver.pending_exception, *
src_yy, *
dst_FF);
329 if (solve_jacobian_system ||
338# if DEAL_II_SUNDIALS_VERSION_LT(6, 0, 0)
353 LS->content =
nullptr;
378 if (solver.solve_with_jacobian)
380 auto src_b = internal::unwrap_nvector_const<VectorType>(b);
381 auto dst_x = internal::unwrap_nvector<VectorType>(
x);
384 solver.solve_with_jacobian,
385 solver.pending_exception,
404 auto src_b = internal::unwrap_nvector_const<VectorType>(b);
405 auto dst_x = internal::unwrap_nvector<VectorType>(
x);
413 solver.solve_jacobian_system,
414 solver.pending_exception,
429# if DEAL_II_SUNDIALS_VERSION_LT(6, 0, 0)
443 A->content =
nullptr;
462 setup_jacobian = [](
const VectorType &,
const VectorType &) {
479 auto ycur = internal::unwrap_nvector_const<VectorType>(
u);
480 auto fcur = internal::unwrap_nvector<VectorType>(f);
484 solver.setup_jacobian, solver.pending_exception, *
ycur, *
fcur);
514 if (pending_exception)
518 std::rethrow_exception(pending_exception);
522 pending_exception =
nullptr;
530 pending_exception =
nullptr;
540 return static_cast<unsigned int>(
nniters);
545 template <
typename VectorType>
549 reinit_vector = [](VectorType &) {
560# ifdef DEAL_II_WITH_MPI
562# ifdef DEAL_II_WITH_TRILINOS
567# ifdef DEAL_II_WITH_PETSC
568# ifndef PETSC_USE_COMPLEX
void add_parameter(const std::string &entry, ParameterType ¶meter, 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, const bool execute_action=true)
void enter_subsection(const std::string &subsection)
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)
void add_parameters(ParameterHandler &prm)
void set_functions_to_trigger_an_assert()
MPI_Comm mpi_communicator
unsigned int solve(VectorType &initial_guess_and_solution)
KINSOL(const AdditionalData &data=AdditionalData())
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_SUNDIALS_VERSION_GTE(major, minor, patch)
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcFunctionNotProvided(std::string arg1)
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & RecoverableUserCallbackError()
#define AssertThrow(cond, exc)
#define AssertKINSOL(code)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
int call_and_possibly_capture_exception(const F &f, std::exception_ptr &eptr, Args &&...args)