Reference documentation for deal.II version 9.5.0
\(\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
discrete_time.cc
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2019 - 2020 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.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16
19
21
22namespace
23{
24 // Helper function that computes the next discrete time, adjusting it if:
25 // - The next time exceeds the end time.
26 // - The next time is smaller but very close to the end time.
27 double
28 calculate_next_time(const double current_time,
29 const double step_size,
30 const double end_time)
31 {
32 Assert(step_size >= 0., ExcMessage("Time step size must be non-negative"));
33 Assert(end_time >= current_time, ExcInternalError());
34 double next_time = current_time + step_size;
35 constexpr double relative_tolerance = 0.05;
36 const double time_tolerance = relative_tolerance * step_size;
37 if (next_time > end_time - time_tolerance)
38 next_time = end_time;
39 return next_time;
40 }
41} // namespace
42
43
44
45DiscreteTime::DiscreteTime(const double start_time,
46 const double end_time,
47 const double desired_start_step_size)
48 : start_time{start_time}
49 , end_time{end_time}
50 , current_time{start_time}
51 , next_time{calculate_next_time(start_time,
52 desired_start_step_size,
53 end_time)}
54 , previous_time{start_time}
55 , start_step_size{next_time - start_time}
56 , step_number{0}
57{}
58
59
60
61void
62DiscreteTime::set_desired_next_step_size(const double next_step_size)
63{
64 next_time = calculate_next_time(current_time, next_step_size, end_time);
65}
66
67
68
69void
70DiscreteTime::set_next_step_size(const double next_step_size)
71{
72 Assert(next_step_size > 0,
73 ExcMessage("Only positive time step size is allowed."));
74 next_time = current_time + next_step_size;
75 Assert(
78 "Time step size is too large. The next time cannot exceed the end time."));
79}
80
81
82
83void
85{
87 ExcMessage("You can't advance time further. "
88 "Either dt==0 or you are at the "
89 "end of the simulation time."));
90 const double step_size = get_next_step_size();
94 next_time = calculate_next_time(current_time, step_size, end_time);
95}
96
97
98
99void
101{
104 next_time = calculate_next_time(current_time, start_step_size, end_time);
105 step_number = 0;
106}
107
double get_next_step_size() const
void set_desired_next_step_size(const double time_step_size)
double previous_time
void set_next_step_size(const double time_step_size)
DiscreteTime(const double start_time, const double end_time, const double desired_start_step_size=0.)
void advance_time()
double current_time
double start_step_size
unsigned int step_number
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)