deal.II version GIT relicensing-6809-ge913b9bb34 2026-09-25 17:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
time_stepping.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2014 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_time_stepping_h
14#define dealii_time_stepping_h
15
16
17#include <deal.II/base/config.h>
18
20
21#include <functional>
22#include <memory>
23#include <vector>
24
26
33namespace TimeStepping
34{
164
165
166
186
187
188
193 template <typename VectorType>
195 {
196 public:
200 virtual ~TimeStepping() = default;
201
212 virtual double
214 std::vector<std::function<VectorType(const double, const VectorType &)>>
215 &F,
216 std::vector<std::function<
217 VectorType(const double, const double, const VectorType &)>> &J_inverse,
218 double t,
219 double delta_t,
220 VectorType &y) = 0;
221
225 struct Status
226 {};
227
231 virtual const Status &
232 get_status() const = 0;
233 };
234
235
236
240 template <typename VectorType>
241 class RungeKutta : public TimeStepping<VectorType>
242 {
243 public:
247 virtual ~RungeKutta() override = default;
248
252 virtual void
254
266 double
268 std::vector<std::function<VectorType(const double, const VectorType &)>>
269 &F,
270 std::vector<std::function<
271 VectorType(const double, const double, const VectorType &)>> &J_inverse,
272 double t,
273 double delta_t,
274 VectorType &y) override;
275
287 virtual double
289 const std::function<VectorType(const double, const VectorType &)> &f,
290 const std::function<
291 VectorType(const double, const double, const VectorType &)>
292 &id_minus_tau_J_inverse,
293 double t,
294 double delta_t,
295 VectorType &y) = 0;
296
297 protected:
301 unsigned int n_stages;
302
306 std::vector<double> b;
307
311 std::vector<double> c;
312
316 std::vector<std::vector<double>> a;
317 };
318
319
320
325 template <typename VectorType>
326 class ExplicitRungeKutta : public RungeKutta<VectorType>
327 {
328 public:
329 using RungeKutta<VectorType>::evolve_one_time_step;
330
337
342
346 void
347 initialize(const runge_kutta_method method) override;
348
362 double
364 const std::function<VectorType(const double, const VectorType &)> &f,
365 const std::function<
366 VectorType(const double, const double, const VectorType &)>
367 &id_minus_tau_J_inverse,
368 double t,
369 double delta_t,
370 VectorType &y) override;
371
379 double
381 const std::function<VectorType(const double, const VectorType &)> &f,
382 double t,
383 double delta_t,
384 VectorType &y);
385
389 struct Status : public TimeStepping<VectorType>::Status
390 {
392 : method(invalid)
393 {}
394
396 };
397
401 const Status &
402 get_status() const override;
403
404 private:
408 void
410 const std::function<VectorType(const double, const VectorType &)> &f,
411 const double t,
412 const double delta_t,
413 const VectorType &y,
414 std::vector<VectorType> &f_stages) const;
415
420 };
421
422
423
431 template <typename VectorType>
432 class LowStorageRungeKutta : public RungeKutta<VectorType>
433 {
434 public:
435 using RungeKutta<VectorType>::evolve_one_time_step;
436
443
448
452 void
453 initialize(const runge_kutta_method method) override;
454
466 double
468 const std::function<VectorType(const double, const VectorType &)> &f,
469 const std::function<
470 VectorType(const double, const double, const VectorType &)>
471 &id_minus_tau_J_inverse,
472 double t,
473 double delta_t,
474 VectorType &y) override;
475
485 double
487 const std::function<VectorType(const double, const VectorType &)> &f,
488 double t,
489 double delta_t,
490 VectorType &solution,
491 VectorType &vec_ri,
492 VectorType &vec_ki);
493
500 void
501 get_coefficients(std::vector<double> &a,
502 std::vector<double> &b,
503 std::vector<double> &c) const;
504
508 struct Status : public TimeStepping<VectorType>::Status
509 {
511 : method(invalid)
512 {}
513
515 };
516
520 const Status &
521 get_status() const override;
522
523 private:
527 void
529 const std::function<VectorType(const double, const VectorType &)> &f,
530 const double t,
531 const double factor_solution,
532 const double factor_ai,
533 const VectorType &current_ri,
534 VectorType &vec_ki,
535 VectorType &solution,
536 VectorType &next_ri) const;
537
542 };
543
544
545
550 template <typename VectorType>
551 class ImplicitRungeKutta : public RungeKutta<VectorType>
552 {
553 public:
554 using RungeKutta<VectorType>::evolve_one_time_step;
555
562
569 const unsigned int max_it = 100,
570 const double tolerance = 1e-6);
571
575 void
576 initialize(const runge_kutta_method method) override;
577
589 double
591 const std::function<VectorType(const double, const VectorType &)> &f,
592 const std::function<
593 VectorType(const double, const double, const VectorType &)>
594 &id_minus_tau_J_inverse,
595 double t,
596 double delta_t,
597 VectorType &y) override;
598
603 void
605 const double tolerance);
606
611 struct Status : public TimeStepping<VectorType>::Status
612 {
614 : method(invalid)
615 , n_iterations(numbers::invalid_unsigned_int)
616 , norm_residual(numbers::signaling_nan<double>())
617 {}
618
620 unsigned int n_iterations;
622 };
623
627 const Status &
628 get_status() const override;
629
630 private:
634 void
636 const std::function<VectorType(const double, const VectorType &)> &f,
637 const std::function<
638 VectorType(const double, const double, const VectorType &)>
639 &id_minus_tau_J_inverse,
640 double t,
641 double delta_t,
642 VectorType &y,
643 std::vector<VectorType> &f_stages);
644
648 void
650 const std::function<void(const VectorType &, VectorType &)> &get_residual,
651 const std::function<VectorType(const VectorType &)>
652 &id_minus_tau_J_inverse,
653 VectorType &y);
654
658 void
660 const std::function<VectorType(const double, const VectorType &)> &f,
661 double t,
662 double delta_t,
663 const VectorType &new_y,
664 const VectorType &y,
665 VectorType &tendency,
666 VectorType &residual) const;
667
671 unsigned int max_it;
672
676 double tolerance;
677
682 };
683
684
685
690 template <typename VectorType>
691 class EmbeddedExplicitRungeKutta : public RungeKutta<VectorType>
692 {
693 public:
694 using RungeKutta<VectorType>::evolve_one_time_step;
695
702
708 const double coarsen_param = 1.2,
709 const double refine_param = 0.8,
710 const double min_delta = 1e-14,
711 const double max_delta = 1e100,
712 const double refine_tol = 1e-8,
713 const double coarsen_tol = 1e-12);
714
718 ~EmbeddedExplicitRungeKutta() override = default;
719
723 void
724 initialize(const runge_kutta_method method) override;
725
739 double
741 const std::function<VectorType(const double, const VectorType &)> &f,
742 const std::function<
743 VectorType(const double, const double, const VectorType &)>
744 &id_minus_tau_J_inverse,
745 double t,
746 double delta_t,
747 VectorType &y) override;
748
756 double
758 const std::function<VectorType(const double, const VectorType &)> &f,
759 double t,
760 double delta_t,
761 VectorType &y);
762
766 void
768 const double refine_param,
769 const double min_delta,
770 const double max_delta,
771 const double refine_tol,
772 const double coarsen_tol);
773
780 struct Status : public TimeStepping<VectorType>::Status
781 {
783 : method(invalid)
784 {}
785
788 unsigned int n_iterations;
791 };
792
796 const Status &
797 get_status() const override;
798
799 private:
803 void
805 const std::function<VectorType(const double, const VectorType &)> &f,
806 const double t,
807 const double delta_t,
808 const VectorType &y,
809 std::vector<VectorType> &f_stages);
810
816
822
827
832
838
844
849 bool last_same_as_first = false;
850
854 std::vector<double> b1;
855
859 std::vector<double> b2;
860
865 std::unique_ptr<VectorType> last_stage;
866
871 };
872} // namespace TimeStepping
873
875
876#endif
double evolve_one_time_step(const std::function< VectorType(const double, const VectorType &)> &f, double t, double delta_t, VectorType &y)
std::unique_ptr< VectorType > last_stage
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 Status & get_status() const override
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)
void initialize(const runge_kutta_method method) override
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) override
~EmbeddedExplicitRungeKutta() override=default
EmbeddedExplicitRungeKutta(const runge_kutta_method method, const double coarsen_param=1.2, const double refine_param=0.8, const double min_delta=1e-14, const double max_delta=1e100, const double refine_tol=1e-8, const double coarsen_tol=1e-12)
const Status & get_status() const override
void initialize(const runge_kutta_method method) override
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
double evolve_one_time_step(const std::function< VectorType(const double, const VectorType &)> &f, double t, double delta_t, VectorType &y)
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) override
ExplicitRungeKutta(const runge_kutta_method method)
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)
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)
const Status & get_status() const override
void initialize(const runge_kutta_method method) override
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) override
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
void set_newton_solver_parameters(const unsigned int max_it, const double tolerance)
ImplicitRungeKutta(const runge_kutta_method method, const unsigned int max_it=100, const double tolerance=1e-6)
void compute_one_stage(const std::function< VectorType(const double, const VectorType &)> &f, const double t, const double factor_solution, const double factor_ai, const VectorType &current_ri, VectorType &vec_ki, VectorType &solution, VectorType &next_ri) const
void initialize(const runge_kutta_method method) override
LowStorageRungeKutta(const runge_kutta_method method)
void get_coefficients(std::vector< double > &a, std::vector< double > &b, std::vector< double > &c) const
double evolve_one_time_step(const std::function< VectorType(const double, const VectorType &)> &f, double t, double delta_t, VectorType &solution, VectorType &vec_ri, VectorType &vec_ki)
const Status & get_status() const override
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) override
std::vector< double > b
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) override
virtual ~RungeKutta() override=default
virtual void initialize(const runge_kutta_method method)=0
std::vector< std::vector< double > > a
std::vector< double > c
virtual 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)=0
virtual 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)=0
virtual ~TimeStepping()=default
virtual const Status & get_status() const =0
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
@ LOW_STORAGE_RK_STAGE9_ORDER5
@ LOW_STORAGE_RK_STAGE3_ORDER3
@ LOW_STORAGE_RK_STAGE7_ORDER4
@ LOW_STORAGE_RK_STAGE5_ORDER4
embedded_runge_kutta_time_step exit_delta_t