29#include "ParticleList.hpp"
38#include <boost/mpi/collectives/reduce.hpp>
39#include <boost/mpi/communicator.hpp>
51 double cutoff_regular,
double skin,
52 std::function<
bool()> get_ghost_flags,
55 std::set<int> n_square_types)
56 : m_comm(
std::move(comm)), m_box(box_geo), m_cutoff_regular(cutoff_regular),
58 m_comm, cutoff_regular + skin, m_box, local_box,
std::nullopt)),
60 m_n_square_types(
std::move(n_square_types)),
61 m_get_global_ghost_flags(
std::move(get_ghost_flags)) {
66 std::ranges::copy(local_cells_n_square, std::back_inserter(m_local_cells));
71 std::ranges::copy(ghost_cells_n_square, std::back_inserter(m_ghost_cells));
75 std::ranges::copy(ghost_cells_n_square, std::back_inserter(additional_reds));
76 for (
auto &local_cell : m_regular_decomposition.
local_cells()) {
77 std::vector<Cell *> red_neighbors(local_cell->m_neighbors.red().begin(),
78 local_cell->m_neighbors.red().end());
79 std::vector<Cell *> black_neighbors(local_cell->m_neighbors.black().begin(),
80 local_cell->m_neighbors.black().end());
81 std::ranges::copy(additional_reds, std::back_inserter(red_neighbors));
85 m_halo_plan = make_halo_plan();
103 c->m_is_boundary =
true;
105#ifdef ESPRESSO_ADDITIONAL_CHECKS
110 "HybridDecomposition"));
130 auto const *regular_plan = m_regular_decomposition.
halo_plan();
132 plan.
neighbors = regular_plan->neighbors;
133 plan.
local = regular_plan->local;
137 auto const *nsq_plan = m_n_square.
halo_plan();
138 if (nsq_plan && nsq_plan->collective) {
146 std::vector<ParticleChange> &diff) {
150 for (
auto &cell_rd : m_regular_decomposition.
local_cells()) {
151 for (
auto it = cell_rd->particles().begin();
152 it != cell_rd->particles().end();) {
154 if (not is_n_square_type(it->type())) {
160 auto p = std::move(*it);
161 it = cell_rd->particles().erase(it);
167 first_local_cell->particles().insert(std::move(p));
168 diff.emplace_back(
ModifiedList{first_local_cell->particles()});
173 for (
auto it = cell_ns->particles().begin();
174 it != cell_ns->particles().end();) {
176 if (is_n_square_type(it->type())) {
182 auto p = std::move(*it);
183 it = cell_ns->particles().erase(it);
190 if (target_cell !=
nullptr) {
191 target_cell->particles().insert(std::move(p));
192 diff.emplace_back(
ModifiedList{target_cell->particles()});
197 first_local_cell->particles().insert(std::move(p));
198 diff.emplace_back(
ModifiedList{first_local_cell->particles()});
205 m_regular_decomposition.
resort(global, diff);
206 m_n_square.
resort(global, diff);
216std::size_t HybridDecomposition::count_particles(
217 std::vector<Cell *>
const &local_cells)
const {
218 std::size_t count_local = 0;
219 std::size_t count_global = 0;
221 count_local += cell->particles().size();
223 boost::mpi::reduce(m_comm, count_local, count_global, std::plus<>{}, 0);
unsigned map_data_parts(unsigned data_parts)
Map the data parts flags from cells to those used internally by the ghost communication.
Asynchronous, split-phase ghost-communication engine.
Vector implementation and trait types for boost qvm interoperability.
Atom decomposition cell system.
GhostComm::HaloPlan const * halo_plan() const override
auto const & get_local_cells() const
auto const & get_ghost_cells() const
void resort(bool global_flag, std::vector< ParticleChange > &diff) override
std::span< Cell *const > local_cells() const override
std::span< Cell *const > local_cells() const override
Cell * particle_to_cell(Particle const &p) override
void resort(bool global, std::vector< ParticleChange > &diff) override
HybridDecomposition(boost::mpi::communicator comm, double cutoff_regular, double skin, std::function< bool()> get_ghost_flags, BoxGeometry const &box_geo, LocalBox const &local_box, std::set< int > n_square_types)
std::span< Cell *const > ghost_cells() const override
Ghost particles and particle exchange.
@ GHOSTTRANS_PARTNUM
resize the receiver particle arrays to the size of the senders
void mark_boundary_cells(std::span< Cell *const > local_cells, std::span< Cell *const > ghost_cells, std::function< bool(Cell const *, Cell const *)> wrap_predicate=nullptr)
Classify each local cell as interior or boundary.
bool report_violations(std::vector< std::string > const &violations, char const *context)
Print violations to stderr and return whether the list was empty.
void halo_exchange(HaloPlan const &plan, BoxGeometry const &box, unsigned data_parts, ExchangeOp op, ExchangeBuffers &bufs)
Blocking wrapper using a caller-owned buffer pool (no per-call alloc after warm-up).
std::vector< std::string > validate_halo_plan(HaloPlan const &plan, std::span< Cell *const > local_cells, std::span< Cell *const > ghost_cells)
Validate a HaloPlan for correctness.
std::optional< CollectiveSection > collective
boost::mpi::communicator comm
std::vector< NeighborComm > neighbors
std::vector< LocalComm > local
Regular decomposition cell system.
void resort(bool global, std::vector< ParticleChange > &diff) override
std::span< Cell *const > local_cells() const override
auto const & get_local_cells() const
GhostComm::HaloPlan const * halo_plan() const override
auto const & get_ghost_cells() const