ExaDG
Loading...
Searching...
No Matches
restart_data.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_FUNCTIONALITIES_RESTART_DATA_H_
23#define INCLUDE_FUNCTIONALITIES_RESTART_DATA_H_
24
25// C/C++
26#include <limits>
27
28// deal.II
29#include <deal.II/base/conditional_ostream.h>
30
31// ExaDG
32#include <exadg/utilities/numbers.h>
33#include <exadg/utilities/print_functions.h>
34
35namespace ExaDG
36{
38{
40 : write_restart(false),
41 interval_time(std::numeric_limits<double>::max()),
42 interval_wall_time(std::numeric_limits<double>::max()),
43 interval_time_steps(std::numeric_limits<unsigned int>::max()),
44 filename("restart"),
45 counter(1)
46 {
47 }
48
49 void
50 print(dealii::ConditionalOStream const & pcout) const
51 {
52 pcout << " Restart:" << std::endl;
53 print_parameter(pcout, "Write restart", write_restart);
54
55 if(write_restart == true)
56 {
57 print_parameter(pcout, "Interval physical time", interval_time);
58 print_parameter(pcout, "Interval wall time", interval_wall_time);
59 print_parameter(pcout, "Interval time steps", interval_time_steps);
60 print_parameter(pcout, "Filename", filename);
61 }
62 }
63
64 bool
65 do_restart(double const wall_time,
66 double const time,
67 types::time_step const time_step_number,
68 bool const reset_counter) const
69 {
70 // After a restart, the counter is reset to 1, but time = current_time - start time != 0 after a
71 // restart. Hence, we have to explicitly reset the counter in that case. There is nothing to do
72 // if the restart is controlled by the wall time or the time_step_number because these
73 // variables are reinitialized after a restart anyway.
74 if(reset_counter)
75 counter += int((time + 1.e-10) / interval_time);
76
77 bool do_restart = wall_time > interval_wall_time * counter or time > interval_time * counter or
78 time_step_number > interval_time_steps * counter;
79
80 if(do_restart)
81 ++counter;
82
83 return do_restart;
84 }
85
86 bool write_restart;
87
88 // physical time
89 double interval_time;
90
91 // wall time in seconds (= hours * 3600)
92 double interval_wall_time;
93
94 // number of time steps after which to write restart
95 unsigned int interval_time_steps;
96
97 // filename for restart files
98 std::string filename;
99
100 // counter needed do decide when to write restart
101 mutable unsigned int counter;
102};
103
104} // namespace ExaDG
105
106#endif /* INCLUDE_FUNCTIONALITIES_RESTART_DATA_H_ */
Definition driver.cpp:33
Definition restart_data.h:38