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 EXADG_TIME_INTEGRATION_RESTART_DATA_H_
23#define EXADG_TIME_INTEGRATION_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/grid/grid_data.h>
33#include <exadg/incompressible_navier_stokes/user_interface/enum_types.h>
34#include <exadg/utilities/numbers.h>
35#include <exadg/utilities/print_functions.h>
36
37namespace ExaDG
38{
39struct RestartData
40{
41 RestartData()
42 : write_restart(false),
43 interval_time(std::numeric_limits<double>::max()),
44 interval_wall_time(std::numeric_limits<double>::max()),
45 interval_time_steps(std::numeric_limits<unsigned int>::max()),
46 directory("./output/"),
47 filename("restart"),
48 counter(1),
49 degree_u(dealii::numbers::invalid_unsigned_int),
50 degree_p(dealii::numbers::invalid_unsigned_int),
51 triangulation_type(TriangulationType::Serial),
52 spatial_discretization(IncNS::SpatialDiscretization::L2),
53 discretization_identical(false),
54 consider_mapping(false),
55 mapping_degree(dealii::numbers::invalid_unsigned_int),
56 rpe_tolerance_unit_cell(1e-12),
57 rpe_enforce_unique_mapping(false)
58 {
59 }
60
61 void
62 print(dealii::ConditionalOStream const & pcout) const
63 {
64 pcout << " Restart:" << std::endl;
65 print_parameter(pcout, "Write restart", write_restart);
66
67 if(write_restart == true)
68 {
69 print_parameter(pcout, "Interval physical time", interval_time);
70 print_parameter(pcout, "Interval wall time", interval_wall_time);
71 print_parameter(pcout, "Interval time steps", interval_time_steps);
72 print_parameter(pcout, "Directory", directory);
73 print_parameter(pcout, "Filename", filename);
74 }
75 }
76
77 bool
78 do_restart(double const wall_time,
79 double const time,
80 types::time_step const time_step_number,
81 bool const reset_counter) const
82 {
83 // After a restart, the counter is reset to 1, but time = current_time - start time != 0 after a
84 // restart. Hence, we have to explicitly reset the counter in that case. There is nothing to do
85 // if the restart is controlled by the wall time or the time_step_number because these
86 // variables are reinitialized after a restart anyway.
87 if(reset_counter)
88 counter += int((time + 1.e-10) / interval_time);
89
90 bool do_restart = wall_time > interval_wall_time * counter or time > interval_time * counter or
91 time_step_number > interval_time_steps * counter;
92
93 if(do_restart)
94 ++counter;
95
96 return do_restart;
97 }
98
99 bool write_restart;
100
101 // physical time
102 double interval_time;
103
104 // wall time in seconds (= hours * 3600)
105 double interval_wall_time;
106
107 // number of time steps after which to write restart
108 unsigned int interval_time_steps;
109
110 // directory for restart files
111 std::string directory;
112
113 // filename for restart files
114 std::string filename;
115
116 // counter needed do decide when to write restart
117 mutable unsigned int counter;
118
119 // Finite element degree used when restart data was written (relevant for restart run only).
120 unsigned int degree_u;
121 unsigned int degree_p;
122
123 // TriangulationType used when restart data was written (relevant for restart run only).
124 TriangulationType triangulation_type;
125
126 // Finite element space used when the restart data was written.
127 IncNS::SpatialDiscretization spatial_discretization;
128
129 // The discretization used when writing the restart data was identical to the current one.
130 // Note that this includes the finite element, uniform and adaptive refinement, and the
131 // `TriangulationType`, *but* one might consider a different number of MPI ranks for
132 // `dealii::parallel::distributed::Triangulation` without the need for the otherwise
133 // necessary global projection.
134 bool discretization_identical;
135
136 // The mapping of the triangulation should be de-/serialized as well to consider for a mapped
137 // geometry at serialization and during deserialization. This is option toggles storing the
138 // mapping via a displacement vector *and* reading it back in. Hence, this parameter needs to
139 // match in serialization/deserialization runs.
140 bool consider_mapping;
141
142 // The `mapping_degree` considered when storing or reading the grid.
143 unsigned int mapping_degree;
144
145 // Parameters for `dealii::RemotePointEvaluation` used for grid-to-grid projection.
146 double rpe_tolerance_unit_cell;
147 bool rpe_enforce_unique_mapping;
148};
149
150} // namespace ExaDG
151
152#endif /* EXADG_TIME_INTEGRATION_RESTART_DATA_H_ */
Definition driver.cpp:33