deal2lkit: A ToolKit library for Deal.II
imex_stepper.h
Go to the documentation of this file.
1 //-----------------------------------------------------------
2 //
3 // Copyright (C) 2015-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_imex_stepper_h
17 #define _d2k_imex_stepper_h
18 
19 #include <deal2lkit/config.h>
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/logstream.h>
25 
26 #ifdef D2K_WITH_SUNDIALS
29 
30 #ifdef DEAL_II_WITH_MPI
31 #include "mpi.h"
32 #endif
33 
34 D2K_NAMESPACE_OPEN
35 
54 template<typename VEC=Vector<double> >
56 {
57 public:
58 
59 #ifdef DEAL_II_WITH_MPI
60 
64  IMEXStepper(std::string name="",
65  MPI_Comm comm = MPI_COMM_WORLD);
66 #else
67 
70  IMEXStepper(std::string &name="");
71 
72 #endif
73 
76 
78  unsigned int solve_dae(VEC &solution, VEC &solution_dot);
79 
80 
85  void compute_consistent_initial_conditions(const double &t,
86  VEC &y,
87  VEC &y_dot);
95  double get_alpha() const;
96 
101  void set_initial_time(const double &t);
102 
103 private:
104 
105 #ifdef DEAL_II_WITH_MPI
106  MPI_Comm communicator;
107 #endif
108 
112 
113  void compute_y_dot(const VEC &y, const VEC &prev, const double alpha, VEC &y_dot);
114 
116  double step_size;
117 
121  std::string _step_size;
122 
127  double evaluate_step_size(const double &t);
128 
130  double initial_time;
131 
133  double final_time;
134 
136  double abs_tol;
137 
139  double rel_tol;
140 
142  unsigned int output_period;
143 
145  double newton_alpha;
146 
149 
152 
155 
160 
163 
165  bool verbose;
166 
168  unsigned int n_max_backtracking;
169 
171  std::string method;
172 
179  double line_search_with_backtracking(const VEC &update,
180  const VEC &prev_sol,
181  const double &alpha,
182  const double &t,
183  VEC &sol,
184  VEC &sol_dot,
185  VEC &residual);
186 
187 
199  void do_newton (const double t,
200  const double alpha,
201  const bool update_Jacobian,
202  const VEC &previous_solution,
203  VEC &solution,
204  VEC &solution_dot);
205 
206 
213  void compute_previous_solution(const VEC &sol,
214  const VEC &sol_dot,
215  const double &alpha,
216  VEC &prev);
217 
218 public:
219 
225  std::function<shared_ptr<VEC>()> create_new_vector;
226 
230  std::function<int(const double t,
231  const VEC &y,
232  const VEC &y_dot,
233  VEC &res)> residual;
234 
238  std::function<int(const double t,
239  const VEC &y,
240  const VEC &y_dot,
241  const double alpha)> setup_jacobian;
242 
246  std::function<int(const VEC &rhs, VEC &dst)> solve_jacobian_system;
247 
251  std::function<void (const double t,
252  const VEC &sol,
253  const VEC &sol_dot,
254  const unsigned int step_number)> output_step;
255 
261  std::function<bool (const double t,
262  VEC &sol,
263  VEC &sol_dot)> solver_should_restart;
264 
270  std::function<VEC&()> get_lumped_mass_matrix;
271 
276  std::function<int(const VEC &src,
277  VEC &dst)> jacobian_vmult;
278 
283  std::function<double(const VEC &vector)> vector_norm;
284 
285 private:
286 
291 
292 };
293 
294 D2K_NAMESPACE_CLOSE
295 
296 #endif
297 
298 
299 #endif
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 tes...
unsigned int max_outer_non_linear_iterations
Maximum number of outer iterations for Newton method.
Definition: imex_stepper.h:148
bool update_jacobian_continuously
Jacobian is updated at each outer iteration and time step.
Definition: imex_stepper.h:154
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.
Definition: imex_stepper.h:277
double abs_tol
Absolute error tolerance for non linear iterations.
Definition: imex_stepper.h:136
A parameter acceptor base class.
ConditionalOStream pcout
Output stream.
Definition: imex_stepper.h:162
virtual void declare_parameters(ParameterHandler &prm)
Declare parameters for this class to function properly.
Definition: imex_stepper.cc:91
void set_functions_to_trigger_an_assert()
Set the std::functions above to trigger an assert if they are not implemented.
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
KINSOLInterface< VEC > kinsol
kinsol solver
Definition: imex_stepper.h:111
void set_initial_time(const double &t)
Set initial time equal to t disregarding what is written in the parameter file.
Definition: imex_stepper.cc:85
std::string method
method used for alpha selection
Definition: imex_stepper.h:171
static ParameterHandler prm
Static parameter.
bool verbose
print useful informations
Definition: imex_stepper.h:165
bool use_kinsol
use kinsol solver true or false
Definition: imex_stepper.h:159
unsigned int max_inner_non_linear_iterations
Maximum number of inner iterations for Newton method.
Definition: imex_stepper.h:151
std::function< VEC &()> get_lumped_mass_matrix
Return the lumped mass matrix vector.
Definition: imex_stepper.h:270
unsigned int solve_dae(VEC &solution, VEC &solution_dot)
Evolve.
void compute_y_dot(const VEC &y, const VEC &prev, const double alpha, VEC &y_dot)
double step_size
Step size.
Definition: imex_stepper.h:116
std::function< void(const double t, const VEC &sol, const VEC &sol_dot, const unsigned int step_number)> output_step
Store solutions to file.
Definition: imex_stepper.h:254
std::function< int(const VEC &rhs, VEC &dst)> solve_jacobian_system
Solve linear system.
Definition: imex_stepper.h:246
std::string _step_size
user defined step_size
Definition: imex_stepper.h:121
Interface to SUNDIALS KINSOL library.
unsigned int output_period
Seconds between each output.
Definition: imex_stepper.h:142
double final_time
Final time.
Definition: imex_stepper.h:133
double rel_tol
Relative error tolerance for non linear iterations.
Definition: imex_stepper.h:139
void compute_consistent_initial_conditions(const double &t, VEC &y, VEC &y_dot)
compute_consistent_initial_conditions
void compute_previous_solution(const VEC &sol, const VEC &sol_dot, const double &alpha, VEC &prev)
compute previous solution from given
IMEXStepper(std::string &name="")
Constructor for the IMEXStepper class.
Definition: imex_stepper.cc:63
std::function< bool(const double t, VEC &sol, VEC &sol_dot)> solver_should_restart
Evaluate wether the mesh should be refined or not.
Definition: imex_stepper.h:263
std::function< int(const double t, const VEC &y, const VEC &y_dot, VEC &res)> residual
Compute residual.
Definition: imex_stepper.h:233
IMEXStepper solves non-linear time dependent problems with user-defined size of the time step and usi...
Definition: imex_stepper.h:55
double get_alpha() const
if initial time is different from final time (i.e., we are solving a time-dep problem and not a stati...
Definition: imex_stepper.cc:73
std::function< int(const double t, const VEC &y, const VEC &y_dot, const double alpha)> setup_jacobian
Compute Jacobian.
Definition: imex_stepper.h:241
double evaluate_step_size(const double &t)
evaluate step size at time t according to the expression stored in _step_size
unsigned int n_max_backtracking
i max
Definition: imex_stepper.h:168
double initial_time
Initial time for the ode.
Definition: imex_stepper.h:130
std::function< shared_ptr< VEC >)> create_new_vector
Return a shared_ptr<VEC>.
Definition: imex_stepper.h:225
std::function< double(const VEC &vector)> vector_norm
Return the norm of vector.
Definition: imex_stepper.h:283
double newton_alpha
Alpha to use in Newton method for the update of the solution.
Definition: imex_stepper.h:145