Skip to content

Commit 89d2ec8

Browse files
committed
wip vtkh5
1 parent bce6d0c commit 89d2ec8

File tree

13 files changed

+847
-264
lines changed

13 files changed

+847
-264
lines changed

pyphare/pyphare/pharein/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ def as_paths(rb):
331331
)
332332

333333
if len(simulation.diagnostics) > 0:
334+
if simulation.diag_options is not None and "format" in simulation.diag_options:
335+
add_string(diag_path + "format", simulation.diag_options["format"])
336+
334337
if simulation.diag_options is not None and "options" in simulation.diag_options:
335338
add_string(
336339
diag_path + "filePath", simulation.diag_options["options"]["dir"]

pyphare/pyphare/pharein/simulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def check_directory(directory, key):
489489
# diag_options = {"format":"phareh5", "options": {"dir": "phare_ouputs/"}}
490490
def check_diag_options(**kwargs):
491491
diag_options = kwargs.get("diag_options", None)
492-
formats = ["phareh5"]
492+
formats = ["phareh5", "pharevtkh5"]
493493
if diag_options is not None and "format" in diag_options:
494494
if diag_options["format"] not in formats:
495495
raise ValueError("Error - diag_options format is invalid")

src/diagnostic/detail/h5writer.hpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
#define PHARE_DETAIL_DIAGNOSTIC_HIGHFIVE_HPP
33

44

5-
#include "core/data/vecfield/vecfield_component.hpp"
6-
#include "core/utilities/mpi_utils.hpp"
75
#include "core/utilities/types.hpp"
8-
#include "core/utilities/meta/meta_utilities.hpp"
6+
#include "core/utilities/mpi_utils.hpp"
7+
#include "core/data/vecfield/vecfield_component.hpp"
98

109
#include "hdf5/detail/h5/h5_file.hpp"
1110

12-
#include "diagnostic/detail/h5typewriter.hpp"
13-
#include "diagnostic/diagnostic_manager.hpp"
1411
#include "diagnostic/diagnostic_props.hpp"
12+
#include "diagnostic/detail/h5typewriter.hpp"
13+
#include "diagnostic/detail/types/info.hpp"
14+
#include "diagnostic/detail/types/meta.hpp"
15+
#include "diagnostic/detail/types/fluid.hpp"
16+
#include "diagnostic/detail/types/particle.hpp"
17+
#include "diagnostic/detail/types/electromag.hpp"
1518

1619

1720
#if !defined(PHARE_DIAG_DOUBLES)
@@ -23,17 +26,6 @@ namespace PHARE::diagnostic::h5
2326
{
2427
using namespace hdf5::h5;
2528

26-
template<typename Writer>
27-
class ElectromagDiagnosticWriter;
28-
template<typename Writer>
29-
class FluidDiagnosticWriter;
30-
template<typename Writer>
31-
class ParticlesDiagnosticWriter;
32-
template<typename Writer>
33-
class MetaDiagnosticWriter;
34-
template<typename Writer>
35-
class InfoDiagnosticWriter;
36-
3729

3830

3931
template<typename ModelView>
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#ifndef PHARE_DIAGNOSTIC_DETAIL_VTK_H5_TYPE_WRITER_HPP
2+
#define PHARE_DIAGNOSTIC_DETAIL_VTK_H5_TYPE_WRITER_HPP
3+
4+
#include <string>
5+
#include <unordered_map>
6+
7+
#include "core/utilities/mpi_utils.hpp"
8+
9+
#include "diagnostic/diagnostic_writer.hpp"
10+
11+
#include "hdf5/detail/h5/h5_file.hpp"
12+
13+
14+
namespace PHARE::diagnostic::vtkh5
15+
{
16+
using namespace hdf5::h5;
17+
18+
template<typename Writer>
19+
class H5TypeWriter : public PHARE::diagnostic::TypeWriter
20+
{
21+
public:
22+
using Attributes = typename Writer::Attributes;
23+
static constexpr auto dimension = Writer::dimension;
24+
25+
H5TypeWriter(Writer& h5Writer)
26+
: h5Writer_{h5Writer}
27+
{
28+
}
29+
30+
//------ defined by each concrete H5TypeWriter---------------------------
31+
// virtual void createFiles(DiagnosticProperties& diagnostic) = 0;
32+
33+
// virtual void getDataSetInfo(DiagnosticProperties& diagnostic, std::size_t iLevel,
34+
// std::string const& patchID, Attributes& patchAttributes)
35+
// = 0;
36+
37+
// virtual void
38+
// initDataSets(DiagnosticProperties& diagnostic,
39+
// std::unordered_map<std::size_t, std::vector<std::string>> const& patchIDs,
40+
// Attributes& patchAttributes, std::size_t maxLevel)
41+
// = 0;
42+
43+
// virtual void writeAttributes(
44+
// DiagnosticProperties&, Attributes&,
45+
// std::unordered_map<std::size_t, std::vector<std::pair<std::string, Attributes>>>&,
46+
// std::size_t maxLevel)
47+
// = 0;
48+
//------------------------------------------------------------------------
49+
50+
51+
52+
//------ valid for all h5type writers -------------------------------------
53+
void finalize(DiagnosticProperties& diagnostic)
54+
{
55+
// // we close the file by removing the associated file
56+
// // from the map. This is done only at flush time otherwise
57+
// ++diagnostic.dumpIdx;
58+
59+
// assert(diagnostic.params.contains("flush_every"));
60+
61+
// std::size_t flushEvery = diagnostic.param<std::size_t>("flush_every");
62+
63+
// if (flushEvery != Writer::flush_never and diagnostic.dumpIdx % flushEvery == 0)
64+
// {
65+
// fileData_.erase(diagnostic.quantity);
66+
// assert(fileData_.count(diagnostic.quantity) == 0);
67+
// }
68+
}
69+
//------------------------------------------------------------------------
70+
71+
72+
protected:
73+
template<typename InitPatch>
74+
void initDataSets_(std::unordered_map<std::size_t, std::vector<std::string>> const& patchIDs,
75+
Attributes& patchAttributes, std::size_t maxLevel, InitPatch&& initPatch)
76+
{
77+
// for (std::size_t lvl = h5Writer_.minLevel; lvl <= maxLevel; lvl++)
78+
// {
79+
// auto& lvlPatches = patchIDs.at(lvl);
80+
// std::size_t patchNbr = lvlPatches.size();
81+
// std::size_t maxPatches = core::mpi::max(patchNbr);
82+
// for (std::size_t i = 0; i < patchNbr; ++i)
83+
// initPatch(lvl, patchAttributes[std::to_string(lvl) + "_" + lvlPatches[i]],
84+
// lvlPatches[i]);
85+
// for (std::size_t i = patchNbr; i < maxPatches; i++)
86+
// initPatch(lvl, patchAttributes);
87+
// }
88+
}
89+
90+
void writeAttributes_(
91+
DiagnosticProperties& diagnostic, HighFiveFile& file, Attributes& fileAttributes,
92+
std::unordered_map<std::size_t, std::vector<std::pair<std::string, Attributes>>>&
93+
patchAttributes,
94+
std::size_t maxLevel, Attributes defaultPatchAttributes = {})
95+
{
96+
// for (std::size_t lvl = h5Writer_.minLevel; lvl <= maxLevel; lvl++)
97+
// {
98+
// auto& lvlPatches = patchAttributes.at(lvl);
99+
// std::size_t patchNbr = lvlPatches.size();
100+
// std::size_t maxPatches = core::mpi::max(patchNbr);
101+
// for (auto const& [patch, attr] : lvlPatches)
102+
// h5Writer_.writeAttributeDict(file, attr,
103+
// h5Writer_.getPatchPathAddTimestamp(lvl, patch));
104+
// for (std::size_t i = patchNbr; i < maxPatches; i++)
105+
// h5Writer_.writeAttributeDict(
106+
// file, h5Writer_.modelView().getEmptyPatchProperties(defaultPatchAttributes),
107+
// "");
108+
// }
109+
110+
// if (diagnostic.nAttributes > 0)
111+
// h5Writer_.writeAttributeDict(file, diagnostic.fileAttributes, "/py_attrs");
112+
113+
// h5Writer_.writeGlobalAttributeDict(file, fileAttributes, "/");
114+
}
115+
116+
template<typename ParticlePopulation>
117+
void writeIonPopAttributes_(HighFiveFile& file, ParticlePopulation const& pop)
118+
{
119+
// auto& h5Writer = this->h5Writer_;
120+
121+
// Attributes popAttributes;
122+
// popAttributes["pop_mass"] = pop.mass();
123+
// h5Writer.writeGlobalAttributeDict(file, popAttributes, "/");
124+
}
125+
126+
void writeGhostsAttr_(HighFiveFile& file, std::string path, std::size_t ghosts, bool null)
127+
{
128+
// Attributes dsAttr;
129+
// dsAttr["ghosts"] = ghosts;
130+
// h5Writer_.writeAttributeDict(file, dsAttr, null ? "" : path);
131+
}
132+
133+
template<typename FileMap, typename... Quantities>
134+
void checkCreateFileFor_(DiagnosticProperties const& diagnostic, FileMap& fileData,
135+
std::string const tree, Quantities const... vars)
136+
{
137+
core::apply(std::forward_as_tuple(vars...), [&](auto const& var) {
138+
if (diagnostic.quantity == tree + var and !fileData.count(diagnostic.quantity))
139+
fileData.emplace(diagnostic.quantity, this->h5Writer_.makeFile(diagnostic));
140+
});
141+
}
142+
143+
144+
auto& h5FileForQuantity(DiagnosticProperties& diagnostic)
145+
{
146+
if (!fileData_.count(diagnostic.quantity))
147+
throw std::runtime_error("Unknown Diagnostic Quantity: " + diagnostic.quantity);
148+
149+
return *fileData_.at(diagnostic.quantity);
150+
}
151+
152+
153+
Writer& h5Writer_;
154+
std::unordered_map<std::string, std::unique_ptr<HighFiveFile>> fileData_;
155+
};
156+
157+
} // namespace PHARE::diagnostic::vtkh5
158+
159+
#endif // PHARE_DIAGNOSTIC_DETAIL_VTK_H5_TYPE_WRITER_HPP

0 commit comments

Comments
 (0)