Skip to content

Commit a4a9262

Browse files
committed
++
1 parent 460ebf0 commit a4a9262

File tree

3 files changed

+43
-53
lines changed

3 files changed

+43
-53
lines changed

src/diagnostic/detail/vtk_types/fluid.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ void FluidDiagnosticWriter<H5Writer>::write(DiagnosticProperties& diagnostic)
5757
std::string tree{"/ions/pop/" + pop.name() + "/"};
5858
if (isActiveDiag(diagnostic, tree, "density"))
5959
initializer.writeField(pop.particleDensity(), layout);
60-
if (isActiveDiag(diagnostic, tree, "charge_density"))
60+
else if (isActiveDiag(diagnostic, tree, "charge_density"))
6161
initializer.writeField(pop.chargeDensity(), layout);
62-
if (isActiveDiag(diagnostic, tree, "flux"))
62+
else if (isActiveDiag(diagnostic, tree, "flux"))
6363
initializer.template writeTensorField<1>(pop.flux(), layout);
6464
}
6565
}

src/diagnostic/detail/vtkh5_type_writer.hpp

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@
1717

1818

1919

20-
namespace PHARE::diagnostic::vtkh5::detail
21-
{
22-
23-
// some testing shows 32 to be the max value supported, something to do with a value `H5S_MAX_RANK`
24-
static inline auto const CHUNK_SIZE = core::get_env_as("PHARE_VTK_H5_CHUNK_SIZE", std::size_t{32});
25-
26-
} // namespace PHARE::diagnostic::vtkh5::detail
27-
28-
2920
namespace PHARE::diagnostic::vtkh5
3021
{
3122

@@ -55,7 +46,7 @@ class H5TypeWriter : public PHARE::diagnostic::TypeWriter
5546
// data is duplicated in lower dimensions to fit a 3d view
5647
// so 2d data is * 2
5748
// and 1d data is * 4
58-
constexpr static auto X_TIMES = std::array{4, 2, /* 3d noop */ 1}[dimension - 1];
49+
constexpr static auto X_TIMES = std::array{4, 2, 1}[dimension - 1];
5950

6051
auto static flatten_boxes(auto const& boxes)
6152
{
@@ -126,7 +117,8 @@ struct H5TypeWriter<Writer>::VTKFileWriter
126117
{
127118
// set global per file attributes and datasets
128119
{
129-
initDSDefault(base + "/Steps/Values");
120+
h5file.create_resizable_1d_data_set<FloatType>(base + "/Steps/Values");
121+
130122
auto steps_group = h5file.file().getGroup(base + "/Steps");
131123
if (!steps_group.hasAttribute("NSteps"))
132124
steps_group.template createAttribute<int>("NSteps", HighFive::DataSpace::From(0))
@@ -199,47 +191,22 @@ struct H5TypeWriter<Writer>::VTKFileWriter
199191
}
200192
}
201193

202-
template<typename T = FloatType>
203-
void initDS(auto const& path, auto const& ds) const
204-
{
205-
h5file.template create_chunked_data_set<T>(path, std::vector<hsize_t>{detail::CHUNK_SIZE},
206-
ds);
207-
}
208194

209-
template<typename T = FloatType>
210-
void initDSDefault(auto const& path) const
211-
{
212-
initDS<T>(path, HighFive::DataSpace({0}, {HighFive::DataSpace::UNLIMITED}));
213-
}
214195

215196
void initFileLevel(int const level) const
216197
{
217198
auto const lvl = std::to_string(level);
218199

219-
{
220-
auto const path = level_base + lvl + "/AMRBox";
221-
h5file.template create_chunked_data_set<int>(
222-
path, std::vector<hsize_t>{detail::CHUNK_SIZE, boxValsIn3D},
223-
HighFive::DataSpace({0, boxValsIn3D},
224-
{HighFive::DataSpace::UNLIMITED, boxValsIn3D}));
225-
}
226-
227-
auto const chucked_int_datasets
228-
= std::array{step_level + lvl + "/PointDataOffset/data",
229-
step_level + lvl + "/AMRBoxOffset", step_level + lvl + "/NumberOfAMRBox"};
230-
231-
for (auto const& path : chucked_int_datasets)
232-
{
233-
h5file.template create_chunked_data_set<int>(
234-
path, std::vector<hsize_t>{detail::CHUNK_SIZE},
235-
HighFive::DataSpace({0}, {HighFive::DataSpace::UNLIMITED}));
236-
}
200+
h5file.create_resizable_2d_data_set<int, boxValsIn3D>(level_base + lvl + "/AMRBox");
201+
h5file.create_resizable_1d_data_set<int>(step_level + lvl + "/PointDataOffset/data");
202+
h5file.create_resizable_1d_data_set<int>(step_level + lvl + "/AMRBoxOffset");
203+
h5file.create_resizable_1d_data_set<int>(step_level + lvl + "/NumberOfAMRBox");
237204

238205
auto level_group = h5file.file().getGroup(level_base + lvl);
239206
if (!level_group.hasAttribute("Spacing"))
240207
{
241-
level_group.template createAttribute<std::array<float, dimension>>(
242-
"Spacing", level_spacing(level));
208+
level_group.createAttribute<std::array<float, dimension>>("Spacing",
209+
level_spacing(level));
243210

244211
level_group.createGroup("CellData");
245212
level_group.createGroup("FieldData");
@@ -253,10 +220,8 @@ struct H5TypeWriter<Writer>::VTKFileWriter
253220
template<std::size_t N = 1>
254221
void initAnyFieldLevel(int const level, auto& boxes)
255222
{
256-
auto const path = level_base + std::to_string(level) + "/PointData/data";
257-
h5file.template create_chunked_data_set<FloatType>(
258-
path, std::vector<hsize_t>{detail::CHUNK_SIZE, N},
259-
HighFive::DataSpace({0, N}, {HighFive::DataSpace::UNLIMITED, N}));
223+
auto const lvl = std::to_string(level);
224+
h5file.create_resizable_2d_data_set<FloatType, N>(level_base + lvl + "/PointData/data");
260225
resize<N>(level, boxes);
261226
}
262227

src/hdf5/detail/h5/h5_file.hpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,24 @@
33

44
#include "core/def.hpp"
55
#include "core/def/phare_mpi.hpp" // IWYU pragma: keep
6-
#include "highfive/H5File.hpp"
7-
#include "highfive/H5Easy.hpp"
8-
96
#include "core/utilities/types.hpp"
107
#include "core/utilities/mpi_utils.hpp"
118
#include "core/utilities/meta/meta_utilities.hpp"
129

10+
11+
#include "highfive/H5File.hpp"
12+
#include "highfive/H5Easy.hpp"
13+
14+
15+
16+
namespace PHARE::hdf5::h5::detail
17+
{
18+
19+
// some testing shows 32 to be the max value supported, something to do with a value `H5S_MAX_RANK`
20+
static inline auto const CHUNK_SIZE = core::get_env_as("PHARE_H5_CHUNK_SIZE", std::size_t{32});
21+
22+
} // namespace PHARE::hdf5::h5::detail
23+
1324
namespace PHARE::hdf5::h5
1425
{
1526
using HiFile = HighFive::File;
@@ -107,14 +118,28 @@ class HighFiveFile
107118
{
108119
if (exist(path))
109120
return h5file_.getDataSet(path);
110-
111-
112121
createGroupsToDataSet(path);
113122
HighFive::DataSetCreateProps props;
114123
props.add(HighFive::Chunking{chunk});
115124
return h5file_.createDataSet(path, dataspace, HighFive::create_datatype<Type>(), props);
116125
}
117126

127+
template<typename Type, std::size_t cols>
128+
auto create_resizable_2d_data_set(auto const& path)
129+
{
130+
return create_chunked_data_set<Type>(
131+
path, std::vector<hsize_t>{detail::CHUNK_SIZE, cols},
132+
HighFive::DataSpace({0, cols}, {HighFive::DataSpace::UNLIMITED, cols}));
133+
}
134+
135+
template<typename Type>
136+
auto create_resizable_1d_data_set(auto const& path)
137+
{
138+
return create_chunked_data_set<Type>(
139+
path, std::vector<hsize_t>{detail::CHUNK_SIZE},
140+
HighFive::DataSpace({0}, {HighFive::DataSpace::UNLIMITED}));
141+
}
142+
118143

119144
/*
120145
* Communicate all dataset paths and sizes to all MPI process to allow each to create all

0 commit comments

Comments
 (0)