deal.II version GIT relicensing-2167-g9622207b8f 2024-11-21 12:40:00+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
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
107
108
109
110std::size_t
121
double get_next_step_size() const
void set_desired_next_step_size(const double time_step_size)
std::size_t memory_consumption() const
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:498
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:499
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
std::enable_if_t< std::is_fundamental_v< T >, std::size_t > memory_consumption(const T &t)