deal2lkit: A ToolKit library for Deal.II
KINSOLInterface< VEC > Class Template Reference

Interface to SUNDIALS KINSOL library. More...

#include <kinsol_interface.h>

Inheritance diagram for KINSOLInterface< VEC >:
ParameterAcceptor Subscriptor

Public Member Functions

 KINSOLInterface (const std::string name="")
 Constructor for the KINSOLInterface class. More...
 
 ~KINSOLInterface ()
 House cleaning. More...
 
virtual void declare_parameters (ParameterHandler &prm)
 Declare parameters for this class to function properly. More...
 
void initialize_solver (VEC &initial_guess)
 Initializes the solver with the initial guess and the residual function. More...
 
void set_scaling_vectors (const VEC &uscale, const VEC &fscale)
 Set the scaling for the solver. More...
 
void set_constraint_vector (const VEC &constraint)
 Set the constraint. More...
 
int solve (VEC &solution)
 solve the non-linear system More...
 
- Public Member Functions inherited from ParameterAcceptor
 ParameterAcceptor (const std::string section_name="")
 The constructor adds derived classes to the list of acceptors. More...
 
virtual ~ParameterAcceptor ()
 The destructor sets to zero the pointer relative to this index, so that it is safe to destroy the mother class. More...
 
virtual void parse_parameters (ParameterHandler &prm)
 Parse the parameter file. More...
 
virtual void parse_parameters_call_back ()
 Parse parameter call back. More...
 
std::string get_section_name () const
 Return the section name of this class. More...
 
std::vector< std::string > get_section_path () const
 Travers all registered classes, and figure out what subsections we need to enter. More...
 
template<class T >
void add_parameter (ParameterHandler &prm, T *parameter, const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation=std::string())
 Add a parameter the given parameter list. More...
 
template<class T >
void add_parameter (T &parameter, const std::string &entry, const std::string &documentation=std::string(), ParameterHandler &prm=ParameterAcceptor::prm)
 Add a parameter to the global parameter handler ParameterAcceptor::prm. More...
 
void enter_my_subsection (ParameterHandler &prm)
 Make sure we enter the right subsection of the global parameter file. More...
 
void leave_my_subsection (ParameterHandler &prm)
 This function undoes what the enter_my_subsection() function did. More...
 
template<>
std_cxx11::shared_ptr< Patterns::PatternBaseto_pattern (const double &)
 double More...
 
template<>
std::string to_string (const double &entry)
 
template<>
double to_type (const std::string &parameter)
 
template<>
std_cxx11::shared_ptr< Patterns::PatternBaseto_pattern (const int &)
 int More...
 
template<>
std::string to_string (const int &entry)
 
template<>
int to_type (const std::string &parameter)
 
template<>
std_cxx11::shared_ptr< Patterns::PatternBaseto_pattern (const unsigned int &)
 unsigned int More...
 
template<>
std::string to_string (const unsigned int &entry)
 
template<>
unsigned int to_type (const std::string &parameter)
 
template<>
std_cxx11::shared_ptr< Patterns::PatternBaseto_pattern (const bool &)
 bool More...
 
template<>
std::string to_string (const bool &entry)
 
template<>
bool to_type (const std::string &parameter)
 
- Public Member Functions inherited from Subscriptor
 Subscriptor ()
 
 Subscriptor (const Subscriptor &)
 
 Subscriptor (Subscriptor &&)
 
virtual ~Subscriptor ()
 
Subscriptoroperator= (const Subscriptor &)
 
Subscriptoroperator= (Subscriptor &&)
 
void subscribe (const char *identifier=0) const
 
void unsubscribe (const char *identifier=0) const
 
unsigned int n_subscriptions () const
 
void list_subscribers () const
 
void serialize (Archive &ar, const unsigned int version)
 

Public Attributes

std::function< shared_ptr< VEC >)> create_new_vector
 this function has to be implemented by the user and it must return a shared pointer to a VEC vector. More...
 
std::function< int(const VEC &y, VEC &res)> residual
 standard function computing residuals More...
 
std::function< int(const VEC &y)> setup_jacobian
 standard function computing the Jacobian More...
 
std::function< int(const VEC &res, VEC &dst)> solve_linear_system
 standard function solving linear system More...
 
std::function< int(const VEC &v, VEC &dst)> jacobian_vmult
 standard function multiplying the Jacobian to a vector More...
 

Private Member Functions

void set_functions_to_trigger_an_assert ()
 This function is executed at construction time to set the std::function above to trigger an assert if they are not implemented. More...
 

Private Attributes

std::string strategy
 Strategy used by the solver: newton = basic Newton iteration global_newton = Newton with line search fixed_point = fixed-point iteration with Anderson Acceleration picard = Picard iteration with Anderson Acceleration. More...
 
unsigned int max_iterations
 Maximum number of iterations. More...
 
double ftol
 Input scalar tolerance for residuals. More...
 
double steptol
 The Newton method will terminate when the scaled norm of the update is smaller than steptol. More...
 
double mbset
 Maximum number of nonlinear iteration that can be done without a Jacobian update. More...
 
unsigned int system_size
 dimension of the system More...
 
bool is_initialized
 Initialization flag. More...
 
bool scaling_is_set
 scaling flag: if the scaling have been provided by the user calling the function set_scaling_vectors(); More...
 
unsigned int verbosity
 Level of verbosity of kinsol solver 0,1,2,3. More...
 
bool use_internal_solver
 if true the internal direct solver of KINSOL is used. More...
 
N_Vector solution
 KINSOL solution vector. More...
 
N_Vector u_scale
 Internal scaling vector for the solution. More...
 
N_Vector f_scale
 Internal scaling vector for the Jacobian. More...
 
ConditionalOStream pcout
 Output stream. More...
 
void * kin_mem
 Kinsol memory object. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from ParameterAcceptor
static void initialize (const std::string filename="", const std::string outfilename="")
 Call declare_all_parameters(), read filename (if it is present as input parameter) and parse_all_parameters() on the static member prm. More...
 
static void clear ()
 Clear class list and global parameter file. More...
 
static void parse_all_parameters (ParameterHandler &prm=ParameterAcceptor::prm)
 Parse the given ParameterHandler. More...
 
static void log_info ()
 Print information about all stored classes. More...
 
static void declare_all_parameters (ParameterHandler &prm=ParameterAcceptor::prm)
 Initialize the ParameterHandler with all derived classes parameters.This function enters the subsection returned by get_section_name() for each derived class, and declares all parameters that were added using add_parameter(). More...
 
template<class T >
static std_cxx11::shared_ptr< Patterns::PatternBaseto_pattern (const T &)
 Given a class T, construct its default pattern to be used when declaring parameters. More...
 
template<class T >
static T to_type (const std::string &)
 Given a string, fill the value of the given parameter. More...
 
template<class T >
static std::string to_string (const T &)
 Given a parameter, return a string containing the given parameter. More...
 
- Static Public Member Functions inherited from Subscriptor
static::ExceptionBase & ExcInUse (int arg1, char *arg2, std::string &arg3)
 
static::ExceptionBase & ExcNoSubscriber (char *arg1, char *arg2)
 
- Static Public Attributes inherited from ParameterAcceptor
static ParameterHandler prm
 Static parameter. More...
 
- Protected Attributes inherited from ParameterAcceptor
const std::string section_name
 The subsection name for this class. More...
 

Detailed Description

template<typename VEC = Vector<double>>
class KINSOLInterface< VEC >

Interface to SUNDIALS KINSOL library.

deal2lkit features an interface for the SUite of Nonlinear and DIfferential/ALgebraic equation Solvers (SUNDIALS).

The class KINSOLInterface is a wrapper to the KINSOL solver in SUNDIALS. This is a general-purpose nonlinear system solver based on Newton-Krylov solver technology. Developed with KINSOL v.2.8.0.

Citing from the SUNDIALS documentation:

blah blah blah

Definition at line 60 of file kinsol_interface.h.

Constructor & Destructor Documentation

§ KINSOLInterface()

template<typename VEC >
KINSOLInterface< VEC >::KINSOLInterface ( const std::string  name = "")

Constructor for the KINSOLInterface class.

It takes the string containing the name of the section for ParameterHandler

Definition at line 174 of file kinsol_interface.cc.

§ ~KINSOLInterface()

template<typename VEC >
KINSOLInterface< VEC >::~KINSOLInterface ( )

House cleaning.

Definition at line 187 of file kinsol_interface.cc.

Member Function Documentation

§ declare_parameters()

template<typename VEC >
void KINSOLInterface< VEC >::declare_parameters ( ParameterHandler prm)
virtual

Declare parameters for this class to function properly.

Reimplemented from ParameterAcceptor.

Definition at line 195 of file kinsol_interface.cc.

§ initialize_solver()

template<typename VEC >
void KINSOLInterface< VEC >::initialize_solver ( VEC &  initial_guess)

Initializes the solver with the initial guess and the residual function.

The system size is set inside this function. So, when a mesh refinement is done, you need to call this function in order to make kinsol aware of the changes.

Definition at line 241 of file kinsol_interface.cc.

§ set_constraint_vector()

template<typename VEC >
void KINSOLInterface< VEC >::set_constraint_vector ( const VEC &  constraint)

Set the constraint.

Citing from the SUNDIALS documentation: if constraint[i] is 0.0 then no constraint is imposed on u_i. 1.0 then u_i will be constrained to be u_i >= 0.0. −1.0 then u_i will be constrained to be u_i <= 0.0. 2.0 then u_i will be constrained to be u_i > 0.0. −2.0 then u_i will be constrained to be u_i < 0.0.

Definition at line 411 of file kinsol_interface.cc.

§ set_functions_to_trigger_an_assert()

template<typename VEC >
void KINSOLInterface< VEC >::set_functions_to_trigger_an_assert ( )
private

This function is executed at construction time to set the std::function above to trigger an assert if they are not implemented.

Definition at line 114 of file kinsol_interface.cc.

§ set_scaling_vectors()

template<typename VEC >
void KINSOLInterface< VEC >::set_scaling_vectors ( const VEC &  uscale,
const VEC &  fscale 
)

Set the scaling for the solver.

uscale is the scaling vector for the solution and fscale is the scaling for the Jacobian. If this function is not called by the user, a scaling factor equal to 1 is assumed.

Definition at line 385 of file kinsol_interface.cc.

§ solve()

template<typename VEC >
int KINSOLInterface< VEC >::solve ( VEC &  solution)

solve the non-linear system

Definition at line 315 of file kinsol_interface.cc.

Member Data Documentation

§ create_new_vector

template<typename VEC = Vector<double>>
std::function<shared_ptr<VEC>)> KINSOLInterface< VEC >::create_new_vector

this function has to be implemented by the user and it must return a shared pointer to a VEC vector.

Definition at line 134 of file kinsol_interface.h.

§ f_scale

template<typename VEC = Vector<double>>
N_Vector KINSOLInterface< VEC >::f_scale
private

Internal scaling vector for the Jacobian.

Definition at line 225 of file kinsol_interface.h.

§ ftol

template<typename VEC = Vector<double>>
double KINSOLInterface< VEC >::ftol
private

Input scalar tolerance for residuals.

This define the condition (small residual) for a successful completion of KINSOL

Definition at line 170 of file kinsol_interface.h.

§ is_initialized

template<typename VEC = Vector<double>>
bool KINSOLInterface< VEC >::is_initialized
private

Initialization flag.

Definition at line 190 of file kinsol_interface.h.

§ jacobian_vmult

template<typename VEC = Vector<double>>
std::function<int(const VEC &v, VEC &dst )> KINSOLInterface< VEC >::jacobian_vmult

standard function multiplying the Jacobian to a vector

Definition at line 146 of file kinsol_interface.h.

§ kin_mem

template<typename VEC = Vector<double>>
void* KINSOLInterface< VEC >::kin_mem
private

Kinsol memory object.

Definition at line 247 of file kinsol_interface.h.

§ max_iterations

template<typename VEC = Vector<double>>
unsigned int KINSOLInterface< VEC >::max_iterations
private

Maximum number of iterations.

Definition at line 164 of file kinsol_interface.h.

§ mbset

template<typename VEC = Vector<double>>
double KINSOLInterface< VEC >::mbset
private

Maximum number of nonlinear iteration that can be done without a Jacobian update.

Definition at line 180 of file kinsol_interface.h.

§ pcout

template<typename VEC = Vector<double>>
ConditionalOStream KINSOLInterface< VEC >::pcout
private

Output stream.

Definition at line 242 of file kinsol_interface.h.

§ residual

template<typename VEC = Vector<double>>
std::function<int(const VEC &y, VEC &res)> KINSOLInterface< VEC >::residual

standard function computing residuals

Definition at line 137 of file kinsol_interface.h.

§ scaling_is_set

template<typename VEC = Vector<double>>
bool KINSOLInterface< VEC >::scaling_is_set
private

scaling flag: if the scaling have been provided by the user calling the function set_scaling_vectors();

Definition at line 196 of file kinsol_interface.h.

§ setup_jacobian

template<typename VEC = Vector<double>>
std::function<int(const VEC &y)> KINSOLInterface< VEC >::setup_jacobian

standard function computing the Jacobian

Definition at line 140 of file kinsol_interface.h.

§ solution

template<typename VEC = Vector<double>>
N_Vector KINSOLInterface< VEC >::solution
private

KINSOL solution vector.

After initialize_solver is called this contains the initial guess. After solve is called this contains the solution to the equations.

Definition at line 215 of file kinsol_interface.h.

§ solve_linear_system

template<typename VEC = Vector<double>>
std::function<int(const VEC &res, VEC &dst)> KINSOLInterface< VEC >::solve_linear_system

standard function solving linear system

Definition at line 143 of file kinsol_interface.h.

§ steptol

template<typename VEC = Vector<double>>
double KINSOLInterface< VEC >::steptol
private

The Newton method will terminate when the scaled norm of the update is smaller than steptol.

Definition at line 175 of file kinsol_interface.h.

§ strategy

template<typename VEC = Vector<double>>
std::string KINSOLInterface< VEC >::strategy
private

Strategy used by the solver: newton = basic Newton iteration global_newton = Newton with line search fixed_point = fixed-point iteration with Anderson Acceleration picard = Picard iteration with Anderson Acceleration.

Definition at line 161 of file kinsol_interface.h.

§ system_size

template<typename VEC = Vector<double>>
unsigned int KINSOLInterface< VEC >::system_size
private

dimension of the system

Definition at line 185 of file kinsol_interface.h.

§ u_scale

template<typename VEC = Vector<double>>
N_Vector KINSOLInterface< VEC >::u_scale
private

Internal scaling vector for the solution.

Definition at line 220 of file kinsol_interface.h.

§ use_internal_solver

template<typename VEC = Vector<double>>
bool KINSOLInterface< VEC >::use_internal_solver
private

if true the internal direct solver of KINSOL is used.

note that the direct solver of KINSOL work only in serial. if false the solver provided by the user is used.

Definition at line 208 of file kinsol_interface.h.

§ verbosity

template<typename VEC = Vector<double>>
unsigned int KINSOLInterface< VEC >::verbosity
private

Level of verbosity of kinsol solver 0,1,2,3.

Definition at line 201 of file kinsol_interface.h.


The documentation for this class was generated from the following files: