OGS
XdmfWriter.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "XdmfWriter.h"
5
6#include <fstream>
7
8#include "BaseLib/Logging.h"
9#include "BaseLib/RunTime.h"
10#include "writeXdmf.h"
11
12namespace MeshLib::IO
13{
14XdmfWriter::XdmfWriter(std::string xdmf_filename,
15 std::function<std::string(std::vector<double>)>
16 xdmf_writer_fn)
17 : filename(std::move(xdmf_filename)), xdmf_writer(xdmf_writer_fn)
18{
19}
20
22{
23 BaseLib::RunTime time_output;
24 time_output.start();
25 std::ofstream fout;
26 fout.open(filename);
27 fout << xdmf_writer(times);
28
29 INFO("[time] Output of XDMF to {:s} took {:g} s.",
31 time_output.elapsed());
32}
33
34void XdmfWriter::addTimeStep(double const& time_step)
35{
36 times.push_back(time_step);
37}
38
39} // namespace MeshLib::IO
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
Count the running time.
Definition RunTime.h:18
double elapsed() const
Get the elapsed time in seconds.
Definition RunTime.h:31
void start()
Start the timer.
Definition RunTime.h:21
std::function< std::string(std::vector< double >)> xdmf_writer
Definition XdmfWriter.h:38
std::vector< double > times
Definition XdmfWriter.h:37
XdmfWriter(std::string xdmf_filename, std::function< std::string(std::vector< double >)> xdmf_writer_fn)
Writes xdmf string into file on class destruction.
void addTimeStep(double const &time_step)
Adds data for lazy (xdmf) writing algorithm.