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

IMEXStepper solves non-linear time dependent problems with user-defined size of the time step and using Newthon's method for the solution of the non-linear problem. More...

#include <imex_stepper.h>

Inheritance diagram for IMEXStepper< VEC >:
ParameterAcceptor Subscriptor

Public Member Functions

 IMEXStepper (std::string &name="")
 Constructor for the IMEXStepper class. More...
 
virtual void declare_parameters (ParameterHandler &prm)
 Declare parameters for this class to function properly. More...
 
unsigned int solve_dae (VEC &solution, VEC &solution_dot)
 Evolve. More...
 
void compute_consistent_initial_conditions (const double &t, VEC &y, VEC &y_dot)
 compute_consistent_initial_conditions More...
 
double get_alpha () const
 if initial time is different from final time (i.e., we are solving a time-dep problem and not a stationay one, return the inverse of dt. More...
 
void set_initial_time (const double &t)
 Set initial time equal to t disregarding what is written in the parameter file. 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
 Return a shared_ptr<VEC>. More...
 
std::function< int(const double t, const VEC &y, const VEC &y_dot, VEC &res)> residual
 Compute residual. More...
 
std::function< int(const double t, const VEC &y, const VEC &y_dot, const double alpha)> setup_jacobian
 Compute Jacobian. More...
 
std::function< int(const VEC &rhs, VEC &dst)> solve_jacobian_system
 Solve linear system. More...
 
std::function< void(const double t, const VEC &sol, const VEC &sol_dot, const unsigned int step_number)> output_step
 Store solutions to file. More...
 
std::function< bool(const double t, VEC &sol, VEC &sol_dot)> solver_should_restart
 Evaluate wether the mesh should be refined or not. More...
 
std::function< VEC &()> get_lumped_mass_matrix
 Return the lumped mass matrix vector. More...
 
std::function< int(const VEC &src, VEC &dst)> jacobian_vmult
 Compute the matrix-vector product Jacobian times src, and the result is put in dst. More...
 
std::function< double(const VEC &vector)> vector_norm
 Return the norm of vector. More...
 

Private Member Functions

void compute_y_dot (const VEC &y, const VEC &prev, const double alpha, VEC &y_dot)
 
double evaluate_step_size (const double &t)
 evaluate step size at time t according to the expression stored in _step_size More...
 
double line_search_with_backtracking (const VEC &update, const VEC &prev_sol, const double &alpha, const double &t, VEC &sol, VEC &sol_dot, VEC &residual)
 line search algorithm with backtracking.The following sequence of Newton relaxation parameters is tested: 1, 1/2, 1/4,...,2^-i. More...
 
void do_newton (const double t, const double alpha, const bool update_Jacobian, const VEC &previous_solution, VEC &solution, VEC &solution_dot)
 find solution applying the newton method with given More...
 
void compute_previous_solution (const VEC &sol, const VEC &sol_dot, const double &alpha, VEC &prev)
 compute previous solution from given More...
 
void set_functions_to_trigger_an_assert ()
 Set the std::functions above to trigger an assert if they are not implemented. More...
 

Private Attributes

KINSOLInterface< VEC > kinsol
 kinsol solver More...
 
double step_size
 Step size. More...
 
std::string _step_size
 user defined step_size More...
 
double initial_time
 Initial time for the ode. More...
 
double final_time
 Final time. More...
 
double abs_tol
 Absolute error tolerance for non linear iterations. More...
 
double rel_tol
 Relative error tolerance for non linear iterations. More...
 
unsigned int output_period
 Seconds between each output. More...
 
double newton_alpha
 Alpha to use in Newton method for the update of the solution. More...
 
unsigned int max_outer_non_linear_iterations
 Maximum number of outer iterations for Newton method. More...
 
unsigned int max_inner_non_linear_iterations
 Maximum number of inner iterations for Newton method. More...
 
bool update_jacobian_continuously
 Jacobian is updated at each outer iteration and time step. More...
 
bool use_kinsol
 use kinsol solver true or false More...
 
ConditionalOStream pcout
 Output stream. More...
 
bool verbose
 print useful informations More...
 
unsigned int n_max_backtracking
 i max More...
 
std::string method
 method used for alpha selection 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 IMEXStepper< VEC >

IMEXStepper solves non-linear time dependent problems with user-defined size of the time step and using Newthon's method for the solution of the non-linear problem.

It allows to use the Kinsol solver of SUNDIALS.

The user has to provide the following std::functions:

  • create_new_vector;
  • residual;
  • setup_jacobian;
  • solve_jacobian_system;
  • output_step;
  • solver_should_restart;
  • get_lumped_mass_matrix (only for kinsol);
  • jacobian_vmult (only for kinsol);
  • vector_norm (if kinsol is not used).

Definition at line 55 of file imex_stepper.h.

Constructor & Destructor Documentation

§ IMEXStepper()

template<typename VEC >
IMEXStepper< VEC >::IMEXStepper ( std::string &  name = "")

Constructor for the IMEXStepper class.

Takes a name for the section in parameter file.

Definition at line 63 of file imex_stepper.cc.

Member Function Documentation

§ compute_consistent_initial_conditions()

template<typename VEC >
void IMEXStepper< VEC >::compute_consistent_initial_conditions ( const double &  t,
VEC &  y,
VEC &  y_dot 
)

compute_consistent_initial_conditions

Parameters
t

Definition at line 576 of file imex_stepper.cc.

§ compute_previous_solution()

template<typename VEC >
void IMEXStepper< VEC >::compute_previous_solution ( const VEC &  sol,
const VEC &  sol_dot,
const double &  alpha,
VEC &  prev 
)
private

compute previous solution from given

Parameters
sol
sol_dot
alpha

Definition at line 539 of file imex_stepper.cc.

§ compute_y_dot()

template<typename VEC >
void IMEXStepper< VEC >::compute_y_dot ( const VEC &  y,
const VEC &  prev,
const double  alpha,
VEC &  y_dot 
)
private

Definition at line 160 of file imex_stepper.cc.

§ declare_parameters()

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

Declare parameters for this class to function properly.

Reimplemented from ParameterAcceptor.

Definition at line 91 of file imex_stepper.cc.

§ do_newton()

template<typename VEC >
void IMEXStepper< VEC >::do_newton ( const double  t,
const double  alpha,
const bool  update_Jacobian,
const VEC &  previous_solution,
VEC &  solution,
VEC &  solution_dot 
)
private

find solution applying the newton method with given

Parameters
t
alpha
update_Jacobian
previous_solution
solution_dotat the end of the computation, the solution_dot is updated as well.

this function is called when KINSOL is NOT used

Definition at line 388 of file imex_stepper.cc.

§ evaluate_step_size()

template<typename VEC >
double IMEXStepper< VEC >::evaluate_step_size ( const double &  t)
private

evaluate step size at time t according to the expression stored in _step_size

Definition at line 559 of file imex_stepper.cc.

§ get_alpha()

template<typename VEC >
double IMEXStepper< VEC >::get_alpha ( ) const

if initial time is different from final time (i.e., we are solving a time-dep problem and not a stationay one, return the inverse of dt.

If the problem is stationary, returns 0.

Returns

Definition at line 73 of file imex_stepper.cc.

§ line_search_with_backtracking()

template<typename VEC >
double IMEXStepper< VEC >::line_search_with_backtracking ( const VEC &  update,
const VEC &  prev_sol,
const double &  alpha,
const double &  t,
VEC &  sol,
VEC &  sol_dot,
VEC &  residual 
)
private

line search algorithm with backtracking.The following sequence of Newton relaxation parameters is tested: 1, 1/2, 1/4,...,2^-i.

it returns the selected alpha and solution, solution_dot and residual are accordingly updated.

Definition at line 315 of file imex_stepper.cc.

§ set_functions_to_trigger_an_assert()

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

Set the std::functions above to trigger an assert if they are not implemented.

Definition at line 610 of file imex_stepper.cc.

§ set_initial_time()

template<typename VEC >
void IMEXStepper< VEC >::set_initial_time ( const double &  t)

Set initial time equal to t disregarding what is written in the parameter file.

Definition at line 85 of file imex_stepper.cc.

§ solve_dae()

template<typename VEC >
unsigned int IMEXStepper< VEC >::solve_dae ( VEC &  solution,
VEC &  solution_dot 
)

Evolve.

This function returns the final number of steps.

Definition at line 168 of file imex_stepper.cc.

Member Data Documentation

§ _step_size

template<typename VEC = Vector<double>>
std::string IMEXStepper< VEC >::_step_size
private

user defined step_size

Definition at line 121 of file imex_stepper.h.

§ abs_tol

template<typename VEC = Vector<double>>
double IMEXStepper< VEC >::abs_tol
private

Absolute error tolerance for non linear iterations.

Definition at line 136 of file imex_stepper.h.

§ create_new_vector

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

Return a shared_ptr<VEC>.

A shared_ptr is needed in order to keep the pointed vector alive, without the need to use a static variable.

Definition at line 225 of file imex_stepper.h.

§ final_time

template<typename VEC = Vector<double>>
double IMEXStepper< VEC >::final_time
private

Final time.

Definition at line 133 of file imex_stepper.h.

§ get_lumped_mass_matrix

template<typename VEC = Vector<double>>
std::function<VEC&()> IMEXStepper< VEC >::get_lumped_mass_matrix

Return the lumped mass matrix vector.

It is used by kinsol as scaling factor for the computations of vector's norms.

Definition at line 270 of file imex_stepper.h.

§ initial_time

template<typename VEC = Vector<double>>
double IMEXStepper< VEC >::initial_time
private

Initial time for the ode.

Definition at line 130 of file imex_stepper.h.

§ jacobian_vmult

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

Compute the matrix-vector product Jacobian times src, and the result is put in dst.

Definition at line 277 of file imex_stepper.h.

§ kinsol

template<typename VEC = Vector<double>>
KINSOLInterface<VEC> IMEXStepper< VEC >::kinsol
private

kinsol solver

Definition at line 111 of file imex_stepper.h.

§ max_inner_non_linear_iterations

template<typename VEC = Vector<double>>
unsigned int IMEXStepper< VEC >::max_inner_non_linear_iterations
private

Maximum number of inner iterations for Newton method.

Definition at line 151 of file imex_stepper.h.

§ max_outer_non_linear_iterations

template<typename VEC = Vector<double>>
unsigned int IMEXStepper< VEC >::max_outer_non_linear_iterations
private

Maximum number of outer iterations for Newton method.

Definition at line 148 of file imex_stepper.h.

§ method

template<typename VEC = Vector<double>>
std::string IMEXStepper< VEC >::method
private

method used for alpha selection

Definition at line 171 of file imex_stepper.h.

§ n_max_backtracking

template<typename VEC = Vector<double>>
unsigned int IMEXStepper< VEC >::n_max_backtracking
private

i max

Definition at line 168 of file imex_stepper.h.

§ newton_alpha

template<typename VEC = Vector<double>>
double IMEXStepper< VEC >::newton_alpha
private

Alpha to use in Newton method for the update of the solution.

Definition at line 145 of file imex_stepper.h.

§ output_period

template<typename VEC = Vector<double>>
unsigned int IMEXStepper< VEC >::output_period
private

Seconds between each output.

Definition at line 142 of file imex_stepper.h.

§ output_step

template<typename VEC = Vector<double>>
std::function<void (const double t, const VEC &sol, const VEC &sol_dot, const unsigned int step_number)> IMEXStepper< VEC >::output_step

Store solutions to file.

Definition at line 254 of file imex_stepper.h.

§ pcout

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

Output stream.

Definition at line 162 of file imex_stepper.h.

§ rel_tol

template<typename VEC = Vector<double>>
double IMEXStepper< VEC >::rel_tol
private

Relative error tolerance for non linear iterations.

Definition at line 139 of file imex_stepper.h.

§ residual

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

Compute residual.

Definition at line 233 of file imex_stepper.h.

§ setup_jacobian

template<typename VEC = Vector<double>>
std::function<int(const double t, const VEC &y, const VEC &y_dot, const double alpha)> IMEXStepper< VEC >::setup_jacobian

Compute Jacobian.

Definition at line 241 of file imex_stepper.h.

§ solve_jacobian_system

template<typename VEC = Vector<double>>
std::function<int(const VEC &rhs, VEC &dst)> IMEXStepper< VEC >::solve_jacobian_system

Solve linear system.

Definition at line 246 of file imex_stepper.h.

§ solver_should_restart

template<typename VEC = Vector<double>>
std::function<bool (const double t, VEC &sol, VEC &sol_dot)> IMEXStepper< VEC >::solver_should_restart

Evaluate wether the mesh should be refined or not.

If so, it refines and interpolate the solutions from the old to the new mesh.

Definition at line 263 of file imex_stepper.h.

§ step_size

template<typename VEC = Vector<double>>
double IMEXStepper< VEC >::step_size
private

Step size.

Definition at line 116 of file imex_stepper.h.

§ update_jacobian_continuously

template<typename VEC = Vector<double>>
bool IMEXStepper< VEC >::update_jacobian_continuously
private

Jacobian is updated at each outer iteration and time step.

Definition at line 154 of file imex_stepper.h.

§ use_kinsol

template<typename VEC = Vector<double>>
bool IMEXStepper< VEC >::use_kinsol
private

use kinsol solver true or false

Definition at line 159 of file imex_stepper.h.

§ vector_norm

template<typename VEC = Vector<double>>
std::function<double(const VEC &vector)> IMEXStepper< VEC >::vector_norm

Return the norm of vector.

Note that Kinsol uses different norms. By default it returns the l2 norm.

Definition at line 283 of file imex_stepper.h.

§ verbose

template<typename VEC = Vector<double>>
bool IMEXStepper< VEC >::verbose
private

print useful informations

Definition at line 165 of file imex_stepper.h.


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