22#ifndef CORE_IO_WRITER_H5MD_CORE_HPP
23#define CORE_IO_WRITER_H5MD_CORE_HPP
31#include <boost/filesystem.hpp>
32#include <boost/mpi/communicator.hpp>
34#include <h5xx/h5xx.hpp>
40#include <unordered_map>
44template <
typename T, std::
size_t size>
45struct is_array<
Utils::Vector<T, size>> : std::true_type {};
73static std::unordered_map<std::string, H5MDOutputFields>
const fields_map = {
91 for (
auto const &field_name : fields) {
93 throw std::invalid_argument(
"Unknown field '" + field_name +
"'");
119 std::vector<std::string>
const &output_fields, std::string
mass_unit,
122 boost::mpi::communicator comm = boost::mpi::communicator())
128 m_charge_unit(std::move(
charge_unit)), m_comm(std::move(comm)),
130 m_h5md_specification(m_fields) {
204 std::vector<std::string> out = {};
206 out.push_back(kv.first);
220 void init_file(std::string
const &
file_path);
226 void create_file(
const std::string &
file_path);
232 void load_file(
const std::string &
file_path);
237 void create_groups();
243 void create_datasets();
248 void load_datasets();
263 void create_hard_links();
265 std::string m_script_path;
266 std::string m_mass_unit;
267 std::string m_length_unit;
268 std::string m_time_unit;
269 std::string m_force_unit;
270 std::string m_velocity_unit;
271 std::string m_charge_unit;
272 boost::mpi::communicator m_comm;
273 unsigned int m_fields;
274 std::string m_backup_filename;
275 boost::filesystem::path m_absolute_script_path;
276 h5xx::file m_h5md_file;
277 std::unordered_map<std::string, h5xx::dataset> datasets;
282 const char *
what() const noexcept
override {
283 return "The given .h5 file does not match the specifications in 'fields'.";
288 const char *
what() const noexcept
override {
289 return "A backup of the .h5 file exists. This usually means that either "
290 "you forgot to call the 'close' method or your simulation crashed.";
Vector implementation and trait types for boost qvm interoperability.
Class for writing H5MD files.
void write(const ParticleRange &particles, double time, int step, BoxGeometry const &geometry)
Write data to the hdf5 file.
auto const & length_unit() const
Retrieve the set length unit.
auto const & time_unit() const
Retrieve the set time unit.
auto file_path() const
Retrieve the path to the hdf5 file.
void close()
Method to perform the renaming of the temporary file from "filename" + ".bak" to "filename".
auto const & force_unit() const
Retrieve the set force unit.
File(std::string file_path, std::string script_path, std::vector< std::string > const &output_fields, std::string mass_unit, std::string length_unit, std::string time_unit, std::string force_unit, std::string velocity_unit, std::string charge_unit, boost::mpi::communicator comm=boost::mpi::communicator())
Constructor.
auto const & mass_unit() const
Retrieve the set mass unit.
auto const & charge_unit() const
Retrieve the set charge unit.
auto const & velocity_unit() const
Retrieve the set velocity unit.
auto valid_fields() const
Build the list of valid output fields.
auto const & script_path() const
Retrieve the path to the simulation script.
void flush()
Method to enforce flushing the buffer to disk.
auto fields_list_to_bitfield(std::vector< std::string > const &fields)
H5MDOutputFields
Constants which indicate what to output.
static std::unordered_map< std::string, H5MDOutputFields > const fields_map
Layout information for H5MD files.
const char * what() const noexcept override
const char * what() const noexcept override