Skip to content

Commit 3987397

Browse files
committed
++
1 parent 89d2ec8 commit 3987397

File tree

12 files changed

+387
-210
lines changed

12 files changed

+387
-210
lines changed

pyphare/pyphare/pharesee/tovtk.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ def ndim_from(npx, npy, npz):
1515
return 2
1616
elif npx > 2 and npy == 2 and npz == 2:
1717
return 1
18-
else:
19-
raise ValueError(
20-
f" cannot infer dimension from (npx, npy, npz) = {npx} {npy} {npz}"
21-
)
18+
raise ValueError(
19+
f" cannot infer dimension from (npx, npy, npz) = {npx} {npy} {npz}"
20+
)
2221

2322

2423
def BtoFlatPrimal(ph_bx, ph_by, ph_bz, npx, npy, npz, gn=2):
25-
2624
nbrPoints = npx * npy * npz
2725
b = np.zeros((nbrPoints, 3), dtype="f")
2826

@@ -114,7 +112,6 @@ def BtoFlatPrimal(ph_bx, ph_by, ph_bz, npx, npy, npz, gn=2):
114112

115113

116114
def EtoFlatPrimal(ph_ex, ph_ey, ph_ez, npx, npy, npz, gn=2):
117-
118115
nbrPoints = npx * npy * npz
119116
e = np.zeros((nbrPoints, 3), dtype="f")
120117

@@ -168,7 +165,6 @@ def EtoFlatPrimal(ph_ex, ph_ey, ph_ez, npx, npy, npz, gn=2):
168165

169166

170167
def primalScalarToFlatPrimal(ph_scalar, npx, npy, npz, gn=2):
171-
172168
scalar3d = np.zeros((npx, npy, npz), dtype="f")
173169
if ndim_from(npx, npy, npz) == 2:
174170
domain = slice(gn, -gn)
@@ -272,7 +268,6 @@ def make3d(root_spacing):
272268

273269

274270
def main():
275-
276271
if len(sys.argv) != 2 or sys.argv[1] in ["-h", "--help"]:
277272
print(f"Usage: {os.path.basename(sys.argv[0])} <path_to_phare_h5>")
278273
print("Works for EM fields, bulk velocity and density")
@@ -316,7 +311,6 @@ def main():
316311
steps.create_dataset("Values", data=times[:numberOfTimes])
317312

318313
for ilvl in range(max_nbr_level)[:]:
319-
320314
print(f"Processing level {ilvl}")
321315

322316
lvl = root.create_group(f"Level{ilvl}")

src/core/data/grid/gridlayout.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,10 @@ namespace core
897897
return GridLayoutImpl::centering(hybridQuantity);
898898
}
899899

900+
NO_DISCARD constexpr static auto centering(auto const& hasQuantity)
901+
{
902+
return centering(hasQuantity.physicalQuantity());
903+
}
900904

901905
/**
902906
* @brief GridLayout<GridLayoutImpl::dim>::allocSize

src/core/utilities/box/box.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct Box
9393
}
9494

9595
NO_DISCARD auto shape() const { return upper - lower + 1; }
96-
NO_DISCARD auto size() const { return core::product(shape()); }
96+
NO_DISCARD auto size() const { return core::product(shape(), std::size_t{1}); }
9797

9898

9999
using iterator = box_iterator<Type, dim>;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#ifndef PHARE_DIAGNOSTIC_DETAIL_VTK_TYPES_ELECTROMAG_HPP
2+
#define PHARE_DIAGNOSTIC_DETAIL_VTK_TYPES_ELECTROMAG_HPP
3+
4+
#include "diagnostic/detail/vtkh5_type_writer.hpp"
5+
6+
#include "core/data/vecfield/vecfield_component.hpp"
7+
8+
namespace PHARE::diagnostic::vtkh5
9+
{
10+
/*
11+
* Possible outputs
12+
*
13+
* /t#/pl#/p#/electromag_(B, E)/(x,y,z)
14+
*/
15+
template<typename H5Writer>
16+
class ElectromagDiagnosticWriter : public H5TypeWriter<H5Writer>
17+
{
18+
public:
19+
using Super = H5TypeWriter<H5Writer>;
20+
using Attributes = Super::Attributes;
21+
using GridLayout = H5Writer::GridLayout;
22+
using FloatType = H5Writer::FloatType;
23+
using Super::fileData_;
24+
using Super::h5Writer_;
25+
26+
ElectromagDiagnosticWriter(H5Writer& h5Writer)
27+
: Super{h5Writer}
28+
{
29+
}
30+
void write(DiagnosticProperties&) override;
31+
void compute(DiagnosticProperties&) override {}
32+
};
33+
34+
35+
template<typename H5Writer>
36+
void ElectromagDiagnosticWriter<H5Writer>::write(DiagnosticProperties& diagnostic)
37+
{
38+
}
39+
40+
41+
42+
43+
} // namespace PHARE::diagnostic::vtkh5
44+
45+
#endif /* PHARE_DIAGNOSTIC_DETAIL_TYPES_ELECTROMAG_H */
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#ifndef PHARE_DIAGNOSTIC_DETAIL_VTK_TYPES_FLUID_HPP
2+
#define PHARE_DIAGNOSTIC_DETAIL_VTK_TYPES_FLUID_HPP
3+
4+
#include "core/utilities/box/box.hpp"
5+
#include "diagnostic/detail/vtkh5_type_writer.hpp"
6+
#include "core/numerics/interpolator/interpolator.hpp"
7+
8+
#include "core/data/vecfield/vecfield_component.hpp"
9+
#include <string>
10+
11+
namespace PHARE::diagnostic::vtkh5
12+
{
13+
/*
14+
* It is assumed that each patch has equal number of populations
15+
*
16+
* Possible outputs
17+
*
18+
* /t#/pl#/p#/ions/density
19+
* /t#/pl#/p#/ions/bulkVelocity/(x,y,z)
20+
* /t#/pl#/p#/ions/pop_(1,2,...)/density
21+
* /t#/pl#/p#/ions/pop_(1,2,...)/bulkVelocity/(x,y,z)
22+
*/
23+
template<typename H5Writer>
24+
class FluidDiagnosticWriter : public H5TypeWriter<H5Writer>
25+
{
26+
public:
27+
using Super = H5TypeWriter<H5Writer>;
28+
using Attributes = Super::Attributes;
29+
using GridLayout = H5Writer::GridLayout;
30+
using FloatType = H5Writer::FloatType;
31+
using Super::fileData_;
32+
using Super::h5Writer_;
33+
34+
static constexpr auto dimension = GridLayout::dimension;
35+
static constexpr auto interp_order = GridLayout::interp_order;
36+
37+
38+
FluidDiagnosticWriter(H5Writer& h5Writer)
39+
: Super{h5Writer}
40+
{
41+
}
42+
void write(DiagnosticProperties&) override;
43+
void compute(DiagnosticProperties&) override;
44+
45+
46+
private:
47+
auto static isActiveDiag(DiagnosticProperties const& diagnostic, std::string const& tree,
48+
std::string const& var)
49+
{
50+
return diagnostic.quantity == tree + var;
51+
};
52+
};
53+
54+
55+
56+
template<typename H5Writer>
57+
void FluidDiagnosticWriter<H5Writer>::compute(DiagnosticProperties& diagnostic)
58+
{
59+
}
60+
61+
62+
template<typename H5Writer>
63+
void FluidDiagnosticWriter<H5Writer>::write(DiagnosticProperties& diagnostic)
64+
{
65+
auto constexpr static box_dim = dimension * 2;
66+
std::string static base = "/VTKHDF/";
67+
std::string static level_base = base + "Level";
68+
std::string static step_level = base + "Steps/Level";
69+
70+
auto& h5Writer = this->h5Writer_;
71+
auto& modelView = h5Writer.modelView();
72+
auto& ions = modelView.getIons();
73+
auto const minLvl = this->h5Writer_.minLevel;
74+
auto const maxLvl = this->h5Writer_.maxLevel;
75+
std::vector<std::vector<int>> boxes(this->h5Writer_.maxLevel + 1);
76+
std::size_t item_offset = 0, data_offset = 0;
77+
78+
for (auto const& pop : ions)
79+
{
80+
std::string const tree{"/ions/pop/" + pop.name() + "/"};
81+
this->checkCreateFileFor_(diagnostic, fileData_, tree, "density", "charge_density", "flux",
82+
"momentum_tensor");
83+
}
84+
std::string const tree{"/ions/"};
85+
this->checkCreateFileFor_(diagnostic, fileData_, tree, "charge_density", "mass_density",
86+
"bulkVelocity", "momentum_tensor");
87+
auto& h5file = Super::h5FileForQuantity(diagnostic);
88+
89+
auto const initDS = [&]<typename T = FloatType>(auto const& path, auto const& ds) {
90+
h5file.template create_chunked_data_set<FloatType>( //
91+
path, std::vector<hsize_t>{2}, ds);
92+
};
93+
auto const initDSDefault = [&]<typename T = FloatType>(auto const& path) {
94+
initDS.template operator()<T>(path,
95+
HighFive::DataSpace({2}, {HighFive::DataSpace::UNLIMITED}));
96+
};
97+
auto const doLevel = [&](std::string const lvl) {
98+
initDSDefault(level_base + lvl + "/PointData/data");
99+
initDSDefault.template operator()<int>(level_base + lvl + "/AMRBox");
100+
initDSDefault(step_level + lvl + "/AMRBoxOffset");
101+
initDSDefault(step_level + lvl + "/NumberOfAMRBox");
102+
initDSDefault(base + "/Steps/Values");
103+
};
104+
105+
auto const setup = [&](auto& layout, auto const& patchID, auto const iLevel) {
106+
doLevel(std::to_string(iLevel));
107+
for (std::size_t i = 0; i < dimension; ++i)
108+
boxes[iLevel].emplace_back(layout.AMRBox().lower[i]);
109+
for (std::size_t i = 0; i < dimension; ++i)
110+
boxes[iLevel].emplace_back(layout.AMRBox().upper[i]);
111+
};
112+
modelView.visitHierarchy(setup, minLvl, maxLvl);
113+
114+
auto const writeDS = [&](auto const& path, auto& field, auto const& layout) {
115+
auto const ilvl = layout.levelNumber();
116+
auto const lvl = std::to_string(ilvl);
117+
auto const primal_box = core::grow(layout.AMRGhostBoxFor(field), -1 * layout.nbrGhosts());
118+
{ // data
119+
auto ds = h5file.getDataSet(level_base + lvl + "/PointData/data");
120+
auto const new_size = data_offset + primal_box.size();
121+
ds.resize({new_size});
122+
// write physical rows
123+
ds.select({data_offset}, {primal_box.size()})
124+
.write_raw(field.data() + layout.nbrGhosts());
125+
data_offset += new_size;
126+
}
127+
{ // boxes
128+
auto ds = h5file.getDataSet(level_base + lvl + "/AMRBox");
129+
ds.resize({item_offset + boxes[ilvl].size()});
130+
ds.select({item_offset}, {boxes[ilvl].size()}).write_raw(boxes[ilvl].data());
131+
item_offset += boxes[ilvl].size();
132+
}
133+
};
134+
auto const write = [&](auto& layout, auto const& patchID, auto const iLevel) {
135+
if (isActiveDiag(diagnostic, tree, "charge_density"))
136+
writeDS("charge_density", ions.chargeDensity(), layout);
137+
};
138+
139+
modelView.visitHierarchy(write, minLvl, maxLvl);
140+
}
141+
142+
143+
144+
} // namespace PHARE::diagnostic::vtkh5
145+
146+
#endif /* PHARE_DIAGNOSTIC_DETAIL_VTK_TYPES_FLUID_H */
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef PHARE_DIAGNOSTIC_DETAIL_VTK_TYPES_INFO_HPP
2+
#define PHARE_DIAGNOSTIC_DETAIL_VTK_TYPES_INFO_HPP
3+
4+
#include "diagnostic/detail/vtkh5_type_writer.hpp"
5+
6+
7+
namespace PHARE::diagnostic::vtkh5
8+
{
9+
10+
11+
template<typename H5Writer>
12+
class InfoDiagnosticWriter : public H5TypeWriter<H5Writer>
13+
{
14+
public:
15+
using Super = H5TypeWriter<H5Writer>;
16+
using Attributes = Super::Attributes;
17+
using GridLayout = H5Writer::GridLayout;
18+
using FloatType = H5Writer::FloatType;
19+
using Super::fileData_;
20+
using Super::h5Writer_;
21+
22+
InfoDiagnosticWriter(H5Writer& h5Writer)
23+
: Super{h5Writer}
24+
{
25+
}
26+
27+
void write(DiagnosticProperties&) override;
28+
29+
void compute(DiagnosticProperties&) override {}
30+
};
31+
32+
33+
34+
template<typename H5Writer>
35+
void InfoDiagnosticWriter<H5Writer>::write(DiagnosticProperties& diagnostic)
36+
{
37+
}
38+
39+
40+
} // namespace PHARE::diagnostic::vtkh5
41+
42+
#endif /* PHARE_DIAGNOSTIC_DETAIL_TYPES_INFO_H */
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#ifndef PHARE_DIAGNOSTIC_DETAIL_VTK_TYPES_META_HPP
2+
#define PHARE_DIAGNOSTIC_DETAIL_VTK_TYPES_META_HPP
3+
4+
#include "diagnostic/detail/vtkh5_type_writer.hpp"
5+
6+
7+
namespace PHARE::diagnostic::vtkh5
8+
{
9+
/*
10+
* Possible outputs
11+
*
12+
* /t#/pl#/p#/tags
13+
*/
14+
template<typename H5Writer>
15+
class MetaDiagnosticWriter : public H5TypeWriter<H5Writer>
16+
{
17+
public:
18+
using Super = H5TypeWriter<H5Writer>;
19+
using Attributes = Super::Attributes;
20+
using GridLayout = H5Writer::GridLayout;
21+
using FloatType = H5Writer::FloatType;
22+
using Super::fileData_;
23+
using Super::h5Writer_;
24+
25+
MetaDiagnosticWriter(H5Writer& h5Writer)
26+
: Super{h5Writer}
27+
{
28+
}
29+
30+
void write(DiagnosticProperties&) override;
31+
32+
void compute(DiagnosticProperties&) override {}
33+
};
34+
35+
template<typename H5Writer>
36+
void MetaDiagnosticWriter<H5Writer>::write(DiagnosticProperties& diagnostic)
37+
{
38+
}
39+
40+
41+
42+
} // namespace PHARE::diagnostic::vtkh5
43+
44+
#endif /* PHARE_DIAGNOSTIC_DETAIL_TYPES_META_H */

0 commit comments

Comments
 (0)