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 DeserializationParameters
40{
41 DeserializationParameters()
42 : degree(dealii::numbers::invalid_unsigned_int),
43 degree_u(dealii::numbers::invalid_unsigned_int),
44 degree_p(dealii::numbers::invalid_unsigned_int),
45 mapping_degree(dealii::numbers::invalid_unsigned_int),
46 consider_mapping_write(false),
47 triangulation_type(TriangulationType::Serial),
48 spatial_discretization(IncNS::SpatialDiscretization::L2)
49 {
50 }
51
52 void
53 print(dealii::ConditionalOStream const & pcout) const
54 {
55 pcout << " Deserialization parameters:" << std::endl;
56 print_parameter(pcout, "Polynomial degree `degree`", degree);
57 print_parameter(pcout, "Polynomial degree `degree_u`", degree_u);
58 print_parameter(pcout, "Polynomial degree `degree_p`", degree_p);
59 print_parameter(pcout, "Mapping degree", mapping_degree);
60 print_parameter(pcout, "Consider mapping", consider_mapping_write);
61 print_parameter(pcout, "Triangulation type", triangulation_type);
62 print_parameter(pcout, "Spatial discretization", spatial_discretization);
63 }
64
65 // Polynomial degrees of the finite elements used at serialization.
66 unsigned int degree;
67 unsigned int degree_u;
68 unsigned int degree_p;
69
70 // Polynomial degree of the mapping used at serialization.
71 unsigned int mapping_degree;
72
73 // The mapping is stored during serialization as a displacement vector.
74 bool consider_mapping_write;
75
76 // Triangulation type used at serialization.
77 TriangulationType triangulation_type;
78
79 // Spatial discretization used at serialization. Relevant for incompressible Navier-Stokes only.
80 IncNS::SpatialDiscretization spatial_discretization;
81};
82
83struct RestartData
84{
85 RestartData()
86 : write_restart(false),
87 n_snapshots_keep(2),
88 interval_time(std::numeric_limits<double>::max()),
89 interval_time_start(std::numeric_limits<double>::lowest()),
90 interval_time_end(std::numeric_limits<double>::max()),
91 interval_wall_time(std::numeric_limits<double>::max()),
92 interval_time_steps(std::numeric_limits<unsigned int>::max()),
93 directory_coarse_triangulation("./output/"),
94 directory("./output/"),
95 filename("restart"),
96 counter(1),
97 discretization_identical(false),
98 consider_mapping_write(false),
100 consider_restart_time_in_mesh_movement_function(true),
101 rpe_rtree_level(0),
102 rpe_tolerance_unit_cell(1e-12),
103 rpe_enforce_unique_mapping(false)
104 {
105 }
106
107 void
108 print(dealii::ConditionalOStream const & pcout) const
109 {
110 pcout << " Restart:" << std::endl;
111 print_parameter(pcout, "Write restart", write_restart);
112
113 if(write_restart == true)
114 {
115 print_parameter(pcout, "Interval physical time", interval_time);
116 print_parameter(pcout, "Interval physical time window start", interval_time_start);
117 print_parameter(pcout, "Interval physical time window end", interval_time_end);
118 print_parameter(pcout, "Interval wall time", interval_wall_time);
119 print_parameter(pcout, "Interval time steps", interval_time_steps);
120 print_parameter(pcout, "Directory coarse triangulation", directory_coarse_triangulation);
121 print_parameter(pcout, "Directory", directory);
122 print_parameter(pcout, "Filename", filename);
123 }
124 }
125
126 bool
127 do_restart(double const wall_time,
128 double const time,
129 types::time_step const time_step_number,
130 bool const reset_counter) const
131 {
132 // After a restart, the counter is reset to 1, but time = current_time - start time != 0 after a
133 // restart. Hence, we have to explicitly reset the counter in that case. There is nothing to do
134 // if the restart is controlled by the wall time or the time_step_number because these
135 // variables are reinitialized after a restart anyway.
136 if(reset_counter)
137 counter += int((time + 1.e-10) / interval_time);
138
139 bool const trigger_restart_base = wall_time > interval_wall_time * counter or
140 time > interval_time * counter or
141 time_step_number > interval_time_steps * counter;
142
143 // Additionally use the physical time window.
144 bool const trigger_restart =
145 trigger_restart_base and time >= interval_time_start and time <= interval_time_end;
146
147 if(trigger_restart)
148 ++counter;
149
150 return trigger_restart;
151 }
152
153 bool write_restart;
154
155 // Number of snapshots to keep
156 unsigned int n_snapshots_keep;
157
158 // physical time interval between serializations
159 double interval_time;
160
161 // physical time interval in which serialization is enabled
162 double interval_time_start;
163 double interval_time_end;
164
165 // wall time in seconds (= hours * 3600)
166 double interval_wall_time;
167
168 // number of time steps after which to write restart
169 unsigned int interval_time_steps;
170
171 // directory for restart files: coarse triangulation and snapshot data can be stored separately.
172 std::string directory_coarse_triangulation;
173 std::string directory;
174
175 // filename for restart files
176 std::string filename;
177
178 // counter needed do decide when to write restart
179 mutable unsigned int counter;
180
181 // The discretization used when writing the restart data was identical to the current one.
182 // Note that this includes the finite element, uniform and adaptive refinement, and the
183 // `TriangulationType`, *but* one might consider a different number of MPI ranks for
184 // `dealii::parallel::distributed::Triangulation` without the need for the otherwise
185 // necessary global projection.
186 bool discretization_identical;
187
188 // Attach the mapping as a displacement vector when *writing* the restart data.
189 bool consider_mapping_write;
190
197
198 // Reconstruct the mapping for the serialized grid (`source`) in the grid-to-grid projection at
199 // restart. Note that the grid use at restart is always considered as defined in the applciation.
201
202 // When creating a mapping function via `create_mesh_movement_function()`, use the `start_time` or
203 // the `time` serialized to evaluate the mapping at restart.
204 bool consider_restart_time_in_mesh_movement_function;
205
206 // Parameters for `dealii::Utilities::MPI::RemotePointEvaluation<dim>::RemotePointEvaluation`
207 // used for grid-to-grid projection.
208 unsigned int rpe_rtree_level;
209 double rpe_tolerance_unit_cell;
210 bool rpe_enforce_unique_mapping;
211};
212
213} // namespace ExaDG
214
215#endif /* EXADG_TIME_INTEGRATION_RESTART_DATA_H_ */
Definition driver.cpp:33
bool consider_mapping_read_source
Definition restart_data.h:200