deal2lkit: A ToolKit library for Deal.II
kinsol_interface.h
Go to the documentation of this file.
1 //-----------------------------------------------------------
2 //
3 // Copyright (C) 2016 by the deal2lkit authors
4 //
5 // This file is part of the deal2lkit library.
6 //
7 // The deal2lkit 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 at
12 // the top level of the deal2lkit distribution.
13 //
14 //-----------------------------------------------------------
15 
16 #ifndef _d2k_kinsol_interface_h
17 #define _d2k_kinsol_interface_h
18 
19 #include <deal2lkit/config.h>
20 
21 
22 #ifdef D2K_WITH_SUNDIALS
23 
24 #include <nvector/nvector_serial.h>
25 #include <sundials/sundials_math.h>
26 #include <sundials/sundials_types.h>
27 
28 #include <deal.II/base/config.h>
31 
33 #include <deal2lkit/utilities.h>
34 
35 #ifdef DEAL_II_WITH_MPI
36 #include "mpi.h"
37 #endif
38 
39 #include <kinsol/kinsol_impl.h>
40 
41 using namespace dealii;
42 
43 D2K_NAMESPACE_OPEN
44 
59 template<typename VEC=Vector<double> >
61 {
62 public:
63 
64 #ifdef DEAL_II_WITH_MPI
65 
71  KINSOLInterface(const std::string name="",
72  const MPI_Comm mpi_comm = MPI_COMM_WORLD);
73 
77  MPI_Comm get_comm() const ;
78 
79 #else
80 
85  KINSOLInterface(const std::string name="");
86 
87 #endif
88 
92  ~KINSOLInterface();
93 
97  virtual void declare_parameters( ParameterHandler &prm );
98 
104  void initialize_solver( VEC &initial_guess );
105 
111  void set_scaling_vectors( const VEC &uscale, const VEC &fscale );
112 
123  void set_constraint_vector( const VEC &constraint );
124 
128  int solve( VEC &solution );
129 
134  std::function<shared_ptr<VEC>()> create_new_vector;
135 
137  std::function<int(const VEC &y, VEC &res)> residual;
138 
140  std::function<int(const VEC &y)> setup_jacobian;
141 
143  std::function<int(const VEC &res, VEC &dst)> solve_linear_system;
144 
146  std::function<int(const VEC &v, VEC &dst )> jacobian_vmult;
147 
148 private:
149 
153  void set_functions_to_trigger_an_assert();
154 
161  std::string strategy;
162 
164  unsigned int max_iterations;
165 
170  double ftol;
171 
175  double steptol;
176 
180  double mbset;
181 
185  unsigned int system_size;
186 
191 
197 
201  unsigned int verbosity;
202 
209 
215  N_Vector solution;
216 
220  N_Vector u_scale;
221 
225  N_Vector f_scale;
226 
227 #ifdef DEAL_II_WITH_MPI
228 
231  unsigned int local_system_size;
232 
236  MPI_Comm communicator;
237 #endif
238 
243 
247  void *kin_mem;
248 
249 
250 };
251 
252 D2K_NAMESPACE_CLOSE
253 
254 #endif
255 
256 #endif
N_Vector solution
KINSOL solution vector.
unsigned int system_size
dimension of the system
A parameter acceptor base class.
bool use_internal_solver
if true the internal direct solver of KINSOL is used.
double steptol
The Newton method will terminate when the scaled norm of the update is smaller than steptol...
std::function< int(const VEC &v, VEC &dst)> jacobian_vmult
standard function multiplying the Jacobian to a vector
std::function< int(const VEC &y, VEC &res)> residual
standard function computing residuals
void * kin_mem
Kinsol memory object.
unsigned int max_iterations
Maximum number of iterations.
double ftol
Input scalar tolerance for residuals.
Interface to SUNDIALS KINSOL library.
unsigned int verbosity
Level of verbosity of kinsol solver 0,1,2,3.
ConditionalOStream pcout
Output stream.
std::string strategy
Strategy used by the solver: newton = basic Newton iteration global_newton = Newton with line search ...
std::function< int(const VEC &y)> setup_jacobian
standard function computing the Jacobian
N_Vector f_scale
Internal scaling vector for the Jacobian.
std::function< int(const VEC &res, VEC &dst)> solve_linear_system
standard function solving linear system
bool scaling_is_set
scaling flag: if the scaling have been provided by the user calling the function set_scaling_vectors(...
bool is_initialized
Initialization flag.
N_Vector u_scale
Internal scaling vector for the solution.
double mbset
Maximum number of nonlinear iteration that can be done without a Jacobian update. ...