ExaDG
Loading...
Searching...
No Matches
restart.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_RESTART_H_
23#define INCLUDE_EXADG_TIME_INTEGRATION_RESTART_H_
24
25// C/C++
26#include <fstream>
27#include <sstream>
28
29// deal.II
30#include <deal.II/base/mpi.h>
31
32namespace ExaDG
33{
34inline std::string
35restart_filename(std::string const & name, MPI_Comm const & mpi_comm)
36{
37 std::string const rank =
38 dealii::Utilities::int_to_string(dealii::Utilities::MPI::this_mpi_process(mpi_comm));
39
40 std::string const filename = name + "." + rank + ".restart";
41
42 return filename;
43}
44
45inline void
46rename_restart_files(std::string const & filename)
47{
48 // backup: rename current restart file into restart.old in case something fails while writing
49 std::string const from = filename;
50 std::string const to = filename + ".old";
51
52 std::ifstream ifile(from.c_str());
53 if((bool)ifile) // rename only if file already exists
54 {
55 int const error = rename(from.c_str(), to.c_str());
56
57 AssertThrow(error == 0, dealii::ExcMessage("Can not rename file: " + from + " -> " + to));
58 }
59}
60
61inline void
62write_restart_file(std::ostringstream & oss, std::string const & filename)
63{
64 std::ofstream stream(filename.c_str());
65
66 stream << oss.str() << std::endl;
67}
68
69} // namespace ExaDG
70
71#endif /* INCLUDE_EXADG_TIME_INTEGRATION_RESTART_H_ */
Definition driver.cpp:33