17#ifndef PECLET_CORE_DECOMP_GRID_REDISTRIBUTE_HPP
18#define PECLET_CORE_DECOMP_GRID_REDISTRIBUTE_HPP
35 for (
int d = 0;
d <
Dim; ++
d) {
51 for (
int d = 0;
d <
Dim; ++
d) {
59 return size[0] * size[1] * size[2];
66 for (
Index z = 0; z < size[2]; ++z)
67 for (
Index y = 0; y < size[1]; ++y)
68 for (
Index x = 0; x < size[0]; ++x, ++n)
69 f(n,
IVec<3>{origin[0] + x, origin[1] + y, origin[2] + z});
84 int rank,
int g,
const std::vector<const T*>&
oldFields,
97 std::vector<Task>
sends;
98 for (std::size_t
d = 0;
d <
newDec.numBlocks(); ++
d) {
100 if (detail::intersectBox<3>(
ob,
newDec.block(
d),
o, s))
101 sends.push_back({
static_cast<int>(
d),
o, s});
105 for (
const auto&
t :
sends)
108 const Index si = detail::localFlat<3>(c, ob, g), di = detail::localFlat<3>(c, nbSelf, g);
109 for (int f = 0; f < nF; ++f)
110 newFields[f][di] = oldFields[f][si];
117 [&](std::vector<char>&
out) ->
int {
124 out.resize(
sizeof(
Index) * 6 +
sizeof(
T) * cells *
nF);
125 char* p =
out.data();
126 std::memcpy(p,
t.origin.data(),
sizeof(
Index) * 3);
127 std::memcpy(p +
sizeof(
Index) * 3,
t.size.data(),
sizeof(
Index) * 3);
128 T*
fp =
reinterpret_cast<T*
>(p +
sizeof(
Index) * 6);
130 const Index sidx = detail::localFlat<3>(c, ob, g);
131 for (int f = 0; f < nF; ++f)
132 fp[f * cells + n] = oldFields[f][sidx];
136 [&](
int, std::vector<char>&
msg) {
137 const char* p =
msg.data();
139 std::memcpy(
o.data(), p,
sizeof(
Index) * 3);
140 std::memcpy(s.data(), p +
sizeof(
Index) * 3,
sizeof(
Index) * 3);
142 const T*
fp =
reinterpret_cast<const T*
>(p +
sizeof(
Index) * 6);
145 for (
int f = 0;
f <
nF; ++
f)
Index boxCellCount(const IVec< 3 > &size)
Index localFlat(const IVec< Dim > &gcell, const Block< Dim > &blk, int g)
bool intersectBox(const Block< Dim > &a, const Block< Dim > &b, IVec< Dim > &origin, IVec< Dim > &size)
void forBox(const IVec< 3 > &origin, const IVec< 3 > &size, F &&f)
void redistributeGridFields(const BlockDecomposer< 3 > &oldDec, const BlockDecomposer< 3 > &newDec, int rank, int g, const std::vector< const T * > &oldFields, const std::vector< T * > &newFields, MPI_Comm comm)
Redistribute nFields grid fields from oldDec to newDec (this rank = rank).
Kokkos::View< T *, MemSpace > View
1D device array.
std::int64_t Index
Signed index type for grids and particles (supersedes block_decomposer's long int IndxT).
IVec< Dim > size
extent in cells along each axis
IVec< Dim > origin
inclusive lower corner in global cell coordinates