Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
pvd_handler.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2019-2020, 2024 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#include <core/pvd_handler.h>
5#include <core/utilities.h>
6
7#include <fstream>
8
9using namespace dealii;
10
11void
12PVDHandler::save(const std::string &prefix) const
13{
14 std::string filename = prefix + ".pvdhandler";
15 std::ofstream output(filename.c_str());
16 output << times_and_names.size() << std::endl;
17 output << "Time File" << std::endl;
18 for (const auto &time_name : times_and_names)
19 {
20 output << time_name.first << " " << time_name.second << std::endl;
21 }
22}
23
24void
25PVDHandler::read(const std::string &prefix)
26{
27 times_and_names.clear();
28 std::string filename = prefix + ".pvdhandler";
29 check_file_exists(filename,
30 "checkpoint file of the pvd handler, given by "
31 "'subsection restart' - 'set filename'");
32 std::ifstream input(filename.c_str());
33
34 std::string buffer;
35 unsigned int size;
36 input >> size;
37
38 std::getline(input, buffer);
39 std::getline(input, buffer);
40 for (unsigned int i = 0; i < size; ++i)
41 {
42 double time;
43 std::string filename_i;
44 input >> time;
45 input >> filename_i;
46 append(time, filename_i);
47 }
48
49 if (size != times_and_names.size())
50 throw std::runtime_error("Error when reading pvd restart file ");
51}
void read(const std::string &filename)
read Reads the content of a pvd times_and_names checpoint
std::vector< std::pair< double, std::string > > times_and_names
Definition pvd_handler.h:43
void append(double time, const std::string &pvtu_filename)
Definition pvd_handler.h:36
void save(const std::string &filename) const
save Saves the content of the pvd times_and_names to a file
void check_file_exists(const std::string &file_name, const std::string &file_description)
Verify that a file that Lethe must read exists and can be opened, and raise an error stated in the us...
Definition utilities.cc:225