Skip to content
Snippets Groups Projects
Commit 6fb5933d authored by Tobias Meisel's avatar Tobias Meisel
Browse files

[MeL/IO] XDMF: Add XdmfWriter RAII class

parent cf284892
No related branches found
No related tags found
No related merge requests found
#include "XdmfWriter.h"
#include <fstream>
#include "writeXdmf.h"
#include "BaseLib/RunTime.h"
#include "BaseLib/Logging.h"
namespace MeshLib::IO
{
XdmfWriter::XdmfWriter(std::string const& xdmf_filename,
std::function<std::string(std::vector<double>)>
xdmf_writer_fn)
: filename(xdmf_filename), xdmf_writer(xdmf_writer_fn)
{
}
XdmfWriter::~XdmfWriter()
{
BaseLib::RunTime time_output;
time_output.start();
std::ofstream fout;
fout.open(this->filename);
fout << xdmf_writer(times);
INFO("[time] Output of XDMF took {:g} s.", time_output.elapsed());
}
void XdmfWriter::addTimeStep(double const& time_step)
{
times.push_back(time_step);
}
} // namespace MeshLib::IO
\ No newline at end of file
/**
* \file
* \author Tobias Meisel
* \date 2021-06-30
* \brief Collects and holds all metadata for writing XDMF file
* \copyright
* Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*/
#pragma once
#include <functional>
#include <string>
namespace MeshLib::IO
{
class XdmfWriter final
{
public:
/**
* \brief Writes xdmf string into file on class destruction
* @param xdmf_filename absolute or relative filepath to the xdmf file
* @param xdmf_writer_fn function that generates xdmf string
*/
XdmfWriter(std::string const& xdmf_filename,
std::function<std::string(std::vector<double>)>
xdmf_writer_fn);
XdmfWriter(XdmfWriter&&) = default;
XdmfWriter& operator=(XdmfWriter&&) = default;
XdmfWriter(XdmfWriter const&) = delete;
XdmfWriter& operator=(XdmfWriter const&) = delete;
~XdmfWriter();
/**
* \brief Adds data for lazy (xdmf) writing algorithm
* @param time_step time value of the current time_step
*/
void addTimeStep(double const& time_step);
private:
std::string filename;
std::vector<double> times;
std::function<std::string(std::vector<double>)> xdmf_writer;
};
} // namespace MeshLib::IO
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment