ExaDG
Loading...
Searching...
No Matches
time_int_base.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_INT_BASE_H_
23#define INCLUDE_EXADG_TIME_INTEGRATION_TIME_INT_BASE_H_
24
25// C/C++
26#include <boost/archive/binary_iarchive.hpp>
27#include <boost/archive/binary_oarchive.hpp>
28#include <boost/archive/text_iarchive.hpp>
29#include <boost/archive/text_oarchive.hpp>
30
31#include <fstream>
32#include <sstream>
33
34// deal.II
35#include <deal.II/base/conditional_ostream.h>
36#include <deal.II/base/timer.h>
37
38// ExaDG
39#include <exadg/time_integration/restart.h>
40#include <exadg/time_integration/restart_data.h>
41#include <exadg/utilities/numbers.h>
42#include <exadg/utilities/timer_tree.h>
43
44
45namespace ExaDG
46{
47class TimeIntBase
48{
49public:
50 // Archive type used for serialization, alternatively choose text archive type.
51 typedef boost::archive::binary_iarchive BoostInputArchiveType;
52 typedef boost::archive::binary_oarchive BoostOutputArchiveType;
53 // typedef boost::archive::text_iarchive BoostInputArchiveType;
54 // typedef boost::archive::text_oarchive BoostOutputArchiveType;
55
56 TimeIntBase(double const & start_time_,
57 double const & end_time_,
58 unsigned int const max_number_of_time_steps_,
59 RestartData const & restart_data_,
60 MPI_Comm const & mpi_comm_,
61 bool const is_test_);
62
63 virtual ~TimeIntBase()
64 {
65 }
66
67 /*
68 * Setup of time integration scheme.
69 */
70 virtual void
71 setup(bool const do_restart) = 0;
72
73 /*
74 * Returns true if the start time has been reached.
75 */
76 bool
77 started() const;
78
79 /*
80 * returns true if the end of time loop has been reached or the maximum number of time steps
81 */
82 bool
83 finished() const;
84
85 /*
86 * Performs the time loop from start_time to end_time by repeatingly calling
87 * advance_one_timestep().
88 */
89 void
90 timeloop();
91
92 /*
93 * Perform only one time step (which is used when coupling different solvers, equations, etc.).
94 */
95 void
96 advance_one_timestep();
97
98 /*
99 * The main sub-routines of advance_one_timestep()
100 */
101 void
102 advance_one_timestep_pre_solve(bool const print_header);
103
104 void
105 advance_one_timestep_solve();
106
107 void
108 advance_one_timestep_post_solve();
109
110 /*
111 * Reset the current time.
112 */
113 void
114 reset_time(double const & current_time);
115
116 /*
117 * In case of adaptive mesh refinement, the driver requests preparing the owned vectors
118 * for refinement and interpolation afterwards.
119 */
120 virtual void
121 prepare_coarsening_and_refinement();
122
123 virtual void
124 interpolate_after_coarsening_and_refinement();
125
126 /*
127 * Get the time step size.
128 */
129 virtual double
130 get_time_step_size() const = 0;
131
132 /*
133 * Set the time step size.
134 */
135 virtual void
136 set_current_time_step_size(double const & time_step_size) = 0;
137
138 /*
139 * Get the current time t_{n}.
140 */
141 double
142 get_time() const;
143
144 /*
145 * Get time at the end of the current time step t_{n+1}.
146 */
147 double
148 get_next_time() const;
149
150 /*
151 * Get number of computed time steps
152 */
153 unsigned int
154 get_number_of_time_steps() const;
155
156 std::shared_ptr<TimerTree>
157 get_timings() const;
158
159protected:
160 /*
161 * Do one time step including pre and post routines done before and after the actual solution of
162 * the current time step. Compared to the function advance_one_timestep(), do_timestep() is a raw
163 * version that does not call postprocessing routines, does not write output to pcout, and does
164 * not perform timer measurements within its sub-routines. The typical use case of do_timestep()
165 * is when using pseudo-timestepping to obtain the solution of a steady-state problem with a
166 * transient solver.
167 */
168 void
169 do_timestep();
170
171 /*
172 * e.g., update of time integrator constants
173 */
174 virtual void
175 do_timestep_pre_solve(bool const print_header) = 0;
176
177 /*
178 * The actual solution of the current time step
179 */
180 virtual void
181 do_timestep_solve() = 0;
182
183 /*
184 * e.g., update of DoF vectors, increment time, adjust time step size, etc.
185 */
186 virtual void
187 do_timestep_post_solve() = 0;
188
189 /*
190 * Postprocessing of solution.
191 */
192 virtual void
193 postprocessing() const = 0;
194
195 /*
196 * Get the current time step number.
197 */
198 types::time_step
199 get_time_step_number() const;
200
201 /*
202 * Write solution vectors to files so that the simulation can be restart from an intermediate
203 * state. Note that the sequence of writing and reading data in `write_restart` and `read_restart`
204 * needs to be identical.
205 */
206 void
207 write_restart() const;
208
209 /*
210 * Read all relevant data from restart files to start the time integrator. Note that the sequence
211 * of writing and reading data in `write_restart` and `read_restart` needs to be identical.
212 */
213 void
214 read_restart();
215
216 /*
217 * Output solver information before solving the time step.
218 */
219 void
220 output_solver_info_header() const;
221
222
223 /*
224 * Output estimated computation time until completion of the simulation.
225 */
226 void
227 output_remaining_time() const;
228
229 /*
230 * Start and end times.
231 */
232 double start_time, end_time;
233
234 /*
235 * Physical time.
236 */
237 double time;
238
239 /*
240 * A small number which is much smaller than the time step size.
241 */
242 double const eps;
243
244 /*
245 * Output to screen.
246 */
247 dealii::ConditionalOStream pcout;
248
249 /*
250 * The number of the current time step starting with time_step_number = 1.
251 */
252 types::time_step time_step_number;
253
254 /*
255 * Maximum number of time steps.
256 */
257 unsigned int const max_number_of_time_steps;
258
259 /*
260 * Restart.
261 */
262 RestartData const restart_data;
263
264 /*
265 * MPI communicator.
266 */
267 MPI_Comm const mpi_comm;
268
269 /*
270 * Computation time (wall clock time).
271 */
272 dealii::Timer global_timer;
273 std::shared_ptr<TimerTree> timer_tree;
274 bool is_test;
275
276private:
277 /*
278 * Write restart data.
279 */
280 virtual void
281 do_write_restart(std::string const & filename) const = 0;
282
283 /*
284 * Read restart data.
285 */
286 virtual void
287 do_read_restart(std::ifstream & in) = 0;
288};
289
290} // namespace ExaDG
291
292
293#endif /* INCLUDE_EXADG_TIME_INTEGRATION_TIME_INT_BASE_H_ */
Definition driver.cpp:33
Definition restart_data.h:38