ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
h5md_specification.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2025 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "hdf5_patches.hpp" // must appear first
23
24#include "h5md_core.hpp"
25#include "h5md_dataset.hpp"
27
28#include <highfive/highfive.hpp>
29
30#include <hdf5.h>
31
32#include <algorithm>
33#include <filesystem>
34#include <string>
35#include <utility>
36
37namespace Writer {
38namespace H5md {
39
40Specification::Specification(unsigned int fields) {
41 auto const add_time_series = [this](Dataset &&dataset, bool link = true) {
42 auto const group = dataset.group;
43 m_datasets.push_back(std::move(dataset));
44 m_datasets.push_back({group, "step", 1, H5T_NATIVE_INT, 1, link});
45 m_datasets.push_back({group, "time", 1, H5T_NATIVE_DOUBLE, 1, link});
46 };
47
48 if (fields & H5MD_OUT_BOX_L) {
49 add_time_series({"/particles/atoms/box/edges", "value", 2,
50 H5T_NATIVE_DOUBLE, 3, false});
51 }
52 if (fields & H5MD_OUT_LE_OFF) {
53 add_time_series({"/particles/atoms/lees_edwards/offset", "value", 2,
54 H5T_NATIVE_DOUBLE, 1, false});
55 }
56 if (fields & H5MD_OUT_LE_DIR) {
57 add_time_series({"/particles/atoms/lees_edwards/direction", "value", 2,
58 H5T_NATIVE_INT, 1, false});
59 }
60 if (fields & H5MD_OUT_LE_NORMAL) {
61 add_time_series({"/particles/atoms/lees_edwards/normal", "value", 2,
62 H5T_NATIVE_INT, 1, false});
63 }
64 if (fields & H5MD_OUT_MASS) {
66 {"/particles/atoms/mass", "value", 2, H5T_NATIVE_DOUBLE, 1, false});
67 }
68 if (fields & H5MD_OUT_CHARGE) {
70 {"/particles/atoms/charge", "value", 2, H5T_NATIVE_DOUBLE, 1, false});
71 }
72 add_time_series({"/particles/atoms/id", "value", 2, H5T_NATIVE_INT, 1, false},
73 false);
74 if (fields & H5MD_OUT_TYPE) {
76 {"/particles/atoms/species", "value", 2, H5T_NATIVE_INT, 1, false});
77 }
78 if (fields & H5MD_OUT_POS) {
80 {"/particles/atoms/position", "value", 3, H5T_NATIVE_DOUBLE, 3, false});
81 }
82 if (fields & H5MD_OUT_VEL) {
84 {"/particles/atoms/velocity", "value", 3, H5T_NATIVE_DOUBLE, 3, false});
85 }
86 if (fields & H5MD_OUT_FORCE) {
88 {"/particles/atoms/force", "value", 3, H5T_NATIVE_DOUBLE, 3, false});
89 }
90 if (fields & H5MD_OUT_IMG) {
92 {"/particles/atoms/image", "value", 3, H5T_NATIVE_INT, 3, false});
93 }
94 if (fields & H5MD_OUT_BONDS) {
96 {"/connectivity/atoms", "value", 3, H5T_NATIVE_INT, 2, false});
97 }
98}
99
100bool Specification::is_compliant(std::filesystem::path const &file) const {
101 HighFive::File h5md_file(file.string(), HighFive::File::ReadOnly);
102
103 auto const all_groups_exist =
104 std::ranges::all_of(m_datasets, [&h5md_file](auto const &d) {
105 return h5md_file.exist(d.group);
106 });
107 auto const all_datasets_exist =
108 std::ranges::all_of(m_datasets, [&h5md_file](auto const &d) {
109 return h5md_file.exist(d.path());
110 });
112}
113
114} // namespace H5md
115} // namespace Writer
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
Specification(unsigned int fields)
bool is_compliant(std::filesystem::path const &file) const