preCICE
Loading...
Searching...
No Matches
src
io
Export.cpp
Go to the documentation of this file.
1
#include "
io/Export.hpp
"
2
#include <filesystem>
3
#include "
utils/fmt.hpp
"
4
5
namespace
precice::io
{
6
7
bool
Export::isParallel
()
const
8
{
9
return
_size
> 1;
10
};
11
12
std::string
Export::formatIndex
(
int
index)
const
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
21
void
Export::writeSeriesFile
(std::string_view filename)
const
22
{
23
if
(
_records
.empty())
24
return
;
25
26
namespace
fs = std::filesystem;
27
fs::path outfile(
_location
);
28
if
(not
_location
.empty()) {
29
fs::create_directories(outfile);
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
44
void
Export::recordExport
(std::string filename,
double
time
)
45
{
46
_records
.push_back(
Record
{filename,
time
});
47
}
48
49
}
// namespace precice::io
Export.hpp
precice::io::Export::_size
int _size
Definition
Export.hpp:70
precice::io::Export::writeSeriesFile
void writeSeriesFile(std::string_view filename) const
Definition
Export.cpp:21
precice::io::Export::_location
std::string _location
Definition
Export.hpp:65
precice::io::Export::isParallel
bool isParallel() const
Definition
Export.cpp:7
precice::io::Export::recordExport
void recordExport(std::string filename, double time)
Definition
Export.cpp:44
precice::io::Export::_kind
ExportKind _kind
Definition
Export.hpp:67
precice::io::Export::_records
std::vector< Record > _records
Definition
Export.hpp:77
precice::io::Export::ExportKind::TimeWindows
@ TimeWindows
Definition
Export.hpp:19
precice::io::Export::formatIndex
std::string formatIndex(int index) const
Definition
Export.cpp:12
fmt.hpp
precice::io
provides Import and Export of the coupling mesh and data.
Definition
Acceleration.hpp:10
precice::time
contains the time interpolation logic.
Definition
Sample.hpp:8
precice::io::Export::Record
Definition
Export.hpp:72