Reference documentation for deal.II version 9.0.0
time_stepping.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2014 - 2017 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II 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 deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_time_stepping_h
17 #define dealii_time_stepping_h
18 
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/signaling_nan.h>
22 
23 #include <functional>
24 #include <vector>
25 
26 DEAL_II_NAMESPACE_OPEN
27 
35 namespace TimeStepping
36 {
56  enum runge_kutta_method { FORWARD_EULER, RK_THIRD_ORDER, RK_CLASSIC_FOURTH_ORDER,
57  BACKWARD_EULER, IMPLICIT_MIDPOINT, CRANK_NICOLSON,
58  SDIRK_TWO_STAGES, HEUN_EULER, BOGACKI_SHAMPINE, DOPRI,
59  FEHLBERG, CASH_KARP,
60  invalid
61  };
62 
63 
64 
71  enum embedded_runge_kutta_time_step { DELTA_T, MIN_DELTA_T, MAX_DELTA_T };
72 
73 
74 
79  template <typename VectorType>
81  {
82  public:
86  virtual ~TimeStepping() = default;
87 
98  virtual double evolve_one_time_step
99  (std::vector<std::function<VectorType (const double, const VectorType &)> > &F,
100  std::vector<std::function<VectorType (const double, const double, const VectorType &)> > &J_inverse,
101  double t,
102  double delta_t,
103  VectorType &y) = 0;
104 
108  struct Status {};
109 
113  virtual const Status &get_status() const = 0;
114  };
115 
116 
117 
124  template <typename VectorType>
125  class RungeKutta : public TimeStepping<VectorType>
126  {
127  public:
131  virtual ~RungeKutta() = default;
132 
136  virtual void initialize(const runge_kutta_method method) = 0;
137 
149  double evolve_one_time_step
150  (std::vector<std::function<VectorType (const double, const VectorType &)> > &F,
151  std::vector<std::function<VectorType (const double, const double, const VectorType &)> > &J_inverse,
152  double t,
153  double delta_t,
154  VectorType &y);
155 
167  virtual double evolve_one_time_step
168  (const std::function<VectorType (const double, const VectorType &)> &f,
169  const std::function<VectorType (const double, const double, const VectorType &)> &id_minus_tau_J_inverse,
170  double t,
171  double delta_t,
172  VectorType &y) = 0;
173 
174  protected:
178  unsigned int n_stages;
179 
183  std::vector<double> b;
184 
188  std::vector<double> c;
189 
193  std::vector<std::vector<double> > a;
194  };
195 
196 
197 
202  template <typename VectorType>
203  class ExplicitRungeKutta : public RungeKutta<VectorType>
204  {
205  public:
207 
213  ExplicitRungeKutta() = default;
214 
219 
223  void initialize(const runge_kutta_method method);
224 
236  double evolve_one_time_step
237  (const std::function<VectorType (const double, const VectorType &)> &f,
238  const std::function<VectorType (const double, const double, const VectorType &)> &id_minus_tau_J_inverse,
239  double t,
240  double delta_t,
241  VectorType &y);
242 
250  double evolve_one_time_step
251  (const std::function<VectorType (const double, const VectorType &)> &f,
252  double t,
253  double delta_t,
254  VectorType &y);
255 
259  struct Status : public TimeStepping<VectorType>::Status
260  {
261  Status ()
262  :
263  method (invalid)
264  {}
265 
266  runge_kutta_method method;
267  };
268 
272  const Status &get_status() const;
273 
274  private:
278  void compute_stages
279  (const std::function<VectorType (const double, const VectorType &)> &f,
280  const double t,
281  const double delta_t,
282  const VectorType &y,
283  std::vector<VectorType> &f_stages) const;
284 
289  };
290 
291 
292 
297  template <typename VectorType>
298  class ImplicitRungeKutta : public RungeKutta<VectorType>
299  {
300  public:
302 
308  ImplicitRungeKutta() = default;
309 
316  const unsigned int max_it = 100,
317  const double tolerance = 1e-6);
318 
322  void initialize(const runge_kutta_method method);
323 
335  double evolve_one_time_step
336  (const std::function<VectorType (const double, const VectorType &)> &f,
337  const std::function<VectorType (const double, const double, const VectorType &)> &id_minus_tau_J_inverse,
338  double t,
339  double delta_t,
340  VectorType &y);
341 
346  void set_newton_solver_parameters(const unsigned int max_it,
347  const double tolerance);
348 
353  struct Status : public TimeStepping<VectorType>::Status
354  {
355  Status ()
356  :
357  method (invalid),
358  n_iterations (numbers::invalid_unsigned_int),
359  norm_residual (numbers::signaling_nan<double>())
360  {}
361 
362  runge_kutta_method method;
363  unsigned int n_iterations;
364  double norm_residual;
365  };
366 
370  const Status &get_status() const;
371 
372  private:
376  void compute_stages
377  (const std::function<VectorType (const double, const VectorType &)> &f,
378  const std::function<VectorType (const double, const double, const VectorType &)> &id_minus_tau_J_inverse,
379  double t,
380  double delta_t,
381  VectorType &y,
382  std::vector<VectorType> &f_stages);
383 
387  void newton_solve(const std::function<void (const VectorType &,VectorType &)> &get_residual,
388  const std::function<VectorType (const VectorType &)> &id_minus_tau_J_inverse,
389  VectorType &y);
390 
394  void compute_residual(const std::function<VectorType (const double, const VectorType &)> &f,
395  double t,
396  double delta_t,
397  const VectorType &new_y,
398  const VectorType &y,
399  VectorType &tendency,
400  VectorType &residual) const;
401 
408 
412  unsigned int max_it;
413 
417  double tolerance;
418 
423  };
424 
425 
426 
431  template <typename VectorType>
432  class EmbeddedExplicitRungeKutta : public RungeKutta<VectorType>
433  {
434  public:
436 
442  EmbeddedExplicitRungeKutta() = default;
443 
449  const double coarsen_param = 1.2,
450  const double refine_param = 0.8,
451  const double min_delta = 1e-14,
452  const double max_delta = 1e100,
453  const double refine_tol = 1e-8,
454  const double coarsen_tol = 1e-12);
455 
460  {
461  free_memory();
462  }
463 
467  void free_memory();
468 
472  void initialize(const runge_kutta_method method);
473 
485  double evolve_one_time_step
486  (const std::function<VectorType (const double, const VectorType &)> &f,
487  const std::function<VectorType (const double, const double, const VectorType &)> &id_minus_tau_J_inverse,
488  double t,
489  double delta_t,
490  VectorType &y);
491 
499  double evolve_one_time_step
500  (const std::function<VectorType (const double, const VectorType &)> &f,
501  double t,
502  double delta_t,
503  VectorType &y);
504 
509  const double refine_param,
510  const double min_delta,
511  const double max_delta,
512  const double refine_tol,
513  const double coarsen_tol);
514 
521  struct Status : public TimeStepping<VectorType>::Status
522  {
523  runge_kutta_method method;
524  embedded_runge_kutta_time_step exit_delta_t;
525  unsigned int n_iterations;
526  double delta_t_guess;
527  double error_norm;
528  };
529 
533  const Status &get_status() const;
534 
535  private:
539  void compute_stages(const std::function<VectorType (const double, const VectorType &)> &f,
540  const double t,
541  const double delta_t,
542  const VectorType &y,
543  std::vector<VectorType> &f_stages);
544 
550 
555  double refine_param;
556 
560  double min_delta_t;
561 
565  double max_delta_t;
566 
571  double refine_tol;
572 
577  double coarsen_tol;
578 
584 
588  std::vector<double> b1;
589 
593  std::vector<double> b2;
594 
599  VectorType *last_stage;
600 
605  };
606 }
607 
608 DEAL_II_NAMESPACE_CLOSE
609 
610 #endif
static const unsigned int invalid_unsigned_int
Definition: types.h:173
void set_newton_solver_parameters(const unsigned int max_it, const double tolerance)
void compute_stages(const std::function< VectorType(const double, const VectorType &)> &f, const double t, const double delta_t, const VectorType &y, std::vector< VectorType > &f_stages) const
virtual ~RungeKutta()=default
void compute_residual(const std::function< VectorType(const double, const VectorType &)> &f, double t, double delta_t, const VectorType &new_y, const VectorType &y, VectorType &tendency, VectorType &residual) const
double evolve_one_time_step(const std::function< VectorType(const double, const VectorType &)> &f, const std::function< VectorType(const double, const double, const VectorType &)> &id_minus_tau_J_inverse, double t, double delta_t, VectorType &y)
const Status & get_status() const
void initialize(const runge_kutta_method method)
void set_time_adaptation_parameters(const double coarsen_param, const double refine_param, const double min_delta, const double max_delta, const double refine_tol, const double coarsen_tol)
double evolve_one_time_step(const std::function< VectorType(const double, const VectorType &)> &f, const std::function< VectorType(const double, const double, const VectorType &)> &id_minus_tau_J_inverse, double t, double delta_t, VectorType &y)
const Status & get_status() const
void newton_solve(const std::function< void(const VectorType &, VectorType &)> &get_residual, const std::function< VectorType(const VectorType &)> &id_minus_tau_J_inverse, VectorType &y)
void compute_stages(const std::function< VectorType(const double, const VectorType &)> &f, const double t, const double delta_t, const VectorType &y, std::vector< VectorType > &f_stages)
void initialize(const runge_kutta_method method)
double evolve_one_time_step(const std::function< VectorType(const double, const VectorType &)> &f, const std::function< VectorType(const double, const double, const VectorType &)> &id_minus_tau_J_inverse, double t, double delta_t, VectorType &y)
std::vector< double > b
std::vector< double > c
std::vector< std::vector< double > > a
void compute_stages(const std::function< VectorType(const double, const VectorType &)> &f, const std::function< VectorType(const double, const double, const VectorType &)> &id_minus_tau_J_inverse, double t, double delta_t, VectorType &y, std::vector< VectorType > &f_stages)
double evolve_one_time_step(std::vector< std::function< VectorType(const double, const VectorType &)> > &F, std::vector< std::function< VectorType(const double, const double, const VectorType &)> > &J_inverse, double t, double delta_t, VectorType &y)
virtual void initialize(const runge_kutta_method method)=0
embedded_runge_kutta_time_step
Definition: time_stepping.h:71
void initialize(const runge_kutta_method method)