Reference documentation for deal.II version GIT relicensing-903-gcd01479aa8 2024-06-25 10:50:02+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
discrete_time.cc
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2020 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15
18
20
21namespace
22{
23 // Helper function that computes the next discrete time, adjusting it if:
24 // - The next time exceeds the end time.
25 // - The next time is smaller but very close to the end time.
26 double
27 calculate_next_time(const double current_time,
28 const double step_size,
29 const double end_time)
30 {
31 Assert(step_size >= 0., ExcMessage("Time step size must be non-negative"));
32 Assert(end_time >= current_time, ExcInternalError());
33 double next_time = current_time + step_size;
34 constexpr double relative_tolerance = 0.05;
35 const double time_tolerance = relative_tolerance * step_size;
36 if (next_time > end_time - time_tolerance)
37 next_time = end_time;
38 return next_time;
39 }
40} // namespace
41
42
43
44DiscreteTime::DiscreteTime(const double start_time,
45 const double end_time,
46 const double desired_start_step_size)
47 : start_time{start_time}
48 , end_time{end_time}
49 , current_time{start_time}
50 , next_time{calculate_next_time(start_time,
51 desired_start_step_size,
52 end_time)}
53 , previous_time{start_time}
54 , start_step_size{next_time - start_time}
55 , step_number{0}
56{}
57
58
59
60void
61DiscreteTime::set_desired_next_step_size(const double next_step_size)
62{
63 next_time = calculate_next_time(current_time, next_step_size, end_time);
64}
65
66
67
68void
69DiscreteTime::set_next_step_size(const double next_step_size)
70{
71 Assert(next_step_size > 0,
72 ExcMessage("Only positive time step size is allowed."));
73 next_time = current_time + next_step_size;
74 Assert(
77 "Time step size is too large. The next time cannot exceed the end time."));
78}
79
80
81
82void
84{
86 ExcMessage("You can't advance time further. "
87 "Either dt==0 or you are at the "
88 "end of the simulation time."));
89 const double step_size = get_next_step_size();
93 next_time = calculate_next_time(current_time, step_size, end_time);
94}
95
96
97
98void
106
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:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)