preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Export.cpp
Go to the documentation of this file.
1#include "io/Export.hpp"
2#include <filesystem>
3#include "utils/fmt.hpp"
4
5namespace precice::io {
6
8{
9 return _size > 1;
10};
11
13{
14 if (index == 0) {
15 return "init";
16 }
17 using std::string_literals::operator""s;
18 return ((_kind == ExportKind::TimeWindows) ? "dt"s : "it"s).append(std::to_string(index));
19}
20
22{
23 if (_records.empty())
24 return;
25
26 namespace fs = std::filesystem;
27 fs::path outfile(_location);
28 if (not _location.empty()) {
30 }
31 outfile /= filename;
32
33 // Prepare filestream
34 std::ofstream outFile(outfile.string(), std::ios::trunc);
35
36 outFile << R"({ "file-series-version" : "1.0", "files" : [)";
37
38 for (std::size_t i = 0; i < _records.size() - 1; ++i) {
39 outFile << fmt::format(R"( {{ "name" : "{}", "time" : {} }},)", _records[i].filename, _records[i].time);
40 }
41 outFile << fmt::format(R"( {{ "name" : "{}", "time" : {} }} ] }})", _records.back().filename, _records.back().time);
42}
43
44void Export::recordExport(std::string filename, double time)
45{
46 _records.push_back(Record{filename, time});
47}
48
49} // namespace precice::io
unsigned int index
void writeSeriesFile(std::string_view filename) const
Definition Export.cpp:21
std::string _location
Definition Export.hpp:65
bool isParallel() const
Definition Export.cpp:7
void recordExport(std::string filename, double time)
Definition Export.cpp:44
ExportKind _kind
Definition Export.hpp:67
std::vector< Record > _records
Definition Export.hpp:77
std::string formatIndex(int index) const
Definition Export.cpp:12
T create_directories(T... args)
T empty(T... args)
provides Import and Export of the coupling mesh and data.
T to_string(T... args)