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-2026 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(Dataset{group, "step", 1, H5T_NATIVE_INT, 1, link});
45 m_datasets.push_back(Dataset{group, "time", 1, H5T_NATIVE_DOUBLE, 1, link});
46 };
47
48 if (fields & H5MD_OUT_BOX_L) {
49 add_time_series(Dataset{"/particles/atoms/box/edges", "value", 2,
50 H5T_NATIVE_DOUBLE, 3, false});
51 }
52 if (fields & H5MD_OUT_LE_OFF) {
53 add_time_series(Dataset{"/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(Dataset{"/particles/atoms/lees_edwards/direction", "value",
58 2, H5T_NATIVE_INT, 1, false});
59 }
60 if (fields & H5MD_OUT_LE_NORMAL) {
61 add_time_series(Dataset{"/particles/atoms/lees_edwards/normal", "value", 2,
62 H5T_NATIVE_INT, 1, false});
63 }
64 if (fields & H5MD_OUT_MASS) {
65 add_time_series(Dataset{"/particles/atoms/mass", "value", 2,
66 H5T_NATIVE_DOUBLE, 1, false});
67 }
68 if (fields & H5MD_OUT_CHARGE) {
69 add_time_series(Dataset{"/particles/atoms/charge", "value", 2,
70 H5T_NATIVE_DOUBLE, 1, false});
71 }
73 Dataset{"/particles/atoms/id", "value", 2, H5T_NATIVE_INT, 1, false},
74 false);
75 if (fields & H5MD_OUT_TYPE) {
76 add_time_series(Dataset{"/particles/atoms/species", "value", 2,
77 H5T_NATIVE_INT, 1, false});
78 }
79 if (fields & H5MD_OUT_POS) {
80 add_time_series(Dataset{"/particles/atoms/position", "value", 3,
81 H5T_NATIVE_DOUBLE, 3, false});
82 }
83 if (fields & H5MD_OUT_VEL) {
84 add_time_series(Dataset{"/particles/atoms/velocity", "value", 3,
85 H5T_NATIVE_DOUBLE, 3, false});
86 }
87 if (fields & H5MD_OUT_FORCE) {
88 add_time_series(Dataset{"/particles/atoms/force", "value", 3,
89 H5T_NATIVE_DOUBLE, 3, false});
90 }
91 if (fields & H5MD_OUT_IMG) {
92 add_time_series(Dataset{"/particles/atoms/image", "value", 3,
93 H5T_NATIVE_INT, 3, false});
94 }
95 if (fields & H5MD_OUT_BONDS) {
97 Dataset{"/connectivity/atoms", "value", 3, H5T_NATIVE_INT, 2, false});
98 }
99}
100
101bool Specification::is_compliant(std::filesystem::path const &file) const {
102 HighFive::File h5md_file(file.string(), HighFive::File::ReadOnly);
103
104 auto const all_groups_exist =
105 std::ranges::all_of(m_datasets, [&h5md_file](auto const &d) {
106 return h5md_file.exist(d.group);
107 });
108 auto const all_datasets_exist =
109 std::ranges::all_of(m_datasets, [&h5md_file](auto const &d) {
110 return h5md_file.exist(d.path());
111 });
113}
114
115} // namespace H5md
116} // 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