deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11: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
discrete_time.cc
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) 2020 - 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
14#include <deal.II/base/config.h>
15
20
21#include <Kokkos_Macros.hpp>
22
23#include <cstddef>
24#include <string>
25
27
28namespace
29{
30 // Helper function that computes the next discrete time, adjusting it if:
31 // - The next time exceeds the end time.
32 // - The next time is smaller but very close to the end time.
33 double
34 calculate_next_time(const double current_time,
35 const double step_size,
36 const double end_time)
37 {
38 Assert(step_size >= 0., ExcMessage("Time step size must be non-negative"));
39 Assert(end_time >= current_time, ExcInternalError());
40 double next_time = current_time + step_size;
41 constexpr double relative_tolerance = 0.05;
42 const double time_tolerance = relative_tolerance * step_size;
43 if (next_time > end_time - time_tolerance)
44 next_time = end_time;
45 return next_time;
46 }
47} // namespace
48
49
50
51DiscreteTime::DiscreteTime(const double start_time,
52 const double end_time,
53 const double desired_start_step_size)
54 : start_time{start_time}
55 , end_time{end_time}
56 , current_time{start_time}
57 , next_time{calculate_next_time(start_time,
58 desired_start_step_size,
59 end_time)}
60 , previous_time{start_time}
61 , start_step_size{next_time - start_time}
62 , step_number{0}
63{}
64
65
66
67void
68DiscreteTime::set_desired_next_step_size(const double next_step_size)
69{
70 next_time = calculate_next_time(current_time, next_step_size, end_time);
71}
72
73
74
75void
76DiscreteTime::set_next_step_size(const double next_step_size)
77{
78 Assert(next_step_size > 0,
79 ExcMessage("Only positive time step size is allowed."));
80 next_time = current_time + next_step_size;
81 Assert(
84 "Time step size is too large. The next time cannot exceed the end time."));
85}
86
87
88
89void
91{
93 ExcMessage("You can't advance time further. "
94 "Either dt==0 or you are at the "
95 "end of the simulation time."));
96 const double step_size = get_next_step_size();
100 next_time = calculate_next_time(current_time, step_size, end_time);
101}
102
103
104
105void
113
114
115
116std::size_t
127
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:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#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)