ExaDG
Loading...
Searching...
No Matches
solver_info_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_SOLVER_INFO_DATA_H_
23#define INCLUDE_FUNCTIONALITIES_SOLVER_INFO_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 : interval_time(std::numeric_limits<double>::max()),
41 interval_wall_time(std::numeric_limits<double>::max()),
42 interval_time_steps(std::numeric_limits<unsigned int>::max()),
43 counter(0),
44 do_output_in_this_time_step(false),
45 old_time_step_number(0)
46 {
47 }
48
49 void
50 print(dealii::ConditionalOStream const & pcout) const
51 {
52 pcout << " Solver information:" << std::endl;
53 print_parameter(pcout, "Interval physical time", interval_time);
54 print_parameter(pcout, "Interval wall time", interval_wall_time);
55 print_parameter(pcout, "Interval time steps", interval_time_steps);
56 }
57
58 bool
59 check_for_output(double const wall_time,
60 double const time,
61 types::time_step const time_step_number) const
62 {
63 // After a restart, the counter is reset to 1, but time = current_time - start time != 0 after a
64 // restart. Hence, we have to explicitly reset the counter in that case. There is nothing to do
65 // if the restart is controlled by the wall time or the time_step_number because these
66 // variables are reinitialized after a restart anyway.
67 if(time_step_number == 1)
68 {
69 counter += int((time + 1.e-10) / interval_time);
70 }
71
72 do_output_in_this_time_step = wall_time > interval_wall_time * counter or
73 time > interval_time * counter or
74 time_step_number % interval_time_steps == 0;
75
76 if(do_output_in_this_time_step)
77 {
78 ++counter;
79 }
80
81 return do_output_in_this_time_step;
82 }
83
84 bool
85 write(double const wall_time, double const time, types::time_step const time_step_number) const
86 {
87 if(time_step_number > old_time_step_number)
88 {
89 old_time_step_number = time_step_number;
90 return check_for_output(wall_time, time, time_step_number);
91 }
92 else
93 {
94 return do_output_in_this_time_step;
95 }
96 }
97
98 // physical time
99 double interval_time;
100
101 // wall time in seconds (= hours * 3600)
102 double interval_wall_time;
103
104 // number of time steps after which to write restart
105 unsigned int interval_time_steps;
106
107 // counter needed do decide when to write restart
108 mutable unsigned int counter;
109
110 // variable that stores whether output should be printed in current time step
111 mutable bool do_output_in_this_time_step;
112
113 // we need to store the old time step number since the function write() might be called multiple
114 // times during one time step
115 mutable unsigned int old_time_step_number;
116};
117
118} // namespace ExaDG
119
120
121#endif /* INCLUDE_FUNCTIONALITIES_SOLVER_INFO_DATA_H_ */
Definition driver.cpp:33
Definition solver_info_data.h:38