Reference documentation for deal.II version 9.2.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\}}\)
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 
22 namespace
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 
45 DiscreteTime::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 
61 void
62 DiscreteTime::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 
69 void
71 {
73  ExcMessage(
74  "You can't advance time further."
75  "Either dt == 0 or you are at the end of the simulation time."));
76  const double step_size = get_next_step_size();
79  ++step_number;
80  next_time = calculate_next_time(current_time, step_size, end_time);
81 }
82 
83 
84 
85 void
87 {
90  next_time = calculate_next_time(current_time, start_step_size, end_time);
91  step_number = 0;
92 }
93 
DiscreteTime::next_time
double next_time
Definition: discrete_time.h:410
DiscreteTime::advance_time
void advance_time()
Definition: discrete_time.cc:70
DiscreteTime::previous_time
double previous_time
Definition: discrete_time.h:415
StandardExceptions::ExcMessage
static ::ExceptionBase & ExcMessage(std::string arg1)
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
discrete_time.h
DiscreteTime::get_next_step_size
double get_next_step_size() const
Definition: discrete_time.h:466
DiscreteTime::set_desired_next_step_size
void set_desired_next_step_size(const double time_step_size)
Definition: discrete_time.cc:62
exceptions.h
DiscreteTime::restart
void restart()
Definition: discrete_time.cc:86
StandardExceptions::ExcInternalError
static ::ExceptionBase & ExcInternalError()
Assert
#define Assert(cond, exc)
Definition: exceptions.h:1419
DiscreteTime::DiscreteTime
DiscreteTime(const double start_time, const double end_time, const double desired_start_step_size=0.)
Definition: discrete_time.cc:45
DiscreteTime::start_time
double start_time
Definition: discrete_time.h:386
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
DiscreteTime::end_time
double end_time
Definition: discrete_time.h:391
DiscreteTime::current_time
double current_time
Definition: discrete_time.h:396
DiscreteTime::start_step_size
double start_step_size
Definition: discrete_time.h:420
DiscreteTime::step_number
unsigned int step_number
Definition: discrete_time.h:426