Skip to content

Commit 60e1f13

Browse files
committed
++
1 parent 1be5b34 commit 60e1f13

File tree

8 files changed

+150
-269
lines changed

8 files changed

+150
-269
lines changed

pyphare/pyphare/pharesee/hierarchy/hierarchy_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def overlap_mask_2d(x, y, dl, level, qty):
298298
return is_overlaped
299299

300300

301-
def flat_finest_field(hierarchy, qty, time=None):
301+
def flat_finest_field(hierarchy, qty, time=None, neghosts=1):
302302
"""
303303
returns 2 flattened arrays containing the data (with shape [Npoints])
304304
and the coordinates (with shape [Npoints, Ndim]) for the given
@@ -311,7 +311,7 @@ def flat_finest_field(hierarchy, qty, time=None):
311311
dim = hierarchy.ndim
312312

313313
if dim == 1:
314-
return flat_finest_field_1d(hierarchy, qty, time)
314+
return flat_finest_field_1d(hierarchy, qty, time, neghosts)
315315
elif dim == 2:
316316
return flat_finest_field_2d(hierarchy, qty, time)
317317
elif dim == 3:
@@ -321,7 +321,7 @@ def flat_finest_field(hierarchy, qty, time=None):
321321
raise ValueError("the dim of a hierarchy should be 1, 2 or 3")
322322

323323

324-
def flat_finest_field_1d(hierarchy, qty, time=None):
324+
def flat_finest_field_1d(hierarchy, qty, time=None, neghosts=1):
325325
lvl = hierarchy.levels(time)
326326

327327
for ilvl in range(hierarchy.finest_level(time) + 1)[::-1]:
@@ -333,7 +333,7 @@ def flat_finest_field_1d(hierarchy, qty, time=None):
333333
# all but 1 ghost nodes are removed in order to limit
334334
# the overlapping, but to keep enough point to avoid
335335
# any extrapolation for the interpolator
336-
needed_points = pdata.ghosts_nbr - 1
336+
needed_points = pdata.ghosts_nbr - neghosts
337337

338338
# data = pdata.dataset[patch.box] # TODO : once PR 551 will be merged...
339339
data = pdata.dataset[needed_points[0] : -needed_points[0]]

pyphare/pyphare/pharesee/particles.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,9 @@ def single_patch_per_level_per_pop_from(hier, only_keep_L0=True): # dragons
292292
particles[key] = []
293293

294294
for patch in patch_level.patches:
295-
for patch_data_key in patch.patch_datas.keys():
296-
particles[key] += [patch[patch_data_key].dataset]
295+
for key in patch.patch_datas.keys():
296+
if key in particles:
297+
particles[key] += [patch[key].dataset]
297298

298299
for key in particles.keys():
299300
if particles[key]:

src/amr/data/field/initializers/samrai_hdf5_field_initializer.hpp

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ void SamraiHDF5FieldInitializer<Field_t, GridLayout>::load(Field_t& field,
4646
GridLayout const& layout) const
4747
{
4848
bool static constexpr c_ordering = false;
49-
// using Viewer = core::NdArrayViewer<Field_t::dimension>;
5049

5150
auto const local_cell = [&](auto const& box, auto const& point) {
5251
core::Point<std::uint32_t, dimension> localPoint;
@@ -56,33 +55,16 @@ void SamraiHDF5FieldInitializer<Field_t, GridLayout>::load(Field_t& field,
5655
return localPoint;
5756
};
5857

59-
// PHARE_LOG_LINE_STR("SamraiHDF5FieldInitializer::load");
60-
58+
auto const& dest_box = layout.AMRBox();
6159
auto const& centering = layout.centering(field.physicalQuantity());
62-
auto const& dest_box = layout.AMRBox(); // grow(layout.AMRBox(), GridLayout::nbrGhosts());
6360
auto const& overlaps = SamraiH5Interface<GridLayout>::INSTANCE().box_intersections(dest_box);
64-
65-
// PHARE_LOG_LINE_STR(layout.AMRBox());
66-
for (auto const& [h5FilePtr, pdataptr] : overlaps)
61+
for (auto const& [overlap_box, h5FilePtr, pdataptr] : overlaps)
6762
{
68-
auto& h5File = *h5FilePtr;
69-
auto& pdata = *pdataptr;
70-
// PHARE_LOG_LINE_STR(pdata.box);
71-
72-
auto const src_box = [&]() {
73-
auto copy = pdata.box;
74-
// for (std::size_t i = 0; i < Field_t::dimension; ++i)
75-
// copy.upper[i] += centering[i] == core::QtyCentering::primal ? 1 : 0;
76-
return copy;
77-
}();
78-
79-
std::vector<double> data;
80-
std::string const fieldpath
81-
= pdata.base_path + "/" + field.name() + "##default/field_" + field.name();
82-
h5File.file().getDataSet(fieldpath).read(data);
83-
84-
// PHARE_LOG_LINE_STR(data.size());
85-
63+
auto& h5File = *h5FilePtr;
64+
auto& pdata = *pdataptr;
65+
auto const src_box = pdata.box;
66+
auto const data = h5File.template read_data_set_flat<double>(
67+
pdata.base_path + "/" + field.name() + "##default/field_" + field.name());
8668
core::Box<std::uint32_t, GridLayout::dimension> const lcl_src_box{
8769
core::Point{core::ConstArray<std::uint32_t, GridLayout::dimension>()},
8870
core::Point{
@@ -91,45 +73,9 @@ void SamraiHDF5FieldInitializer<Field_t, GridLayout>::load(Field_t& field,
9173
src_box.upper[i] - src_box.lower[i] + (GridLayout::nbrGhosts() * 2)
9274
+ (centering[i] == core::QtyCentering::primal ? 1 : 0));
9375
})}};
94-
95-
// PHARE_LOG_LINE_STR(lcl_src_box.size());
96-
97-
assert(data.size() == lcl_src_box.size());
98-
9976
auto data_view = core::make_array_view<c_ordering>(data.data(), *lcl_src_box.shape());
100-
auto dst_iter = dest_box.begin();
101-
auto src_iter = src_box.begin();
102-
for (; src_iter != src_box.end(); ++src_iter)
103-
{
104-
// for (auto const& el : **src_iter)
105-
// if (el < 0)
106-
// continue;
107-
// if (core::any(*src_iter, [](auto const& el) { el < 0; }))
108-
// continue; // skip ghosts
109-
110-
if (isIn(core::Point{*src_iter}, dest_box))
111-
{
112-
while (*dst_iter != *src_iter and dst_iter != dest_box.end())
113-
++dst_iter;
114-
115-
if (dst_iter == dest_box.end() or not isIn(core::Point{*dst_iter}, dest_box))
116-
break;
117-
118-
// auto src_idx = Viewer::idx(lcl_src_box.shape(), *src_iter);
119-
// auto dst_idx = Viewer::idx(dest_box.shape(), *dst_iter);
120-
121-
// PHARE_LOG_LINE_STR(src_idx);
122-
// PHARE_LOG_LINE_STR(dst_idx);
123-
124-
field(local_cell(dest_box, *dst_iter)) = data_view(local_cell(src_box, *src_iter));
125-
126-
// PHARE_LOG_LINE_STR(*src_iter);
127-
// PHARE_LOG_LINE_STR(*dst_iter);
128-
129-
// PHARE_LOG_LINE_STR(field(local_cell(dest_box, *dst_iter)));
130-
// PHARE_LOG_LINE_STR(data_view(local_cell(src_box, *src_iter)));
131-
}
132-
}
77+
for (auto const& point : overlap_box)
78+
field(local_cell(dest_box, point)) = data_view(local_cell(src_box, point));
13379
}
13480
}
13581

@@ -138,4 +84,5 @@ void SamraiHDF5FieldInitializer<Field_t, GridLayout>::load(Field_t& field,
13884
} // namespace PHARE::amr
13985

14086

87+
14188
#endif

src/amr/data/initializers/samrai_hdf5_initializer.hpp

Lines changed: 24 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include "core/logger.hpp"
1818

1919
#include "hdf5/detail/h5/h5_file.hpp"
20+
21+
#include "SAMRAI/tbox/HDFDatabase.h"
22+
2023
#include "amr/utilities/box/amr_box.hpp"
2124

2225
#include "SAMRAI/hier/PatchDataRestartManager.h"
@@ -57,7 +60,8 @@ class SamraiH5Interface
5760
return i;
5861
}
5962

60-
void populate_from(std::string const& dir, int const& idx, int const& mpi_size);
63+
void populate_from(std::string const& dir, int const& idx, int const& mpi_size,
64+
std::string const& field_name = "field_EM_B_x");
6165

6266
NO_DISCARD auto static getRestartFileFullPath(std::string path, int const& idx,
6367
int const& mpi_size, int const& rank)
@@ -70,13 +74,13 @@ class SamraiH5Interface
7074

7175
auto box_intersections(Box_t const& box)
7276
{
73-
using Pair = std::pair<SamraiHDF5File const* const,
77+
using Tup = std::tuple<Box_t, SamraiHDF5File const* const,
7478
SamraiH5PatchDataInfo<GridLayout::dimension> const* const>;
75-
std::vector<Pair> overlaps;
79+
std::vector<Tup> overlaps;
7680
for (auto const& h5File : restart_files)
7781
for (auto const& patch : h5File->patches)
7882
if (auto const intersection = box * patch.box)
79-
overlaps.emplace_back(h5File.get(), &patch);
83+
overlaps.emplace_back(*intersection, h5File.get(), &patch);
8084
return overlaps;
8185
}
8286

@@ -88,26 +92,6 @@ class SamraiH5Interface
8892
};
8993

9094

91-
// struct BoxData
92-
// {
93-
// int dim;
94-
// std::array<int, 3> lo;
95-
// std::array<int, 3> hi;
96-
// };
97-
98-
typedef struct
99-
{
100-
int dim;
101-
std::array<int, 3> lo;
102-
std::array<int, 3> hi;
103-
} BoxData;
104-
105-
HighFive::CompoundType static box_compound_type()
106-
{
107-
return {{"dim", HighFive::create_datatype<int>()},
108-
{"lo", HighFive::create_datatype<std::array<int, 3>>()},
109-
{"hi", HighFive::create_datatype<std::array<int, 3>>()}};
110-
}
11195

11296
template<typename GridLayout>
11397
struct SamraiH5Interface<GridLayout>::SamraiHDF5File : public hdf5::h5::HighFiveFile
@@ -116,83 +100,43 @@ struct SamraiH5Interface<GridLayout>::SamraiHDF5File : public hdf5::h5::HighFive
116100

117101
SamraiHDF5File(std::string const& filepath)
118102
: Super{filepath, HighFive::File::ReadOnly, /*para=*/false}
103+
, filepath_{filepath}
119104
{
120-
// auto box_type = box_compound_type();
121-
// box_type.commit(file(), "d_box");
122-
123-
// getBoxFromPath("/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/"
124-
// "EM_B_y##default/d_box");
125105
}
126106

127-
128-
129-
/*
130-
DATASET "d_box" {
131-
DATATYPE H5T_COMPOUND {
132-
H5T_STD_I32BE "dim";
133-
H5T_ARRAY { [3] H5T_STD_I32BE } "lo";
134-
H5T_ARRAY { [3] H5T_STD_I32BE } "hi";
135-
}
136-
DATASPACE SIMPLE { ( 1 ) / ( 1 ) }
137-
DATA {
138-
(0): {
139-
1,
140-
[ 0, 0, 0 ],
141-
[ 199, 0, 0 ]
142-
}
143-
}
144-
ATTRIBUTE "Type" {
145-
DATATYPE H5T_STD_I8BE
146-
DATASPACE SCALAR
147-
DATA {
148-
(0): 2
149-
}
150-
}
151-
}
152-
*/
153-
154107
auto getBoxFromPath(std::string const& path) const
155108
{
156-
// auto const& data = Super::read_data_set<int>(path);
157-
PHARE_LOG_LINE_STR(path);
158-
std::vector<BoxData> data;
159-
Super::file().getDataSet(path).read(data);
160-
assert(data.size() == 1);
161-
162-
// return Box_t{core::as_sized_array<GridLayout::dimension>(data[1], data[2], data[3]),
163-
// core::as_sized_array<GridLayout::dimension>(data[4], data[5], data[6])};
164-
165-
// return Box_t{core::as_sized_array<GridLayout::dimension>(bx.lo0, bx.lo1, bx.lo2),
166-
// core::as_sized_array<GridLayout::dimension>(bx.hi0, bx.hi1, bx.hi2)};
167-
168-
return Box_t{core::sized_array<GridLayout::dimension>(data[0].lo),
169-
core::sized_array<GridLayout::dimension>(data[0].hi)};
109+
std::size_t constexpr samrai_dim = 3; // always 3!
110+
auto constexpr _to_std_array = [](auto& i) {
111+
return core::sized_array<GridLayout::dimension>(
112+
*reinterpret_cast<std::array<int, samrai_dim> const*>(&i));
113+
};
114+
115+
SAMRAI::tbox::HDFDatabase db{"db"};
116+
db.open(filepath_);
117+
auto const boxes = db.getDatabaseBoxVector(path);
118+
return Box_t{_to_std_array(boxes[0].d_data.d_lo), _to_std_array(boxes[0].d_data.d_hi)};
170119
}
171120

121+
std::string const filepath_;
172122
std::vector<SamraiH5PatchDataInfo<GridLayout::dimension>> patches;
173123
};
174124

175125

176126

177127
template<typename GridLayout>
178128
void SamraiH5Interface<GridLayout>::populate_from(std::string const& dir, int const& idx,
179-
int const& mpi_size)
129+
int const& mpi_size,
130+
std::string const& field_name)
180131
{
181-
auto upstr = core::get_env("PHARE_RESTART_BUP", "199");
182-
int up = 199;
183-
std::stringstream ss{upstr};
184-
ss >> up;
185-
186-
187-
Box_t const mock{{0}, {up}};
188132
for (int rank = 0; rank < mpi_size; ++rank)
189133
{
190134
auto const hdf5_filepath = getRestartFileFullPath(dir, idx, mpi_size, rank);
191135
auto& h5File = *restart_files.emplace_back(std::make_unique<SamraiHDF5File>(hdf5_filepath));
192-
for (auto const& group : h5File.scan_for_groups({"level_0000", "field_EM_B_x"}))
136+
for (auto const& group : h5File.scan_for_groups({"level_0000", field_name}))
193137
{
194138
auto const em_path = group.substr(0, group.rfind("/"));
195-
h5File.patches.emplace_back(/*h5File.getBoxFromPath(em_path + "/d_box")*/ mock,
139+
h5File.patches.emplace_back(h5File.getBoxFromPath(em_path + "/d_box"),
196140
em_path.substr(0, em_path.rfind("/")));
197141
}
198142
}
@@ -202,6 +146,5 @@ void SamraiH5Interface<GridLayout>::populate_from(std::string const& dir, int co
202146

203147
} // namespace PHARE::amr
204148

205-
HIGHFIVE_REGISTER_TYPE(PHARE::amr::BoxData, PHARE::amr::box_compound_type)
206149

207150
#endif

src/amr/data/particles/initializers/samrai_hdf5_particle_initializer.hpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,10 @@ void SamraiHDF5ParticleInitializer<ParticleArray, GridLayout>::loadParticles(
5252
ParticleArray& particles, GridLayout const& layout, std::string const& popname) const
5353
{
5454
using Packer = core::ParticlePacker<ParticleArray::dimension>;
55-
PHARE_LOG_LINE_STR("SamraiHDF5ParticleInitializer::loadParticles");
56-
PHARE_LOG_LINE_SS(popname << " " << layout.AMRBox());
5755

58-
auto const& dest_box = layout.AMRBox();
59-
60-
auto const& overlaps = SamraiH5Interface<GridLayout>::INSTANCE().box_intersections(dest_box);
61-
for (auto const& [h5FilePtr, pdataptr] : overlaps)
56+
auto const& overlaps
57+
= SamraiH5Interface<GridLayout>::INSTANCE().box_intersections(layout.AMRBox());
58+
for (auto const& [overlap_box, h5FilePtr, pdataptr] : overlaps)
6259
{
6360
auto& h5File = *h5FilePtr;
6461
auto& pdata = *pdataptr;
@@ -69,19 +66,13 @@ void SamraiHDF5ParticleInitializer<ParticleArray, GridLayout>::loadParticles(
6966
std::size_t part_idx = 0;
7067
core::apply(soa.as_tuple(), [&](auto& arg) {
7168
auto const datapath = poppath + Packer::keys()[part_idx++];
72-
PHARE_LOG_LINE_STR("SamraiHDF5ParticleInitializer::loadParticles");
73-
PHARE_LOG_LINE_STR(datapath);
7469
h5File.file().getDataSet(datapath).read(arg);
75-
PHARE_LOG_LINE_STR("SamraiHDF5ParticleInitializer::loadParticles");
7670
});
7771
}
7872

7973
for (std::size_t i = 0; i < soa.size(); ++i)
80-
if (auto const p = soa.copy(i); core::isIn(core::Point{p.iCell}, dest_box))
74+
if (auto const p = soa.copy(i); core::isIn(core::Point{p.iCell}, overlap_box))
8175
particles.push_back(p);
82-
83-
PHARE_LOG_LINE_STR("SamraiHDF5ParticleInitializer::loadParticles");
84-
PHARE_LOG_LINE_STR(particles.size());
8576
}
8677
}
8778

tests/simulator/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ add_no_mpi_python3_test(periodicity test_init_periodicity.py ${CMAKE_CURRENT_BIN
1414

1515
if(HighFive)
1616
## These test use dump diagnostics so require HighFive!
17-
phare_python3_exec(9 diagnostics test_diagnostics.py ${CMAKE_CURRENT_BINARY_DIR}) # serial or n = 2
18-
phare_python3_exec(9 restarts test_restarts.py ${CMAKE_CURRENT_BINARY_DIR}) # serial or n = 2
19-
phare_python3_exec(9 run test_run.py ${CMAKE_CURRENT_BINARY_DIR}) # serial or n = 2
17+
phare_python3_exec(9 diagnostics test_diagnostics.py ${CMAKE_CURRENT_BINARY_DIR}) # serial or n = 2
18+
phare_python3_exec(9 restarts test_restarts.py ${CMAKE_CURRENT_BINARY_DIR}) # serial or n = 2
19+
phare_python3_exec(9 run test_run.py ${CMAKE_CURRENT_BINARY_DIR}) # serial or n = 2
20+
phare_python3_exec(9 initing test_init_from_restart.py ${CMAKE_CURRENT_BINARY_DIR}) # serial or n = 2
2021
# phare_python3_exec(9 tagging test_tagging.py ${CMAKE_CURRENT_BINARY_DIR}) # serial or n = 2
2122

2223
if(testMPI)

0 commit comments

Comments
 (0)