ExaDG
Loading...
Searching...
No Matches
time_step_calculation.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2021 by the ExaDG authors
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * ______________________________________________________________________
20 */
21
22#ifndef INCLUDE_EXADG_TIME_INTEGRATION_TIME_STEP_CALCULATION_H_
23#define INCLUDE_EXADG_TIME_INTEGRATION_TIME_STEP_CALCULATION_H_
24
25namespace ExaDG
26{
27/*
28 * limit the maximum increase/decrease of the time step size
29 */
30inline void
31limit_time_step_change(double & new_time_step, double const & last_time_step, double const & fac)
32{
33 if(new_time_step >= fac * last_time_step)
34 {
35 new_time_step = fac * last_time_step;
36 }
37 else if(new_time_step <= last_time_step / fac)
38 {
39 new_time_step = last_time_step / fac;
40 }
41}
42
43/*
44 * Decrease time_step in order to exactly hit end_time.
45 */
46inline double
47adjust_time_step_to_hit_end_time(double const start_time,
48 double const end_time,
49 double const time_step)
50{
51 return (end_time - start_time) / (1 + int((end_time - start_time) / time_step));
52}
53
54/*
55 * This function calculates the time step size for a given time step size and a specified number of
56 * refinements, where the time step size is reduced by a factor of 2 for each refinement level.
57 */
58inline double
59calculate_const_time_step(double const dt, unsigned int const n_refine_time)
60{
61 double const time_step = dt / std::pow(2., n_refine_time);
62
63 return time_step;
64}
65
66} // namespace ExaDG
67
68#endif /* INCLUDE_EXADG_TIME_INTEGRATION_TIME_STEP_CALCULATION_H_ */
Definition driver.cpp:33