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