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>
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 ¶meter, 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::PatternBase > | to_pattern (const double &) |
double More... | |
template<> | |
std::string | to_string (const double &entry) |
template<> | |
double | to_type (const std::string ¶meter) |
template<> | |
std_cxx11::shared_ptr< Patterns::PatternBase > | to_pattern (const int &) |
int More... | |
template<> | |
std::string | to_string (const int &entry) |
template<> | |
int | to_type (const std::string ¶meter) |
template<> | |
std_cxx11::shared_ptr< Patterns::PatternBase > | to_pattern (const unsigned int &) |
unsigned int More... | |
template<> | |
std::string | to_string (const unsigned int &entry) |
template<> | |
unsigned int | to_type (const std::string ¶meter) |
template<> | |
std_cxx11::shared_ptr< Patterns::PatternBase > | to_pattern (const bool &) |
bool More... | |
template<> | |
std::string | to_string (const bool &entry) |
template<> | |
bool | to_type (const std::string ¶meter) |
Public Member Functions inherited from Subscriptor | |
Subscriptor () | |
Subscriptor (const Subscriptor &) | |
Subscriptor (Subscriptor &&) | |
virtual | ~Subscriptor () |
Subscriptor & | operator= (const Subscriptor &) |
Subscriptor & | operator= (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::PatternBase > | to_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... | |
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:
Definition at line 55 of file imex_stepper.h.
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.
void IMEXStepper< VEC >::compute_consistent_initial_conditions | ( | const double & | t, |
VEC & | y, | ||
VEC & | y_dot | ||
) |
|
private |
compute previous solution from given
sol | |
sol_dot | |
alpha |
Definition at line 539 of file imex_stepper.cc.
|
private |
Definition at line 160 of file imex_stepper.cc.
|
virtual |
Declare parameters for this class to function properly.
Reimplemented from ParameterAcceptor.
Definition at line 91 of file imex_stepper.cc.
|
private |
find solution applying the newton method with given
t | |
alpha | |
update_Jacobian | |
previous_solution | |
solution_dot | at 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.
|
private |
evaluate step size at time t
according to the expression stored in _step_size
Definition at line 559 of file imex_stepper.cc.
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.
Definition at line 73 of file imex_stepper.cc.
|
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.
|
private |
Set the std::functions above to trigger an assert if they are not implemented.
Definition at line 610 of file imex_stepper.cc.
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.
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.
|
private |
user defined step_size
Definition at line 121 of file imex_stepper.h.
|
private |
Absolute error tolerance for non linear iterations.
Definition at line 136 of file imex_stepper.h.
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.
|
private |
Final time.
Definition at line 133 of file imex_stepper.h.
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.
|
private |
Initial time for the ode.
Definition at line 130 of file imex_stepper.h.
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.
|
private |
kinsol solver
Definition at line 111 of file imex_stepper.h.
|
private |
Maximum number of inner iterations for Newton method.
Definition at line 151 of file imex_stepper.h.
|
private |
Maximum number of outer iterations for Newton method.
Definition at line 148 of file imex_stepper.h.
|
private |
method used for alpha selection
Definition at line 171 of file imex_stepper.h.
|
private |
i max
Definition at line 168 of file imex_stepper.h.
|
private |
Alpha to use in Newton method for the update of the solution.
Definition at line 145 of file imex_stepper.h.
|
private |
Seconds between each output.
Definition at line 142 of file imex_stepper.h.
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.
|
private |
Output stream.
Definition at line 162 of file imex_stepper.h.
|
private |
Relative error tolerance for non linear iterations.
Definition at line 139 of file imex_stepper.h.
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.
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.
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.
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.
|
private |
Step size.
Definition at line 116 of file imex_stepper.h.
|
private |
Jacobian is updated at each outer iteration and time step.
Definition at line 154 of file imex_stepper.h.
|
private |
use kinsol solver true or false
Definition at line 159 of file imex_stepper.h.
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.
|
private |
print useful informations
Definition at line 165 of file imex_stepper.h.