Skip to content

Commit d96f39e

Browse files
committed
++
1 parent 7769929 commit d96f39e

File tree

5 files changed

+35
-24
lines changed

5 files changed

+35
-24
lines changed

src/amr/data/particles/particles_data.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,8 @@ namespace amr
161161
particles.sortMapping();
162162

163163
Packer{particles}.pack_ranges_into(
164-
[&](auto&&... args) {
165-
auto&& [arr, _] = std::forward_as_tuple(args...);
166-
core::double_apply(arr(), [&](auto const& key, auto const& arg, auto...) {
164+
[&](auto const& arr, auto const...) {
165+
core::double_apply(arr(), [&](auto const& key, auto const& arg) {
167166
restart_db->putVector(name + "_" + key, arg);
168167
});
169168
},
@@ -202,7 +201,7 @@ namespace amr
202201
= restart_db->getArraySize(name + "_" + Packer::arbitrarySingleValueKey());
203202
core::ContiguousParticles<dim> soa{n_particles};
204203

205-
core::double_apply(soa(), [&](auto const& key, auto& arg, auto...) {
204+
core::double_apply(soa(), [&](auto const& key, auto& arg) {
206205
restart_db->getVector(name + "_" + key, arg);
207206
});
208207

src/core/data/particles/particle_array.hpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -342,25 +342,32 @@ namespace core
342342

343343

344344
template<typename T>
345-
using tuple_element = std::tuple<std::string, container_t<T>&, std::size_t>;
345+
using tuple_element_t = std::tuple<std::string, container_t<T>&>;
346346

347-
auto static _as_named_tuple(auto&& self)
347+
auto operator()()
348348
{
349-
return std::make_tuple(tuple_element<double>("weight", self.weight, 1),
350-
tuple_element<double>("charge", self.charge, 1),
351-
tuple_element<int>("iCell", self.iCell, dim),
352-
tuple_element<double>("delta", self.delta, dim),
353-
tuple_element<double>("v", self.v, 3));
349+
return std::make_tuple(
350+
tuple_element_t<double>("weight", weight),
351+
tuple_element_t<double>("charge", charge), tuple_element_t<int>("iCell", iCell),
352+
tuple_element_t<double>("delta", delta), tuple_element_t<double>("v", v));
354353
}
355354

356-
auto operator()() { return _as_named_tuple(*this); }
357-
auto operator()() const { return _as_named_tuple(*this); }
355+
template<typename T>
356+
using tuple_element_ct = std::tuple<std::string, container_t<T> const&>;
357+
358+
auto operator()() const
359+
{
360+
return std::make_tuple(
361+
tuple_element_ct<double>("weight", weight),
362+
tuple_element_ct<double>("charge", charge), tuple_element_ct<int>("iCell", iCell),
363+
tuple_element_ct<double>("delta", delta), tuple_element_ct<double>("v", v));
364+
}
358365

359366

360367
void clear()
361368
{
362369
if constexpr (OwnedState)
363-
core::double_apply((*this)(), [](auto& key, auto& vec, auto _) { vec.clear(); });
370+
core::double_apply((*this)(), [](auto& key, auto& vec) { vec.clear(); });
364371
}
365372

366373
void push_back(auto const& particle)

src/core/data/particles/particle_packer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ParticlePacker
2323
{
2424
}
2525

26-
NO_DISCARD static auto get(Particle<dim> const& particle)
26+
NO_DISCARD static constexpr auto get(Particle<dim> const& particle)
2727
{
2828
return std::forward_as_tuple(particle.weight, particle.charge, particle.iCell,
2929
particle.delta, particle.v);

src/hdf5/writer/particle_writer.hpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,23 @@ class ParticleWriter
1818
template<typename H5File, typename Particles>
1919
static void write(H5File& h5file, Particles const& particles, std::string const& path)
2020
{
21-
auto constexpr dim = Particles::dimension;
22-
using Packer = core::ParticlePacker<dim>;
21+
constexpr auto dim = Particles::dimension;
22+
using Packer = core::ParticlePacker<dim>;
23+
constexpr auto particle_members = Packer::empty();
24+
static auto& keys = Packer::keys();
2325

24-
Packer{particles}.pack_ranges_into([&](auto&&... args) {
25-
auto&& [arr, from] = std::forward_as_tuple(args...);
2626

27-
core::double_apply(arr(), [&](auto const& key, auto const& arg, auto size) {
27+
Packer{particles}.pack_ranges_into([&](auto const& arr, auto const from) {
28+
auto const soa_members = arr();
29+
30+
core::for_N<Packer::n_keys>([&](auto ki) {
31+
auto const [key, member] = std::get<ki>(soa_members);
32+
auto const actual = std::get<ki>(particle_members);
33+
2834
h5file.file()
29-
.getDataSet(path + key)
30-
.select({from, 0ul}, {arr.size(), size})
31-
.write_raw(arg.data());
35+
.getDataSet(path + keys[ki])
36+
.select({from, 0ul}, size_for<dim>(actual, arr.size()))
37+
.write_raw(member.data());
3238
});
3339
});
3440
}

tests/core/data/particles/test_interop.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ TYPED_TEST(ParticleListTest, SoAandAoSInterop)
5656
EXPECT_EQ(contiguous.size(), particleArray.size());
5757

5858
ContiguousParticles<dim> AoSFromSoA{particleArray.size()};
59-
AoSFromSoA.clear();
6059
EXPECT_EQ(AoSFromSoA.size(), 0);
6160
ParticlePacker<dim>{particleArray}.pack(AoSFromSoA);
6261
EXPECT_EQ(AoSFromSoA.size(), size);

0 commit comments

Comments
 (0)